I'm writing a little program where a ball is bouncing at some walls.
How do i get the right code for bouncing of a line..??
Gugge
Hope some of you can answer this....
some of the code I got:
----------------
typedef struct line lineT;
struct line
{
int x1, x2;
int y1, y2;
};
typedef struct ball ballT;
struct ball
{
int x,y,r; /*r = radius */ /* RADIUS1 = 8 */
};
void bounce_check_ball(int *x, int *y, int *xstep, int *ystep, ballT *ball, lineT lines)
{
if(*ball[0] <= lines[6]) /* Theres something WRONG here */
{
*y = lines[6]-1;
*ystep = -1*(random(2)+1);
}
}
main()......
lineT lines[30]; /* Array to keep all borderlines */
ballT ball[1];
/* A line whice the ball should bounce off at */
lines[6].x1 = 510;
lines[6].y1 = 116;
lines[6].x2 = 100;
lines[6].y2 = 116;
ball[0].x = x; /* Startcoordinater for Ball */
ball[0].y = y; /* ----------||----------- */
ball[0].r = RADIUS1; /* Radius for ball[0] */
while(1)
{........
bounce_check_ball(&x, &y, &xstep, &ystep, &ball, lineT lines[6]);
x += xstep;
y += ystep;
setcolor(LIGHTCYAN);
restorescreen((x-RADIUS1),(y-RADIUS1), &ball1);
delay(15);
restorescreen((oldx-RADIUS1),(oldy-RADIUS1), &blank); oldx=x; oldy=y;
return 0;
}



LinkBack URL
About LinkBacks


