コード例 #1
0
        public void Execute(IGameObject gameObject1, IGameObject gameObject2)
        {
            Koopa2 koopa1 = (Koopa2)gameObject1;

            if (koopa1.State.GetType() == typeof(KoopaSideDeathState))
            {
                return;
            }
            Koopa2 koopa2 = (Koopa2)gameObject2;

            if (koopa2.State.GetType() == typeof(KoopaSideDeathState))
            {
                return;
            }

            if (koopa1.State.GetType() == typeof(KoopaDeadState) &&
                koopa1.Velocity.X != GameUtilities.StationaryVelocity)
            {
                ScoringSystem.Player1Score.AddPointsForEnemyHitByShell(gameObject1);
                koopa2.Terminate("DOWN");
                return;
            }
            if (koopa2.State.GetType() == typeof(KoopaDeadState) &&
                koopa2.Velocity.X != GameUtilities.StationaryVelocity)
            {
                ScoringSystem.Player1Score.AddPointsForEnemyHitByShell(gameObject2);
                koopa1.Terminate("DOWN");
                return;
            }

            koopa1.Location = new Vector2(koopa1.Location.X + GameUtilities.SinglePixel, koopa1.Location.Y);
            koopa1.ChangeDirection();
            koopa2.ChangeDirection();
        }
コード例 #2
0
        public void Execute(IGameObject gameObject1, IGameObject gameObject2)
        {
            if (gameObject2.GetType() == typeof(HiddenBlock))
            {
                HiddenBlock hiddenBlock = (HiddenBlock)gameObject2;
                if (!hiddenBlock.Used)
                {
                    return;
                }
            }

            if (gameObject2.GetType() == typeof(LPipeBottom) ||
                gameObject2.GetType() == typeof(LPipeBottomLeft))
            {
                return;
            }

            Koopa2 koopa = (Koopa2)gameObject1;

            if (koopa.State.GetType() == typeof(KoopaSideDeathState))
            {
                return;
            }
            koopa.Location = new Vector2(koopa.Location.X, gameObject2.Location.Y - koopa.Destination.Height);
            koopa.Velocity = new Vector2(koopa.Velocity.X, GameUtilities.StationaryVelocity);
        }
コード例 #3
0
        public void Execute(IGameObject gameObject1, IGameObject gameObject2)
        {
            Koopa2 koopa = (Koopa2)gameObject1;

            if (koopa.State.GetType() == typeof(KoopaSideDeathState))
            {
                return;
            }

            if (gameObject2.GetType() == typeof(LPipeBottom) ||
                gameObject2.GetType() == typeof(LPipeBottomLeft))
            {
                return;
            }

            int koopaPreY = (int)(koopa.Location.Y - (koopa.Velocity.Y - GameUtilities.SinglePixel));

            if (koopaPreY + koopa.Destination.Height <= gameObject2.Location.Y)
            {
                return;
            }

            else if (koopaPreY > gameObject2.Location.Y + gameObject2.Destination.Height)
            {
                return;
            }
            if (koopa.Velocity.X < GameUtilities.StationaryVelocity)
            {
                koopa.ChangeDirection();
            }
        }
コード例 #4
0
        public void Execute(IGameObject gameObject1, IGameObject gameObject2)
        {
            Koopa2 koopa = (Koopa2)gameObject1;

            if (koopa.State.GetType() == typeof(KoopaSideDeathState))
            {
                return;
            }
            Goomba2 goomba = (Goomba2)gameObject2;

            if (!goomba.Alive)
            {
                return;
            }

            if (koopa.State.GetType() == typeof(KoopaDeadState) &&
                koopa.Velocity.X != GameUtilities.StationaryVelocity)
            {
                ScoringSystem.Player1Score.AddPointsForEnemyHitByShell(gameObject1);
                goomba.Terminate("LEFT");
                return;
            }

            koopa.Location = new Vector2(koopa.Location.X - GameUtilities.SinglePixel, koopa.Location.Y);
            koopa.ChangeDirection();
            goomba.ChangeDirection();
        }
