1 year ago
#258006
Asher Heetderks
Does anybody know a way to make a video game in turbo c where you have an A moving around on the screen?
I am trying to make a game with ms-dos called find the key.
What i am struggling with is using graphics.h to move an ASCII character move over a red screen using keyboard input.
Here is a snippet of my source code:
if (cn == 1) {
initgraph(&gd, &gm,"C:\\TC\\BGI");
settextstyle(DEFAULT_FONT,HORIZ_DIR,3);
setbkcolor(RED);
setcolor(BLACK);
outtextxy(100+i,100,"a");
while (getch() != '\033') { // if the first value is esc
getch(); // skip the [
switch(getch()) { // the real value
case 'D':
moveleft();
case 'A':
// code for arrow down
break;
case 'W':
// code for arrow right
break;
case 'S':
// code for arrow left
break;
}
}
Here is the moveleft() Function:
void moveleft() {
int i;
int j;
for( i = 0 ; i <= 420 ; i = i + 10, j++ ){
outtextxy(100+i,100,"a");
setcolor(j);
delay(100);
if( i == 420 )
break;
if ( j == 15 )
j = 2;
cleardevice(); // clear screen
}
}
c
bgi
0 Answers
Your Answer