rsi/enemy.lua

42 lines
864 B
Lua
Raw Permalink Normal View History

2023-08-27 12:32:38 +00:00
enemy=object:extend()
2023-08-27 23:00:22 +00:00
function enemy:new(x,y,sounds,hp)
2023-08-27 12:32:38 +00:00
self.x=x
self.y=y
self.dx=0
self.dy=-1
2023-08-27 23:00:22 +00:00
self.hp=hp or 10
2023-08-27 12:32:38 +00:00
self.sounds=sounds;
sounds.loop:setPosition(x,y,0)
2023-08-27 23:00:22 +00:00
for k,v in pairs(sounds) do
if v:typeOf("Source") then
v:setAttenuationDistances(110,game.field.height)
end
end
2023-08-27 12:32:38 +00:00
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
2023-08-27 23:00:22 +00:00
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