public GameManager(Puck puck, List <PlayerStriker> playerStrikers, GraphicsDeviceManager graphics) { this.puck = puck; this.playerStrikers = playerStrikers; this.graphics = graphics; currentState = GameState.MainMenu; scores = new Dictionary <Teams, int>() { { Teams.Left, 0 }, { Teams.Right, 0 } }; }
public void HandlePlayer(KeyboardState kstate, GameTime gameTime, Puck puck) { previousPosition = position; if (kstate.IsKeyDown(up) || kstate.IsKeyDown(left) || kstate.IsKeyDown(down) || kstate.IsKeyDown(right)) { if (speed * 1.4f < maxSpeed) { speed *= 1.4f; } if (kstate.IsKeyDown(up)) { if (position.Y - radius > 0) { position.Y += -1 * speed * (float)gameTime.ElapsedGameTime.TotalSeconds; } else { position.Y = 0 + radius; velocity.Y = -1 * velocity.Y; position.Y += 1 * speed * (float)gameTime.ElapsedGameTime.TotalSeconds; } } if (kstate.IsKeyDown(left) && position.X - radius > 0) { position.X += -1 * speed * (float)gameTime.ElapsedGameTime.TotalSeconds; } if (kstate.IsKeyDown(down) && position.Y + radius < graphics.PreferredBackBufferHeight) { position.Y += 1 * speed * (float)gameTime.ElapsedGameTime.TotalSeconds; } if (kstate.IsKeyDown(right) && position.X + radius < graphics.PreferredBackBufferWidth) { position.X += 1 * speed * (float)gameTime.ElapsedGameTime.TotalSeconds; } } else { speed = oldSpeed; } if (position.Y - radius > 0 && position.X - radius > 0 && position.Y + radius < graphics.PreferredBackBufferHeight && position.X + radius < graphics.PreferredBackBufferWidth) { velocity.X = (velocity.X + position.X - previousPosition.X) * 0.988f; velocity.Y = (velocity.Y + position.Y - previousPosition.Y) * 0.988f; position.X += velocity.X / 20; position.Y += velocity.Y / 20; } puck.HandleCollision(this, gameTime); }