Пример #1
0
        public void MarioLuigiCollisionTest(Mario mario, Luigi luigi, SoundEffects sound)
        {
            Rectangle marioRectangle = myMario.GetRectangle();
            Rectangle luigiRectangle = luigi.GetRectangle();
            Rectangle intersectionRectangle;

            intersectionRectangle = Rectangle.Intersect(marioRectangle, luigiRectangle);

            if (!intersectionRectangle.IsEmpty)
            {
                if (intersectionRectangle.Width > intersectionRectangle.Height)
                {
                    if (marioRectangle.Y > luigiRectangle.Y)
                    {
                        luigi.BoostJump();
                        sound.Bump();

                    }
                    else if (luigiRectangle.Y > marioRectangle.Y)
                    {
                        mario.BoostJump();
                        sound.Bump();
                    }
                }
            }
        }
Пример #2
0
        public Tuple<int, bool> EnemyCollisionTest(Luigi luigi, HUD hud, IList<IEnemy> enemies, int x, SoundEffects sound)
        {
            Rectangle luigiRectangle = myLuigi.GetRectangle();
            Rectangle enemyRectangle;
            bool enemyKilled = false;
            bool invincible = myLuigi.Invincible();
            int xpos = x;
            Rectangle intersectionRectangle;
            Queue<IEnemy> doomedEnemies = new Queue<IEnemy>();

            foreach (IEnemy enemy in enemies)
            {

                enemyRectangle = enemy.GetRectangle();
                intersectionRectangle = Rectangle.Intersect(luigiRectangle, enemyRectangle);

                if (!intersectionRectangle.IsEmpty)
                {

                    if (intersectionRectangle.Width >= intersectionRectangle.Height)
                    {
                        sound.Bump();
                        doomedEnemies.Enqueue(enemy);
                        hud.luigiEnemyKill(luigi);
                        enemyKilled = true;
                    }
                    else if (invincible)
                    {
                        doomedEnemies.Enqueue(enemy);
                    }
                    else
                    {
                        myLuigi.Hit();
                        if (luigiRectangle.X < enemyRectangle.X)
                        {
                            xpos = xpos - intersectionRectangle.Width;
                        }
                        else
                        {
                            xpos = xpos + intersectionRectangle.Width;

                        }
                        if (myLuigi.IsDead())
                        {
                            hud.lifeLostLuigi();
                        }
                    }

                }
            }

            while (doomedEnemies.Count() > 0)
            {
                IEnemy enemie = doomedEnemies.Dequeue();
                enemies.Remove(enemie);
            }

            return new Tuple<int,bool>(xpos, enemyKilled);
        }