You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
49 lines
1.2 KiB
Blaster = Object:extend()
|
|
|
|
function Blaster:new(x, y, owner)
|
|
self.x = x
|
|
self.y = y
|
|
self.radius = 10
|
|
self.height = self.radius * 2
|
|
self.width = self.radius * 2
|
|
self.speed = 700
|
|
self.color = { 1, 0, 0 }
|
|
self.destroy = false
|
|
self.owner = owner
|
|
|
|
self.bounds = { self.x, (self.x + self.width), self.y, (self.y + self.height) }
|
|
end
|
|
|
|
function Blaster:draw()
|
|
--draw stuff
|
|
love.graphics.circle("fill", self.x, self.y, self.radius)
|
|
end
|
|
|
|
function Blaster:update(dt)
|
|
if self.owner == "player" then
|
|
self.y = self.y - self.speed * dt
|
|
elseif self.owner == "enemy" then
|
|
self.y = self.y + self.speed * dt
|
|
end
|
|
|
|
self.bounds = { self.x, (self.x + self.width), self.y, (self.y + self.height) }
|
|
end
|
|
|
|
function Blaster:checkCollision(obj)
|
|
local self_left = self.bounds[1]
|
|
local self_right = self.bounds[2]
|
|
local self_top = self.bounds[3]
|
|
local self_bottom = self.bounds[4]
|
|
|
|
local obj_left = obj.bounds[1]
|
|
local obj_right = obj.bounds[2]
|
|
local obj_top = obj.bounds[3]
|
|
local obj_bottom = obj.bounds[4]
|
|
|
|
if (self_right > obj_left) and (self_left < obj_right) and (self_bottom > obj_top) and (self_top < obj_bottom) then
|
|
self.destroy = true
|
|
obj.health = obj.health - 25
|
|
--other blaster logic here
|
|
print("Collision! ", self.owner, " bullet struck ", obj.type)
|
|
end
|
|
end
|
|
|