C++ Game

This is a discussion on C++ Game within the C++ Programming forums, part of the General Programming Boards category; Code: sleep(1000); pauses the program for 1000 milliseconds (1 second). Does not work with DJGPP....

  1. #16
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Code:
    sleep(1000);
    pauses the program for 1000 milliseconds (1 second).

    Does not work with DJGPP.

  2. #17
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    but that still pauses the program
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  3. #18
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Originally posted by bluehead
    but that still pauses the program
    okay, here:

    Code:
     int x; 
     while(x != 'q') // break out of the loop if the user presses q
     {
      while(!kbhit()) // check  to see if keyboard buffer has anything in it
      {                     // WITHOUT pausing the program to wait
       drawGraphicsBit(); // drawgraphics bit draws the graphics
       sleep(10); // wait 10 ms before drawing next frame
      }
      if(kbhit()) // if the keyboard buffer has stuff in it
      {
       x = getch(); // move the first character from the buffer to int x
       switch(x)
       {
        case 52/*left*/: moveLeft(); break; // moveleft and
        case 54/*right*/:moveRight();break; // moveright move the ship
        case ' '/*space*/:shoot();break;
        default: break;
       }
      }
      /* go back to the beginning of the loop and do next frame */
     }
    Last edited by Brian; 02-23-2002 at 10:45 PM.

  4. #19
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    Ok...picture this
    You have a little circle bouncing around while a timer goes up one every second(1000 milliseconds). Right now we are trying to figure out how to do that....
    like
    Code:
    while(1)
    {
           delay(1000);//one second
           counter++;
           printf("Time: %d",counter);
           //do bouncing ball
    }
    Now the problem with this is After the timer goes up one, the ball bounces. We want it to bounce with the timer. Get it? Please help us...we stranded.

  5. #20
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    okay hang on..I'll cook up some code..I know how to do this..

  6. #21
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Code:
    int microcounter = 0; // the microcounter counts milliseconds
    int counter = 0;
    while(1)
    {
           delay(1);//one ms
           microcounter++; 
           if(microcounter == 1000) // 1000 ms = 1 second
           {
            printf("Time: %d",counter); 
            counter++; // so add one second to the counter :)
            microcounter = 0; // reset microcounter
           }
           //do bouncing ball
    }
    Understand?
    Last edited by Brian; 02-23-2002 at 10:55 PM.

  7. #22
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    nope...ive tried that. That may work with the bouncing ball, but input? When someone inputs somthing, it doesn't work because its doing delay(1).

  8. #23
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    No, the character stays in the keyboard buffer until getch() is called, so the delay shouldn't affect it.

  9. #24
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269

    I may have got it..

    #include <all of the #includes.h>

    int time;

    int main()
    {
    while (1)
    {
    while(!khbit())
    {
    clrscr();
    seconds = seconds + 1;
    cout<<seconds;
    }
    while(khbit())
    {
    }
    }
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  10. #25
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    I think this is closer (it will not compile because some functions haven't been done):

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
     int microcounter = 0; // the microcounter counts milliseconds
     int counter = 0;
     int x; 
     while(x != 'q') // break out of the loop if the user presses q
     {
      while(!kbhit()) // check  to see if keyboard buffer has anything in it
      {                     // WITHOUT pausing the program to wait
       microcounter += 10;  // add 10 ms to the microcounter because we are pausing 10 ms
       if(microcounter == 1000)
       {
        counter++;
        microcounter = 0;
       }
       drawGraphicsBit(); // drawgraphics bit draws the graphics
       sleep(10); // wait 10 ms before drawing next frame
      }
      if(kbhit()) // if the keyboard buffer has stuff in it
      {
       x = getch(); // move the first character from the buffer to int x
       switch(x)
       {
        case 52/*left*/: moveLeft(); break; // moveleft and
        case 54/*right*/:moveRight();break; // moveright move the ship
        case ' '/*space*/:shoot();break;
        default: break;
       }
      }
      /* go back to the beginning of the loop and do next frame */
     }
    }

  11. #26
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    *sigh* Allegro is so much easier than BGI.

  12. #27
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    he, i have something that works and is alot simpler: in the attachments, tell me if it works
    Attached Files Attached Files
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  13. #28
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    THIS ONE IS BETTER:
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  14. #29
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    >.< i KEEP doing mistakes!!!! here is the attachment

    SOWWIE
    Attached Files Attached Files
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  15. #30
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    Muahahahahaha!!!i have solved the problem~!
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

Page 2 of 4 FirstFirst 1234 LastLast
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-08-2010, 12:08 AM
  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, 11:44 AM
  3. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 03:46 PM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-25-2002, 12:00 AM

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