diff options
author | Aki <nthirtyone@gmail.com> | 2017-08-13 02:26:55 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2017-08-13 02:26:55 +0200 |
commit | b1cf14d64a2d3e28683db87190c4b2c7799c259d (patch) | |
tree | e45dac5cc6ce5265e3e3e2c914eb7cc92a820b8b /not/MenuBackground.lua | |
parent | 0dd01913fe0eefc7ba4bc0797877f40fdedf9315 (diff) | |
parent | ed62b573417bdc85bec616f6016846b02de4c906 (diff) | |
download | roflnauts-b1cf14d64a2d3e28683db87190c4b2c7799c259d.zip roflnauts-b1cf14d64a2d3e28683db87190c4b2c7799c259d.tar.gz roflnauts-b1cf14d64a2d3e28683db87190c4b2c7799c259d.tar.bz2 |
Merge branch 'multi'maps
Diffstat (limited to 'not/MenuBackground.lua')
-rw-r--r-- | not/MenuBackground.lua | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/not/MenuBackground.lua b/not/MenuBackground.lua new file mode 100644 index 0000000..83b409c --- /dev/null +++ b/not/MenuBackground.lua @@ -0,0 +1,49 @@ +--- `MenuBackground` +-- Represented as space background with blinking stars and moving asteroids. +-- It might be too specific, but whatever. It is still better than hardcoded background in `Menu` class. +MenuBackground = require "not.Element":extends() + +MenuBackground.BASE_STARS_DELAY = .8 +MenuBackground.QUAD_STARS = { + love.graphics.newQuad( 0, 0, 320, 200, 640,200), + love.graphics.newQuad(320, 0, 320, 200, 640,200) +} + +function MenuBackground:new (parent) + MenuBackground.__super.new(parent) + self.starsFrame = 1 + self.starsDelay = self.BASE_STARS_DELAY + self.asteroidsBounce = 0 + -- Load statically. + if MenuBackground.IMAGE_BACKGROUND == nil then + MenuBackground.IMAGE_BACKGROUND = love.graphics.newImage("assets/backgrounds/menu.png") + MenuBackground.IMAGE_ASTEROIDS = love.graphics.newImage("assets/asteroids.png") + MenuBackground.IMAGE_STARS = love.graphics.newImage("assets/stars.png") + end +end + +function MenuBackground:update (dt) + self.asteroidsBounce = self.asteroidsBounce + dt*0.1 + if self.asteroidsBounce > 2 then + self.asteroidsBounce = self.asteroidsBounce - 2 + end + self.starsDelay = self.starsDelay - dt + if self.starsDelay < 0 then + self.starsDelay = self.starsDelay + self.BASE_STARS_DELAY + if self.starsFrame == 2 then + self.starsFrame = 1 + else + self.starsFrame = 2 + end + end +end + +function MenuBackground:draw () + local scale = self.scale + local scaler = getRealScale() + love.graphics.draw(self.IMAGE_BACKGROUND, 0, 0, 0, scaler, scaler) + love.graphics.draw(self.IMAGE_STARS, self.QUAD_STARS[self.starsFrame], 0, 0, 0, scaler, scaler) + love.graphics.draw(self.IMAGE_ASTEROIDS, 0, math.floor(64+math.sin(self.asteroidsBounce*math.pi)*4)*scaler, 0, scaler, scaler) +end + +return MenuBackground |