Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Problem with coding a game...

Options
  • 19-07-2002 9:03pm
    #1
    Registered Users Posts: 455 ✭✭


    I'm relatively new to C/C++... until now, the extent of my game programming has been text adventures and an attempt at a turn based RPG.

    Recently I decided I'd take the plunge and try and make something real time... so I decided to go with Snake, the game present on most Nokia mobile phones, or as some of you may know it, the original Nibbles programmed in QBasic.

    I was surprised with how well it went - most of the gameplay related code is now in place (the snake's body staying in sync, the snake eating food, the snake dying by collisions), but I have one problem... the delay per game loop.

    The only delay command I'm aware of is sleep, but it only seems to be capable of handling full seconds... too slow. Are there any alternative delay commands out there?

    EDIT: Just in case its significant, I'm using Borland C++ 5.02 as my compiler. I tried Bloodshed Dev C++ recently, but it failed to recognise Borland specific commands such as kbhit.


Comments

  • Registered Users Posts: 1,481 ✭✭✭satchmo


    What platform are you writing this for? If it's a windows program then you could use timeGetTime() in the Winmm.lib, or for a more precise counter use QueryPerformanceCounter() in Kernel32.dll. However I've no idea if these will work in Borland, it might have different Windows libraries?

    timeGetTime() seems to have a resolution of about 5 to 10 ms in reality, and I think QueryPerformanceCounter is accurate to less than 1ms. You can use these to implement a delay if you want:
    startTime = getTime();
    while(getTime() - startTime < delayTime) doNothing();


  • Registered Users Posts: 1,481 ✭✭✭satchmo


    it seems they work fine in Borland.


  • Registered Users Posts: 455 ✭✭Lyconix


    Thanks anyway, but I'm coding a console app I'm afraid...


Advertisement