public void Execute() { if (!Game1.Instance.isPkMode) { warpRectangle = Game1.Instance.warpPipe.GetSizeRectangle(); } Rectangle marioRectangle = mario.GetSizeRectangle(); marioRectangle.Height += 2; CollisionDirection dir = CollisionDetection.DetectCollisionDirection(marioRectangle, warpRectangle); if (dir == CollisionDirection.Top) { if (Game1.Instance.backgroundColor == Color.CornflowerBlue) { SoundFactory.Instance.playPipeSoundEffect(); Game1.Instance.LoadUndergroundLevel(); } else if (Game1.Instance.backgroundColor == Color.Black) { SoundFactory.Instance.playPipeSoundEffect(); Game1.Instance.LoadOvergroundLevel(); } return; } Game1.Instance.Mario.ToDown(); }
public static void HandleCollision(Game1 game, Mario mario, IEnemy collidingEnemy) { if (mario.state.isDead()) { return; } Rectangle marioRectangle = mario.GetSizeRectangle(); if (collidingEnemy is IEnemy enemy) { if (enemy is Koopa koopa && koopa.state is FlipedKoopaState) { return; } if (enemy is Goomba goomba && goomba.state is FlipedGoombaState) { return; } if (mario.state.isStar() && !mario.isStarDoingDamage) { return; } Rectangle enemyRectangle = enemy.GetSizeRectangle(); CollisionDirection direction = CollisionDetection.DetectCollisionDirection(marioRectangle, enemyRectangle); if (!(direction is CollisionDirection.NoCollision)) { if (mario.state.isStar() && mario.isStarDoingDamage) { game.HUD.GetScore(ConstantNumber.SCORE_100); enemy.Flip(); SoundFactory.Instance.playStompEnemySoundEffect(); } else if (direction is CollisionDirection.Top) { game.HUD.GetScore(ConstantNumber.SCORE_100); enemy.BeStomped(); SoundFactory.Instance.playStompEnemySoundEffect(); mario.Bounce(); } else if (enemy is Koopa stompedKoopa && stompedKoopa.isStompedIdle) { if (direction is CollisionDirection.Left) { stompedKoopa.TurnRight(); } else if (direction is CollisionDirection.Right) { stompedKoopa.TurnLeft(); } } else { mario.TakeDamage(); SoundFactory.Instance.playTakeDamageSoundEffect(); } } }
public static void HandleCollision(Mario mario, Block collidingBlock, ref Collection <IGameObject> collidingGameObjects) { if (mario.state is DeadMarioState) { return; } Rectangle marioRectangle = mario.GetSizeRectangle(); Rectangle marioLargeRectangle = mario.GetLargeSizeRectangle(); Rectangle blockRectangle = collidingBlock.GetSizeRectangle(); CollisionDirection direction = DetectCollisionDirection(marioRectangle, blockRectangle); CollisionDirection directionLargeRectangle = DetectCollisionDirection(marioLargeRectangle, blockRectangle); if (directionLargeRectangle != CollisionDirection.NoCollision) { collidingGameObjects.Add(collidingBlock); } if (!(direction is CollisionDirection.NoCollision) && !(collidingBlock.state is HiddenBlockState)) { if (direction is CollisionDirection.Top) { mario.Position = new Vector2(mario.Position.X, collidingBlock.GetSizeRectangle().Y - mario.GetSizeRectangle().Height); mario.state.ToIdle(); mario.isOnGround = true; } else if (direction is CollisionDirection.Right) { mario.Position = new Vector2(collidingBlock.GetSizeRectangle().X + collidingBlock.GetSizeRectangle().Width, mario.Position.Y); mario.isOnGround = false; } else if (direction is CollisionDirection.Left) { mario.Position = new Vector2(collidingBlock.GetSizeRectangle().X - mario.GetSizeRectangle().Width, mario.Position.Y); mario.isOnGround = false; } else if (direction is CollisionDirection.Bottom) { mario.Position = new Vector2(mario.Position.X, collidingBlock.GetSizeRectangle().Y + collidingBlock.GetSizeRectangle().Height); if (mario.state.isBig() || !(collidingBlock.state is BrickBlockState)) { collidingBlock.GetHit(); SoundFactory.Instance.playBreakBlockSoundEffect(); } else { collidingBlock.GetBump(); SoundFactory.Instance.playBumpBlockSoundEffect(); } mario.physics.ApplyForce(new Vector2(ConstantNumber.BLOCK_BOUNCE_X, ConstantNumber.BLOCK_BOUNCE_Y)); } } if ((direction is CollisionDirection.Bottom) && (collidingBlock.state is HiddenBlockState) && mario.physics.Velocity.Y < 0) { collidingBlock.GetHit(); SoundFactory.Instance.playBreakBlockSoundEffect(); } }
public static void HandleCollision(Mario mario, Pipe collidingPipe, ref Collection <IGameObject> collidingGameObjects) { if (mario.state.isDead()) { return; } Rectangle marioRectangle = mario.GetSizeRectangle(); Rectangle marioLargeRectangle = mario.GetLargeSizeRectangle(); if (collidingPipe is IPipe pipe) { Rectangle pipeRectangle = pipe.GetSizeRectangle(); CollisionDirection direction = CollisionDetection.DetectCollisionDirection(marioRectangle, pipeRectangle); CollisionDirection directionLargeRectangle = CollisionDetection.DetectCollisionDirection(marioLargeRectangle, pipeRectangle); if (directionLargeRectangle != CollisionDirection.NoCollision) { collidingGameObjects.Add(collidingPipe); } if (!(direction is CollisionDirection.NoCollision)) { if (direction is CollisionDirection.Top) { mario.Position = new Vector2(mario.Position.X, pipe.GetSizeRectangle().Y - mario.GetSizeRectangle().Height); collidingGameObjects.Add(pipe); mario.state.ToIdle(); } else if (direction is CollisionDirection.Left) { mario.Position = new Vector2(pipe.GetSizeRectangle().X - mario.GetSizeRectangle().Width, mario.Position.Y); } else if (direction is CollisionDirection.Right) { mario.Position = new Vector2(pipe.GetSizeRectangle().X + pipe.GetSizeRectangle().Width, mario.Position.Y); } else if (direction is CollisionDirection.Bottom) { mario.Position = new Vector2(mario.Position.X, pipe.GetSizeRectangle().Y + pipe.GetSizeRectangle().Height); } } } }
public static void HandleCollision(Mario player1, Mario player2) { Rectangle player1Rectangle = player1.GetSizeRectangle(); Rectangle player2Rectangle = player2.GetSizeRectangle(); CollisionDirection direction = DetectCollisionDirection(player1Rectangle, player2Rectangle); if (!(direction is CollisionDirection.NoCollision)) { if (direction is CollisionDirection.Top) { player2.GetInjured(); player1.Bounce(); } else if (direction is CollisionDirection.Left) { player1.Position = new Vector2(player2.GetSizeRectangle().X - player1.GetSizeRectangle().Width, player1.Position.Y); } else if (direction is CollisionDirection.Right) { player1.Position = new Vector2(player2.GetSizeRectangle().X + player1.GetSizeRectangle().Width, player1.Position.Y); } } }
public static void HandleCollision(Game1 game, Mario mario, IItem collidingItem, ref Collection <IGameObject> collidingGameObjects) { if (mario.state.isDead()) { return; } Rectangle marioRectangle = mario.GetSizeRectangle(); Rectangle marioLargeRectangle = mario.GetLargeSizeRectangle(); if (collidingItem is IItem item) { Rectangle itemRectangle = item.GetSizeRectangle(); CollisionDirection direction = CollisionDetection.DetectCollisionDirection(marioRectangle, itemRectangle); CollisionDirection directionLargeRectangle = CollisionDetection.DetectCollisionDirection(marioLargeRectangle, itemRectangle); if (!(direction is CollisionDirection.NoCollision) || !(directionLargeRectangle is CollisionDirection.NoCollision)) { if (item is FireFlowerItem) { FireFlowerItem temp = (FireFlowerItem)item; if (temp.triggered) { game.HUD.GetScore(ConstantNumber.SCORE_1000); mario.Evolve(); SoundFactory.Instance.playPowerUpSoundEffect(); item.Disappear(); } else { if (direction is CollisionDirection.Bottom) { item.GetTrigger(); SoundFactory.Instance.playVineSoundEffect(); } } } if (item is MushroomItem) { MushroomItem temp = (MushroomItem)item; if (temp.triggered) { game.HUD.GetScore(ConstantNumber.SCORE_1000); mario.Evolve(); SoundFactory.Instance.playPowerUpSoundEffect(); item.Disappear(); } else { if (direction is CollisionDirection.Bottom) { item.GetTrigger(); SoundFactory.Instance.playVineSoundEffect(); } } } if (item is PoisonMushroomItem) { PoisonMushroomItem temp = (PoisonMushroomItem)item; if (temp.triggered) { mario.TakeDamage(); SoundFactory.Instance.playTakeDamageSoundEffect(); item.Disappear(); } else { item.GetTrigger(); SoundFactory.Instance.playVineSoundEffect(); } } if (item is StarItem) { StarItem temp = (StarItem)item; if (temp.triggered) { game.HUD.GetScore(ConstantNumber.SCORE_1000); mario.ToStar(); SoundFactory.Instance.playStarMaioSong(); item.Disappear(); } else { if (direction is CollisionDirection.Bottom) { item.GetTrigger(); SoundFactory.Instance.playVineSoundEffect(); } } } if (item is CoinItem) { CoinItem temp = (CoinItem)item; if (!temp.consumed) { if (temp.inBlock) { if (direction is CollisionDirection.Bottom) { item.GetTrigger(); SoundFactory.Instance.playCoinSoundEffect(); game.HUD.GetCoin(); } } else { item.GetTrigger(); SoundFactory.Instance.playCoinSoundEffect(); game.HUD.GetCoin(); } } } if (item is FlagPole flag) { flag.GetTrigger(); Game1.Instance.DisableUserControl(); Game1.Instance.LoadBasicCommand(); mario.Position = new Vector2(flag.GetSizeRectangle().X - mario.GetSizeRectangle().Width, mario.Position.Y); mario.ToCreepDown(); SoundFactory.Instance.playFlagpoleSoundEffect(); if (flag.flagFallTime < 0 || collidingGameObjects.Count > 0) { mario.Position = new Vector2(flag.GetSizeRectangle().X - ConstantNumber.FlAG_POSITION_X_ADJUST + mario.GetSizeRectangle().Width, mario.Position.Y); mario.ToLeft(); if (mario.standingTime < 0) { mario.ToRight(); mario.ReachDestination = true; } mario.standingTime--; } } } } }