Dungeon Explorer [Pre-Alpha 0.8]

Show off your games, demos and other (playable) creations.
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Dungeon Explorer [Pre-Alpha 0.8]

Post by substitute541 »

Original Post:
A dungeon generator demo that I made for my game.
-- Attachment was deleted accidentally while editing the post ._.
Edit: The actual code:

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
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:
  • Health, EXP, and Levels system
  • Dungeon Generator (procedurally generated)
  • Map system
  • Basic Lighting System
  • A cool menu (first time using particle effects so yeah)
Libraries/Snippets that I used: Upcoming features:
  • Monsters
  • A storyline
  • Shops n' stuff
  • etc.
Bugs that need fixing:
  • 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)
Download:
Pre-Alpha 0.8 -- Sounds + other small things
Pre-Alpha 0.7 -- More tiles + Character image :D
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
Last edited by substitute541 on Thu Jul 18, 2013 7:12 am, edited 24 times in total.
Currently designing themes for WordPress.

Sometimes lurks around the forum.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Dungeon Generator

Post by micha »

I have a small suggestion.

I got this image.
dungeon.png
dungeon.png (6.12 KiB) Viewed 3673 times
In the lower left corner, it is difficult to say, if this is a grid of vertical and horizontal hallways of a large room. If you use this kind of visualization in your game, I suggest you fill the rooms with a gray color. Maybe you find this helpful.
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: Dungeon Generator

Post by jjmafiae »

substitute541 wrote:A dungeon generator demo that I made for my game.
dungeon generator test.love
looks cool :ultraglee:, will this be used for any projects or just another test game?
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: Dungeon Generator

Post by substitute541 »

jjmafiae wrote:
substitute541 wrote:A dungeon generator demo that I made for my game.
dungeon generator test.love
looks cool :ultraglee:, will this be used for any projects or just another test game?
It will be used for a project of mine. You can also go ahead and take a peek of the code (VERY messy tbh) if you want to.
Currently designing themes for WordPress.

Sometimes lurks around the forum.
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: Dungeon Generator

Post by jjmafiae »

substitute541 wrote:
jjmafiae wrote:
substitute541 wrote:A dungeon generator demo that I made for my game.
dungeon generator test.love
looks cool :ultraglee:, will this be used for any projects or just another test game?
It will be used for a project of mine. You can also go ahead and take a peek of the code (VERY messy tbh) if you want to.
i dont want to look at your code i just wanted to make sure this is getting used for a project
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: Dungeon Explorer [in dev]

Post by substitute541 »

Updated Original Post...
Currently designing themes for WordPress.

Sometimes lurks around the forum.
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: Dungeon Explorer [in dev]

Post by Davidobot »

substitute541 wrote:Updated Original Post...
Looks awesome! :D
Does the dungeon generate in the begining of the game or does it generate as you explore?
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: Dungeon Explorer [in dev]

Post by substitute541 »

Davidobot wrote:
substitute541 wrote:Updated Original Post...
Looks awesome! :D
Does the dungeon generate in the begining of the game or does it generate as you explore?
It generates at the beginning of the game. The map's size is 40x40 so you can't just go ahead and go explore real far. The way you go to the next floor in a dungeon is using the ladders (not implemented yet), somewhat like the Pokemon Mystery Dungeon series. :3
Currently designing themes for WordPress.

Sometimes lurks around the forum.
User avatar
NightKawata
Party member
Posts: 294
Joined: Tue Jan 01, 2013 9:18 pm
Location: Cyberspace, Room 6502
Contact:

Re: Dungeon Explorer [Pre-Alpha 0.5]

Post by NightKawata »

damn it 800 height screens (or anything > 768)
is there a close key that I'm trying to look for that I can't find?
"I view Python for game usage about the same as going fishing with a stick of dynamite. It will do the job but it's big, noisy, you'll probably get soaking wet and you've still got to get the damn fish out of the water." -taylor
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: Dungeon Explorer [Pre-Alpha 0.5]

Post by substitute541 »

NightKawata wrote:damn it 800 height screens (or anything > 768)
is there a close key that I'm trying to look for that I can't find?
Haven't implemented that yet, sorry D:

edit: Now implemented in 0.5.1
Currently designing themes for WordPress.

Sometimes lurks around the forum.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests