As i wanted to make a ball move on the screen (wich is my first attempt on doing that) i though ill use 13 h mode .... my ball movement went slow and i could see the ball getting refreshed evry time. So i was thinking mayb the 13h mode is just slow (wich i already speeded up as much as i could) so i would port it to BGI (borland graphixs interface).
Although ive got a higher resolution now im still having the same problem i can see the ball getting refreshed...
heres my code
of main...
And heres my draw_ball functionCode:#include <graphics.h> #include <conio.h> #include <stdlib.h> #include <dos.h> #include <math.h> int main( ) { int gdriver, gmode, errorcode; char driver_path; detectgraph(&gdriver, &gmode); /*VGA HI 640*480*/ initgraph(&gdriver, &gmode, &driver_path); int angle; float COS_TABLE[360], SIN_TABLE[360]; float pi=3.14159; for(angle=0;angle<360;angle++){ COS_TABLE[angle]=cos((float)angle/180 * pi); SIN_TABLE[angle]=sin((float)angle/180 * pi); } int moves=0; int direction; int r; srand(NULL); for(moves=0;moves<10;moves++){ direction=rand() %361; for(r=0;r<40;r++){ draw_ball(100+(COS_TABLE[direction]*r),100+(SIN_TABLE[direction]*r),5,COS_TABLE,SIN_TABLE); delay(100); draw_ball(100+(COS_TABLE[direction]*r),100+(SIN_TABLE[direction]*r),0,COS_TABLE,SIN_TABLE); } } sleep(2); return 0; }
I think i know where the problem is. Its that the app always has to recalculate every ball and then put it onto the screen....Code:int draw_ball(int x,int y,int color, float COS_TABLE[] , float SIN_TABLE[]){ for(int a=0;a<360;a++){ for(int radius=0;radius<5;radius++){ putpixel(x+COS_TABLE[a]*radius,y+SIN_TABLE[a]*radius,color); } } return 0; }
Is there some way i can save this "ball" at runtime.
So that the app has to calculate the ball one time and then just moves the ball by choosing direction, speed, x start and y start.
Thx in advance.
::edit::
sry bout the indentations when im writing code i always use tabs to indent.



LinkBack URL
About LinkBacks


