Room Generator (Source Included)
BlitzMax Forums/BlitzMax Programming/Room Generator (Source Included)
| ||
UPDATE: Works now ! See bottom ! What is this ? This is an attempt to write a program to generate catacombs like you might find in a dungeon game. It is different from a standard maze maker in that there are actual rooms of varying sizes in it which do not touch each other. As it is not entirely a self-generated dungeon, it is up to the Worldbuilder to doodle simple corridors in the editor to link the rooms together as they see fit for their game. It is a piece and part of a larger project of an RPG Maker and a Wizard to assist in the game and map making process. If you find this code helpful, feel free to use it in your own projects ! Here is the code (which doesn't work, see bottom for final working model I wrote) Strict Local i,j,x,y,h,v,ok,c Local rh[50],rv[50],rx[50],ry[50],rn Graphics 640,480 SetBlend solidblend For i=0 To 99 x=Rand(3,15) y=Rand(3,15) h=Rand(0,50-x) v=Rand(0,50-y) ok=1 For j=0 To rn-1 If h>=rh[j] And v>=rv[j] And x<=rx[j] And y<=ry[j] ok=0 EndIf Next If ok=1 rh[rn]=h rv[rn]=v rx[rn]=x ry[rn]=y rn:+1 EndIf Cls For j=0 To rn-1 DrawRect rh[j],rv[j],rx[j],ry[j] Next DrawText rn,100,0 Flip c=WaitChar() Next |
| ||
Comment your code. Also having seen your other graphics demos you are more than capable of figuring this out for yourself-- getting help with algorithm issues deprives you of mental exercise. To make a 1-pixel border, choose a region of width, height at x,y Then inside it, plot another rectangle of width-2, height-2 at x+1, y+1. Another way you can do map generation is to have a certain number of tunnelers moving through your map. They can vary their tunnel width and tunnel type-- some tunnel types might have pillars evenly spaced along them, etc. Every so often they can spawn a room. Every so often they might split off one or two more tunnelers to the left and right. One reason why that method is good is because it ensures that all areas of the map are accessible from all other areas. Another method is to throw elements like halls and rooms in from the edges of your map. When they connect up with another piece, they will stick there, similar to the way blocks stack up in Tetris. This method is somewhat similar to the way your aggregate fractal works. |
| ||
Ow, not really. I've been fighting it for a few hours now since morning. Something somewhere is wrong. I'm certainly able and capable to help others. Sometimes I need a bit myself. As this only has =1= error in =1= line. It should be solvable. Your solution above does not solve the code. Let me comment the code however, if you think that will help: Strict ' all variables must be defined Local i ' Index Local j ' Secondary Index Local x ' X-Coordinates Local y ' Y-Coordinates Local h ' H-Coordinates Local v ' V-Coordinates Local ok ' Check to ensure a status has gone through Local c ' simple retrieve keystroke Local rh[50],rv[50],rx[50],ry[50] ' storage for previously accepted boxes Local rn ' number of boxes (minus 1) Graphics 640,480 ' Default graphics mode SetBlend alphablend ' ensure black is black and white is white For i=0 To 99 ' Try this 99 times, then exit x=Rand(3,15) ' Room across is from 3 to 15 y=Rand(3,15) ' Room down is from 3 to 15 h=Rand(0,50-x) ' Room position minus size appears randomly in 50 area H v=Rand(0,50-y) ' Room position minus size appears randomly in 50 area V ok=1 ' set our check to ACCEPT For j=0 To rn-1 ' loop for number of rooms -1 If h>=rh[j] And v>=rv[j] And x<=rx[j] And y<=ry[j] ' ERROR IS HERE SOMEWHERE ' check to ensure the coordinates chosen from h,v,x,y are not within parameters of ' a room already built ok=0 ' if so, check is set to DENY EndIf Next If ok=1 ' if check was unfazed by the previous room check, rh[rn]=h ' record new room H rv[rn]=v ' record new room V rx[rn]=x ' record new room X ry[rn]=y ' record new room Y rn:+1 ' increase room number EndIf Cls ' clear screen to black For j=0 To rn-1 ' draw all rooms minus 1 DrawRect rh[j],rv[j],rx[j],ry[j] ' draw simple white rectangle from room array Next DrawText rn,100,0 ' show total rooms created by number Flip ' show the screen c=WaitChar() ' wait for a keystroke Next ' continue 100 times then end |
| ||
Trying to work out if the commenting there has a touch of sarcasm in its overkill ;-) |
| ||
No, I just want to be ACCURATE, Xerra. Believe me when I first started programming in 6502 assembly, I =HAD= to REMARK every little binary command or I got lost pretty quickly. I have been told I code 'differently' from others in BlitzMAX so I thought I would be specific here. setblend alphablend, for instance, not everyone knows you need this to ensure that you have default transparency for black. |
| ||
Can someone please tell me what I'm doing wrong here You're spamming the programming topic instead of the beginners area? |
| ||
Criticism outside the topic is a poor way of showing you don't know the answer, GW. I don't consider myself a beginner having written and sold both business applications and games in the past. Let me guess, you've never had any problems in programming before ? If you have, do you know EXACTLY where you would ask your question ? In any case, I've made the following changes and can debug it carefully to see what is happening now. For j=0 To rn-1 SetColor Sin(j*20)*256,Sin(j*40)*256,Sin(j*60)*256 DrawRect rh[j],rv[j],rx[j],ry[j] DrawText rh[j]+" "+rv[j]+" "+rx[j]+" "+ry[j],100,j*16 Next |
| ||
Oh yeah, GW is just trying to hide his ignorance of Blitzmax and programming in general. DW, your attitude and attention seeking behavior will get you nowhere fast. I've spent a fair bit of time trying to assist you and I'm not doing that anymore. Others are not as accommodating as I am and you will find that to be true on programming forums in general. It's one thing helping someone and quite another thing to try to help someone while getting an attitude from that person. I suspect I know why you are behaving this way and I'm sure others suspect as well. Good luck with it-- your demos are nice but your demeanor is not. |
| ||
I think you will find I tend to treat others as they treat me. Treat me with kindness and I can be your best friend. Treat me with abuse and I may well be your worst enemy. In any case you will see I have solved the problem. You two can go on prattling if you like. As for me, when someone asks for coding help in here, I don't give them a lecture. I give the help to them, and by EXAMPLE CODE - every time, if I can. If not, I TRY to contribute actual code positively in some way that leads them to solving their problem. |
| ||
I think you will find I tend to treat others as they treat me. Treat me with kindness and I can be your best friend. Treat me with abuse and I may well be your worst enemy. In any case you will see I have solved the problem. You two can go on prattling if you like. As for me, when someone asks for coding help in here, I don't give them a lecture. I give the help to them, and by EXAMPLE CODE - every time, if I can. If not, I TRY to contribute actual code positively in some way that leads them to solving their problem. |
| ||
Asperger's much? |
| ||
You did mention in here that you were sick, Endive. Hope you get to feeling better soon. |
| ||
Play nice, children. |
| ||
Best advice of the day. Thanks, Brucey. |
| ||
Yeah I am a little irascible at the best of times and right now I am feeling like death warmed over. |
| ||
What Brucey said, methinks. I have a sister with Asperger's and a nephew with full blown autism so I both understood what the comment meant as well as found it offensive. For the record it looks more like a symptom of OCD which isn't the same thing. And I'll retract my sarcasm comment because who am I to tell someone how they should write their code. Moan over. Happy new year one and all. And I hope most of you are planning on getting pissed, if not already. |
| ||
I'll take OCD as a compliment, Xerra. They are dedicated to their work - and I most certainly am. :) |