Progress life indicator

This commit is contained in:
Andros Fenollosa
2017-01-05 10:49:04 +01:00
parent 908c28ec90
commit 815069d293
33 changed files with 105 additions and 30 deletions

View File

@ -3,6 +3,8 @@ local game = {}
function game.load()
-- Configuration
math.randomseed(os.time())
PADDING = 50
game.lifes = 3
local width, height = love.window.getDesktopDimensions( display )
game.window = { width = width , height = height }
game.canvas = { width = width, height = 2880 }

View File

@ -3,21 +3,20 @@ local controls = {}
local BUTTONS = {}
function controls.load(game)
local padding = 50
-- Button left
local img_button_left = love.graphics.newImage('assets/sprites/hui/button_left.png')
local left_x = padding
local left_y = (game.window.height / 3 * 2) - img_button_left:getHeight() - padding
local img_button_left = love.graphics.newImage('assets/sprites/gui/button_left.png')
local left_x = PADDING
local left_y = (game.window.height / 3 * 2) - img_button_left:getHeight() - PADDING
controls.new_button('button_left', left_x, left_y, img_button_left)
-- Button right
local img_button_right = love.graphics.newImage('assets/sprites/hui/button_right.png')
local right_x = game.window.width - (img_button_right:getWidth() / 2) - padding
local right_y = (game.window.height / 3 * 2) - img_button_right:getHeight() - padding
local img_button_right = love.graphics.newImage('assets/sprites/gui/button_right.png')
local right_x = game.window.width - (img_button_right:getWidth() / 2) - PADDING
local right_y = (game.window.height / 3 * 2) - img_button_right:getHeight() - PADDING
controls.new_button('button_right', right_x, right_y, img_button_right)
-- Button up
local img_button_up = love.graphics.newImage('assets/sprites/hui/button_up.png')
local up_x = game.window.width - (img_button_up:getWidth() / 2) - padding
local up_y = (game.window.height / 3) - img_button_up:getHeight() - padding
local img_button_up = love.graphics.newImage('assets/sprites/gui/button_up.png')
local up_x = game.window.width - (img_button_up:getWidth() / 2) - PADDING
local up_y = (game.window.height / 3) - img_button_up:getHeight() - PADDING
controls.new_button('button_up', up_x, up_y, img_button_up)
end

View File

@ -0,0 +1,59 @@
local anim8 = require 'assets/scripts/vendor/anim8'
local tools = require 'assets/scripts/tools'
local life = {}
function life.load(game)
local PADDING = 50
-- Up
life.top = {
x = PADDING,
y = PADDING,
img = love.graphics.newImage('assets/sprites/gui/life_top.png'),
num_frames = 2
}
g = anim8.newGrid(life.top.img:getWidth() / life.top.num_frames, life.top.img:getHeight(), life.top.img:getWidth(), life.top.img:getHeight())
life.top.animation = anim8.newAnimation(g('1-' .. life.top.num_frames, 1), 1)
life.top.animation:gotoFrame(1)
life.top.animation:pause()
-- Down
life.down = {
img = love.graphics.newImage('assets/sprites/gui/life_down.png'),
x = PADDING,
y = life.top.y + life.top.img:getHeight()
}
-- Indicator
life.indicator = {
x_shaft = life.down.x + (life.down.img:getWidth() / 2),
y_shaft = life.down.y + (life.down.img:getHeight() / 2),
x_target = life.top.x + (life.top.img:getWidth() / 2 / life.top.num_frames),
y_target = life.top.y + (life.top.img:getHeight() / 2),
width = 10,
color = {0, 0, 0},
angle = 230,
move_up = false
}
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)
end
function life.update(dt, game)
life.top.animation:update(dt)
-- 1 230 240
if game.life == 3 then
end
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
function life.draw()
-- Background top
life.top.animation:draw(life.top.img, life.top.x, life.top.y)
-- Indicator
love.graphics.setColor(life.indicator.color)
love.graphics.line(life.indicator.x_shaft, life.indicator.y_shaft, life.indicator.x_target, life.indicator.y_target)
love.graphics.setColor(255, 255, 255)
-- Background down
love.graphics.draw(life.down.img, life.down.x, life.down.y)
end
return life

View File

@ -71,4 +71,15 @@ function tools.print_r(t)
print()
end
function tools.distance(x1, y1, x2, y2)
local dx = x1 - x2
local dy = y1 - y2
return math.sqrt ( dx * dx + dy * dy )
end
function tools.circle_position(angle, radius, x_center, y_center)
local angle_temp = angle * math.pi / 180
return x_center + radius * math.cos(angle_temp), y_center + radius * math.sin(angle_temp)
end
return tools

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB