示例#1
0
        public string checkPlayerLevelCollision(PlayerAnimations animation, Player player, Level level)
        {
            string collision = "";
            foreach (Rectangle rectangle in level.levelRec)
            {
                if (player.playerRecRight.Intersects(rectangle))
                {
                    collision += "Right";
                }

                if (player.playerRecLeft.Intersects(rectangle))
                {
                    collision += "Left";
                }

                if (player.playerRecBottom.Intersects(rectangle))
                {
                    collision += "Bottom";
                }
            }
            return collision;
        }
示例#2
0
        public bool Move(Player player, Collision collision, Level level, GameTime gameTime, PlayerAnimations playerAnimations)
        {
            if (!Recoil(player))
            {
                if (location.X + enemyTex[currentFrame].Width < player.location.X)
                {
                    if (!collision.checkEnemyLevelCollision(this, level).Contains("Right"))
                    {
                        direction = 1;
                        location.X += 5;
                        animateMove(gameTime);
                        lastAttack = gameTime.TotalGameTime - TimeSpan.FromSeconds(0.5);
                        return false;
                    }
                }

                if (location.X > player.location.X + playerAnimations.playerTex[playerAnimations.currentframe].Width)
                {
                    if (!collision.checkEnemyLevelCollision(this, level).Contains("Left"))
                    {
                        direction = 0;
                        location.X -= 5;
                        animateMove(gameTime);
                        lastAttack = gameTime.TotalGameTime -TimeSpan.FromSeconds(0.5);
                        return false;
                    }
                }
                return true;
            }
            return false;
        }
示例#3
0
        public void UpdateHitboxes(PlayerAnimations animation)
        {
            int width = animation.playerTex[animation.currentframe].Width;
            int height = animation.playerTex[animation.currentframe].Height;
            int x = (int)location.X;
            int y = (int)location.Y;

            playerRecRight = new Rectangle(
                x + width / 2,
                y + 20,
                width / 2,
                height - 40);

            playerRecLeft = new Rectangle(
                x,
                y + 20,
                width / 2,
                height - 40);

            playerRecTop = new Rectangle(
                x + 10,
                y,
                width - 20,
                20);

            playerRecBottom = new Rectangle(
                x + 10,
                y + height - 20,
                width - 20,
                20);

            playerRec = new Rectangle(
                x,
                y,
                width,
                height);
        }
示例#4
0
 public Player(PlayerAnimations animation)
 {
     ResetPlayer(animation);
 }
示例#5
0
 public void ResetPlayer(PlayerAnimations animation)
 {
     location = new Vector2(GlobalVars.resolutionWidth / 2 - animation.playerTex[animation.currentframe].Width, 0);
     health = 100;
     nextAttack = TimeSpan.FromSeconds(0);
     lastAttack = TimeSpan.FromSeconds(0);
     comboCounter = 0;
     velocity = 15f;
     jumping = false;
     grounded = false;
     allowJump = false;
 }
示例#6
0
        public void UpdateHeight(PlayerAnimations animation, Level level, Collision collision)
        {
            if (jumping && allowJump)
            {
                if (grounded)
                {
                    velocity = 15f;
                }

                grounded = false;
                location = new Vector2(location.X, location.Y - velocity);
                velocity -= 0.5f;
                if (velocity <= 0)
                {
                    jumping = false;
                    allowJump = false;
                }
            }
            else
            {
                if (grounded)
                {
                    velocity = 1f;
                }
                if (!collision.checkPlayerLevelCollision(animation, this, level).Contains("Bottom"))
                {
                    if (velocity <= 15)
                    {
                        velocity += 0.5f;
                    }
                    location = new Vector2(location.X, location.Y + velocity);
                    allowJump = false;
                    grounded = false;
                }
                else
                {
                    grounded = true;
                    allowJump = true;
                }
            }
        }
示例#7
0
 public bool MoveToEnd(PlayerAnimations animation, GameTime gameTime)
 {
     if (location.X < GlobalVars.resolutionWidth)
     {
         animation.Moving(gameTime);
         location += new Vector2(GlobalVars.playerSpeed, 0);
         return false;
     }
     else
     {
         return true;
     }
 }
示例#8
0
        public bool MoveToCenter(PlayerAnimations animation, Level level)
        {
            if (!screenLocked)
            {
                int center = GlobalVars.resolutionWidth / 2 - animation.playerTex[animation.currentframe].Width;

                if (location.X > center)
                {
                    location -= new Vector2(GlobalVars.playerSpeed, 0);
                    level.MoveLevel(1);
                }

                if (location.X < center)
                {
                    location += new Vector2(GlobalVars.playerSpeed, 0);
                    level.MoveLevel(-1);
                }

                if (location.X == center)
                {
                    return true;
                }
                return false;
            }
            return true;
        }
示例#9
0
 public void MoveRight(PlayerAnimations animation, Level level, GameTime gameTime, Collision collision)
 {
     if (!collision.checkPlayerLevelCollision(animation, this, level).Contains("Right"))
     {
         animation.BotState = PlayerAnimations.BottomAnimationState.Walking;
         if (!screenLocked)
         {
             level.MoveLevel(1);
         }
         else
         {
             if (location.X < GlobalVars.resolutionWidth - animation.playerTex[animation.currentframe].Width)
             {
                 location += new Vector2(GlobalVars.playerSpeed, 0);
             }
         }
     }
 }
示例#10
0
        public void MoveLeft(PlayerAnimations animation, Level level, GameTime gameTime, Collision collision)
        {
            if (level.location > 0)
            {
                if (!collision.checkPlayerLevelCollision(animation, this, level).Contains("Left"))
                {
                    animation.Moving(gameTime);

                    if (!screenLocked)
                    {
                        level.MoveLevel(-1);
                    }
                    else
                    {
                        if (location.X > 0)
                        {
                            location -= new Vector2(GlobalVars.playerSpeed, 0);
                        }
                    }
                }
            }
        }
示例#11
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            font = Content.Load<SpriteFont>(@"Arial");

            playerAnimations = new PlayerAnimations(Content);
            playerInterface = new Interface(Content);
            player = new Player(playerAnimations);
            keyboardInput = new KeyboardInput();
            database = new DatabaseClass();
            collision = new Collision();
            enemies = new List<Enemy>();
            level = new Level(Content);
            menu = new Menu(Content);
            text = new Text();

            GlobalVars.currentState = GlobalVars.gameState.mainMenu;
        }