private void tick(uint id, uint msg, ref int userCtx, int rsv1, int rsv2) { if (controller != null) { if (collectSectorData) { if (collectionInProgress) { if (!collectionInputCalled) { ThreadPool.QueueUserWorkItem(new WaitCallback(collectDangerData)); collectionInputCalled = true; } return; } else if (DateTime.Now.Subtract(lastCollection) > TimeSpan.FromSeconds(5)) { collectionInProgress = true; } } } //Picture.SuspendLayout(); // I doubt this helps here ... (how to stop unfinished drawings being shown ...) int livesLeft = gameState.Pacman.Lives; int score = gameState.Pacman.Score; if (step) { gameState.ResumePlay(); } // update pacman if (gameState.Started) { if (controller != null) { Direction thinkDirection = controller.Think(gameState); if (thinkDirection != Direction.None) { gameState.Pacman.SetDirection(thinkDirection); } } else if (gameStream != null) { if (readIndex == gameStream.Length) { readIndex = 0; gameState.InvokeGameOver(); } gameState.Pacman.SetPosition((int)gameStream[readIndex++], (int)gameStream[readIndex++], (Direction)gameStream[readIndex++]); livesLeft = (int)gameStream[readIndex++]; score = (int)gameStream[readIndex++] * 255 + (int)gameStream[readIndex++]; foreach (Ghost ghost in gameState.Ghosts) { ghost.SetPosition((int)gameStream[readIndex++], (int)gameStream[readIndex++], ((int)gameStream[readIndex++]) == 1 ? true : false, ((int)gameStream[readIndex++]) == 1 ? true : false, (Direction)gameStream[readIndex++], ((int)gameStream[readIndex++]) == 1 ? true : false); } } } drawScreen(score, livesLeft, null); // draw shortest path /* if( startNode != null && endNode != null ) { * startNode.Draw(g, Brushes.Red); * endNode.Draw(g, Brushes.Red); * if( true ) { * List<Node> path = gameState.Map.GetRoute(startNode.X, startNode.Y, endNode.X, endNode.Y); * if( path != null ) { * foreach( Node n in path ) { * n.Draw(g, Brushes.Red); * } * } * } * }*/ // update game state if (gameState.Started) { gameState.Update(); } if (step) { gameState.PausePlay(); step = false; } // set picture //Picture.ResumeLayout(); frames++; }
private void tick(uint id, uint msg, ref int userCtx, int rsv1, int rsv2) { int livesLeft = gameState.Pacman.Lives; int score = gameState.Pacman.Score; if (step) { gameState.ResumePlay(); } // update pacman if (gameState.Started) { if (gameState.Controller != null) { Direction thinkDirection = gameState.Controller.Think(gameState); if (thinkDirection != Direction.None) { gameState.Pacman.SetDirection(thinkDirection); } } else if (gameStream != null) { if (readIndex == gameStream.Length) { readIndex = 0; gameState.InvokeGameOver(); } gameState.Pacman.SetPosition((int)gameStream[readIndex++], (int)gameStream[readIndex++], (Direction)gameStream[readIndex++]); livesLeft = (int)gameStream[readIndex++]; score = (int)gameStream[readIndex++] * 255 + (int)gameStream[readIndex++]; foreach (Ghost ghost in gameState.Ghosts) { ghost.SetPosition((int)gameStream[readIndex++], (int)gameStream[readIndex++], ((int)gameStream[readIndex++]) == 1 ? true : false, ((int)gameStream[readIndex++]) == 1 ? true : false, (Direction)gameStream[readIndex++], ((int)gameStream[readIndex++]) == 1 ? true : false); } } } drawScreen(score, livesLeft, null); // draw shortest path /* if( startNode != null && endNode != null ) { * startNode.Draw(g, Brushes.Red); * endNode.Draw(g, Brushes.Red); * if( true ) { * List<Node> path = gameState.Map.GetRoute(startNode.X, startNode.Y, endNode.X, endNode.Y); * if( path != null ) { * foreach( Node n in path ) { * n.Draw(g, Brushes.Red); * } * } * } * }*/ // update game state if (gameState.Started) { gameState.Update(); } if (step) { gameState.PausePlay(); step = false; } // set picture //Picture.ResumeLayout(); frames++; }