Reset() public method

public Reset ( ) : void
return void
Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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;
            }
        }