Skip to content

Commit

Permalink
Target the second player some of the time.
Browse files Browse the repository at this point in the history
  • Loading branch information
dulsi committed Feb 2, 2023
1 parent 96d51dc commit ca167cc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion entities/Enemy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ function Enemy:init(enemyDef, speed, entityManager)
self.state = "trapped"

self.movedBy = 0
if (table.getn(entityManager.player) == 2 and love.math.random() > 0.5) then
self.target = 2
else
self.target = 1
end
end

function Enemy:moveTo(row, col)
Expand Down Expand Up @@ -183,8 +188,15 @@ function Enemy:update(dt)
self.hitbox.y1 = self.y + 2
self.hitbox.y2 = self.y + 14

if (table.getn(self.entityManager.player) == 2 and love.math.random() > 0.95) then
if self.target == 1 then
self.target = 2
else
self.target = 1
end
end
local ownRow, ownCol = getTileForPosition(self.x, self.y)
local playerRow, playerCol = getTileForPosition(self.entityManager.player[1].x, self.entityManager.player[1].y)
local playerRow, playerCol = getTileForPosition(self.entityManager.player[self.target].x, self.entityManager.player[self.target].y)

local row, col = self:getNextStep(ownRow, ownCol, playerRow, playerCol, self.entityManager.tilemap)
self:moveTo(row, col)
Expand Down

0 comments on commit ca167cc

Please sign in to comment.