Dungeon Explorer [Pre-Alpha 0.8]
Posted: Tue Jul 02, 2013 9:26 am
Original Post:
New Stuff comes here
---------------------------------------------------------------------------------
This is a game I have been working on since last month called Dungeon Explorer. It's currently in development but here are the features:
Pre-Alpha 0.8 -- Sounds + other small things
Pre-Alpha 0.7 -- More tiles + Character image
Pre Alpha 0.6.1 -- More tiles.
Pre-Alpha 0.6 -- Bugfix. See above.
Pre-Alpha 0.5.1 -- Menu updates and ability to quit game by pressing the escape key.
Pre-Alpha 0.5
Edit: The actual code:A dungeon generator demo that I made for my game.
-- Attachment was deleted accidentally while editing the post ._.
Code: Select all
-- Very messy and unoptimized.
function generateMap(n, chance, maxcorridorlength)
local map = {}
for x=1, grid_width do
map[x] = {}
for y=1, grid_height do
map[x][y] = "e"
end
end
-- create a 5x5 center room
createRoom(map, math.floor(grid_width/2 - math.random()*2.5), math.floor(grid_height/2 - math.random()*2.5), 5, 5)
local numFeatures = 0
while numFeatures < n do
-- pick a wall by selecting a random node until it finds one with a room beside it
local wnode = {}
local anode = {}
while true do
wnode.x = math.floor(math.random()*(grid_width-2))+2
wnode.y = math.floor(math.random()*(grid_height-2))+2
if map[wnode.x-1][wnode.y] == "a" and
map[wnode.x+1][wnode.y] ~= "a" and
map[wnode.x][wnode.y-1] ~= "a" and
map[wnode.x][wnode.y+1] ~= "a" then
anode.x = wnode.x-1
anode.y = wnode.y
break
elseif map[wnode.x+1][wnode.y] == "a" and
map[wnode.x-1][wnode.y] ~= "a" and
map[wnode.x][wnode.y+1] ~= "a" and
map[wnode.x][wnode.y-1] ~= "a" then
anode.x = wnode.x+1
anode.y = wnode.y
break
elseif map[wnode.x][wnode.y-1] == "a" and
map[wnode.x-1][wnode.y] ~= "a" and
map[wnode.x+1][wnode.y] ~= "a" and
map[wnode.x][wnode.y+1] ~= "a" then
anode.x = wnode.x
anode.y = wnode.y-1
break
elseif map[wnode.x][wnode.y+1] == "a" and
map[wnode.x-1][wnode.y] ~= "a" and
map[wnode.x+1][wnode.y] ~= "a" and
map[wnode.x][wnode.y-1] ~= "a" then
anode.x = wnode.x
anode.y = wnode.y+1
break
end
end
local dirX = wnode.x - anode.x
local dirY = wnode.y - anode.y
-- select a random feature
local feature = "corridor"
if math.random() < chance then -- 25% chance that it will generate a room
feature = "room"
end
-- if the feature is a corridor
if feature == "corridor" then
-- select a random length
local length = math.floor(math.random()*maxcorridorlength+2)
-- scan all the sides to check if there is space
local vacant = true
for i=1, length do
local _x = wnode.x+dirX*(i-1)
local _y = wnode.y+dirY*(i-1)
if _x < grid_width and
_x > 0 and
_y < grid_height and
_y > 0 then
if map[_x][_y] == "a" or
map[_x+(1-math.abs(dirX))][_y+(1-math.abs(dirY))] == "a" or
map[_x-(1-math.abs(dirX))][_y-(1-math.abs(dirY))] == "a" then
vacant = false
end
end
end
-- generate corridor
if vacant then
for i=1, length do
local _x = wnode.x+dirX*(i-1)
local _y = wnode.y+dirY*(i-1)
if _x < grid_width and
_x > 0 and
_y < grid_height and
_y > 0 then
map[_x][_y] = "a"
end
end
numFeatures = numFeatures + 1
end
elseif feature == "room" then -- if the feature is a room
-- select a random width and height
local width = math.floor(math.random()*4+4)
local height = math.floor(math.random()*4+4)
-- position based on locations of a wall node and direction
local xPos = wnode.x + math.floor(dirX*width/2) - 2*dirX
local yPos = wnode.y + math.floor(dirY*height/2) - 2*dirY
-- check if there is vacant space
local vacant = true
if xPos + width > grid_width or
yPos + height > grid_height or
xPos < 1 or
yPos < 1 then
vacant = false
end
if vacant then
for i=1, width do
for j=1, height do
if map[xPos+(i-1)][yPos+(j-1)] == "a" then
vacant = false
end
end
end
end
-- generate room
if vacant then
map[wnode.x][wnode.y] = "a"
map[anode.x][anode.y] = "a"
for i=1, width do
for j=1, height do
map[xPos+(i-1)][yPos+(j-1)] = "a"
end
end
numFeatures = numFeatures + 1
end
end
end
-- Create a staircase to the boss room
while true do
local bn = {}
bn.x = math.floor((1-math.sin(math.random()*math.pi))*(grid_width-2))+2 -- The calculation for the random
bn.y = math.floor((1-math.sin(math.random()*math.pi))*(grid_height-2))+2 -- number ensures that it generates
if map[bn.x][bn.y] == "a" and -- the stair near the edge of the map
map[bn.x-1][bn.y] == "a" and
map[bn.x+1][bn.y] == "a" and
map[bn.x][bn.y-1] == "a" and
map[bn.x][bn.y+1] == "a" and
map[bn.x-1][bn.y+1] == "a" and
map[bn.x-1][bn.y-1] == "a" and
map[bn.x+1][bn.y+1] == "a" and
map[bn.x+1][bn.y-1] == "a" then
map[bn.x][bn.y] = "b"
break
end
end
return map
end
function createRoom(map, x, y, width, height)
for i=1, width do
for j=1, height do
map[x+(i-1)][y+(j-1)] = "a"
end
end
end
---------------------------------------------------------------------------------
This is a game I have been working on since last month called Dungeon Explorer. It's currently in development but here are the features:
- Health, EXP, and Levels system
- Dungeon Generator (procedurally generated)
- Map system
- Basic Lighting System
- A cool menu (first time using particle effects so yeah)
- Monsters
- A storyline
- Shops n' stuff
- etc.
-
Sometimes getting stuck when moving near the top-left, top-right, or bottom-left corners.Fixed in Pre-Alpha 0.6 (reason was because of inaccuracies of the trig functions)
Pre-Alpha 0.8 -- Sounds + other small things
Pre-Alpha 0.7 -- More tiles + Character image
Pre Alpha 0.6.1 -- More tiles.
Pre-Alpha 0.6 -- Bugfix. See above.
Pre-Alpha 0.5.1 -- Menu updates and ability to quit game by pressing the escape key.
Pre-Alpha 0.5