コード例 #5
0
        public void Execute(IGameObject gameObject1, IGameObject gameObject2)
        {
            Koopa2 k = (Koopa2)gameObject1;

            if (k.State.GetType() == typeof(KoopaSideDeathState))
            {
                return;
            }
            k.Location = new Vector2(k.Location.X, gameObject2.Location.Y - gameObject2.Destination.Height);
            if (k.Velocity.Y < GameUtilities.StationaryVelocity)
            {
                k.Velocity = new Vector2(k.Velocity.X, GameUtilities.StationaryVelocity);
            }
        }
コード例 #6
0
        public void Execute(IGameObject gameObject1, IGameObject gameObject2)
        {
            Koopa2 koopa1 = (Koopa2)gameObject1;

            if (koopa1.State.GetType() == typeof(KoopaSideDeathState))
            {
                return;
            }
            Koopa2 koopa2 = (Koopa2)gameObject2;

            if (koopa2.State.GetType() == typeof(KoopaSideDeathState))
            {
                return;
            }
            koopa2.Location = new Vector2(koopa2.Location.X, gameObject1.Location.Y - gameObject2.Destination.Height - GameUtilities.SinglePixel);
        }
コード例 #7
0
        public void Execute(IGameObject gameObject1, IGameObject gameObject2)
        {
            Koopa2 koopa = (Koopa2)gameObject1;

            if (koopa.State.GetType() == typeof(KoopaSideDeathState))
            {
                return;
            }
            IEnemy goomba = (IEnemy)gameObject2;

            if (!goomba.Alive)
            {
                return;
            }
            koopa.Location = new Vector2(koopa.Location.X, gameObject2.Location.Y - koopa.Destination.Height);
        }
コード例 #8
0
        public void Execute(IGameObject gameObject1, IGameObject gameObject2)
        {
            Koopa2 koopa = (Koopa2)gameObject1;

            if (koopa.State.GetType() == typeof(KoopaSideDeathState))
            {
                return;
            }
            Goomba2 goomba = (Goomba2)gameObject2;

            if (!goomba.Alive)
            {
                return;
            }
            goomba.Location = new Vector2(goomba.Location.X, koopa.Location.Y - gameObject2.Destination.Height - GameUtilities.SinglePixel);
        }
コード例 #9
0
        public void Execute(IGameObject gameObject1, IGameObject gameObject2)
        {
            Horse  horse = (Horse)gameObject1;
            Koopa2 koopa = (Koopa2)gameObject2;

            horse.Location = new Vector2(horse.Location.X - GameUtilities.SinglePixel, horse.Location.Y);
            if (!horse.Alive)
            {
                return;
            }
            if (koopa.State.GetType() == typeof(KoopaDeadState) &&
                koopa.Velocity.X != GameUtilities.StationaryVelocity)
            {
                ScoringSystem.Player1Score.AddPointsForEnemyHitByShell(gameObject2);
                horse.Terminate("LEFT");
                return;
            }
            horse.ChangeDirection();
            koopa.ChangeDirection();
        }
コード例 #10
0
 public KoopaSideDeathState(Koopa2 koopa)
 {
     this.koopa_          = koopa;
     this.koopa_.Velocity = new Vector2(0, -3.5f);
     StateSprite          = EnemySpriteFactory.Instance.CreateKoopaSideDeathSprite();
 }
