Ejemplo n.º 1
0
 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;
             }
     }
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            Batch = new SpriteBatch(GraphicsDevice);
            Viewport = new Rectangle(
               Graphics.GraphicsDevice.Viewport.X,
               Graphics.GraphicsDevice.Viewport.Y,
               Graphics.GraphicsDevice.Viewport.Width,
               Graphics.GraphicsDevice.Viewport.Height);

            GameLoader loader = new GameLoader(this.Content);
            Manager = new StateManager();

            this.Stage = loader.LoadStage("GameProperties\\Stage1.txt", this.Viewport);
            Player = new Character(Stage.StartPosition, Content.Load<Texture2D>("Sprites\\Kirby\\KirbyStanding"));
            Player.Move(0, -Player.Height);
            Player.MaxHealth = Player.CurrentHealth = 100;
            Player.ContactDamage = 10;
        }