Add a loss screen
This commit is contained in:
parent
5b5a72a780
commit
5d9e9113ea
|
@ -20,8 +20,8 @@ local last_key_pressed = nil
|
||||||
local last_direction_moved = nil
|
local last_direction_moved = nil
|
||||||
local move_repeat_counter = nil
|
local move_repeat_counter = nil
|
||||||
|
|
||||||
local gamemodes = {normal = 0, won = 1, config = 2}
|
local gamemodes = {normal = 0, won = 1, lost = 2, config = 3}
|
||||||
local game_mode = gamemodes.normal
|
local game_mode = nil
|
||||||
|
|
||||||
local configuration_steps = {quit = -3, restart = -2, configure = -1}
|
local configuration_steps = {quit = -3, restart = -2, configure = -1}
|
||||||
local configuration_step = nil
|
local configuration_step = nil
|
||||||
|
@ -589,7 +589,6 @@ end
|
||||||
-- ------------------------------------------------------------------
|
-- ------------------------------------------------------------------
|
||||||
function newGame()
|
function newGame()
|
||||||
game_mode = gamemodes.normal
|
game_mode = gamemodes.normal
|
||||||
|
|
||||||
generateCavern()
|
generateCavern()
|
||||||
|
|
||||||
spawnPlayer()
|
spawnPlayer()
|
||||||
|
@ -690,7 +689,7 @@ function step(direction)
|
||||||
|
|
||||||
if collidedPlayerSlime() then
|
if collidedPlayerSlime() then
|
||||||
if math.random(0, 1) == 0 then
|
if math.random(0, 1) == 0 then
|
||||||
newGame()
|
game_mode = gamemodes.lost
|
||||||
else
|
else
|
||||||
killSlime()
|
killSlime()
|
||||||
end
|
end
|
||||||
|
@ -819,6 +818,46 @@ function drawWin()
|
||||||
love.graphics.draw(win_image, x_offset, y_offset, 0, scale, scale)
|
love.graphics.draw(win_image, x_offset, y_offset, 0, scale, scale)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function drawLoss()
|
||||||
|
local width = 54
|
||||||
|
local height = 140
|
||||||
|
|
||||||
|
local screen_width = love.graphics.getWidth()
|
||||||
|
local screen_height = love.graphics.getHeight()
|
||||||
|
|
||||||
|
local width_scale = screen_width / width
|
||||||
|
local height_scale = screen_height / height
|
||||||
|
local scale = math.min(width_scale, height_scale)
|
||||||
|
|
||||||
|
local x_offset = (screen_width - width * scale) / 2
|
||||||
|
local y_offset = (screen_height - height * scale) / 2
|
||||||
|
|
||||||
|
local vertices = {18, 20, 0, 40, 0, 60, 6, 80, 12, 100, 18, 120, 36, 120, 42, 100, 48, 80, 54, 60, 54, 40, 36, 20}
|
||||||
|
|
||||||
|
local transformed_vertices = {}
|
||||||
|
for i = 1, #vertices, 2 do
|
||||||
|
local x = vertices[i] * scale + x_offset
|
||||||
|
local y = vertices[i + 1] * scale + y_offset
|
||||||
|
|
||||||
|
transformed_vertices[i] = x
|
||||||
|
transformed_vertices[i + 1] = y
|
||||||
|
end
|
||||||
|
|
||||||
|
love.graphics.setColor(0.6, 0.3, 0.2)
|
||||||
|
love.graphics.polygon('fill', transformed_vertices)
|
||||||
|
|
||||||
|
love.graphics.setColor(1, 1, 1)
|
||||||
|
local lines = {27, 40, 27, 80, 18, 50, 36, 50}
|
||||||
|
for i = 1, #lines, 4 do
|
||||||
|
local sx = lines[i] * scale + x_offset
|
||||||
|
local sy = lines[i + 1] * scale + y_offset
|
||||||
|
local ex = lines[i + 2] * scale + x_offset
|
||||||
|
local ey = lines[i + 3] * scale + y_offset
|
||||||
|
|
||||||
|
love.graphics.line(sx, sy, ex, ey)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function drawConfig()
|
function drawConfig()
|
||||||
local text = nil
|
local text = nil
|
||||||
if configuration_step == configuration_steps.quit then
|
if configuration_step == configuration_steps.quit then
|
||||||
|
@ -926,6 +965,8 @@ function love.draw()
|
||||||
end
|
end
|
||||||
elseif game_mode == gamemodes.won then
|
elseif game_mode == gamemodes.won then
|
||||||
drawWin()
|
drawWin()
|
||||||
|
elseif game_mode == gamemodes.lost then
|
||||||
|
drawLoss()
|
||||||
elseif game_mode == gamemodes.config then
|
elseif game_mode == gamemodes.config then
|
||||||
drawConfig()
|
drawConfig()
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue