Art - Finished Dung - The Dungeon Generator (Read 812 times)

  • Avatar of goldenratio
  • now das fresh
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Member
  • Joined: Jun 27, 2002
  • Posts: 4550
Dung - The Dungeon Generator
Collect the treasure and escape the dungeon, if you can!


So here's a thing I did in Python using pygame. The core is a random dungeon generator, which at this point is very simple, but that is the piece I actually set out to write, and the "game" I built around it is really only there so there's something to DO with the dungeon. I find it briefly yet strangely enthralling.

This is my first test using py2exe, and it was a bitch to finally get working, but it will run on my computer. Hopefully it will work for you, but if it doesn't let me know so I can fiddle until it finally gets right. I had to include a bunch of DLLs for pygame, which together is only 1mb, but I also had to include all my resources. I can't get the damn thing to compile it ALL into the EXE. If anybody knows, help me out.


So anyways, I was just hoping you could maybe play it for a bit, and assuming it works check out the random dungeons. It's not very random at this point, and you may be able to see what I'm doing, but I plan on improving it, hopefully with some input.

If anybody is interested in my methods or wants to see source code, let me know. I'm not trying to keep it secret.



Download Link
Direct Mirror - Thanks Tomato!
Download Source - requires Python 2.6 and pygame

download size: 6.5mb

sorry its the only place i know to upload stuff. I can upload it anywhere if you want me to.
Last Edit: August 13, 2009, 04:59:23 am by Gabriel
yes coulombs are "germaine", did you learn that word at talk like a dick school?
  • Avatar of Sludgelord
  • Who's the boss? Not you, bitch.
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Premium Member
  • Joined: Jan 28, 2004
  • Posts: 5571
i will be checking this out in a little bit pal. i like the name.
Barkley, Shut Up and Jam: Gaiden
  • *untis* *untis* ^
  • PipPip
  • Group: Member
  • Joined: Feb 11, 2008
  • Posts: 247
Are you the first of about 4 people to finish this, or just the first to release it? I thought there was a race or something going on. :welp:
How about no!? You are an idiotic version of a baboon.
  • Avatar of goldenratio
  • now das fresh
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Member
  • Joined: Jun 27, 2002
  • Posts: 4550
what are you talking about? i just made this for fun.
Last Edit: August 12, 2009, 02:02:53 am by Gabriel
yes coulombs are "germaine", did you learn that word at talk like a dick school?
  • Avatar of unusualgamer
  • I'M ON TV, I'M ON TV!!!!
  • PipPipPipPipPip
  • Group: Premium Member
  • Joined: Aug 3, 2002
  • Posts: 760
cool I downloaded this, will try it soon.
  • None of them knew they were robots.
  • PipPipPipPipPipPipPipPipPip
  • Group: Premium Member
  • Joined: Nov 5, 2006
  • Posts: 3242
