Hey guys,
I'm making a small game on c++ using code::blocks.I use winbgi graphics for doing it. Its basically a ball game like dx-ball. I am an amateur programmer and I did upto making a moving ball which will rebounce whenever the boundaries of the screen are encountered.My method is to clear viewport each time the ball is printed so that the motion of the ball will be achieved . But I have been told that it is an inefficient method and there is another way by XORing the pixels to clear only parts of the screen instead of clearviewport()
Please enlighten me on it
here is my code
#include<winbgim.h> #include<stdio.h> #include<stdlib.h> #include <iostream> using namespace std; int main() { int x,y,i,j; i=1; j=1; x=11; y=11; initwindow(1366,768); setbkcolor(BLACK); setcolor(RED); setfillstyle(SOLID_FILL,RED); rectangle(500,730,700,740); while(!kbhit()) { if(x==getmaxx()-10) { i=-1; } if(x==10) { i=1; } if(y==10) { j=1; } if(y==getmaxy()-30) { j=-1; } x=x+i; y=y+j; fillellipse (x,y,10,10); delay(5); clearviewport(); } getch(); closegraph(); return 0; }