Finish autoexplore
This commit is contained in:
parent
15be546152
commit
a85b6de70a
|
@ -44,8 +44,6 @@ local control_keys = {quit = 'q', restart = 'r', configure = 'c', autoexplore =
|
||||||
|
|
||||||
local win_image = nil
|
local win_image = nil
|
||||||
|
|
||||||
local distances = {} --debg
|
|
||||||
|
|
||||||
-- ------------------------------------------------------------------
|
-- ------------------------------------------------------------------
|
||||||
-- Cavern generation
|
-- Cavern generation
|
||||||
-- ------------------------------------------------------------------
|
-- ------------------------------------------------------------------
|
||||||
|
@ -724,8 +722,7 @@ function autoexplore()
|
||||||
-- then each known accessible space gets labelled with min(neighbours) + 1. Once we have
|
-- 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
|
-- computed that table, we can then move towards closest unknown accessible space by
|
||||||
-- moving to our neighbouring space with lowest score
|
-- moving to our neighbouring space with lowest score
|
||||||
--local distances = {}
|
local distances = {}
|
||||||
distances = {} --debg
|
|
||||||
for x = 1, cavern.width do
|
for x = 1, cavern.width do
|
||||||
local list = {}
|
local list = {}
|
||||||
for y = 1, cavern.height do
|
for y = 1, cavern.height do
|
||||||
|
@ -772,7 +769,49 @@ function autoexplore()
|
||||||
queue = new_queue
|
queue = new_queue
|
||||||
until #queue == 0
|
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
|
end
|
||||||
|
|
||||||
-- ------------------------------------------------------------------
|
-- ------------------------------------------------------------------
|
||||||
|
@ -852,11 +891,6 @@ function drawCavern()
|
||||||
love.graphics.setColor(1, 1, 0)
|
love.graphics.setColor(1, 1, 0)
|
||||||
love.graphics.rectangle('fill', x + 0.5 * scale, y + 0.5 * scale, scale/2, scale/2)
|
love.graphics.rectangle('fill', x + 0.5 * scale, y + 0.5 * scale, scale/2, scale/2)
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue