Add a win image
This commit is contained in:
parent
d79fa1abf4
commit
b497deffd9
123
bundle/main.lua
123
bundle/main.lua
|
@ -30,9 +30,10 @@ direction_keys['k'] = directions.down
|
|||
direction_keys['.'] = directions.downright
|
||||
direction_keys['l'] = directions.right
|
||||
direction_keys['o'] = directions.upright
|
||||
|
||||
local control_keys = {quit = 'q', restart = 'r'}
|
||||
|
||||
local win_image = nil
|
||||
|
||||
-- ------------------------------------------------------------------
|
||||
-- Cavern generation
|
||||
-- ------------------------------------------------------------------
|
||||
|
@ -593,50 +594,12 @@ function step(direction)
|
|||
end
|
||||
|
||||
-- ------------------------------------------------------------------
|
||||
-- Callbacks
|
||||
-- Drawing
|
||||
-- ------------------------------------------------------------------
|
||||
|
||||
function love.load()
|
||||
math.randomseed(os.time())
|
||||
|
||||
newGame()
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
if move_repeat_counter ~= nil and move_repeat_counter > 0 then
|
||||
move_repeat_counter = move_repeat_counter - dt
|
||||
if move_repeat_counter <= 0 then
|
||||
step(last_direction_moved)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function love.keypressed(key)
|
||||
last_key_pressed = key
|
||||
|
||||
if key == control_keys.quit then
|
||||
love.event.quit()
|
||||
elseif key == control_keys.restart then
|
||||
newGame()
|
||||
elseif direction_keys[key] ~= nil then
|
||||
step(direction_keys[key])
|
||||
elseif key == 'printscreen' then
|
||||
debug = true
|
||||
end
|
||||
end
|
||||
|
||||
function love.keyreleased(key)
|
||||
if last_key_pressed == key then
|
||||
last_direction_moved = nil
|
||||
move_repeat_counter = nil
|
||||
end
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
function drawCavern()
|
||||
local x_scale = love.graphics.getWidth() / cavern.width
|
||||
local y_scale = love.graphics.getHeight() / cavern.height
|
||||
|
||||
-- Draw the cavern
|
||||
for tile_x, list in ipairs(visibility_map) do
|
||||
local x = (tile_x - 1) * x_scale
|
||||
for tile_y, visible in ipairs(list) do
|
||||
|
@ -681,11 +644,15 @@ function love.draw()
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function drawPlayer()
|
||||
local x_scale = love.graphics.getWidth() / cavern.width
|
||||
local y_scale = love.graphics.getHeight() / cavern.height
|
||||
|
||||
-- Draw the player
|
||||
local player_head_center_x = (player_x - 1) * x_scale + 0.5 * x_scale
|
||||
local player_head_center_y = (player_y - 1) * y_scale + 0.5 * y_scale
|
||||
love.graphics.setColor(0.6, 0.2, 0.2)
|
||||
love.graphics.setColor(0.6, 0.3, 0.2)
|
||||
love.graphics.ellipse('fill', player_head_center_x, player_head_center_y, x_scale/2, y_scale/2)
|
||||
|
||||
local player_body_x, player_body_y = getBodyLocation()
|
||||
|
@ -694,3 +661,73 @@ function love.draw()
|
|||
love.graphics.setColor(0, 0, 1)
|
||||
love.graphics.rectangle('fill', player_body_x, player_body_y, x_scale, y_scale)
|
||||
end
|
||||
|
||||
function drawWin()
|
||||
local img_width, img_height = win_image:getDimensions()
|
||||
|
||||
local screen_width = love.graphics.getWidth()
|
||||
local screen_height = love.graphics.getHeight()
|
||||
|
||||
local width_scale = screen_width / img_width
|
||||
local height_scale = screen_height / img_height
|
||||
local scale = math.min(width_scale, height_scale)
|
||||
|
||||
local left_border = (screen_width - img_width * scale) / 2
|
||||
local up_border = (screen_height - img_height * scale) / 2
|
||||
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
love.graphics.draw(win_image, left_border, up_border, 0, scale, scale)
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------
|
||||
-- Callbacks
|
||||
-- ------------------------------------------------------------------
|
||||
|
||||
function love.load()
|
||||
math.randomseed(os.time())
|
||||
|
||||
newGame()
|
||||
|
||||
win_image = love.graphics.newImage("win_image.png")
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
if move_repeat_counter ~= nil and move_repeat_counter > 0 then
|
||||
move_repeat_counter = move_repeat_counter - dt
|
||||
if move_repeat_counter <= 0 then
|
||||
step(last_direction_moved)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function love.keypressed(key)
|
||||
last_key_pressed = key
|
||||
|
||||
if key == control_keys.quit then
|
||||
love.event.quit()
|
||||
elseif key == control_keys.restart then
|
||||
newGame()
|
||||
elseif direction_keys[key] ~= nil then
|
||||
step(direction_keys[key])
|
||||
elseif key == 'printscreen' then
|
||||
debug = true
|
||||
end
|
||||
end
|
||||
|
||||
function love.keyreleased(key)
|
||||
if last_key_pressed == key then
|
||||
last_direction_moved = nil
|
||||
move_repeat_counter = nil
|
||||
end
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
if game_mode == gamemodes.normal then
|
||||
drawCavern()
|
||||
drawPlayer()
|
||||
elseif game_mode == gamemodes.won then
|
||||
drawWin()
|
||||
else
|
||||
error("Impossible game mode")
|
||||
end
|
||||
end
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
Loading…
Reference in New Issue