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