How can i make my programm do several things at a time? F. ex. two units move at the same time. Should i make an array with functions that have to be executed?
How can i make my programm do several things at a time? F. ex. two units move at the same time. Should i make an array with functions that have to be executed?
You can't do several things at the same time, however with good structuration of your program you can make it look like it.
Code:void MainGameLoop() { HandleInputFromKeyboard(); HandleInputFromMouse(); MovePlayer(); MoveEnemy1(); MoveEnemy2(); HandleCollisionTests(); RenderScreen(); }
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
multithreading.
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
Multithreading AND more than 1 processor.
You don't need multithreading or multiple CPUs. The types of
things he's talking about are simple AI movement calculation,
sprite movement, hit point calculation functions, etc. Basic game loop functions. Magos' answer summed it up.
MathFan, your game will execute several functions inline in the
main game loop. These functions will be so small and require such
little execution time that they can all execute seemlessly. Your
game loop will probably execute anywhere from 30 to 90 times
per second, so you won't be able to tell that the functions are
being executed one at a time.