|
|
|
@ -13,8 +13,6 @@ function Enemy:new(x, y, radius, playableArea) |
|
|
|
|
|
|
|
self.x = x |
|
|
|
self.y = y |
|
|
|
self.width = self.image:getWidth() |
|
|
|
self.height = self.image:getHeight() |
|
|
|
self.playableLeft = playableArea[1] |
|
|
|
self.playableRight = playableArea[2] |
|
|
|
|
|
|
|
@ -26,6 +24,8 @@ function Enemy:new(x, y, radius, playableArea) |
|
|
|
self.destroy = false |
|
|
|
|
|
|
|
self.hitbox = { (self.x + 18), (self.x + 44), (self.y + 20), (self.y + 44) } |
|
|
|
self.move_bounds = self:setMoveBounds({ 18, 44 }, self.move_radius) |
|
|
|
print("Move Bounds: ", self.move_bounds[1], " , ", self.move_bounds[2]) |
|
|
|
enemyBullets = {} |
|
|
|
end |
|
|
|
|
|
|
|
@ -41,16 +41,19 @@ function Enemy:draw() |
|
|
|
end |
|
|
|
|
|
|
|
function Enemy:update(dt, player) |
|
|
|
local game_bounds = { self.origin[1] - self.move_radius, self.origin[1] + self.move_radius } |
|
|
|
-- if spawn location is near the edge, adjust the bounds such that the radius |
|
|
|
-- does not overlap the bounds of the playable area |
|
|
|
local window_height = love.graphics.getHeight() |
|
|
|
|
|
|
|
self.x = self.x + self.speed * dt |
|
|
|
|
|
|
|
self.hitbox = { (self.x + 18), (self.x + 44), (self.y + 20), (self.y + 44) } |
|
|
|
|
|
|
|
--movement |
|
|
|
if self.x > game_bounds[2] then |
|
|
|
if self.x < self.move_bounds[1] then |
|
|
|
print("Reversing direction! Hitbox Left Location: ", self.hitbox[1], " Play Bound Left: ", self.playableLeft) |
|
|
|
self.speed = -self.speed |
|
|
|
elseif self.x < game_bounds[1] then |
|
|
|
elseif self.x > self.move_bounds[2] then |
|
|
|
print("Reversing direction! Hitbox Right Location: ", self.hitbox[2], " Play Bound Right: ", self.playableRight) |
|
|
|
self.speed = -self.speed |
|
|
|
end |
|
|
|
|
|
|
|
@ -65,7 +68,7 @@ function Enemy:update(dt, player) |
|
|
|
end |
|
|
|
|
|
|
|
if v.destroy == true then |
|
|
|
print("Enemy Bullet Removed! Bullets in table remaining: ", #enemyBullets) |
|
|
|
--print("Enemy Bullet Removed! Bullets in table remaining: ", #enemyBullets) |
|
|
|
table.remove(enemyBullets, i) |
|
|
|
end |
|
|
|
|
|
|
|
@ -84,3 +87,19 @@ function Enemy:fire() |
|
|
|
fireTime = love.timer.getTime() |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
function Enemy:setMoveBounds(hitbox_bounds, move_radius) |
|
|
|
local result = {} |
|
|
|
|
|
|
|
if (self.origin[1] - hitbox_bounds[1] - move_radius) < self.playableLeft then |
|
|
|
result[1] = self.playableLeft |
|
|
|
result[2] = self.playableLeft + hitbox_bounds[1] + (move_radius * 2) |
|
|
|
elseif (self.origin[2] + hitbox_bounds[2] + move_radius) > self.playableRight then |
|
|
|
result[2] = self.playableRight |
|
|
|
result[1] = self.playableRight - hitbox_bounds[2] - (move_radius * 2) |
|
|
|
else |
|
|
|
result[1] = self.x - move_radius |
|
|
|
result[2] = self.x + move_radius |
|
|
|
end |
|
|
|
return result |
|
|
|
end |
|
|
|
|