call me stupid...
or sleepy...
but how can I apply that to my code..
(I plan on rewriting it to be more visually pleasing).
Printable View
call me stupid...
or sleepy...
but how can I apply that to my code..
(I plan on rewriting it to be more visually pleasing).
Copy my whole fire() function into your program, and get rid of shoot() in your program, and replace the call you made to shoot with a call to fire. Be sure to pass an x and a y.
[edit]I would have replied earlier, but my internet connection went down/[/edit]
Check this out... I used kbhit and th problem now is the bullet erases when you move or shoot again....
What can I do?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;
}
}
}
I do not understand while you have that for loop calling game, it only gets called once anyway, why not just put game(); Then the program will end when while loop becomes false.