NeutronLoved/objects/background.lua

38 lines
917 B
Lua
Raw Normal View History

2022-03-04 14:57:05 +01:00
gen = {}
2022-03-08 09:44:31 +01:00
function gen:new(game,sprite,speedx,speedy,depth)
2022-03-04 14:57:05 +01:00
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
2022-03-08 09:44:31 +01:00
Background.speedx = speedx or 30
Background.speedy = speedy or 30
Background.depth = depth or -2
2022-03-04 14:57:05 +01:00
Background.offx = 0
Background.offy = 0
function Background:step(dt)
2022-03-08 09:44:31 +01:00
self.offx = (self.offx + dt*self.speedx)%self.spritewidth
self.offy = (self.offy + dt*self.speedy)%self.spriteheight
2022-03-04 14:57:05 +01:00
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