Exemple #1
0
 public void Handle(ICollidable player, ICollidable koopa, CollisionDirection.DirectionTag direction)
 {
     if (player.GetType() == typeof(Mario) && koopa.GetType() == typeof(Koopa))
     {
         this.player     = (Mario)player;
         this.koopa      = (Koopa)koopa;
         this.koopaShell = new KoopaShell(this.koopa.Location());
         if (direction == CollisionDirection.DirectionTag.Top)
         {
             this.player.Physics.yPosition  = this.koopa.GetTopSide() - this.player.GetHeight();
             this.player.Physics.yVelocity *= -1;
             GameManager.Instance.Replace(this.koopa, koopaShell);
             koopaShell.Still();
         }
         else if (direction == CollisionDirection.DirectionTag.Bottom ||
                  direction == CollisionDirection.DirectionTag.Left ||
                  direction == CollisionDirection.DirectionTag.Right)
         {
             if (this.player.IsBig() || this.player.IsFire())
             {
                 this.player.TakeDamage();
             }
             else if (this.player.IsSmall())
             {
                 this.player.TakeDamage();
             }
             else
             {
                 GameManager.Instance.Replace(this.koopa, koopaShell);
                 koopaShell.Fall();
             }
         }
     }
 }
    void OnTriggerEnter2D(Collider2D col)
    {
        EnemyController enemy = col.gameObject.GetComponentInParent <EnemyController>();

        switch (col.gameObject.tag)
        {
        case "enemy_body_collider":
            if (!enemy.IsDead())
            {
                HandlePlayerDeath(enemy);
            }
            break;

        case "koopa_side_collider":
            Koopa koopa = col.gameObject.GetComponentInParent <Koopa>();
            if (koopa.GetCanDamage())
            {
                goto case "enemy_body_collider";
            }


            koopa.ShellMove(gbase.GetSide(gameObject.transform, col.gameObject.transform, false));
            break;

        default:
            Jump(3f);
            enemy.SendMethod(string.Format("Handle{0}", enemy.enemyType.ToString()), enemy);
            break;
        }
    }
Exemple #3
0
 public void Init()
 {
     _contentManager = new TestContentManager();
     _level          = new Level();
     _koopa          = new Koopa(0, 0, _level, _contentManager);
     _level.ToAddGameObject(_koopa);
     _level.UpdateLevel();
 }
Exemple #4
0
        public void Initialize()
        {
            IGameObject Goomba = new Koopa(DefaultSpawn);
            IGameObject Koopa  = new Koopa(DefaultSpawn);

            AllEnemies.Add(Goomba);
            AllEnemies.Add(Koopa);
        }
 public KoopaMovingState(Koopa koopa)
 {
     this.koopa = koopa;
     sprite     = EnemyFactory.Instance.CreateKoopaMovingSprite();
     Width      = sprite.Width;
     Height     = sprite.Height;
     Removal    = false;
 }
Exemple #6
0
        public static void NormalMarioVsShelledMovingKoopaLeftOrRightCollision(IMario mario, IEnemy enemy)
        {
            Koopa koopa = (Koopa)enemy;

            if (!koopa.DealDemage)
            {
                mario.TakeDamage();
            }
        }
 public KoopaStompedState(Koopa koopa)
 {
     this.koopa = koopa;
     sprite     = EnemyFactory.Instance.CreateKoopaStompedSprite();
     Width      = sprite.Width;
     Height     = sprite.Height;
     Removal    = false;
     time       = Constant.Instance.MarioDelay;
 }
Exemple #8
0
        public static void MoverFlipped(IEnemy mover, IEnemy target, Direction direction)
        {
            Koopa koopa = (Koopa)target;

            mover.Flipped();
            koopa.EnemyKillStreakCounter++;
            mover.ObjState = ObjectState.NonCollidable;
            StatsManager.Instance.Enemykilled(mover.Position, mover.Score, koopa.EnemyKillStreakCounter);
            AudioFactory.Instance.CreateSound(Stomp).Play();
        }
Exemple #9
0
        public void Koopa_FacingTest()
        {
            Koopa koopa = new Koopa(new Vector2(0, 0));

            bool actual = koopa.FacingRight;

            bool expected = false;

            Assert.AreEqual(expected, actual);
        }
Exemple #10
0
 public KoopaFlippedState(Koopa koopa)
 {
     this.koopa            = koopa;
     koopa.EnemyCollidable = true;
     sprite = EnemySpriteFactory.Instance.CreateKoopaFlippedSprite();
     Width  = sprite.Width;
     Height = sprite.Height;
     koopa.Physics.Location += new Vector2(0, -Utils.Instance.EnemyFlipHeight);
     koopa.IsDead            = true;
 }
Exemple #11
0
 public KoopaRevivingState(Koopa koopa)
 {
     this.koopa            = koopa;
     koopa.EnemyCollidable = true;
     sprite       = EnemySpriteFactory.Instance.CreateKoopaRevivingSprite();
     Width        = sprite.Width;
     Height       = sprite.Height;
     revivalTimer = Utils.Instance.EnemyTimeToRevive;
     koopa.Physics.ResetMotion();
 }
Exemple #12
0
        public static void HandleKoopaCollision(IPlayer player, Koopa koopa, CollisionSide side)
        {
            if (player.IsInvincible)
            {
                koopa.BeFlipped();
                ScoreManager.CollectEnemyScore(koopa, false);
                SoundFactory.Instance.PlayKickEnemySound();
            }
            else
            {
                if (koopa.State is KoopaStompedIdleState || koopa.State is KoopaRevivingState)
                {
                    switch (side)
                    {
                    case CollisionSide.Top:
                        if (koopa.Physics.Location.X <= player.MovementState.Location.X)
                        {
                            koopa.EnemyPhysics.FaceLeft();
                        }
                        else
                        {
                            koopa.EnemyPhysics.FaceRight();
                        }
                        player.MovementState.Bounce();
                        ScoreManager.CollectEnemyScore(koopa, true);
                        break;

                    case CollisionSide.Left:
                        koopa.EnemyPhysics.FaceRight();
                        break;

                    case CollisionSide.Right:
                        koopa.EnemyPhysics.FaceLeft();
                        break;

                    default:
                        break;
                    }
                    koopa.BeKicked();
                }
                else
                {
                    if (side == CollisionSide.Top)
                    {
                        koopa.BeStomped();
                        ScoreManager.CollectEnemyScore(koopa, true);
                        player.MovementState.Bounce();
                    }
                    else
                    {
                        player.TakeDamage();
                    }
                }
            }
        }
Exemple #13
0
        public KoopaKickedState(Koopa koopa)
        {
            this.koopa            = koopa;
            koopa.EnemyCollidable = true;
            sprite = EnemySpriteFactory.Instance.CreateKoopaStompedSprite();
            Width  = sprite.Width;
            Height = sprite.Height;

            koopa.EnemyPhysics.KoopaKicked();
            koopa.EnemyPhysics.KoopaMove();
        }
Exemple #14
0
        public KoopaWalkingState(Koopa koopa)
        {
            this.koopa = koopa;
            sprite     = EnemySpriteFactory.Instance.CreateKoopaMovingLeftSprite();
            Width      = sprite.Width;
            Height     = sprite.Height;

            koopa.EnemyPhysics.FaceLeft();
            koopa.EnemyPhysics.EnemyWalk();
            koopa.EnemyPhysics.KoopaMove();
            facingLeft = true;
        }
Exemple #15
0
        public static void EnemyVsShelledMovingKoopaTopCollision(IEnemy mover, IEnemy target, Direction direction)
        {
            Koopa koopa = (Koopa)target;

            if (!koopa.DealDemage)
            {
                koopa.Flipped();
                koopa.EnemyKillStreakCounter++;
                koopa.ObjState = ObjectState.NonCollidable;
                StatsManager.Instance.Enemykilled(koopa.Position, koopa.Score, mover.EnemyKillStreakCounter);
                AudioFactory.Instance.CreateSound(Stomp).Play();
            }
            ResolveOverlap(mover, koopa, direction);
        }
Exemple #16
0
        public static void NormalMarioVsShelledMovingKoopaTopSideCollision(IMario mario, IEnemy enemy)
        {
            Koopa koopa = (Koopa)enemy;

            if (koopa.DealDemage)
            {
                koopa.Flipped();
                mario.EnemyKillStreakCounter++;
                koopa.ObjState = ObjectState.NonCollidable;
                StatsManager.Instance.Enemykilled(koopa.Position, koopa.Score, mario.EnemyKillStreakCounter);
                AudioFactory.Instance.CreateSound(Stomp).Play();
            }
            ResolveOverlap(mario, koopa, Direction.top);
        }
        public KoopaFeetOutOfShellState(Koopa koopa)
        {
            this.koopa           = koopa;
            this.transitionTimer = 0;

            if (this.koopa.isRedKoopa)
            {
                this.koopa.Sprite = this.koopa.SpriteFactory.CreateProduct(EnemyTypes.RedKoopaFeetOutOfShell);
            }
            else
            {
                this.koopa.Sprite = this.koopa.SpriteFactory.CreateProduct(EnemyTypes.GreenKoopaFeetOutOfShell);
            }
        }
        public void MarioKoopaTopCollision()
        {
            TestGame = new MarioGame();
            TestWorld = TestGame.World;
            Content = TestGame.Content;
            TestMario = TestGame.World.Mario;
            TestKoopa = TestGame.World.Koopa;
            TestCommand = new MarioDownCommand(TestGame);
            TestMario.PassCommand(TestCommand);

            //Check if Mario is alive
            Assert.AreEqual(false, TestMario.Alive);
            //Check if Koopa is Shell
            //Assert.AreEqual("ShellKoopaSprite", TestKoopa.SpriteState);
        }
        public void MarioKoopaBottomCollision()
        {
            TestGame = new MarioGame();
            TestWorld = TestGame.World;
            Content = TestGame.Content;
            TestMario = TestGame.World.Mario;
            TestKoopa = TestGame.World.Koopa;
            TestCommand = new MarioUpCommand(TestGame);
            TestMario.PassCommand(TestCommand);

            //Check if Mario is dead
            Assert.AreEqual(true, TestMario.Alive);
            //Check if Koopa is Shell
            //Assert.AreEqual("WalkingKoopaSprite", TestKoopa.SpriteState);
        }
Exemple #20
0
        public static void MoveShelledIdleKoopa(IMario mario, IEnemy enemy)
        {
            Koopa koopa = (Koopa)enemy;

            if (mario.HitBox.Center.X <= koopa.EnemyHitBox().Center.X)
            {
                koopa.MoveRight();
                ResolveOverlap(mario, koopa, Direction.left);
            }
            else
            {
                koopa.MoveLeft();
                ResolveOverlap(mario, koopa, Direction.right);
            }
        }
        public KoopaShellState(Koopa koopa)
        {
            Systems.Events.TheInstance.KoopaDied();
            this.koopa           = koopa;
            this.koopa.XSpeed    = 0.0f;
            this.transitionTimer = 0;

            if (this.koopa.isRedKoopa)
            {
                this.koopa.Sprite = this.koopa.SpriteFactory.CreateProduct(EnemyTypes.RedKoopaInShell);
            }
            else
            {
                this.koopa.Sprite = this.koopa.SpriteFactory.CreateProduct(EnemyTypes.GreenKoopaInShell);
            }
        }
        public KoopaWalkLeftState(Koopa koopa)
        {
            this.koopa               = koopa;
            this.koopa.XSpeed       *= -1;
            this.koopa.isWalkingLeft = true;
            this.koopa.gravity.Enable();

            if (this.koopa.isRedKoopa)
            {
                this.koopa.Sprite = this.koopa.SpriteFactory.CreateProduct(EnemyTypes.RedKoopaWalkLeft);
            }
            else
            {
                this.koopa.Sprite = this.koopa.SpriteFactory.CreateProduct(EnemyTypes.GreenKoopaWalkLeft);
            }
        }
    void OnTriggerEnter2D(Collider2D col)
    {
        Koopa koopa = col.gameObject.GetComponentInParent<Koopa>();
        switch (col.gameObject.tag)
        {
            case "koopa_side_collider":
                if (koopa.GetShellMoving())
                {
                    SetHitByShell(true);
                    rigidBody.AddForce(new Vector2(0.75f, 1f), ForceMode2D.Impulse);
                    StartCoroutine(Death(10f));
                }

                break;

        }
    }
Exemple #24
0
 public CollisionMarioKoopaTests()
     : base()
 {
     tangible1  = new Mario();
     tangible2  = new Koopa();
     collisions = new List <Tuple <ITangibleState, PhysicsBundle, ITangibleState, PhysicsBundle, Collider.CollisionFrom> >()
     {
         // mario Koopa above collision
         Tuple.Create <ITangibleState, PhysicsBundle, ITangibleState, PhysicsBundle, Collider.CollisionFrom>(
             new SIdleLeftBigMario((Mario)tangible1), new PhysicsBundle(40, 0, 0, 1), new SKoopaWalkingLeft((Koopa)tangible2), new PhysicsBundle(40, 5), WindowsGame2.Collider.CollisionFrom.Below),
         Tuple.Create <ITangibleState, PhysicsBundle, ITangibleState, PhysicsBundle, Collider.CollisionFrom>(
             new SIdleLeftBigMario((Mario)tangible1), new PhysicsBundle(40, 5, 0, -1), new SKoopaWalkingLeft((Koopa)tangible2), new PhysicsBundle(40, 0), WindowsGame2.Collider.CollisionFrom.Above),
         Tuple.Create <ITangibleState, PhysicsBundle, ITangibleState, PhysicsBundle, Collider.CollisionFrom>(
             new SIdleLeftBigMario((Mario)tangible1), new PhysicsBundle(40, 0, -1), new SKoopaWalkingLeft((Koopa)tangible2), new PhysicsBundle(45, 0), WindowsGame2.Collider.CollisionFrom.Left),
         Tuple.Create <ITangibleState, PhysicsBundle, ITangibleState, PhysicsBundle, Collider.CollisionFrom>(
             new SIdleLeftBigMario((Mario)tangible1), new PhysicsBundle(40, 0, 1), new SKoopaWalkingLeft((Koopa)tangible2), new PhysicsBundle(45, 0), WindowsGame2.Collider.CollisionFrom.Right),
         Tuple.Create <ITangibleState, PhysicsBundle, ITangibleState, PhysicsBundle, Collider.CollisionFrom>(
             new SIdleLeftBigMario((Mario)tangible1), new PhysicsBundle(0, 0), new SKoopaWalkingLeft((Koopa)tangible2), new PhysicsBundle(40, 0), WindowsGame2.Collider.CollisionFrom.None),
     };
 }
Exemple #25
0
        public static void NormalMarioVsShelledIdleKoopaTopSideCollision(IMario mario, IEnemy enemy)
        {
            Koopa koopa = (Koopa)enemy;

            if (!koopa.DealDemage)
            {
                if (mario.HitBox.Center.X <= koopa.EnemyHitBox().Center.X)
                {
                    koopa.MoveRight();
                }
                else
                {
                    koopa.MoveLeft();
                }
                koopa.DealDemage = true;
                StatsManager.Instance.Enemykilled(koopa.Position, koopa.Score, mario.EnemyKillStreakCounter);
            }
            BumpUp(mario);
            ResolveOverlap(mario, koopa, Direction.top);
        }
Exemple #26
0
        public static void EnemyVsShelledIdleKoopaTopCollision(IEnemy mover, IEnemy target, Direction direction)
        {
            Koopa koopa = (Koopa)target;

            if (!koopa.DealDemage)
            {
                if (mover.HitBox.Center.X <= koopa.EnemyHitBox().Center.X)
                {
                    koopa.MoveRight();
                }
                else
                {
                    koopa.MoveLeft();
                }
                koopa.DealDemage = true;
                mover.EnemyKillStreakCounter++;
                StatsManager.Instance.Enemykilled(koopa.Position, koopa.Score, mover.EnemyKillStreakCounter);
            }
            ResolveOverlap(mover, koopa, direction);
        }
Exemple #27
0
        public KoopaFireBallDeathState(Koopa koopa, bool isFireBallMovingLeft)
        {
            Systems.Events.TheInstance.KoopaDied();
            this.koopa = koopa;
            this.koopa.gravity.Enable();

            if (isFireBallMovingLeft)
            {
                this.koopa.XSpeed = 1.0f;
            }
            else
            {
                this.koopa.XSpeed = -1.0f;
            }
            this.koopa.YSpeed = -2.0f;

            if (this.koopa.isRedKoopa)
            {
                if (isFireBallMovingLeft)
                {
                    this.koopa.Sprite = this.koopa.SpriteFactory.CreateProduct(EnemyTypes.RedKoopaLeftFireBallDeath);
                }
                else
                {
                    this.koopa.Sprite = this.koopa.SpriteFactory.CreateProduct(EnemyTypes.RedKoopaRightFireBallDeath);
                }
            }
            else
            {
                if (isFireBallMovingLeft)
                {
                    this.koopa.Sprite = this.koopa.SpriteFactory.CreateProduct(EnemyTypes.GreenKoopaLeftFireBallDeath);
                }
                else
                {
                    this.koopa.Sprite = this.koopa.SpriteFactory.CreateProduct(EnemyTypes.GreenKoopaRightFireBallDeath);
                }
            }

            this.koopa.IsCollidable = false;
        }
Exemple #28
0
        public static void HandleKoopaCollision(Koopa koopa, IBlock block, CollisionSide side)
        {
            Physics.GeneralPhysics.RepelObject(block, koopa, side);

            if (block.BlockPhysics.BlockBumped)
            {
                koopa.BeFlipped();
                SoundFactory.Instance.PlayKickEnemySound();
            }
            else
            {
                if (IsHorizontalCollision(side))
                {
                    koopa.ChangeDirection(side);
                    if (koopa.IsKicked)
                    {
                        SoundFactory.Instance.PlayBumpBlockSound();
                    }
                }
            }
        }
Exemple #29
0
        private void HandleKoopa(IEnemy enemy)
        {
            Koopa koopa = enemy as Koopa;

            if (koopa.movingL || koopa.movingR)
            {
                koopa.almostDead = true;
                koopa.startLifeTimer();
                koopa.dead    = false;
                koopa.movingL = false;
                koopa.movingR = false;
            }
            else if (koopa.almostDead)
            {
                koopa.dead       = true;
                koopa.almostDead = false;
                koopa.movingL    = false;
                koopa.movingR    = false;
                KillEnemy(koopa);
            }
        }
        public static void HandleKoopaCollision(Koopa koopa, IEnemy collidedEnemy, CollisionSide side)
        {
            Physics.GeneralPhysics.RepelObject(collidedEnemy, koopa, side);

            if (koopa.IsKicked)
            {
                collidedEnemy.TakeDamage();
                SoundFactory.Instance.PlayKickEnemySound();
            }
            else
            {
                if (!IsHorizontalCollision(side))
                {
                    return;
                }

                switch (collidedEnemy)
                {
                case Goomba collidedGoomba:
                    collidedGoomba.ChangeDirection(GetOppositeSide(side));
                    break;

                case Koopa collidedKoopa:
                    if (collidedKoopa.IsKicked)
                    {
                        koopa.TakeDamage();
                        SoundFactory.Instance.PlayKickEnemySound();
                    }
                    else
                    {
                        collidedKoopa.ChangeDirection(GetOppositeSide(side));
                    }
                    break;
                }

                koopa.ChangeDirection(side);
            }
        }
Exemple #31
0
    void OnTriggerEnter2D(Collider2D col)
    {
        Koopa koopa = col.gameObject.GetComponentInParent <Koopa>();

        switch (col.gameObject.tag)
        {
        case "koopa_side_collider":
            if (koopa.GetShellMoving())
            {
                float x = 0.125f;
                if (koopa.GetInShell() && koopa.getXVel() > 0 && GetInShell())
                {
                    enemySpeed *= -1;
                    x          *= -1;
                }

                SetHitByShell(true);

                rigidBody.AddForce(new Vector2(x, 1f), ForceMode2D.Impulse);
                StartCoroutine(Death(2f));
            }
            break;
        }
    }
Exemple #32
0
 public KoopaFlipCommand(Koopa koopa, CollisionData collisionData)
 {
     this.koopa = koopa;
 }