42 lines
864 B
Lua
42 lines
864 B
Lua
enemy=object:extend()
|
|
|
|
function enemy:new(x,y,sounds,hp)
|
|
self.x=x
|
|
self.y=y
|
|
self.dx=0
|
|
self.dy=-1
|
|
self.hp=hp or 10
|
|
self.sounds=sounds;
|
|
sounds.loop:setPosition(x,y,0)
|
|
for k,v in pairs(sounds) do
|
|
if v:typeOf("Source") then
|
|
v:setAttenuationDistances(110,game.field.height)
|
|
end
|
|
end
|
|
self.lastMoveTick=0
|
|
self.rate=game.currentTrack.info.beatDivisions
|
|
end -- new
|
|
|
|
function enemy:update(dt)
|
|
if game.ticker.ticks-self.lastMoveTick>=self.rate then
|
|
self:move()
|
|
end -- rate
|
|
end -- update
|
|
|
|
function enemy:move()
|
|
self.lastMoveTick=game.ticker.ticks
|
|
self.x=self.x+self.dx
|
|
self.y=self.y+self.dy
|
|
utils.setSourcePosition(self.sounds.loop, self.x,self.y)
|
|
if(self.y<=0) then self:land() end
|
|
end
|
|
|
|
function enemy:land()
|
|
tts.say("landed")
|
|
for k,v in pairs(self.sounds) do
|
|
if v:typeOf("Source") then
|
|
if v:isLooping() then v:stop() end
|
|
end
|
|
end -- stop all loops
|
|
self.destroy=true
|
|
end -- land |