Skip to content

Commit

Permalink
refactor and make HUD cooler
Browse files Browse the repository at this point in the history
  • Loading branch information
djflorio committed May 27, 2018
1 parent f6e0be2 commit a0fdb5a
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 13 deletions.
Binary file added assets/fonts/OpenSans-ExtraBold.ttf
Binary file not shown.
Binary file added assets/fonts/OpenSans-Regular.ttf
Binary file not shown.
12 changes: 8 additions & 4 deletions globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ end
local themes = {
easy = {
primary = genColor(49, 71, 49),
secondary = genColor(154, 224, 154)
secondary = genColor(154, 224, 154),
hud = genColor(255, 255, 255, 0.8)
},
medium = {
primary = genColor(104, 74, 19),
secondary = genColor(239, 206, 141)
secondary = genColor(239, 206, 141),
hud = genColor(255, 255, 255, 0.8)
},
hard = {
primary = genColor(81, 30, 7),
secondary = genColor(247, 140, 91)
secondary = genColor(247, 140, 91),
hud = genColor(255, 255, 255, 0.8)
},
expert = {
primary = genColor(255, 50, 50),
secondary = genColor(0, 0, 0)
secondary = genColor(0, 0, 0),
hud = genColor(255, 255, 255, 0.8)
}
}

Expand Down
11 changes: 7 additions & 4 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ local background = require 'parts.background'
local audio = require 'assets.audio'
local animations = require 'parts.animations'
local globals = require 'globals'
local gameover = require 'parts.gameover'
local fonts = require 'parts.fonts'

function love.load()
world = bump.newWorld(16)
font = love.graphics.newFont(16)
love.graphics.setFont(font)

fonts.init()
globals.init()
animations.init()
floor.init(world)
Expand All @@ -33,7 +33,7 @@ end

function love.draw()
local xOffset = 0
local yOffset = -player.y + love.graphics.getHeight() - 200
local yOffset = -player.y + love.graphics.getHeight() - 170
if animations.hurt.playing then
xOffset = love.math.random(-10, 10)
yOffset = yOffset + love.math.random(-10, 10)
Expand All @@ -44,4 +44,7 @@ function love.draw()
platforms.draw()
player.draw()
hud.draw(yOffset)
if not globals.playing then
gameover.draw(yOffset)
end
end
8 changes: 8 additions & 0 deletions parts/fonts.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local fonts = {}

fonts.init = function()
fonts.big = love.graphics.newFont("assets/fonts/OpenSans-ExtraBold.ttf", 50)
fonts.medium = love.graphics.newFont("assets/fonts/OpenSans-ExtraBold.ttf", 25)
end

return fonts
36 changes: 36 additions & 0 deletions parts/gameover.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
local globals = require 'globals'
local fonts = require 'parts.fonts'

local gameover = {}

gameover.draw = function(offset)
love.graphics.setFont(fonts.big)
love.graphics.setColor(0, 0, 0, 0.9)
love.graphics.rectangle(
'fill',
0,
0 - offset,
love.graphics.getWidth(),
love.graphics.getHeight()
)
local w = love.graphics.getWidth()
love.graphics.setColor(1, 1, 1)
love.graphics.printf("GAME OVER", 0, 170 - offset, w, "center")
love.graphics.setFont(fonts.medium)
love.graphics.printf(
"Layers Passed: " .. tostring(globals.layersPassed),
0,
240 - offset,
w,
"center"
)
love.graphics.printf(
"Press ENTER to try again",
0,
270 - offset,
w,
"center"
)
end

return gameover
13 changes: 8 additions & 5 deletions parts/hud.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
local globals = require 'globals'
local fonts = require 'parts.fonts'

local hud = {}

hud.draw = function(offset)
--love.graphics.setColor(globals.colors.hudBack)
--love.graphics.rectangle('fill', 0, -offset, love.graphics.getWidth(), 30)
love.graphics.setFont(fonts.big)
love.graphics.setColor(globals.colors.primary)
local cleared = "Cleared: " .. tostring(globals.layersPassed)
love.graphics.print(cleared, 6, 6 - offset)
local cleared = globals.layersPassed
love.graphics.print(cleared, 10, -5 - offset)
for h=1,globals.playerHealth do
love.graphics.rectangle('fill', 200 + 12*h, 10-offset, 10, 10)
local size = 30
local spacing = 5
local start = love.graphics.getWidth() - (size + 2*spacing + 4*size)
love.graphics.rectangle('fill', start + (size+spacing)*h, 20-offset, size, size)
end
end

Expand Down

0 comments on commit a0fdb5a

Please sign in to comment.