Check this out... I used kbhit and th problem now is the bullet erases when you move or shoot again....
Code:
#include <iostream.h>
#include <graphics.h>
#include <dos.h>
#include <conio.h>
int fire ( int x, int y );
int i;
int count = 0;
int quit = 0;
int mve, x = 300, y = 430;
int ch;
void game();
void playermve();
int main()
{
int graphdriver = DETECT;
int graphmode = 2;
initgraph ( &graphdriver, &graphmode, "C:\\BC5\\BGI" ); //Replace with you BGI dir.
for ( count = 0; !quit; count++ ){
game();
}
closegraph();
return 0;
}
void game()
{
while ( !quit )
{
gotoxy(1,1);
cout << "X: " << x << " Y: " << y;
settextstyle ( 1, HORIZ_DIR, 2 );
setcolor(RED);
outtextxy ( 230, -5, "Sonic Space" );
setcolor (GREEN);
rectangle ( 140, 20, 440, 470 );
playermve();
}
}
void playermve()
{
mve = getch();
switch ( mve )
{
case 77: if( x != 430 ) x += 10; break;
case 75: if( x != 150 ) x -= 10; break;
case 's': fire( x, y ); break;
case 'q': quit=1; break;
}
cleardevice();
setfillstyle ( SOLID_FILL, BLUE );
setcolor (RED);
pieslice ( x, y, 240, 300, 15 );
}
int fire ( int x, int y )
{
int tempy = y;
for ( i = y; 1 < 100; i-- )
{
setcolor(WHITE);
line(x, tempy, x, tempy-5);
delay(3);
setcolor(BLACK);
line(x, tempy, x, tempy-5);
tempy--;
if ( kbhit() ){
ch = getch();
if ( ch == 77 && x!= 430 ) x += 10; break;
if ( ch == 75 && x!= 150 ) x -= 10; break;
if ( ch = 's' ) fire ( x, y ); break;
if ( ch = 'q' ) quit = 1; break;
}
}
}
What can I do?