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