[Help] Procedural Dungeon Generator

This forum is currently in read-only mode.
0 favourites
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Alright, so I have some experience with procedural dungeon generators and I figured this would make an excellent starting point for a Construct project. My problem is I'm still learning the interface and I don't know a lot of the built-in variables. I'll update this thread with questions as they arise instead of making new ones, but for now let's handle it one at a time.

    I have two 32x32 tiles (to signify a wall and a floor) and I'm trying to fill the room with wall tiles to start. In the Event Sheet Editor I set a CurX and CurY variable, then I'm attempting to loop a number of times equal to the width and height of the room divided by 32. I can't figure out how to get the loop to run according to the size of the room. I've tried "Width / 32" as a parameter, but that didn't work.

    After I determine the width and height of the room, I will increase CurX or CurY accordingly and place a tile at CurX * 32, CurY * 32 for each iteration.

    EDIT: ehh, I made some progress using 'layoutwidth' and 'layoutheight' as the parameters for the number of iterations. I'm not sure if those are correct, though. I also cannot figure out how to nest the loops for the life of me.

  • this is how I'd fill the display with wall tiles

  • Does the LoopIndex start at 0 or 1? Thanks for the help, though, this did work.

    EDIT: I'm still playing around. I've set up a variable to be either 0 or 1 and I'd like to create either a Tile1 or Tile2 object depending, how do I do this within the loop?

  • yeah the loop starts with 1 which is why I put a -1 in the positioning thing so that I could get it to 0.

    Not sure what you mean exactly in the edit, but if you want to create 2 types I guess you could do it this way

    <img src="http://files.getdropbox.com/u/1024727/images/imageslkjd.png">

  • At least to me, using the Array object would make things clearer. Arrays have the For Each element condition you can use to cycle through them and do whatever you like. You can check the values with the Array.CurrentX and CurrentY expressions.

    So to make your map filled with walls, you'd use something like this:

    For Each element -> Array: Set index (Array.CurrentX, Array.CurrentY) to 1
    [/code:2r9c38bf]
    
    And to draw your tiles:
    [code:2r9c38bf]
    For Each element
    [ul]
    	[li]> Value at (Array.CurrentX, Array.CurrentY) equal to 1[/li]
    	[li]> -> Create Wall at (Array.CurrentX * 32, Array.CurrentY * 32)[/li]
    [/ul][/code:2r9c38bf]
    
    Note that Arrays range from 1 to whatever you specify in their properties.
    So there's no element [0,0] etc.
    
    Edit: Made a lil' example: [url]http://files.getdropbox.com/u/1496418/MapArray.cap[/url]
  • thats a fair awesome aproach eyeguy

  • thats a fair awesome aproach eyeguy

    Hehe, thanks. It's just something I happened to be working on.

  • At least to me, using the Array object would make things clearer. Arrays have the For Each element condition you can use to cycle through them and do whatever you like. You can check the values with the Array.CurrentX and CurrentY expressions.

    So to make your map filled with walls, you'd use something like this:

    > For Each element -> Array: Set index (Array.CurrentX, Array.CurrentY) to 1
    [/code:13p4ykug]
    
    And to draw your tiles:
    [code:13p4ykug]
    For Each element
     -> Value at (Array.CurrentX, Array.CurrentY) equal to 1
     -> -> Create Wall at (Array.CurrentX * 32, Array.CurrentY * 32)
    
    [/code:13p4ykug]
    
    Note that Arrays range from 1 to whatever you specify in their properties.
    So there's no element [0,0] etc.
    
    Edit: Made a lil' example: [url]http://files.getdropbox.com/u/1496418/MapArray.cap[/url]
    

    I've actually already gone ahead and done that, although I've run into a problem. I seem to have a memory leak or infinite loop because it starts using up 500+mb of ram fairly quickly. Does the For Each event continue to run over and over?

    Also I tried looking at your example, but it said that it was made using a newer version (despite the fact I have the newest stable release).

    Edit: Using the Run Once condition for the For Each element condition seems to have stopped the memory usage from climbing leading me to believe my speculation about it continually running is correct. However I still notice that, despite the program isn't doing anything particular, CPU usage is 40% (E8200, 2.66Ghz Core2Duo) and it is using about 130mb of RAM (this is steady now that I have fixed the previous issue). These numbers seem very high considering it is idling.

    Edit2: *image removed, I changed the Sampling from Linear to Point and this dropped CPU usage to 5-6% and only 13mb of ram. When I change it back to Linear is uses a constant 40-50% CPU and 130mb of ram, again, despite the program not doing anything? This seems very odd. GPU is an 8800GT.

  • Also I tried looking at your example, but it said that it was made using a newer version (despite the fact I have the newest stable release).

    Yeah I just realized I made the example on 0.99.4 (an unstable build). I cba to redo it on another version so I'll just post pics of it instead

    http://www.hdimage.org/images/8rok494gcu7b6uczl03.png

    http://www.hdimage.org/images/vbxzi1ehghw80ybzml1.png

    (My pictures are always too big!)

    I changed the Sampling from Linear to Point and this dropped CPU usage to 5-6% and only 13mb of ram. When I change it back to Linear is uses a constant 40-50% CPU and 130mb of ram, again, despite the program not doing anything? This seems very odd. GPU is an 8800GT.

    I'm not sure what's causing this on your end. The example I posted uses linear sampling and it's not really using much resources at all on my end. I have a 8800GTS.

  • Here's what I currently have:

    Code

    http://pub.gamingw.net/39880/procgen1.jpg

    Output

    http://pub.gamingw.net/39880/procgen2.jpg

    I don't get it!

    I've tried using DungeonArray.SizeX and SizeY to determine the outer edge, but that has no effect.

  • I don't mean to bump unnecessarily, but I still haven't figured this out and I can't move forward without it. I could rewrite it to fit into the previous example, but I'm looking to learn and I've either misunderstood a function or cannot see the error in my logic.

    Halp plox

  • what are you doing with that global variable "edge"?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • what are you doing with that global variable "edge"?

    I was using it as an ELSE switch, because ELSE didn't seem to work and I was advised it wasn't functioning properly and might not work with all those ORs.

  • Ah, ha! Another peculiar find! (I am not having much luck with Construct at all)

    Here is an updated version of what I have: http://pub.gamingw.net/39880/construct.jpg

    Now, I still can't see what I've done wrong with my logic, but I've noticed something off. We can ignore the GenerateMap function, because I've disabled it at the startup for testing purposes.

    So the layout is clean and the entire array should be null save for the one tile at (3, 1) that I instruct to be turned on and set as a wall. But the output is this:

    <img src="http://pub.gamingw.net/39880/construct2.jpg">

    Where the hell is (1, 1) coming from? That should be null. Nothing is setting that value to 0. Unless this is some hidden aspect of arrays and there needs to be at least one value or something, but I doubt this because even when I turn GenerateMap back on (1, 1) is still always a wall tile no matter how many maps I generate.

    I don't understand what is going on with this program. CPU usage is seemingly high still, and I cannot see where I have erred in my logic (see previous posts for an overview of what it should be doing). Sorry if I come off as a bit angry, but I'm just getting really frustrated. I hear Construct is supposed to do all these wonderful things even in beta (maybe it can and I am just wrong somewhere), but I can't even get what I consider BASIC things to work.

  • [quote:2vn3opxt]Unless this is some hidden aspect of arrays and there needs to be at least one value or something

    Why wouldn't the beginning of the array be 0?

    You need to either fill the array, or use a different value for on/off.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)