I am planning to write a Pacman game in C language, right from scratch. The most basic challenge that I am facing is how to maintain multiple flows of control at the same time. I mean how does the Pacman move, the ghosts move, the score being updated -- all at the same time. In general it i开发者_运维知识库s very common for all games. Is any kind of threading involved here? If so can anyone please tell as to how to make your program do many things at the same time (it will be helpful if you tell for C language).
Thanks in advance
One of the fundamental principle in real time game development is the game tick. It represents a small unit of time for things to happen in. So you might have a tick every 0.100 seconds. The smaller the tick, the finer control you have.
You can think of them as really fast turns with a time limit on them. If you don't do anything on that turn you forfeit the turn.
I think it's pretty unlikely that the original version of Pac-Man was multithreaded in the sense we use the term today. It was more likely implemented as a simple loop with some kind of interrupt support. You can do the same to implement rudimentary multithreading - write your program in a while (1)
or for (;;)
loop, and set up a timer to interrupt your loop at regular intervals to perform the screen updates.
精彩评论