Added animated background

This commit is contained in:
theo@manjaro 2022-03-04 14:57:05 +01:00
parent e41a42fda4
commit 1df23cb4aa
4 changed files with 41 additions and 0 deletions

BIN
assets/pattern.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 839 B

View File

@ -10,6 +10,7 @@ function Game:reinit()
self.objects.grid = require "objects/grid"
self.objects.circle = require "objects/circle"
self.objects.ending = require "objects/end"
self.objects.background = require "objects/background"
self.rect = require "lib/rect"
self.maxobjects = 0
self.camerax = 0

36
objects/background.lua Normal file
View File

@ -0,0 +1,36 @@
gen = {}
function gen:new(game,sprite)
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.speed = 30
Background.depth = -2
Background.offx = 0
Background.offy = 0
function Background:step(dt)
self.offx = (self.offx + dt*self.speed)%self.spritewidth
self.offy = (self.offy + dt*self.speed)%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

View File

@ -7,12 +7,16 @@ function scenes:main(game)
local y = (game.HEIGHT-cellsize*5)/2
local grid = game.objects.grid:new(game,x,y,cellsize)
game:summon(grid)
local background = game.objects.background:new(game,game:newImage("pattern.png"))
game:summon(background)
end
function scenes:ending(game,winner)
game.gameloop = {}
local ending = game.objects.ending:new(game,winner)
game:summon(ending)
local background = game.objects.background:new(game,game:newImage("pattern.png"))
game:summon(background)
end
return scenes