Instead of creating a single map that gets used over and over again for Slender: the Eight Pages, I thought it might be cooler to generate a map in game. This way, while the mechanics and the basic layout of the terrain remain the same, the map won't be entirely the same from one play through to the next. While I'm not sure if that randomness will work for a remake of Slender: The Arrival, that's something to deal with when the time comes.

I'm trying to create a routine that spawns in trees, cars, oil tankers, and sheds. There is a spawn probability set for each object to spawn:


Code:

#define spawnProb_Tree 13 ; value of 6≤x<13
#define spawnProb_Car  6 ; value of 3≤x<6 will spawn
#define spawnProb_OilTank 3  ; value of 1≤x<3 will spawn
#define spawnProb_Shed 1   ; value of x<1 will spawn
any number above 13 will mean an unoccupied tile


This is meant to work in tangent with a random number generator to create terrain. However, the one thing I can't figure in is how to limit the number of objects without having the map thin out toward the end bc the algorithm knows it can't spawn as much. Anyone any ideas?


Code:

#define numObjects 50  ; change this to put more objects in map


^That controls how many objects are generated.
Would it work if it was approached from a different angle, in which you say that X% of tiles in a map would be trees, and then generate random coordinates to place each of those trees? You could then do the same for cars, oil tanks, sheds, etc.
Could you make another variable that defines the chance of making an object as the algorithm moves outward? So start at like 50 and increase the chance as you move towards the edges or something like that?
@james: yes.
@mateo: yes

Any way of doing it is fine, as long as it works. Lol. It just needs to limit numbers of objects. Theoretically, I could calculate how many actual objects are each and just loop for each but that gives less randomization.
I'd likely do something like James suggested. Generate how many of an object I want, then randomly place them. Just make sure nothing that needs to be accessed is inaccessible. That's more-or-less how I did it in Robot Finds Kitten.
Ok then left me ask you this. Would an assembler accept this:


Code:

#define numObjects 50

#define percTree numObjects*.7
#define percCar numObjects*.1
#define percOilTank numObjects*.1
#define percShack numObjects*.1
I dunno. What happens when you try to assemble it?
Well it seems to compile without error, so it must work! Perfect!

So now, second bit of advice. Would looping a random number routine for coordinates for each object suffice, or would there be a better way to ensure objects are more evenly scattered?
bump.
ACagliano wrote:
Well it seems to compile without error, so it must work! Perfect!

So now, second bit of advice. Would looping a random number routine for coordinates for each object suffice, or would there be a better way to ensure objects are more evenly scattered?
Perhaps you could try generating a random set of coordinates for the first object, and then have a routine to calculate the coords for the rest of them based on where the first one was placed? This routine would be designed to keep them all roughly the same distance apart - is that what you're after?
Yes. I wouldn't mind some areas being more congested than others, and there isn't anything you can't walk through so its not like you need to have space to walk. But a dispersal of objects would be my goal.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement