NeutronLoved/objects/background.lua

38 lines
917 B
Lua

gen = {}
function gen:new(game,sprite,speedx,speedy,depth)
local Background = game.objects.base:new(game,0,0,game.WIDTH,game.HEIGHT)
Background.sprite = sprite
Background.spritewidth = sprite:getWidth()
Background.spriteheight = sprite:getHeight()
Background.nbwidth = game.WIDTH%sprite:getWidth()+2
Background.nbheight = game.HEIGHT%sprite:getHeight()+2
Background.speedx = speedx or 30
Background.speedy = speedy or 30
Background.depth = depth or -2
Background.offx = 0
Background.offy = 0
function Background:step(dt)
self.offx = (self.offx + dt*self.speedx)%self.spritewidth
self.offy = (self.offy + dt*self.speedy)%self.spriteheight
end
function Background:draw()
local i=0
local j=0
for i=-1,self.nbwidth-1 do
for j=-1,self.nbheight-1 do
lg.draw(self.sprite,i*self.spritewidth+self.offx,j*self.spritewidth+self.offy)
end
end
end
return Background
end
return gen