public void ProcessInput(GameTime time) { foreach(var keyHandlerPair in KeyHandlers) { Key key = keyHandlerPair.Key; InputActionHandler handler = keyHandlerPair.Value; bool keyIsDown = Keyboard.IsKeyDown(key); if(keyIsDown) { if(!handler.WasDown) { handler.WasDown = true; KeyHandlers[key].FireKeyDown(key, time); } KeyHandlers[key].FireKeyPressed(key, time); } else if(handler.WasDown) { handler.WasDown = false; KeyHandlers[key].FireKeyUp(key, time); } } }
protected virtual void RenderFrame(GameTime time) { }
protected virtual void HandleInput(GameTime time) { Input.ProcessInput(time); }
private void DrawSnakes(GameTime time) { for(int i = 0; i < Snakes.Count; i++) { Rect snake = Snakes[i]; Image snakeImage = SnakeImages[i]; snake.Offset(time.ElapsedSeconds * -(Container.ActualWidth / 5), 0); Snakes[i] = snake; snakeImage.SetValue(Canvas.LeftProperty, snake.Left); snakeImage.SetValue(Canvas.TopProperty, snake.Top); if(snake.X + snake.Width < 0) { SnakeImages.Remove(snakeImage); Container.Children.Remove(snakeImage); Snakes.Remove(snake); RemainingSnakes--; } } }
private void CheckCollisions(GameTime time) { Rect girlBox = GetBoundingBox(GirlImage); foreach(var snake in Snakes) if(girlBox.IntersectsWith(snake)) EndGame(); }
protected override void RenderFrame(GameTime time) { base.RenderFrame(time); if(GameOver || Advancing) return; DrawSnakes(time); CheckCollisions(time); if(RemainingSnakes <= 0) GetGoldenCup(); }
protected void GirlJump(Key key, GameTime time) { if(GameOver) return; if(Jumping) return; Jumping = true; WalkStoryboard.Stop(this); JumpStoryboard.Begin(this, true); }
public void FireKeyUp(Key key, GameTime time) { if(KeyUp != null) KeyUp(key, time); }
public void FireKeyPressed(Key key, GameTime time) { if(KeyPressed != null) KeyPressed(key, time); }
public void FireKeyDown(Key key, GameTime time) { if(KeyDown != null) KeyDown(key, time); }