Created
November 18, 2012 16:17
-
-
Save vgheri/4106062 to your computer and use it in GitHub Desktop.
Outer physics update loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Run the physics update loop for each game registered in _games | |
/// </summary> | |
private static void ProcessGamesTick() | |
{ | |
DateTime timestamp; | |
foreach(var game in _games.Values) | |
{ | |
// If in one of the previous rounds we had a goal condition | |
if (_goalTimestamps.TryGetValue(game.GameId, out timestamp)) | |
{ | |
var now = DateTime.Now; | |
var timelapse = (now - timestamp).TotalSeconds; | |
// If not enough time has passed yet since the last goal, proceed with the next game | |
if (timelapse <= PAUSE_AFTER_GOAL) | |
{ | |
continue; | |
} | |
//If more than 3 seconds have passed, let's update the state of the game! | |
else | |
{ | |
// Let's remove the timestamp, so that next round everything will be back to normal | |
_goalTimestamps.Remove(game.GameId); | |
// In the meantime a user could have sent inputs, but these inputs must be discarded | |
game.Player1.ResetPlayerToIntialPositionAndState(FIELD_WIDTH); | |
game.Player2.ResetPlayerToIntialPositionAndState(FIELD_WIDTH); | |
} | |
} | |
// Process the new state | |
ProcessTick(game); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment