コード例 #1
0
ファイル: StateManager.cs プロジェクト: ruxeom/Kirby
 public void ManageFloorStates(List<GameObject> terrain, Character player, ref Rectangle viewport)
 {
     foreach (GameObject tile in terrain)
     {
         //Vector2 playercenter = player.Center;
         //Vector2 floorcenter;
         //if the tile is on-screen
         if (viewport.Intersects(tile.BoundingBox))
             if (player.BoundingBox.Intersects(tile.BoundingBox) && tile.HasState(State.SOLID))
             {
                 //floorcenter = tile.Center;
                 if (player.HasState(State.FALLING))
                 {
                     player.AddState(State.STANDING);
                     player.RemoveState(State.FALLING);
                 }
                 player.Move(0, (int)(tile.Position.Y - player.Position.Y - player.Height));
                 break;
             }
     }
 }
コード例 #2
0
ファイル: StateManager.cs プロジェクト: ruxeom/Kirby
        public void ManagePlayerStates(Character player, Keys[] pressedkeys, int stagelimit)
        {
            if (player.HasState(State.DYING))
                return;

            if (player.CurrentHealth <= 0 || player.Position.Y > stagelimit)
            {
                player.CurrentHealth = 0;
                player.AddState(State.ALIVE);
                player.AddState(State.DYING);
                return;
            }

            int dx = 0, dy = 0;
            //Here we manage Horizontal movement
            if (pressedkeys.Contains<Keys>(Keys.Left))
            {
                dx -= 5;
                player.RemoveState(State.FACERIGHT);
                player.AddState(State.FACELEFT);
                player.AddState(State.MOVING);
            }
            else if (pressedkeys.Contains<Keys>(Keys.Right))
            {
                dx += 5;
                player.RemoveState(State.FACELEFT);
                player.AddState(State.FACERIGHT);
                player.AddState(State.MOVING);
            }
            else
                player.RemoveState(State.MOVING);

            //Here we manage vertical movement based on jumping actions
            if (pressedkeys.Contains<Keys>(Keys.Up))
            {
                if (player.HasState(State.JUMPING))
                {
                    if (player.Position.Y < player.MaxHeight)
                    {
                        dy = (int)player.Position.Y - player.MaxHeight;
                        player.RemoveState(State.JUMPING);
                        player.AddState(State.FALLING);
                    }
                    else
                        dy -= 15;
                }
                if (player.HasState(State.STANDING))
                {
                    player.MaxHeight = ((int)player.Position.Y - 200);
                    if (player.MaxHeight < 0)
                        player.MaxHeight = 0;
                    player.RemoveState(State.STANDING);
                    player.AddState(State.JUMPING);
                    dy -= 3;
                }
            }
            else
            {
                if (player.HasState(State.JUMPING))
                {
                    player.AddState(State.FALLING);
                    player.RemoveState(State.JUMPING);
                }
            }

            dy += 5;
            player.Move(dx, dy);
        }