Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Problem with coding a game...

  • 19-07-2002 09:03PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    it seems they work fine in Borland.


  • Registered Users, Registered Users 2 Posts: 455 ✭✭Lyconix


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


Advertisement