Page 1 of 1

random levels???????

PostPosted: Tue Aug 16, 2011 10:58 am
by master0500
does anyone know how to make levels with random paths
for example http://www.coptergame.net/?
like how each time it's different

Re: random levels???????

PostPosted: Tue Aug 16, 2011 11:16 am
by foleyjo
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.

Re: random levels???????

PostPosted: Wed Aug 17, 2011 1:27 am
by master0500
ok, but what about the top and bottom
:|

Re: random levels???????

PostPosted: Wed Aug 17, 2011 2:01 am
by skydereign
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.