I am trying to make a dartboard game with a moving dartboard. I have animated the dartboard but it flickers like hell. I have been facing this problem from the day i started to animate objects. Can someone please suggest a solution for minimising the flickering without going overboard in Assembly and VGA programming(cos I am still learning Assembly).
Check out the following code in Turbo C++ to animate the dartboard(which flickers)
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<dos.h>
void driver()
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
errorcode = graphresult();
if (errorcode != grOk) exit(1);
}
void DrawBoard(int x,int y)
{
setfillstyle(1,14);
bar(x,y-5,x+5,y+5);
setfillstyle(1,13);
bar(x+5,y-10,x+15,y+10);
setfillstyle(1,12);
bar(x+15,y-20,x+25,y+20);
setfillstyle(1,7);
bar(x+25,y-30,x+35,y+30);
}
void EraseBoard(int x,int y)
{
setfillstyle(1,0);
bar(x,y-30,x+40,y+30);
}
void MoveBoard()
{
int y=240;
DrawBoard(450,y);
getch();
EraseBoard(450,y);
while(!kbhit())
{
static flag=1;
DrawBoard(450,y);
EraseBoard(450,y);
delay(10);
y+=flag;
if(y==400) flag*=-1;
if(y==100) flag*=-1;
}
}
void main()
{
driver();
//setcolor(10);
MoveBoard();
getch();
}