New Game

This is a discussion on New Game within the Game Programming forums, part of the General Programming Boards category; call me stupid... or sleepy... but how can I apply that to my code.. (I plan on rewriting it to ...

  1. #46
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    call me stupid...
    or sleepy...

    but how can I apply that to my code..

    (I plan on rewriting it to be more visually pleasing).
    What is C++?

  2. #47
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    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]

  3. #48
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200

    SOOOO CLOSE!!!

    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?
    What is C++?

  4. #49
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    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.

Page 4 of 4 FirstFirst 1234
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-07-2010, 11:08 PM
  2. Open Source / Semi Open source game idea. Help needed
    By CaptainPatent in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 05-16-2007, 10:44 AM
  3. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 02:46 PM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21