I'm working on a game that has mechanics based upon random outcomes.
Essentially, every time the game is opened, it will have a small chance to randomly spawn an entity.
So basically every time the game loads there's a chance it will be a slightly different experience.
What is the simplest way I can execute this?
Thanks guys!
Let's say I have a bad guy that I want to spawn randomly with random traits and position, I would do something like this:
function spawn_baddy()
{
int rand = Random(10);
if (rand == 0)// one in ten chance
{
cBaddy.ChangeRoom(player.Room);// cBaddy is a character I've created
cBaddy.x = Random(Room.Width);// places it randomly in my room
cBaddy.y = Random(Room.Height);
badGuyAggressiveness = (1 + Random(9));// will always be at least 1, this is a variable I would have made earlier.
}
}
function on_event (EventType event, int data)
{
if ((player.Room == 10) && (event == eEventEnterRoomBeforeFadein))
{
spawn_baddy()
}
}
What Retro Wolf said should work depending on what you are needing. All I have to add is if you want to do this at the start of each game I would put it in the game_start function.