Created
November 18, 2012 16:15
-
-
Save vgheri/4106053 to your computer and use it in GitHub Desktop.
The server physics update loop
This file contains hidden or 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> | |
/// Compute the next state for this game, based on player inputs and ball position | |
/// </summary> | |
/// <param name="game"></param> | |
private static void ProcessTick(Game game) | |
{ | |
// 1: Apply inputs received from players (and progressively remove them from the buffer) | |
// 2: Update ball position | |
// 3: Check for collisions and if collision, update ball status | |
// 4: If no collision, check for a goal condition and update status if goal | |
// 1: TODO Write Unit Test | |
MovePlayer(game.Player1, FIELD_HEIGHT); | |
MovePlayer(game.Player2, FIELD_HEIGHT); | |
// 2: TODO Write Unit Test | |
UpdateBallPosition(game.Ball); // Just update (X,Y) based on the angle | |
// 3: TODO Write Unit Test | |
if (!CheckCollisions(game)) | |
{ | |
// 4: TODO Write Unit Test | |
var goal = CheckGoalConditionAndUpdateStatus(game); | |
if (goal) | |
{ | |
_goalTimestamps.Add(game.GameId, DateTime.Now); | |
RestartGameAfterGoal(game); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment