Implement first enemy, bullet damage and collision.
This commit is contained in:
parent
032cc0a2ed
commit
4aa4c129dc
7 changed files with 82 additions and 26 deletions
18
src/kani.lua
18
src/kani.lua
|
@ -3,6 +3,7 @@ import "CoreLibs/object"
|
|||
import "CoreLibs/graphics"
|
||||
import "CoreLibs/sprites"
|
||||
import "CoreLibs/timer"
|
||||
import "entity"
|
||||
import "bullet"
|
||||
import "ui"
|
||||
|
||||
|
@ -19,19 +20,16 @@ local WEAPON_CHARGE_LOOKUP <const> = {
|
|||
[3]=50
|
||||
}
|
||||
|
||||
class("Kani").extends(gfx.sprite)
|
||||
class("Kani").extends(Entity)
|
||||
|
||||
function Kani:init(ui)
|
||||
local img = gfx.image.new("images/kani.png")
|
||||
Kani.super.init(self, img)
|
||||
Kani.super.init(self, img, 100)
|
||||
|
||||
self:setCollideRect(0, 0, self:getSize())
|
||||
self.vector = {x=0,y=0} -- movement direction
|
||||
self:setGroupMask(0x2)
|
||||
self:setCollidesWithGroupsMask(0x19)
|
||||
|
||||
-- stats
|
||||
self.health = 100
|
||||
self.reserveCharge = 100
|
||||
|
||||
-- controls the speed the crank recharges the player's reserves. A lower number allows faster charging.
|
||||
|
@ -106,12 +104,12 @@ function Kani:fire()
|
|||
end
|
||||
|
||||
function Kani:damage(amount)
|
||||
self.health = math.max(self.health - amount, 0)
|
||||
|
||||
if self.health <= 0 then
|
||||
-- TODO: destroy ship
|
||||
end
|
||||
Kani.super.damage(self, amount)
|
||||
self.ui.healthMeter:setValue(self.health)
|
||||
|
||||
if self.health == 0 then
|
||||
-- TODO: end game here
|
||||
end
|
||||
end
|
||||
|
||||
function Kani:addInputHandlers()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue