|
|
|
@ -23,19 +23,24 @@ function Enemy:new(x, y, radius, playableArea) |
|
|
|
self.fireRate = 1 |
|
|
|
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]) |
|
|
|
self.hitbox = { (self.x + 20), (self.x + 20), (self.y + 20), (self.y + 44) } |
|
|
|
self.move_bounds = self:setMoveBounds() |
|
|
|
--print("Move Bounds: ", self.move_bounds[1], " , ", self.move_bounds[2]) |
|
|
|
enemyBullets = {} |
|
|
|
end |
|
|
|
|
|
|
|
function Enemy:draw() |
|
|
|
--draw stuff |
|
|
|
--love.graphics.rectangle("line", self.x, self.y, self.width, self.height) |
|
|
|
love.graphics.draw(self.image, self.x, self.y, 0, -1) |
|
|
|
love.graphics.rectangle( |
|
|
|
"line", |
|
|
|
self.hitbox[1], |
|
|
|
self.hitbox[3], |
|
|
|
(self.hitbox[2] - self.hitbox[1]), |
|
|
|
(self.hitbox[4] - self.hitbox[3]) |
|
|
|
) |
|
|
|
love.graphics.draw(self.image, self.x, self.y, 0, 1, 1) |
|
|
|
|
|
|
|
for _, v in ipairs(enemyBullets) do |
|
|
|
--love.graphics.circle("fill", v.x, v.y, v.radius) |
|
|
|
v:draw() |
|
|
|
end |
|
|
|
end |
|
|
|
@ -50,10 +55,8 @@ function Enemy:update(dt, player) |
|
|
|
|
|
|
|
--movement |
|
|
|
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 > self.move_bounds[2] then |
|
|
|
print("Reversing direction! Hitbox Right Location: ", self.hitbox[2], " Play Bound Right: ", self.playableRight) |
|
|
|
self.speed = -self.speed |
|
|
|
end |
|
|
|
|
|
|
|
@ -82,24 +85,25 @@ end |
|
|
|
|
|
|
|
--shoot at the player a variable number of seconds |
|
|
|
function Enemy:fire() |
|
|
|
local fire_origin = { self.x + 26, self.y + 44 } |
|
|
|
if love.timer.getTime() - fireTime > self.fireRate then |
|
|
|
table.insert(enemyBullets, Blaster(self.x, self.y, "enemy")) |
|
|
|
table.insert(enemyBullets, Blaster(fire_origin[1], fire_origin[2], "enemy")) |
|
|
|
fireTime = love.timer.getTime() |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
function Enemy:setMoveBounds(hitbox_bounds, move_radius) |
|
|
|
function Enemy:setMoveBounds() |
|
|
|
local result = {} |
|
|
|
|
|
|
|
if (self.origin[1] - hitbox_bounds[1] - move_radius) < self.playableLeft then |
|
|
|
if (self.hitbox[1] - self.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.playableLeft + self.hitbox[1] + move_radius |
|
|
|
elseif (self.hitbox[2] + self.move_radius) > self.playableRight then |
|
|
|
result[2] = self.playableRight |
|
|
|
result[1] = self.playableRight - hitbox_bounds[2] - (move_radius * 2) |
|
|
|
result[1] = self.playableRight - self.hitbox[2] - move_radius |
|
|
|
else |
|
|
|
result[1] = self.x - move_radius |
|
|
|
result[2] = self.x + move_radius |
|
|
|
result[1] = self.x - self.move_radius |
|
|
|
result[2] = self.x + self.move_radius |
|
|
|
end |
|
|
|
return result |
|
|
|
end |
|
|
|
|