コード例 #11
0
        public void Execute(IGameObject gameObject1, IGameObject gameObject2)
        {
            IMario mario = (IMario)gameObject1;

            if (mario.State.MarioShape == MarioState.MarioShapeEnums.Dead ||
                mario.IsProtected)
            {
                return;
            }
            Koopa2 koopa = (Koopa2)gameObject2;

            if (koopa.State.GetType() == typeof(KoopaSideDeathState))
            {
                return;
            }

            int marioPreY = (int)(mario.Destination.Y - (mario.Velocity.Y - GameUtilities.SinglePixel));

            if (marioPreY + mario.Destination.Height < gameObject2.Destination.Y)
            {
                ICollisionCommand TopCommand = new MarioKoopaCollisionTop();

                TopCommand.Execute(gameObject1, gameObject2);
                return;
            }

            else if (marioPreY > gameObject2.Destination.Y + gameObject2.Destination.Height)
            {
                ICollisionCommand BottomCommand = new MarioKoopaCollisionBottom();
                BottomCommand.Execute(gameObject1, gameObject2);
                return;
            }

            if (mario.State.IsStar == true)
            {
                ScoringSystem.PlayerScore(mario.Player).AddPointsForSpecialKoopaHit(gameObject2);
                koopa.Terminate("DOWN");
            }
            else
            {
                if (koopa.State.GetType() == typeof(KoopaDeadState) &&
                    koopa.Velocity.X == GameUtilities.StationaryVelocity)
                {
                    ScoringSystem.PlayerScore(mario.Player).AddPointsForInitiatingShell(gameObject2);
                    koopa.Velocity = new Vector2(GameUtilities.KoopaShellVelocity, koopa.Velocity.Y);

                    SoundManager.Instance.PlayKickSound();
                    return;
                }
                else if (koopa.State.GetType() == typeof(KoopaDeadState) && koopa.Velocity.X > 0)
                {
                    return;
                }
                switch (mario.State.MarioShape)
                {
                case MarioState.MarioShapeEnums.Small:
                    mario.State.Terminated();
                    break;

                case MarioState.MarioShapeEnums.Big:
                    mario.IsProtected = true;
                    GameUtilities.GameObjectManager.MarioTransition(mario.State.MarioShape, MarioState.MarioShapeEnums.Small, mario);
                    SoundManager.Instance.PlayPipeSound();
                    break;

                case MarioState.MarioShapeEnums.Fire:
                    mario.IsProtected = true;
                    SoundManager.Instance.PlayPipeSound();
                    GameUtilities.GameObjectManager.MarioTransition(mario.State.MarioShape, MarioState.MarioShapeEnums.Small, mario);
                    break;
                }
                mario.Location = new Vector2(mario.Location.X, mario.Location.Y);
            }
        }
コード例 #12
0
 public KoopaAliveState(Koopa2 koopa)
 {
     StateSprite = EnemySpriteFactory.Instance.CreateKoopaSprite();
     this.koopa_ = koopa;
 }
