From 327ebbf23e19828fb6779607e2364b8b76ba627c Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 13 Jan 2017 20:43:51 +0100 Subject: Menu background animation --- assets/asteroids.png | Bin 0 -> 1227 bytes assets/backgrounds/menu.png | Bin 13640 -> 11447 bytes assets/stars.png | Bin 0 -> 1644 bytes menu.lua | 19 ++++++++++++++++++- 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 assets/asteroids.png create mode 100644 assets/stars.png diff --git a/assets/asteroids.png b/assets/asteroids.png new file mode 100644 index 0000000..cb85a2b Binary files /dev/null and b/assets/asteroids.png differ diff --git a/assets/backgrounds/menu.png b/assets/backgrounds/menu.png index 9be3233..b42f8f6 100644 Binary files a/assets/backgrounds/menu.png and b/assets/backgrounds/menu.png differ diff --git a/assets/stars.png b/assets/stars.png new file mode 100644 index 0000000..4965389 Binary files /dev/null and b/assets/stars.png differ diff --git a/menu.lua b/menu.lua index b72ea09..36e06ef 100644 --- a/menu.lua +++ b/menu.lua @@ -12,6 +12,10 @@ Menu = { music, sprite, background, + asteroids, + stars, + asteroids_bounce = 0, + stars_timer = 0, allowMove = true, quads = { button = { @@ -28,6 +32,10 @@ Menu = { }, arrow_l = love.graphics.newQuad(68, 0, 6, 6, 80,130), arrow_r = love.graphics.newQuad(74, 0, 6, 6, 80,130), + stars = { + love.graphics.newQuad( 0, 0, 320, 200, 640,200), + love.graphics.newQuad(320, 0, 320, 200, 640,200) + }, } } function Menu:new(name) @@ -36,6 +44,8 @@ function Menu:new(name) self.__index = self self.sprite = love.graphics.newImage("assets/menu.png") self.background = love.graphics.newImage("assets/backgrounds/menu.png") + self.asteroids = love.graphics.newImage("assets/asteroids.png") + self.stars = love.graphics.newImage("assets/stars.png") o.elements = {} o:load(name) o.music = Music:new("menu.ogg") @@ -84,10 +94,17 @@ function Menu:update(dt) for _,element in pairs(self.elements) do element:update(dt) end + self.asteroids_bounce = self.asteroids_bounce + dt*0.1 + if self.asteroids_bounce > 2 then self.asteroids_bounce = self.asteroids_bounce - 2 end + self.stars_timer = self.stars_timer + dt * 0.7 + if self.stars_timer > 2 then self.stars_timer = self.stars_timer - 2 end end function Menu:draw() local scale = self.scale - love.graphics.draw(self.background, 0, 0, 0, getRealScale(), getRealScale()) + local scaler = getRealScale() + love.graphics.draw(self.background, 0, 0, 0, scaler, scaler) + love.graphics.draw(self.stars, self.quads.stars[math.ceil(self.stars_timer)], 0, 0, 0, scaler, scaler) + love.graphics.draw(self.asteroids, 0, math.floor(64+math.sin(self.asteroids_bounce*math.pi)*4)*scaler, 0, scaler, scaler) love.graphics.setFont(Font) for _,element in pairs(self.elements) do element:draw(scale) -- cgit v1.1