meteo
12-18-2007, 06:48 PM
I seem to be posting here a lot lately, but that's OK, right? ;)
I have a tank game with two tanks: a user controlled tank and an AI tank. To control these tanks, I have two timers (one for each tank). They both fire on the same interval. I have found out that I cannot do this (is it because they share the same thread?). Only one tank can move at a time. Both timers make a call to the function that controls movement. I didn't want to have to duplicate code, so I pass the tank object, the direction, the speed, etc and move that object... could this also be why only one tank can move at once?
So my question should be pretty obvious, I hope. How can I get both tank objects moving simultaneously? Do I need to look in to multi-threading or should I just put the contents of both timers into one timer (the interval is 25) and deal with the slight delay between tank movements due to having to wait for one tank to move before the next one can move? What is the best approach at this type of thing?
I have a tank game with two tanks: a user controlled tank and an AI tank. To control these tanks, I have two timers (one for each tank). They both fire on the same interval. I have found out that I cannot do this (is it because they share the same thread?). Only one tank can move at a time. Both timers make a call to the function that controls movement. I didn't want to have to duplicate code, so I pass the tank object, the direction, the speed, etc and move that object... could this also be why only one tank can move at once?
So my question should be pretty obvious, I hope. How can I get both tank objects moving simultaneously? Do I need to look in to multi-threading or should I just put the contents of both timers into one timer (the interval is 25) and deal with the slight delay between tank movements due to having to wait for one tank to move before the next one can move? What is the best approach at this type of thing?