Posted:

**Mon Apr 30, 2001 1:19 am**Does anyone have any idea how to stop flickering, I.E buffering the screen ?

have a look at my sample app

#define num_of_balls 20 //you must change number below as well.

#define gravity 3

#define friction 1

int quit = 0;

struct abl

{

int color; //a ball has a color

int velx; //x > 0 right, x < 0 left

int vely; //y > 0 up, y < 0 down

int locx; //currect x location

int locy; //currect y location

int diameter; // ball diameter

};

#define a_ball struct abl

a_ball balls[20]; //for some readin balls[num_of_balls] does not work ?

setup()

{

int i;

for(i = 0; i < num_of_balls; i++)

{

balls[i].locx = 120;

balls[i].locy = 300;

balls[i].velx = random(30)-15;

balls[i].vely = random(20)-40;

balls[i].color = random(255);

balls[i].diameter = random(8)+1;

}

}

display_balls()

{

int i;

for (i = 0; i < num_of_balls; i++)

{

setbrushattr(balls[i].color,0,0);

setbkcolor(balls[i].color,0,0);

circle(balls[i].locx,balls[i].locy,balls[i].diameter);

}

}

move_balls()

{

int i;

for (i = 0; i < num_of_balls; i++)

{

balls[i].vely = balls[i].vely + gravity; //adjust velocity

balls[i].locy = balls[i].locy + balls[i].vely; //new y location.

if (balls[i].locy > 320) //off the screen, going up.

{

balls[i].vely = 0 - balls[i].vely;

balls[i].locy = 320 - (balls[i].locy - 320);

}

balls[i].locx = balls[i].locx + balls[i].velx; //new x location.

if ((balls[i].locx > 240) || (balls[i].locx < 0)) //off the screen, other dir

{

balls[i].velx = 0 - balls[i].velx;

}

}

}

main()

{

setup();

while(quit == 0)

{

display_balls();

move_balls();

event(quit);

clearg();

}

}

have a look at my sample app

#define num_of_balls 20 //you must change number below as well.

#define gravity 3

#define friction 1

int quit = 0;

struct abl

{

int color; //a ball has a color

int velx; //x > 0 right, x < 0 left

int vely; //y > 0 up, y < 0 down

int locx; //currect x location

int locy; //currect y location

int diameter; // ball diameter

};

#define a_ball struct abl

a_ball balls[20]; //for some readin balls[num_of_balls] does not work ?

setup()

{

int i;

for(i = 0; i < num_of_balls; i++)

{

balls[i].locx = 120;

balls[i].locy = 300;

balls[i].velx = random(30)-15;

balls[i].vely = random(20)-40;

balls[i].color = random(255);

balls[i].diameter = random(8)+1;

}

}

display_balls()

{

int i;

for (i = 0; i < num_of_balls; i++)

{

setbrushattr(balls[i].color,0,0);

setbkcolor(balls[i].color,0,0);

circle(balls[i].locx,balls[i].locy,balls[i].diameter);

}

}

move_balls()

{

int i;

for (i = 0; i < num_of_balls; i++)

{

balls[i].vely = balls[i].vely + gravity; //adjust velocity

balls[i].locy = balls[i].locy + balls[i].vely; //new y location.

if (balls[i].locy > 320) //off the screen, going up.

{

balls[i].vely = 0 - balls[i].vely;

balls[i].locy = 320 - (balls[i].locy - 320);

}

balls[i].locx = balls[i].locx + balls[i].velx; //new x location.

if ((balls[i].locx > 240) || (balls[i].locx < 0)) //off the screen, other dir

{

balls[i].velx = 0 - balls[i].velx;

}

}

}

main()

{

setup();

while(quit == 0)

{

display_balls();

move_balls();

event(quit);

clearg();

}

}