protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(backgroundColor); spriteBatch.Begin(); foreach (BackgroundSprite backgroundSprite in backgroundList) { backgroundSprite.Draw(spriteBatch); } if (!levelSelected) { menu.Draw(spriteBatch); } else { List <IGameObject> notItemList = new List <IGameObject>(); foreach (IGameObject gameObj in gameObjects) { if (gameObj is IItem) { gameObj.Draw(spriteBatch, Color.White); } else { notItemList.Add(gameObj); } } foreach (IGameObject miscObj in notItemList) { if (!(miscObj is Mario)) { miscObj.Draw(spriteBatch, Color.White); } } Mario.Draw(spriteBatch, Color.White); if (isPkMode) { Luigi.Draw(spriteBatch, Color.Green); marioHealthBar.Draw(spriteBatch, Mario.health); luigiHealthBar.Draw(spriteBatch, Luigi.health); } HUD.Draw(spriteBatch); } spriteBatch.End(); base.Draw(gameTime); }
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 FireRightJumpingMarioState(Mario mario) : base(mario) { marioSprite = MarioSpriteFactory.Instance.CreateFireRightJumpMario(); mario.isLeft = false; isJumping = true; }
public StarFireRightCrouchingMarioState(Mario mario) : base(mario) { marioSprite = MarioSpriteFactory.Instance.CreateFireRightCrouchMario(); }
public static void InvokeCollisonMario(Game1 game, Collection <IGameObject> gameObjects, Mario collidedMario) { Collection <IGameObject> collidingList = new Collection <IGameObject>(); foreach (IGameObject collidingGameObject in gameObjects) { if (collidingGameObject is Pipe pipe) { MarioPipeCollisionHandler.HandleCollision(collidedMario, pipe, ref collidingList); } if (collidingGameObject is Block block) { MarioBlockCollisionHandler.HandleCollision(collidedMario, block, ref collidingList); } if (collidingGameObject is IEnemy enemy) { MarioEnemyCollisionHandler.HandleCollision(game, collidedMario, enemy); } if (collidingGameObject is IItem item) { MarioItemCollisionHandler.HandleCollision(game, collidedMario, item, ref collidingList); } if (collidingGameObject == Game1.Instance.Luigi) { MarioLuigiCollisionHandler.HandleCollision(Game1.Instance.Mario, Game1.Instance.Luigi); } } int numHiddenBlocks = 0; foreach (IGameObject igo in collidingList) { if (igo is Block block) { if (block.state is HiddenBlockState) { numHiddenBlocks++; } } } if (collidingList.Count == 0 || collidingList.Count == numHiddenBlocks) { collidedMario.ToFall(); collidedMario.physics.ApplyForce(new Vector2(ConstantNumber.Support_Force_X, ConstantNumber.Support_Force_Y)); } else { collidedMario.state.IsJumping = false; } }
public static void InvokeCollisonLuigi(Game1 game, Collection <IGameObject> gameObjects, Mario collidedLuigi) { Collection <IGameObject> collidingList = new Collection <IGameObject>(); foreach (IGameObject collidingGameObject in gameObjects) { if (collidingGameObject is Block block) { MarioBlockCollisionHandler.HandleCollision(collidedLuigi, block, ref collidingList); } if (collidingGameObject is IItem item) { MarioItemCollisionHandler.HandleCollision(game, collidedLuigi, item, ref collidingList); } if (collidingGameObject == Game1.Instance.Mario) { MarioLuigiCollisionHandler.HandleCollision(Game1.Instance.Luigi, Game1.Instance.Mario); } } if (collidingList.Count == 0) { collidedLuigi.ToFall(); collidedLuigi.physics.ApplyForce(new Vector2(ConstantNumber.Support_Force_X, ConstantNumber.Support_Force_Y)); } else { collidedLuigi.state.IsJumping = false; } }
public BigRightCrouchingMarioState(Mario mario) : base(mario) { marioSprite = MarioSpriteFactory.Instance.CreateBigRightCrouchMario(); mario.isLeft = false; }
public StarFireRightFallingMarioState(Mario mario) : base(mario) { marioSprite = MarioSpriteFactory.Instance.CreateFireRightJumpMario(); }
public SetMarioDirectionToLeftCommand(Mario mario) { this.mario = mario; }
public SetLuigiDirectionToRightCommand(Mario luigi) { this.luigi = luigi; }
public StarFireLeftJumpingMarioState(Mario mario) : base(mario) { marioSprite = MarioSpriteFactory.Instance.CreateFireLeftJumpMario(); isJumping = true; }
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--; } } } } }
public ShootFireBallCommand(Mario mario) { this.mario = mario; }
public SetLuigiRunCommand(Mario luigi) { this.luigi = luigi; }
public FireRightWalkingMarioState(Mario mario) : base(mario) { marioSprite = MarioSpriteFactory.Instance.CreateFireRightRunMario(); mario.isLeft = false; }
public SmallRightIdleMarioState(Mario mario) : base(mario) { marioSprite = MarioSpriteFactory.Instance.CreateSmallRightIdleMario(); mario.physics.velocity.Y = 0; }
public SetLuigiToIdleOrJumpingStateCommand(Mario luigi) { this.luigi = luigi; }
public FireLeftCrouchingMarioState(Mario mario) : base(mario) { marioSprite = MarioSpriteFactory.Instance.CreateFireLeftCrouchMario(); mario.isLeft = true; }
public FireLeftWalkingMarioState(Mario mario) : base(mario) { marioSprite = MarioSpriteFactory.Instance.CreateFireLeftRunMario(); }
public StarSmallRightJumpingMarioState(Mario mario) : base(mario) { marioSprite = MarioSpriteFactory.Instance.CreateSmallRightJumpMario(); isJumping = true; }
public CollisionInvoker(Mario Mario) { mario = Mario; }
public SetMarioToIdleOrCrouchingStateCommand(Mario mario) { this.mario = mario; }
public StarBigLeftIdleMarioState(Mario mario) : base(mario) { marioSprite = MarioSpriteFactory.Instance.CreateBigLeftIdleMario(); mario.physics.velocity.Y = 0; }
public BigLeftFallingingMarioState(Mario mario) : base(mario) { marioSprite = MarioSpriteFactory.Instance.CreateBigLeftJumpMario(); mario.isLeft = true; }
public StarBigLeftFallingMarioState(Mario mario) : base(mario) { marioSprite = MarioSpriteFactory.Instance.CreateBigLeftJumpMario(); }
public SmallLeftFallingMarioState(Mario mario) : base(mario) { mario.jumpingPower = ConstantNumber.MARIO_JUMPING_POWER; marioSprite = MarioSpriteFactory.Instance.CreateSmallLeftJumpMario(); }
public StarFireLeftCreepDownMarioState(Mario mario) : base(mario) { marioSprite = MarioSpriteFactory.Instance.CreateFireLeftCreepingDownMario(); mario.physics.velocity.Y = 0; }
public DeadMarioState(Mario mario) : base(mario) { marioSprite = MarioSpriteFactory.Instance.CreateSmallDeadMario(); }
public StarSmallLeftWalkingMarioState(Mario mario) : base(mario) { marioSprite = MarioSpriteFactory.Instance.CreateSmallLeftRunMario(); mario.physics.velocity.Y = 0; }