Exemple #1
0
        public static void handleCollision(Mario mario, IEnemyObject enemy, ICollision side, LevelStorage levelStorage)
        {
            ICommand command;

            if (!(side.returnCollisionSide().Equals(CollisionSide.None)))
            {
                handleMarioMovement(mario, enemy, side);
            }

            if (side.returnCollisionSide().Equals(CollisionSide.Top) && enemy.canHurtMario())
            {
                command = new MarioHitsEnemyCollision(enemy, mario);
                command.Execute();
                levelStorage.decreaseEnemyCount();
            }
            else if (!(side.returnCollisionSide().Equals(CollisionSide.None)) && enemy.canHurtMario())
            {
                command = new EnemyHitsMarioCollision(mario, enemy);
                command.Execute();
                if (!mario.Star)
                {
                    StatePuaseAlterationCall.Execute();
                }
            }
            if (enemy.canHurtOtherEnemies() && !(side.returnCollisionSide().Equals(CollisionSide.None)) && !enemy.canHurtMario())
            {
                handleMarioMovement(mario, enemy, side);
                handleEnemyMovement(enemy, side);
            }
            handleAchievement(enemy, side);
        }
        private static ICommand chooseCorrectCommand(IItemObjects item, IPlayer mario)
        {
            ICommand command;

            if (item.returnItemType().Equals(ItemType.Coin))
            {
                command = new MarioCoinCollisionCommand(mario, item);
            }
            else if (item.returnItemType().Equals(ItemType.FireFlower))
            {
                command = new MarioFireFlowerCollisionCommand(mario, item);
                if (!((Mario)mario).Fire)
                {
                    StatePuaseAlterationCall.Execute();
                }
            }
            else if (item.returnItemType().Equals(ItemType.IceFlower))
            {
                command = new MarioIceFlowerCollisionCommand(mario, item);
            }
            else if (item.returnItemType().Equals(ItemType.OneUpMushroom))
            {
                command = new MarioOneUpMushroomCollisionCommand(mario, item);
            }
            else if (item.returnItemType().Equals(ItemType.Star))
            {
                command = new MarioStarCollisionCommand(mario, item);
            }
            else
            {
                command = new MarioSuperMushroomCollisionCommand(mario, item);
                if (((Mario)mario).Small)
                {
                    StatePuaseAlterationCall.Execute();
                }
            }
            return(command);
        }
Exemple #3
0
        protected override void Update(GameTime gameTime)
        {
            if (!hitFlagpole)
            {
                keyboard.Update();
                gamepad.Update();
            }

            foreach (IBlock block in levelStore.blocksList)
            {
                if (block.returnBlockType() == BlockType.QuestionCoin)
                {
                    if (((QuestionCoinBlock)block).returnVineDispense() && !vine_box_hit)
                    {
                        vine_box_hit = true;
                        skytransition.seVineBoxHit(true);
                    }
                }
            }

            float elapsedtime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            levelWon = (mario.GetLocation().X >= UtilityClass.flagpoleLocation && mario.GetLocation().X < UtilityClass.aboveGroundEndLocation);

            if (!pause && !marioPause)
            {
                keyNotPressed.Execute();
                if (!levelWon)
                {
                    mario.Update(gameTime);
                }
                levelStore.Update();
                levelStore.handleCollision(mario, this);
                cameraController.Update();
                pipeTransition.Update((Mario)mario, elapsedtime, camera);
                skytransition.Update((Mario)mario, elapsedtime, this);
                gameover.Update((Mario)mario, elapsedtime, this);
                gui.Update();
                if (time.UpdateTime(gameTime))
                {
                    resetCommand.Execute();
                }
                base.Update(gameTime);
            }

            else if (marioPause && !pause)
            {
                if (!levelWon)
                {
                    mario.Update(gameTime);
                }
                levelStore.handleCollision(mario, this);
                stateTransistionPauseTimer--;
            }

            if (stateTransistionPauseTimer == UtilityClass.zero)
            {
                StatePuaseAlterationCall.Execute();
            }

            pole.Update();
            flag.Update();
            if (levelWon)
            {
                AchievementEventTracker.levelFinishAcievement();
                if (!hitFlagpole)
                {
                    endMario    = new EndingSequenceMario(((Mario)mario), ((Mario)mario).Small, ((Mario)mario).Fire, ((Mario)mario).Ice, time);
                    hitFlagpole = true;
                }
                flag.MoveDown();
                endMario.FlagAtBottom = flag.FlagAtBottom();
                endMario.Update();
                if (endMario.EndSequenceFinished && Keyboard.GetState().GetPressedKeys().Length > 0)
                {
                    resetCommand.Execute();
                }
            }
        }