I have an assignment to create a game like Frogger (you know - the game where a frog has to cross the street). So far I've created the logic behind the movement of the frog and the cars but I can't seem to run the processes simultaneously. I know that multithreading is the correct way to do this, but I'm having some trouble in passing my parameters through _beginthread.
Here's what I have so far:
void moveCarsLeft(int x, int y) {
if (y < 0) {
field[x][y + 4] = '_';
Sleep(600);
refreshField();
showField();
if (y == -4) {
moveCarsLeft(x, WIDTH-1);
}
moveCarsLeft(x, y - 1);
}
else {
if (y > WIDTH-4) {
field[x][y] = '-';
Sleep(600);
refreshField();
showField();
moveCarsLeft(x, y - 1);
}
else {
field[x][y + 4] = '_';
field[x][y] = '-';
Sleep(600); // this is what's messing up the whole thing
// it stops the whole program
// and that's why I think I need multithreading
refreshField();
showField();
moveCarsLeft(x, y - 1);
}
}
}
void moveCarsRight(int x, int y) {
... // the opposite of moveCarsLeft()
}
...
int main() {
...
_beginthread(moveCarsLeft, 0, what do I put here?);
...
}
So, I'd be really grateful if someone could tell me the correct way to achieve this functionality. Thanks in advance : ]