It works can you post the source? I'm curious about the algorithm can you describe what it does before posting the sauce?
Play Raimond Ex (if you haven't already)


I'll not TAKE ANYTHING you write like this seriously because it looks dumb
  • Avatar of goldenratio
  • now das fresh
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Member
  • Joined: Jun 27, 2002
  • Posts: 4550
Sure.

Basically I call the dungeon generator with the rows, columns, rooms ("features"), and "specials". I create a list of lists of ints, all 0. The values I use are:

0: can't walk
1: can walk
2: start
3: exit
4: "special" (item)

So I have a grid of values, and I just create the specified number of "features" (which are random rectangles, between 2 and 6 units wide/tall). As I am creating features, I keep track of which features are the farthest apart. This is where I'll place the start and end points.

After I create all the features, I go through each one like a linked list, and conect each one together (using a very simple "go x cells over, and y cells up/down (actually this is random, and will either go x/y or y/x, just to give it some randomness)")

Then I place the start and end points (in the farthest apart rooms, just so you dont randomly spawn right next to the exit. although this wouldn't be so bad, since you have to collect the treasure first. I did this part before I had items at all.)

At the very end I just pick random open spaces, and make them items.

This is just the dungeon generator part (I tried to make it reusable so this class only generates the grid of numbers). My "World" class then actually creates all the "game" related stuff.

http://snipplr.com/view/18189/random-dungeon-generator/
yes coulombs are "germaine", did you learn that word at talk like a dick school?
  • Avatar of the bloddy ghost
  • ::pulls another Hideo Kojima::
  • PipPipPipPipPipPipPip
  • Group: Premium Member
  • Joined: Mar 25, 2003
  • Posts: 1050
This looks like DUNG compared to my generator. nice try..... why dont  u just let the pros do it kid?
has a girl in his bed. pot in his pipe and family guy on the tube. i like life
  • Avatar of goldenratio
  • now das fresh
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Member
  • Joined: Jun 27, 2002
  • Posts: 4550
i dont care about the naysayers. i think my game is good and thats all that matters so you can take it somewhere else :P
yes coulombs are "germaine", did you learn that word at talk like a dick school?
  • Avatar of the bloddy ghost
  • ::pulls another Hideo Kojima::
  • PipPipPipPipPipPipPip
  • Group: Premium Member
  • Joined: Mar 25, 2003
  • Posts: 1050
in all seriousness, your source code is 3000 times easier to understand than mine. so good job dude! if pygame is faster than ika, i might switch over to it.
has a girl in his bed. pot in his pipe and family guy on the tube. i like life
  • Avatar of goldenratio
  • now das fresh
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Member
  • Joined: Jun 27, 2002
  • Posts: 4550
let me see yours!

this is like the 6th iteration. Early on, I was trying to just move forward in random directions, but it was way complex and didn't work at all. I made it simpler and simpler each time, and this is my end result. I tried to be as "pythonic" as I knew how, and in the spirit of python tried to do everything as simple as possible.
yes coulombs are "germaine", did you learn that word at talk like a dick school?
  • Avatar of the bloddy ghost
  • ::pulls another Hideo Kojima::
  • PipPipPipPipPipPipPip
  • Group: Premium Member
  • Joined: Mar 25, 2003
  • Posts: 1050
http://templeofskulls.tomatopia.com/game/Sandbox%202.7z

and here's a mirror for your game: http://templeofskulls.tomatopia.com/game/dung%20-%20the%20dungeon%20generator.zip.

Last Edit: August 12, 2009, 03:07:05 am by Tomato
has a girl in his bed. pot in his pipe and family guy on the tube. i like life
  • Avatar of goldenratio
  • now das fresh
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Member
  • Joined: Jun 27, 2002
  • Posts: 4550
i see your section for "check to make sure rooms don't overlap" code isn't there, just like mine :)
yes coulombs are "germaine", did you learn that word at talk like a dick school?
  • Avatar of the bloddy ghost
  • ::pulls another Hideo Kojima::
  • PipPipPipPipPipPipPip
  • Group: Premium Member
  • Joined: Mar 25, 2003
  • Posts: 1050
hmm?? uh, it should be there! I just forget to update the comments.

def abletogen(self,ch_sx, ch_sy, ch_w, ch_h):
    check = 1
    global points
    for check_w in range(ch_w):
    for check_h in range(ch_h):
    if self.map[ch_sx+check_w][ch_sy+check_h] > 0:
    check = 0
    for check_w in range(ch_w):
    for check_h in range(ch_h):
    if self.map[ch_sx-check_w][ch_sy-check_h] > 0:
    check = 0
        return check
has a girl in his bed. pot in his pipe and family guy on the tube. i like life
  • Avatar of goldenratio
  • now das fresh
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Member
  • Joined: Jun 27, 2002
  • Posts: 4550
i must have been looking in another place. nevermind.

Also here is the full source for my game. You need python 2.6 and pygame. I've never used ika but i've looked at it quite a bit. ika basically just has all the boilerplate rendering/update loop/common stuff for you. Not sure if its faster, as I would imagine the ika code should be pretty optimized and not get in the way, but you do get more control with pygame, even if you have to set up all that rendering shit (although as you can see from my 'dung.py' (the main script) there's not much in the way of rendering/boilerplate code.

Run dung.py like

python dung.py

http://sharebee.com/65c381c6
Last Edit: August 12, 2009, 05:25:05 am by Gabriel
yes coulombs are "germaine", did you learn that word at talk like a dick school?
  • Avatar of Ciox
  • Buttshit.
  • Group: Member
  • Joined: May 21, 2009
  • Posts: 55
I love random generation and this is pretty good, the smooth movement is so soothing..
You might want to add something so that you don't have to perfectly dock with corridors, so if you're a bit misaligned it nudges you in and you can go down the corridor.
Can't think of anything else since there isn't much to do.


I tried to run yours Tomato but it asked for like a zillion extra dlls and I kinda stopped when I couldn't find python25.dll on the net.
valves industrial valves tanks and valves valves and ball valves excess flow valves control valves valves industrial solenoid valves quality valves expansion valves check valves gas valves automatic drain valves gate valves air valves relief valves
  • Avatar of goldenratio
  • now das fresh
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Member
  • Joined: Jun 27, 2002
  • Posts: 4550
Cool thanks man. I made the collision boxes for the player smaller when testing with walls, and  larger when testing with treasure. Maybe I need to make it a few more pixels smaller.
Last Edit: August 12, 2009, 05:48:01 am by Gabriel
yes coulombs are "germaine", did you learn that word at talk like a dick school?
  • Avatar of unusualgamer
  • I'M ON TV, I'M ON TV!!!!
  • PipPipPipPipPip
  • Group: Premium Member
  • Joined: Aug 3, 2002
  • Posts: 760
I noticed that too; when I approach the 'treasure' I didn't have to be exactly near it to grab it, but for passages I had to be exactly lined up to get through them. Not really a big deal.

I liked the simplicity of it. The random generator worked great. Movement was as smooth as butter.

Overall excellent work.
  • Avatar of the bloddy ghost
  • ::pulls another Hideo Kojima::
  • PipPipPipPipPipPipPip
  • Group: Premium Member
  • Joined: Mar 25, 2003
  • Posts: 1050
Yeah, the movement was really smooth. i might have to put something like that into my game.
has a girl in his bed. pot in his pipe and family guy on the tube. i like life
  • Avatar of unusualgamer
  • I'M ON TV, I'M ON TV!!!!
  • PipPipPipPipPip
  • Group: Premium Member
  • Joined: Aug 3, 2002
  • Posts: 760
Alright, so I found a gripe.

The text gets in the way of the 'treasures' and 'exits' sometimes. It's not really a big deal, but if I were you I would make the instructions text at the bottom disappear over time, and probably put the alert text at the top of the screen in its own HUD.