random levels???????

Non-platform specific questions.

random levels???????

Postby master0500 » Tue Aug 16, 2011 10:58 am

does anyone know how to make levels with random paths
for example http://www.coptergame.net/?
like how each time it's different
master0500
 
Posts: 409
Joined: Sun Jun 26, 2011 9:42 pm
Score: 27 Give a positive score

Re: random levels???????

Postby foleyjo » Tue Aug 16, 2011 11:16 am

Well for the obstacles when they go out of vision you would put them back in front of the player (off screen) and then give them a random y value between the top and bottom of the screen.
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: random levels???????

Postby master0500 » Wed Aug 17, 2011 1:27 am

ok, but what about the top and bottom
:|
master0500
 
Posts: 409
Joined: Sun Jun 26, 2011 9:42 pm
Score: 27 Give a positive score

Re: random levels???????

Postby skydereign » Wed Aug 17, 2011 2:01 am

You could use this (put it in Global Code).
Code: Select all
#define game_height 300
#define rand_range 15
#define tile_width 20
void
create_level ()
{
    static int i;
    static int slope;
    static int offset;
    i+=xvelocity;
    if(i%(40)==0)
    {
        offset+=slope;
        CreateActor("tile", "tilemask", "(none)", "(none)", x+width+tile_width, y+tile_width+offset, true);
        CreateActor("tile", "tilemask", "(none)", "(none)", x+width+tile_width, y+game_height-tile_width+offset, true);
    }
 
    if(i>=width)
    {
        i=0;
        slope=rand_range-rand(rand_range*2);
        while(offset+game_height+slope*width/tile_width>height || offset+slope*width/tile_width<0)
        {
            slope=rand_range-rand(rand_range*2);
        }
    }
}


Then add this to the view's draw.
view -> Draw Actor -> Script Editor
Code: Select all
create_level();

You also need to set the view's xvelocity, so probably in create.
view -> Create Actor -> Script Editor
Code: Select all
xvelocity=5;


For this you need an actor named tile, with an animation named tile_anim (but you can change those in the function to fit your game). You'd also probably want to add an out of vision event to destroy the tiles when they leave view. There are definitions in the global code that set the height of the flyable area, and also one for the dimension of the square tile.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest