private void CheckObstacles(Player player) { for (int i = game.obstacles.Count - 1; i >= 0; i--) { Obstacle obstacle = game.obstacles[i]; Vector2 translation = player.Intersects(obstacle); if (translation != Vector2.Zero) { //if (player.CurrentState == Player.State.Slamming) //{ // game.obstacles.RemoveAt(i); // MakeParticles(obstacle.Position, obstacle, GameData.NUM_PART_OBSTACLE, 0, 0); //} if (player.Velocity.Y < 0) // player going up { player.Velocity.Y = -GameData.OBSTACLE_JUMP; player.StunTime = GameData.OBSTACLE_STUN; //player.CurrentState = Player.State.Flying; } else if (translation.Y == 0) // hitting from side { player.Velocity.X *= GameData.OBSTACLE_SLOW; player.Velocity.Y = 0; player.CurrentState = Player.State.Stunned; player.StunTime = GameData.OBSTACLE_HIT_STUN; game.obstacles.RemoveAt(i); MakeParticles(obstacle.Position, obstacle.texture, GameData.NUM_PART_OBSTACLE, 0, 0, obstacle.Color); } else if (translation.Y > 0) // hitting from top { player.MoveByPosition(-translation); player.Velocity.Y = 0; player.CurrentState = Player.State.Walking; } } } }
private void CheckPlatforms(Player player) { int totalCollisions = 0; foreach (Platform platform in game.platforms) { Vector2 translation = player.Intersects(platform); if (translation != Vector2.Zero) { totalCollisions++; //if (Math.Abs(translation.X) > Math.Abs(translation.Y)/* && !player.WallAbove*/) //{ // player.CurrentState = Player.State.Climbing; // //player.Velocity.Y = player.ActionTime > 0 ? -GameData.CLIMB_SPEED_FAST : -GameData.CLIMB_SPEED; //} //else if (player.CurrentState == Player.State.Climbing) // player.CurrentState = Player.State.Walking; if (translation.Y == 0) // Horizontal collision { if (player.CurrentState == Player.State.Stunned) player.Velocity.X *= -1; else { player.Velocity.X = 0; //if (player.InAir && player.JumpTime <= 0) //{ //if (player.WallJump == Player.Jump.None && player.Velocity.Y > 0) // player.Velocity.Y *= GameData.WALL_STICK_SCALE; if (player.Velocity.Y >= GameData.WALL_STICK_VEL) { if (translation.X > 0 && player.TargetVelocity == Player.Direction.Right || translation.X < 0 && player.TargetVelocity == Player.Direction.Left) player.CurrentState = Player.State.WallStick; } //player.WallJumpLeway = GameData.WALL_JUMP_LEWAY; //} } } else // Vertical or diagonal collision { if (player.CurrentState == Player.State.Stunned) player.Velocity.Y *= -1; else { player.Velocity.Y = 0; player.JumpTime = 0f; if (translation.Y > 0 && player.InAir) { player.CurrentState = Player.State.Walking; player.GrappleTarget = Vector2.Zero; player.JetpackTime = GameData.JETPACK_TIME; player.JetpackEnabled = false; player.JumpsLeft = GameData.TOTAL_JUMPS; } } } player.MoveByPosition(-translation); #if DEBUG if (translation.LengthSquared() > 1) { Console.WriteLine("Collision translation of {0}", translation); platform.Color = Color.Green; } #endif } //else // player is Slamming or Stunned //{ // if (platform.Rotation != 0) // { // MakeParticles(player.Position, platform, GameData.NUM_PART_FLOOR, 0, 1); // } // else // { // MakeParticles(player.Position, platform, GameData.NUM_PART_FLOOR, 0, 1); // float newFloorX = platform.Position.X + player.Position.X; // float sizeDiff = platform.Size.X / 2 + GameData.FLOOR_HOLE / 2; // float halfWidth = platform.Size.X / 2 - GameData.FLOOR_HOLE / 2; // float playerDist = player.Position.X - platform.Position.X; // if (halfWidth + playerDist > GameData.MIN_FLOOR_WIDTH) // game.platforms.Add(new Platform(platform.texture, new Vector2((newFloorX - sizeDiff) / 2, platform.Position.Y), halfWidth + playerDist)); // if (halfWidth - playerDist > GameData.MIN_FLOOR_WIDTH) // game.platforms.Add(new Platform(platform.texture, new Vector2((newFloorX + sizeDiff) / 2, platform.Position.Y), halfWidth - playerDist)); // } // game.platforms.Remove(platform); // break; //} } if (player.Position.Y > BOTTOM) { // bottom of the level // Kill the player player.Reset(); //if (player.Score == 0) { // for (int i = 0; i < game.players.Count; i++) { // game.players [i].Score++; // } //} //player.Score--; } if (totalCollisions == 0 && player.CurrentState != Player.State.Stunned && player.WallJump == Player.Direction.None) player.CurrentState = Player.State.Jumping; }
private void CheckPlatforms(Player player) { int totalCollisions = 0; foreach (Platform platform in game.platforms) { Vector2 translation = player.Intersects(platform); if (translation != Vector2.Zero) { totalCollisions++; //if (Math.Abs(translation.X) > Math.Abs(translation.Y)/* && !player.WallAbove*/) //{ // player.CurrentState = Player.State.Climbing; // //player.Velocity.Y = player.ActionTime > 0 ? -GameData.CLIMB_SPEED_FAST : -GameData.CLIMB_SPEED; //} //else if (player.CurrentState == Player.State.Climbing) // player.CurrentState = Player.State.Walking; if (translation.Y == 0) // Horizontal collision { if (player.CurrentState == Player.State.Stunned) { player.Velocity.X *= -1; } else { player.Velocity.X = 0; //if (player.InAir && player.JumpTime <= 0) //{ //if (player.WallJump == Player.Jump.None && player.Velocity.Y > 0) // player.Velocity.Y *= GameData.WALL_STICK_SCALE; if (player.Velocity.Y >= GameData.WALL_STICK_VEL) { if (translation.X > 0 && player.TargetVelocity == Player.Direction.Right || translation.X < 0 && player.TargetVelocity == Player.Direction.Left) { player.CurrentState = Player.State.WallStick; } } //player.WallJumpLeway = GameData.WALL_JUMP_LEWAY; //} } } else // Vertical or diagonal collision { if (player.CurrentState == Player.State.Stunned) { player.Velocity.Y *= -1; } else { player.Velocity.Y = 0; player.JumpTime = 0f; if (translation.Y > 0 && player.InAir) { player.CurrentState = Player.State.Walking; player.GrappleTarget = Vector2.Zero; player.JetpackTime = GameData.JETPACK_TIME; player.JetpackEnabled = false; player.JumpsLeft = GameData.TOTAL_JUMPS; } } } player.MoveByPosition(-translation); #if DEBUG if (translation.LengthSquared() > 1) { Console.WriteLine("Collision translation of {0}", translation); platform.Color = Color.Green; } #endif } //else // player is Slamming or Stunned //{ // if (platform.Rotation != 0) // { // MakeParticles(player.Position, platform, GameData.NUM_PART_FLOOR, 0, 1); // } // else // { // MakeParticles(player.Position, platform, GameData.NUM_PART_FLOOR, 0, 1); // float newFloorX = platform.Position.X + player.Position.X; // float sizeDiff = platform.Size.X / 2 + GameData.FLOOR_HOLE / 2; // float halfWidth = platform.Size.X / 2 - GameData.FLOOR_HOLE / 2; // float playerDist = player.Position.X - platform.Position.X; // if (halfWidth + playerDist > GameData.MIN_FLOOR_WIDTH) // game.platforms.Add(new Platform(platform.texture, new Vector2((newFloorX - sizeDiff) / 2, platform.Position.Y), halfWidth + playerDist)); // if (halfWidth - playerDist > GameData.MIN_FLOOR_WIDTH) // game.platforms.Add(new Platform(platform.texture, new Vector2((newFloorX + sizeDiff) / 2, platform.Position.Y), halfWidth - playerDist)); // } // game.platforms.Remove(platform); // break; //} } if (player.Position.Y > BOTTOM) // bottom of the level // Kill the player { player.Reset(); //if (player.Score == 0) { // for (int i = 0; i < game.players.Count; i++) { // game.players [i].Score++; // } //} //player.Score--; } if (totalCollisions == 0 && player.CurrentState != Player.State.Stunned && player.WallJump == Player.Direction.None) { player.CurrentState = Player.State.Jumping; } }