コード例 #13
0
        public bool SpawnEnemy(GameObjectType.ObjectType type)
        {
            // if the spawner is not in the game screen dont use it
            if (!hasBeenInView)
            {
                return(false);
            }

            // if an enemy hasnt recently been spawned allow one to be spawned
            else if (bufferVelocity.X == GameUtilities.StationaryVelocity)
            {
                Vector2 spawnLocation;
                if (RightFacing)
                {
                    spawnLocation = new Vector2(Location.X + Destination.Width - horizontalOffset, Location.Y + verticalOffset);//  + Destination.X- 17 * GameUtilities.SinglePixel
                }
                else
                {
                    spawnLocation = new Vector2(Location.X, Location.Y + verticalOffset);
                }

                IEnemy newEnemy;
                switch (type)
                {
                case GameObjectType.ObjectType.Goomba:
                    newEnemy = new Goomba2(spawnLocation);
                    break;

                case GameObjectType.ObjectType.Koopa:
                    newEnemy = new Koopa2(spawnLocation);
                    break;

                case GameObjectType.ObjectType.Horse:
                    newEnemy = new Horse(spawnLocation);
                    break;

                default:
                    newEnemy = new Goomba2(spawnLocation);
                    break;
                }

                // makes sure the enemy is moving in the right direction
                if (newEnemy.Velocity.X > GameUtilities.StationaryVelocity && RightFacing == false)
                {
                    newEnemy.ChangeDirection();
                }

                else if (newEnemy.Velocity.X < GameUtilities.StationaryVelocity && RightFacing == true)
                {
                    newEnemy.ChangeDirection();
                }

                bufferVelocity = newEnemy.Velocity;
                GameUtilities.GameObjectManager.AddEnemy(newEnemy);
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #14
0
 public KoopaAliveRightState(Koopa2 koopa)
 {
     StateSprite = EnemySpriteFactory.Instance.CreateKoopaRightSprite();
     koopa_      = koopa;
 }
コード例 #15
0
        public bool TestMarioEnemyCollisionsKoopa()
        {
            bool isSuccess = true;

            IGameObject marioLeftKoopa   = new Mario(new Vector2(40, 52));
            IGameObject leftKoopa        = new Koopa2(new Vector2(50, 50));
            IGameObject marioTopKoopa    = new Mario(new Vector2(101, 90));
            IGameObject topKoopa         = new Koopa2(new Vector2(100, 100));
            IGameObject marioRightKoopa  = new Mario(new Vector2(160, 153));
            IGameObject rightKoopa       = new Koopa2(new Vector2(150, 150));
            IGameObject marioBottomKoopa = new Mario(new Vector2(200, 210));
            IGameObject bottomKoopa      = new Koopa2(new Vector2(200, 200));
            IGameObject marioNoKoopa     = new Mario(new Vector2(0, 100));
            IEnemy      noCollisionKoopa = new Koopa2(new Vector2(0, 0));

            Dictionary <Tuple <ObjectType, ObjectType, Object2Side>, ICollisionCommand> testDictionary = new Dictionary <Tuple <ObjectType, ObjectType, Object2Side>, ICollisionCommand>
            {
                { new Tuple <ObjectType, ObjectType, Object2Side>(ObjectType.Mario, ObjectType.Koopa, Object2Side.Top), new MarioKoopaCollisionTop() },
                { new Tuple <ObjectType, ObjectType, Object2Side>(ObjectType.Mario, ObjectType.Koopa, Object2Side.Right), new MarioKoopaCollisionRight() },
                { new Tuple <ObjectType, ObjectType, Object2Side>(ObjectType.Mario, ObjectType.Koopa, Object2Side.Bottom), new MarioKoopaCollisionBottom() },
                { new Tuple <ObjectType, ObjectType, Object2Side>(ObjectType.Mario, ObjectType.Koopa, Object2Side.Left), new MarioKoopaCollisionLeft() }
            };
            AllCollisionHandler testHandler = new AllCollisionHandler(testDictionary);

            Console.WriteLine("Tests for collision side of Mario-Koopa collisions.");
            Console.Write("Succesful recognition of left side of Koopa collision: ");
            Console.WriteLine(AllCollisionHandler.DetermineCollisionSide(marioLeftKoopa.Destination, leftKoopa.Destination) == Object2Side.Left);
            Console.Write("Succesful recognition of top side of Koopa collision: ");
            Console.WriteLine(AllCollisionHandler.DetermineCollisionSide(marioTopKoopa.Destination, topKoopa.Destination) == Object2Side.Top);
            Console.Write("Succesful recognition of right side of Koopa collision: ");
            Console.WriteLine(AllCollisionHandler.DetermineCollisionSide(marioRightKoopa.Destination, rightKoopa.Destination) == Object2Side.Right);
            Console.Write("Succesful recognition of bottom side of Koopa collision: ");
            Console.WriteLine(AllCollisionHandler.DetermineCollisionSide(marioBottomKoopa.Destination, bottomKoopa.Destination) == Object2Side.Bottom);
            Console.Write("Succesful recognition of no Koopa collision: ");
            Console.WriteLine(AllCollisionHandler.DetermineCollisionSide(marioNoKoopa.Destination, noCollisionKoopa.Destination) == Object2Side.NoCollision);
            Console.WriteLine();

            testHandler.HandleCollision(marioLeftKoopa, leftKoopa);
            testHandler.HandleCollision(marioRightKoopa, rightKoopa);
            testHandler.HandleCollision(marioBottomKoopa, bottomKoopa);
            testHandler.HandleCollision(marioTopKoopa, topKoopa);
            testHandler.HandleCollision(marioNoKoopa, noCollisionKoopa);

            /*Vector2 leftCollisionResult = new Vector2(50 - 12, 52);
             * Vector2 topCollisionResult = new Vector2(101, 100 - 15);
             * Vector2 rightCollisionResult = new Vector2(150 + 16, 153);
             * Vector2 bottomCollisionResult = new Vector2(200, 200 + 16);
             * Vector2 noCollisionResult = new Vector2(0, 100);
             *
             * Console.WriteLine("Tests for Mario-Koopa collisions.");
             * Console.Write("Succesful left side of Koopa collision: (38, 52) = (");
             * Console.Write(marioLeftKoopa.Destination.X);
             * Console.Write(", ");
             * Console.Write(marioLeftKoopa.Destination.Y);
             * Console.WriteLine(")");
             * isSuccess = isSuccess && (marioLeftKoopa.Destination.X == (int)leftCollisionResult.X && marioLeftKoopa.Destination.Y == (int)leftCollisionResult.Y);
             * Console.Write("Succesful top side of Koopa collision: (101, 85) = (");
             * Console.Write(marioTopKoopa.Destination.X);
             * Console.Write(", ");
             * Console.Write(marioTopKoopa.Destination.Y);
             * Console.WriteLine(")");
             * isSuccess = isSuccess && (marioTopKoopa.Destination.X == (int)topCollisionResult.X && marioTopKoopa.Destination.Y == (int)topCollisionResult.Y);
             * Console.Write("Succesful right side of Koopa collision: (166, 153) = (");
             * Console.Write(marioRightKoopa.Destination.X);
             * Console.Write(", ");
             * Console.Write(marioRightKoopa.Destination.Y);
             * Console.WriteLine(")");
             * isSuccess = isSuccess && (marioRightKoopa.Destination.X == (int)rightCollisionResult.X && marioRightKoopa.Destination.Y == (int)rightCollisionResult.Y);
             * Console.Write("Succesful bottom side of Koopa collision: (200, 216) = (");
             * Console.Write(marioBottomKoopa.Destination.X);
             * Console.Write(", ");
             * Console.Write(marioBottomKoopa.Destination.Y);
             * Console.WriteLine(")");
             * isSuccess = isSuccess && (marioBottomKoopa.Destination.X == (int)bottomCollisionResult.X && marioBottomKoopa.Destination.Y == (int)bottomCollisionResult.Y);
             * Console.Write("Succesful no Koopa collision: (0, 100) = (");
             * Console.Write(marioNoKoopa.Destination.X);
             * Console.Write(", ");
             * Console.Write(marioNoKoopa.Destination.Y);
             * Console.WriteLine(")");
             * isSuccess = isSuccess && (marioNoKoopa.Destination.X == (int)noCollisionResult.X && marioNoKoopa.Destination.Y == (int)noCollisionResult.Y);
             * Console.WriteLine();
             * Console.Write("Mario-Koopa collision tests are successful: ");
             * Console.WriteLine(isSuccess);
             * Console.WriteLine();
             *
             * marioLeftKoopa.Draw(spriteBatch);
             * leftKoopa.Draw(spriteBatch);
             * marioTopKoopa.Draw(spriteBatch);
             * topKoopa.Draw(spriteBatch);
             * marioRightKoopa.Draw(spriteBatch);
             * rightKoopa.Draw(spriteBatch);
             * marioBottomKoopa.Draw(spriteBatch);
             * bottomKoopa.Draw(spriteBatch);
             * marioNoKoopa.Draw(spriteBatch);
             * noCollisionKoopa.Draw(spriteBatch);*/

            return(isSuccess);
        }
コード例 #16
0
 public KoopaDeadState(Koopa2 koopa)
 {
     this.koopa_ = koopa;
     StateSprite = EnemySpriteFactory.Instance.CreateDeadKoopaSprite();
     duration    = totalDuration;
 }