Two layer background

This commit is contained in:
theo@manjaro 2022-03-08 09:44:31 +01:00
parent 50d489b598
commit 6d35f1a9d3
4 changed files with 10 additions and 5 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 839 B

After

Width:  |  Height:  |  Size: 6.5 KiB

BIN
assets/pattern2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 747 B

View File

@ -1,6 +1,6 @@
gen = {} gen = {}
function gen:new(game,sprite) function gen:new(game,sprite,speedx,speedy,depth)
local Background = game.objects.base:new(game,0,0,game.WIDTH,game.HEIGHT) local Background = game.objects.base:new(game,0,0,game.WIDTH,game.HEIGHT)
Background.sprite = sprite Background.sprite = sprite
@ -8,14 +8,15 @@ function gen:new(game,sprite)
Background.spriteheight = sprite:getHeight() Background.spriteheight = sprite:getHeight()
Background.nbwidth = game.WIDTH%sprite:getWidth()+2 Background.nbwidth = game.WIDTH%sprite:getWidth()+2
Background.nbheight = game.HEIGHT%sprite:getHeight()+2 Background.nbheight = game.HEIGHT%sprite:getHeight()+2
Background.speed = 30 Background.speedx = speedx or 30
Background.depth = -2 Background.speedy = speedy or 30
Background.depth = depth or -2
Background.offx = 0 Background.offx = 0
Background.offy = 0 Background.offy = 0
function Background:step(dt) function Background:step(dt)
self.offx = (self.offx + dt*self.speed)%self.spritewidth self.offx = (self.offx + dt*self.speedx)%self.spritewidth
self.offy = (self.offy + dt*self.speed)%self.spriteheight self.offy = (self.offy + dt*self.speedy)%self.spriteheight
end end
function Background:draw() function Background:draw()

View File

@ -9,6 +9,8 @@ function scenes:main(game)
game:summon(grid) game:summon(grid)
local background = game.objects.background:new(game,game:newImage("pattern.png")) local background = game.objects.background:new(game,game:newImage("pattern.png"))
game:summon(background) game:summon(background)
local background = game.objects.background:new(game,game:newImage("pattern2.png"),22,18)
game:summon(background)
end end
function scenes:ending(game,winner) function scenes:ending(game,winner)
@ -17,6 +19,8 @@ function scenes:ending(game,winner)
game:summon(ending) game:summon(ending)
local background = game.objects.background:new(game,game:newImage("pattern.png")) local background = game.objects.background:new(game,game:newImage("pattern.png"))
game:summon(background) game:summon(background)
local background = game.objects.background:new(game,game:newImage("pattern2.png"),22)
game:summon(background)
end end
return scenes return scenes