From 52929bdd8430fa464fddd7ec416a5fbf5e2fc982 Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Thu, 5 Jan 2017 11:53:52 +0100 Subject: [PATCH] animation indicator --- assets/scripts/game.lua | 8 ++++++++ assets/scripts/gui/life.lua | 28 ++++++++++++++++++++++++---- assets/scripts/spaceship.lua | 1 + main.lua | 1 + 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/assets/scripts/game.lua b/assets/scripts/game.lua index 23b6fa7..31ca060 100644 --- a/assets/scripts/game.lua +++ b/assets/scripts/game.lua @@ -11,6 +11,7 @@ function game.load() love.window.setMode(game.window.width, game.window.height) game.level = 1 game.play = true + game.die = false -- Physics DEBUG = true local world_meter = 64 @@ -19,4 +20,11 @@ function game.load() game.world = love.physics.newWorld(0, gravity * world_meter, true) -- Make earth end +function game.update(dt) + if game.die then + game.lifes = game.lifes - 1 + game.die = false + end +end + return game \ No newline at end of file diff --git a/assets/scripts/gui/life.lua b/assets/scripts/gui/life.lua index 2501f3c..302c437 100644 --- a/assets/scripts/gui/life.lua +++ b/assets/scripts/gui/life.lua @@ -31,17 +31,37 @@ function life.load(game) width = 10, color = {0, 0, 0}, angle = 230, - move_up = false + move_up = false, + vel = 1 } life.indicator.radius = tools.distance(life.indicator.x_shaft, life.indicator.y_shaft, life.indicator.x_target, life.indicator.y_target) love.graphics.setLineWidth(life.indicator.width) + life.indicator.limits = {} + life.indicator.limits[2] = { + min = 260, + max = 270 + } + life.indicator.limits[3] = { + min = 230, + max = 240 + } end function life.update(dt, game) life.top.animation:update(dt) - -- 1 230 240 - if game.life == 3 then - end + -- Direction + if life.indicator.limits[game.lifes].max < life.indicator.angle then + life.indicator.move_up = false + elseif life.indicator.limits[game.lifes].min > life.indicator.angle then + life.indicator.move_up = true + end + -- Increment + if life.indicator.move_up then + life.indicator.angle = life.indicator.angle + life.indicator.vel + else + life.indicator.angle = life.indicator.angle - life.indicator.vel + end + -- Calculate pos indicator life.indicator.x_target, life.indicator.y_target = tools.circle_position(life.indicator.angle, life.indicator.radius, life.indicator.x_shaft, life.indicator.y_shaft) end diff --git a/assets/scripts/spaceship.lua b/assets/scripts/spaceship.lua index cefdc97..03c081e 100644 --- a/assets/scripts/spaceship.lua +++ b/assets/scripts/spaceship.lua @@ -100,6 +100,7 @@ function spaceship.update(dt, game) -- Check for collisions for shape, delta in pairs(HC.collisions(body.collision.hc)) do game.play = false + game.die = true explosion.x, explosion.y, explosion.enable = body.body:getX() - explosion.claim_x, body.body:getY() - explosion.claim_y, true explosion.animation:resume() end diff --git a/main.lua b/main.lua index 2ce6e9c..c8b671c 100644 --- a/main.lua +++ b/main.lua @@ -25,6 +25,7 @@ function love.update(dt) require('assets/scripts/vendor/lovebird').update() end game.world:update(dt) + game.update(dt) background.update(dt) asteroids.update(dt, game) moon.update()