Beginnings of winning the game
This commit is contained in:
parent
f72520689a
commit
6617a243ce
|
@ -1,3 +1,5 @@
|
|||
local debug = false
|
||||
|
||||
local cavern = {}
|
||||
local tiletypes = {unknown = 0, empty = 1, wall = 2, orb = 3}
|
||||
|
||||
|
@ -16,6 +18,9 @@ local last_key_pressed = nil
|
|||
local last_direction_moved = nil
|
||||
local move_repeat_counter = nil
|
||||
|
||||
local gamemodes = {normal = 0, won = 1}
|
||||
local game_mode = gamemodes.normal
|
||||
|
||||
-- ------------------------------------------------------------------
|
||||
-- Cavern generation
|
||||
-- ------------------------------------------------------------------
|
||||
|
@ -383,6 +388,11 @@ function passable(x, y)
|
|||
return cavern[x][y] == tiletypes.empty or cavern[x][y] == tiletypes.orb
|
||||
end
|
||||
|
||||
function collidedPlayerOrb()
|
||||
local body_x, body_y = getBodyLocation()
|
||||
return cavern[player_x][player_y] == tiletypes.orb or cavern[body_x][body_y] == tiletypes.orb
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------
|
||||
-- Player helper functions
|
||||
-- ------------------------------------------------------------------
|
||||
|
@ -535,6 +545,8 @@ end
|
|||
-- Gameloop functions
|
||||
-- ------------------------------------------------------------------
|
||||
function newGame()
|
||||
game_mode = gamemodes.normal
|
||||
|
||||
generateCavern()
|
||||
|
||||
spawnPlayer()
|
||||
|
@ -542,20 +554,30 @@ function newGame()
|
|||
|
||||
generateVisibilityMap()
|
||||
initializeRememberedCavern()
|
||||
|
||||
if collidedPlayerOrb() then
|
||||
game_mode = gamemodes.won
|
||||
end
|
||||
end
|
||||
|
||||
function step(direction)
|
||||
if last_direction_moved == direction then
|
||||
-- Repeat faster after the initial threshold for repetition has been met
|
||||
move_repeat_counter = 0.1
|
||||
else
|
||||
last_direction_moved = direction
|
||||
move_repeat_counter = 0.3
|
||||
end
|
||||
if game_mode == gamemodes.normal then
|
||||
if last_direction_moved == direction then
|
||||
-- Repeat faster after the initial threshold for repetition has been met
|
||||
move_repeat_counter = 0.1
|
||||
else
|
||||
last_direction_moved = direction
|
||||
move_repeat_counter = 0.3
|
||||
end
|
||||
|
||||
rememberVisible()
|
||||
movePlayer(direction)
|
||||
generateVisibilityMap()
|
||||
rememberVisible()
|
||||
movePlayer(direction)
|
||||
generateVisibilityMap()
|
||||
|
||||
if collidedPlayerOrb() then
|
||||
game_mode = gamemodes.won
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------
|
||||
|
@ -599,6 +621,8 @@ function love.keypressed(key)
|
|||
step(directions.upright)
|
||||
elseif key == 'q' then
|
||||
love.event.quit()
|
||||
elseif key == 'printscreen' then
|
||||
debug = true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -619,7 +643,7 @@ function love.draw()
|
|||
for tile_y, visible in ipairs(list) do
|
||||
local y = (tile_y - 1) * y_scale
|
||||
|
||||
if visible then
|
||||
if visible or debug then
|
||||
tile = cavern[tile_x][tile_y]
|
||||
|
||||
if tile == tiletypes.empty then
|
||||
|
|
Loading…
Reference in New Issue