Ejemplo n.º 1
0
 public bool checkIfPlayerHitEnemy(Enemy enemy, Player player)
 {
     if (player.playerRec.Intersects(enemy.enemyRec))
     {
         return true;
     }
     return false;
 }
Ejemplo n.º 2
0
 public int CheckDamageCollision(Level level, Player player)
 {
     for (int i = 0; i < level.damageRec.Count; i++)
     {
         if (player.playerRecBottom.Intersects(level.damageRec[i]))
         {
             return i;
         }
     }
     return -1;
 }
Ejemplo n.º 3
0
 public int CheckObjectCollision(Level level, Player player)
 {
     for (int i = 0; i < level.objectRec.Count; i++)
     {
         if (player.playerRecRight.Intersects(level.objectRec[i]))
         {
             Rectangle r = level.objectRec[i];
             r.Y = 5000;
             level.objectRec[i] = r;
             return i;
         }
     }
     return -1;
 }
Ejemplo n.º 4
0
 public void UpdateInterface(Player player)
 {
     healthbarWith = player.health * 4.38;
 }
Ejemplo n.º 5
0
 public void DrawPlayer(SpriteBatch sprite, Player player)
 {
     sprite.Begin();
     sprite.Draw(playerTex[currentframe], player.location , Color.White);
     sprite.End();
 }
Ejemplo n.º 6
0
 public void Attack(GameTime gameTime, Player player, Collision collision)
 {
     animateAttack(gameTime);
     if (nextAttack >= (lastAttack + TimeSpan.FromSeconds(1.08)))
     {
         if (collision.checkIfEnemyHitPlayer(this, player))
         {
             player.Hit(damage);
         }
         lastAttack = gameTime.TotalGameTime;
     }
     else
     {
         nextAttack = gameTime.TotalGameTime;
     }
 }
Ejemplo n.º 7
0
        public bool Recoil(Player player)
        {
            if (recoilCounter > 0)
            {
                int direction;
                if (location.X < player.location.X)
                {
                    direction = -1;
                }
                else
                {
                    direction = 1;
                }

                if (recoilCounter < 20)
                {
                    location.X += 15 / (recoilCounter / 2) * direction;
                }
                recoilCounter++;

                if (recoilCounter > 40)
                {
                    recoilCounter = 0;
                }
                return true;
            }
            return false;
        }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
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;
        }