diff --git a/Chat.lua b/Chat.lua index f503e73..6f4f06c 100644 --- a/Chat.lua +++ b/Chat.lua @@ -4,8 +4,9 @@ local lg = love.graphics function Chat(x, y, level) - local CHAT_SPEED = math.random(50) + (level * 2) + local CHAT_SPEED = math.random(30) + (level * 2) local vel = -1 + local life = 5 if math.random() < 0.5 then vel = 1 @@ -18,27 +19,27 @@ function Chat(x, y, level) x_vel = math.random() * CHAT_SPEED * vel, y_vel = math.random() * CHAT_SPEED * vel, radius = 30, + life = 5, draw = function(self) lg.draw(self.sprite, self.x, self.y, 0, 1, 1, self.sprite:getWidth() / 2, self.sprite:getHeight() / 2) lg.circle("line", self.x, self.y, self.radius) end, - move = function(self, dt) - self.x = self.x + self.x_vel * dt - self.y = self.y + self.y_vel * dt + move = function(self, player_x, player_y, dt) + -- direction is the vector from the enemy to the player + local direction_x = player_x - self.x + local direction_y = player_y - self.y + local distance = math.sqrt(direction_x * direction_x + direction_y * direction_y) - if self.x + self.radius < 0 then - self.x = love.graphics.getWidth() + self.radius - elseif self.x - self.radius > love.graphics.getWidth() then - self.x = -self.radius + if dist ~= 0 then -- avoid division by zero + self.x = self.x + direction_x / distance * CHAT_SPEED * dt + self.y = self.y + direction_y / distance * CHAT_SPEED * dt end + end, - if self.y + self.radius < 0 then - self.y = love.graphics.getHeight() + self.radius - elseif self.y - self.radius > love.graphics.getHeight() then - self.y = -self.radius - end + decreaseLife = function(self) + self.life = self.life - 1 end, destroy = function(self, chat_table, index) diff --git a/Game.lua b/Game.lua index ef357d9..16315a0 100644 --- a/Game.lua +++ b/Game.lua @@ -24,13 +24,11 @@ function Game() chats = {} - local chat_x = math.floor(math.random(love.graphics.getWidth() )) - local chat_y = math.floor(math.random(love.graphics.getHeight())) - - table.insert(chats, 1, Chat(chat_x, chat_y, self.level)) - table.insert(chats, 2, Chat(chat_x, chat_y, self.level)) - table.insert(chats, 3, Chat(chat_x, chat_y, self.level)) - table.insert(chats, 4, Chat(chat_x, chat_y, self.level)) + for i = 1, 1 do + local chat_x = math.floor(math.random(love.graphics.getWidth())) + local chat_y = math.floor(math.random(love.graphics.getHeight())) + table.insert(chats, i, Chat(chat_x, chat_y, self.level)) + end end } diff --git a/Player.lua b/Player.lua index e591078..3944934 100644 --- a/Player.lua +++ b/Player.lua @@ -39,7 +39,6 @@ function Player(debugging) end end, destroyBan = function (self, index) - print(self.ban, index) table.remove(self.bans, index) end, @@ -50,7 +49,6 @@ function Player(debugging) if love.keyboard.isDown('left') then self.angle = self.angle - self.rotation_speed * dt self.facing = self.angle - print(self.facing) end if love.keyboard.isDown('right') then self.angle = self.angle + self.rotation_speed * dt diff --git a/assets/f1065sk1.pdf b/assets/f1065sk1.pdf new file mode 100644 index 0000000..5d71f7d Binary files /dev/null and b/assets/f1065sk1.pdf differ diff --git a/main.lua b/main.lua index ec093b5..2652e2e 100644 --- a/main.lua +++ b/main.lua @@ -64,7 +64,7 @@ function love.update(dt) end end - chat:move(dt) + chat:move(player.x, player.y, dt) end elseif game.state.menu then