Browse Source

little adjustments

master
NCLanceman 8 months ago
parent
commit
4af3319a72
  1. 18
      blaster.lua
  2. 3
      entities/enemy.lua
  3. 3
      ui.lua

18
blaster.lua

@ -22,3 +22,21 @@ function Blaster:update(dt)
self.y = self.y + self.speed * dt self.y = self.y + self.speed * dt
end end
end end
function Blaster:checkCollision(obj)
local self_left = self.x
local self_right = self.x + self.radius * 2
local self_top = self.y
local self_bottom = self.y + self.radius * 2
local obj_left = obj.x
local obj_right = obj.x + obj.width
local obj_top = obj.y
local obj_bottom = obj.y + obj.height
if self_right > obj_left and self_left < obj_right and self_bottom > obj_top and self_top < obj_bottom then
self.destroy = true
--other blaster logic here
end
end

3
entities/enemy.lua

@ -13,6 +13,7 @@ function Enemy:new(x, y, radius)
self.health = 100 self.health = 100
self.move_radius = radius self.move_radius = radius
self.speed = 100 self.speed = 100
self.fireRate = 2
listOfBullets = {} listOfBullets = {}
end end
@ -58,7 +59,7 @@ end
--shoot at the player a variable number of seconds --shoot at the player a variable number of seconds
function Enemy:fire() function Enemy:fire()
if love.timer.getTime() - fireTime > 2 then if love.timer.getTime() - fireTime > self.fireRate then
table.insert(listOfBullets, Blaster(self.x, self.y, "enemy")) table.insert(listOfBullets, Blaster(self.x, self.y, "enemy"))
fireTime = love.timer.getTime() fireTime = love.timer.getTime()
end end

3
ui.lua

@ -0,0 +1,3 @@
--display the score
--display player health
Loading…
Cancel
Save