Treat orb as passable
This commit is contained in:
parent
e79fdc5c9b
commit
f72520689a
|
@ -123,16 +123,16 @@ function spawnPlayer()
|
|||
player_y = spawn_y
|
||||
|
||||
-- Check what direction we can spawn the player
|
||||
if cavern[player_x][player_y + 1] == tiletypes.empty then
|
||||
if passable(player_x, player_y + 1) then
|
||||
-- There's space under, spawn facing up
|
||||
player_direction = directions.up
|
||||
elseif cavern[player_x + 1][player_y] == tiletypes.empty then
|
||||
elseif passable(player_x + 1, player_y) then
|
||||
-- There's space to the right, spawn facing left
|
||||
player_direction = directions.left
|
||||
elseif cavern[player_x - 1][player_y] == tiletypes.empty then
|
||||
elseif passable(player_x - 1, player_y) then
|
||||
-- There's space to the left, spawn facing right
|
||||
player_direction = directions.right
|
||||
elseif cavern[player_x][player_y - 1] == tiletypes.empty then
|
||||
elseif passable(player_x, player_y - 1) then
|
||||
-- There's space above, spawn facing down
|
||||
player_direction = directions.down
|
||||
else
|
||||
|
@ -147,7 +147,7 @@ function spawnOrb()
|
|||
repeat
|
||||
orb_x = math.random(2, cavern.width - 1)
|
||||
orb_y = math.random(2, cavern.height - 1)
|
||||
until cavern[orb_x][orb_y] == tiletypes.empty
|
||||
until passable(orb_x, orb_y)
|
||||
|
||||
cavern[orb_x][orb_y] = tiletypes.orb
|
||||
end
|
||||
|
@ -270,22 +270,22 @@ function stepVisibilityMapGeneration(queue)
|
|||
for i, item in ipairs(queue) do
|
||||
if item.direction == directions.up then
|
||||
visibility_map[item.x][item.y] = true
|
||||
if cavern[item.x][item.y] == tiletypes.empty then
|
||||
if passable(item.x, item.y) then
|
||||
table.insert(new_queue, {x = item.x, y = item.y - 1, direction = directions.up})
|
||||
end
|
||||
elseif item.direction == directions.left then
|
||||
visibility_map[item.x][item.y] = true
|
||||
if cavern[item.x][item.y] == tiletypes.empty then
|
||||
if passable(item.x, item.y) then
|
||||
table.insert(new_queue, {x = item.x - 1, y = item.y, direction = directions.left})
|
||||
end
|
||||
elseif item.direction == directions.down then
|
||||
visibility_map[item.x][item.y] = true
|
||||
if cavern[item.x][item.y] == tiletypes.empty then
|
||||
if passable(item.x, item.y) then
|
||||
table.insert(new_queue, {x = item.x, y = item.y + 1, direction = directions.down})
|
||||
end
|
||||
elseif item.direction == directions.right then
|
||||
visibility_map[item.x][item.y] = true
|
||||
if cavern[item.x][item.y] == tiletypes.empty then
|
||||
if passable(item.x, item.y) then
|
||||
table.insert(new_queue, {x = item.x + 1, y = item.y, direction = directions.right})
|
||||
end
|
||||
elseif item.direction == directions.upleft then
|
||||
|
@ -301,9 +301,9 @@ function stepVisibilityMapGeneration(queue)
|
|||
-- it is not. We can therefore check whether the movement is valid
|
||||
-- by testing if either the cell to our right or below us (the
|
||||
-- directions opposite to the ones in an up.left movement) is empty
|
||||
if cavern[item.x + 1][item.y] == tiletypes.empty or cavern[item.x][item.y + 1] == tiletypes.empty then
|
||||
if passable(item.x + 1, item.y) or passable(item.x, item.y + 1) then
|
||||
visibility_map[item.x][item.y] = true
|
||||
if cavern[item.x][item.y] == tiletypes.empty then
|
||||
if passable(item.x, item.y) then
|
||||
-- ⌜^
|
||||
-- ⌜ <x
|
||||
table.insert(new_queue, {x = item.x - 1, y = item.y - 1, direction = directions.upleft})
|
||||
|
@ -313,9 +313,9 @@ function stepVisibilityMapGeneration(queue)
|
|||
end
|
||||
elseif item.direction == directions.downleft then
|
||||
-- See under item.direction == directions.upleft
|
||||
if cavern[item.x + 1][item.y] == tiletypes.empty or cavern[item.x][item.y - 1] == tiletypes.empty then
|
||||
if passable(item.x + 1, item.y) or passable(item.x, item.y - 1) then
|
||||
visibility_map[item.x][item.y] = true
|
||||
if cavern[item.x][item.y] == tiletypes.empty then
|
||||
if passable(item.x, item.y) then
|
||||
-- ⌞ <x
|
||||
-- ⌞v
|
||||
table.insert(new_queue, {x = item.x - 1, y = item.y, direction = directions.left})
|
||||
|
@ -325,9 +325,9 @@ function stepVisibilityMapGeneration(queue)
|
|||
end
|
||||
elseif item.direction == directions.downright then
|
||||
-- See under item.direction == directions.upleft
|
||||
if cavern[item.x - 1][item.y] == tiletypes.empty or cavern[item.x][item.y - 1] == tiletypes.empty then
|
||||
if passable(item.x - 1, item.y) or passable(item.x, item.y - 1) then
|
||||
visibility_map[item.x][item.y] = true
|
||||
if cavern[item.x][item.y] == tiletypes.empty then
|
||||
if passable(item.x, item.y) then
|
||||
-- ⌟ x>
|
||||
-- v⌟
|
||||
table.insert(new_queue, {x = item.x + 1, y = item.y, direction = directions.right})
|
||||
|
@ -337,9 +337,9 @@ function stepVisibilityMapGeneration(queue)
|
|||
end
|
||||
elseif item.direction == directions.upright then
|
||||
-- See under item.direction == directions.upleft
|
||||
if cavern[item.x - 1][item.y] == tiletypes.empty or cavern[item.x][item.y + 1] == tiletypes.empty then
|
||||
if passable(item.x - 1, item.y) or passable(item.x, item.y + 1) then
|
||||
visibility_map[item.x][item.y] = true
|
||||
if cavern[item.x][item.y] == tiletypes.empty then
|
||||
if passable(item.x, item.y) then
|
||||
-- ^⌝
|
||||
-- ⌝ x>
|
||||
table.insert(new_queue, {x = item.x, y = item.y - 1, direction = directions.up})
|
||||
|
@ -376,6 +376,13 @@ function rememberVisible()
|
|||
end
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------
|
||||
-- Collision
|
||||
-- ------------------------------------------------------------------
|
||||
function passable(x, y)
|
||||
return cavern[x][y] == tiletypes.empty or cavern[x][y] == tiletypes.orb
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------
|
||||
-- Player helper functions
|
||||
-- ------------------------------------------------------------------
|
||||
|
@ -517,8 +524,7 @@ function movePlayer(direction)
|
|||
|
||||
local body_x, body_y = getBodyLocation(player_x + dx, player_y + dy, new_direction)
|
||||
|
||||
if cavern[player_x + dx][player_y + dy] == tiletypes.empty and
|
||||
cavern[body_x][body_y] == tiletypes.empty then
|
||||
if passable(player_x + dx, player_y + dy) and passable(body_x, body_y) then
|
||||
player_x = player_x + dx
|
||||
player_y = player_y + dy
|
||||
player_direction = new_direction
|
||||
|
|
Loading…
Reference in New Issue