Finish autoexplore

This commit is contained in:
Juhani Krekelä 2019-06-30 18:37:12 +03:00
parent 15be546152
commit a85b6de70a
1 changed files with 44 additions and 10 deletions

View File

@ -44,8 +44,6 @@ local control_keys = {quit = 'q', restart = 'r', configure = 'c', autoexplore =
local win_image = nil
local distances = {} --debg
-- ------------------------------------------------------------------
-- Cavern generation
-- ------------------------------------------------------------------
@ -724,8 +722,7 @@ function autoexplore()
-- then each known accessible space gets labelled with min(neighbours) + 1. Once we have
-- computed that table, we can then move towards closest unknown accessible space by
-- moving to our neighbouring space with lowest score
--local distances = {}
distances = {} --debg
local distances = {}
for x = 1, cavern.width do
local list = {}
for y = 1, cavern.height do
@ -772,7 +769,49 @@ function autoexplore()
queue = new_queue
until #queue == 0
step(distances[player_x][player_y].direction)
local direction = distances[player_x][player_y].direction
local body_x, body_y = getBodyLocation()
-- If we are backing up, consider feet
if player_direction == directions.up and direction == directions.down then
direction = distances[body_x][body_y].direction
if direction == directions.left then
direction = directions.downleft
elseif direction == directions.right then
direction = directions.downright
else
direction = directions.down
end
elseif player_direction == directions.left and direction == directions.right then
direction = distances[body_x][body_y].direction
if direction == directions.up then
direction = directions.upright
elseif direction == directions.down then
direction = directions.downright
else
direction = directions.right
end
elseif player_direction == directions.down and direction == directions.up then
direction = distances[body_x][body_y].direction
if direction == directions.left then
direction = directions.upleft
elseif direction == directions.right then
direction = directions.upright
else
direction = directions.up
end
elseif player_direction == directions.right and direction == directions.left then
direction = distances[body_x][body_y].direction
if direction == directions.up then
direction = directions.upleft
elseif direction == directions.down then
direction = directions.downleft
else
direction = directions.left
end
end
step(direction)
end
-- ------------------------------------------------------------------
@ -852,11 +891,6 @@ function drawCavern()
love.graphics.setColor(1, 1, 0)
love.graphics.rectangle('fill', x + 0.5 * scale, y + 0.5 * scale, scale/2, scale/2)
end
if distances[tile_x] ~= nil and distances[tile_x][tile_y].value ~= nil then --debg
love.graphics.setColor(0.5, 0.5, 0.5) --debg
love.graphics.print(distances[tile_x][tile_y].value, x, y) --debg
end --debg
end
end
end