diff --git a/assets/pattern.png b/assets/pattern.png new file mode 100644 index 0000000..da14f96 Binary files /dev/null and b/assets/pattern.png differ diff --git a/game.lua b/game.lua index c15b7e4..66d356f 100644 --- a/game.lua +++ b/game.lua @@ -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 diff --git a/objects/background.lua b/objects/background.lua new file mode 100644 index 0000000..60b170b --- /dev/null +++ b/objects/background.lua @@ -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 diff --git a/scenes.lua b/scenes.lua index 486523f..51b979a 100644 --- a/scenes.lua +++ b/scenes.lua @@ -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