public static void HandleCollision(IEnemy enemy, IBlock block, Game1.Side side) { EnemyGravityHandler gravity = new EnemyGravityHandler(); if (side.Equals(Game1.Side.Left) || side.Equals(Game1.Side.Right))// || side.Equals(Game1.Side.Top)) { if (block.IsHit()) { enemy.BeFlipped(); gravity.ApplyGravityToEnemy(enemy); } else if (block is UnbreakableBlock) { enemy.ChangeDirection(); } } else if (side.Equals(Game1.Side.Bottom)) { if (block.IsHit()) { enemy.BeFlipped(); gravity.ApplyGravityToEnemy(enemy); Display.UpdateKilledEnemy(); } enemy.ManualMoveY(-1 * enemy.GetVerticalVelocity()); } }
public static void HandleCollision(IItem mushroom, IPipe pipe, Game1.Side side) { RedMushroom localRM; GreenMushroom localGM; if (mushroom is RedMushroom) { localRM = (RedMushroom)mushroom; if (side == Game1.Side.Bottom) { localRM.location.Y += 2; } if (side == Game1.Side.Left) { localRM.movingRight = false; } else if (side == Game1.Side.Right) { localRM.movingRight = true; } } if (mushroom is GreenMushroom) { localGM = (GreenMushroom)mushroom; if (side == Game1.Side.Left) { localGM.movingRight = false; } else if (side == Game1.Side.Right) { localGM.movingRight = true; } } }
public void ChangeStateWhenSmall(Game1.Side side) { if (side.Equals(Game1.Side.Top)) { isHit = true; } }
public void CheckKoopaCollisions(List <IBlock> blocks, List <IPipe> pipes, List <IEnemy> goombas, List <IEnemy> koopas) { Game1.Side collisionType = Game1.Side.None; GeneralCollisionDetector generalDetector = new GeneralCollisionDetector(); foreach (Koopa koopa in koopas) { Rectangle currentKoopa = koopa.GetRectangle(); foreach (Goomba goomba in goombas) { Rectangle currentGoomba = koopa.GetRectangle(); collisionType = generalDetector.DetermineCollision(currentKoopa, currentGoomba); EnemyEnemyCollisionHandler.HandleCollision(goomba, koopa, collisionType); } foreach (IPipe pipe in pipes) { Rectangle currentPipe = pipe.GetRectangle(); collisionType = generalDetector.DetermineCollision(currentKoopa, currentPipe); EnemyPipeCollisionHandler.HandleCollision(koopa, pipe, collisionType); } foreach (IBlock block in blocks) { Rectangle currentBlock = block.GetRectangle(); collisionType = generalDetector.DetermineCollision(currentKoopa, currentBlock); EnemyBlockCollisionHandler.HandleCollision(koopa, block, collisionType); } } }
public void CheckKoopaCollisions(List <IBlock> blocks, List <IPipe> pipes, List <IEnemy> koopas) { Game1.Side collisionType = Game1.Side.None; GeneralCollisionDetector generalDetector = new GeneralCollisionDetector(); EnemyGravityHandler gravityHandler = new EnemyGravityHandler(); for (int loop = 0; loop < koopas.Count; loop++) { Koopa koopa = (Koopa)koopas.ElementAt(loop); Rectangle currentKoopa = koopa.GetRectangle(); for (int secondLoop = loop + 1; secondLoop < koopas.Count; secondLoop++) { Koopa secondKoopa = (Koopa)koopas.ElementAt(secondLoop); Rectangle currentSecondKoopa = secondKoopa.GetRectangle(); collisionType = generalDetector.DetermineCollision(currentKoopa, currentSecondKoopa); EnemyEnemyCollisionHandler.HandleCollision(koopa, secondKoopa, collisionType); } foreach (IPipe pipe in pipes) { Rectangle currentPipe = pipe.GetRectangle(); collisionType = generalDetector.DetermineCollision(currentKoopa, currentPipe); EnemyPipeCollisionHandler.HandleCollision(koopa, pipe, collisionType); } foreach (IBlock block in blocks) { Rectangle currentBlock = block.GetRectangle(); collisionType = generalDetector.DetermineCollision(currentKoopa, currentBlock); EnemyBlockCollisionHandler.HandleCollision(koopa, block, collisionType); } } }
public static void HandleCollision(IEnemy enemy1, IEnemy enemy2, Game1.Side side) { if (side.Equals(Game1.Side.Left) || side.Equals(Game1.Side.Right)) { enemy1.ChangeDirection(); enemy2.ChangeDirection(); } }
public void ChangeState(Game1.Side side) { if (side.Equals(Game1.Side.Top)) { sourceRectangle = new Rectangle(BlockUtility.blockSize * 3, 0, BlockUtility.blockSize, BlockUtility.blockSize); isHidden = false; hasItem = false; } }
public static void HandleCollision(KoopaShell shell, IBlock block, Game1.Side side) { if (shell.isHit) { if (side.Equals(Game1.Side.Left) || side.Equals(Game1.Side.Right)) { shell.ChangeDirection(); } } }
public static void HandleCollision(IPlayer player, IBlock block, Game1.Side side) { int collisionFix = 4; if (!player.IsInSpecialAnimationState()) { if (side.Equals(Game1.Side.Left)) { player.ManualMoveX(collisionFix); player.SetVelo(0); } else if (side.Equals(Game1.Side.Right)) { player.ManualMoveX(-1 * collisionFix); player.SetVelo(0); } else if (side.Equals(Game1.Side.Top)) { player.ManualMoveY(player.GetVerticalVelocity() * (-2)); player.SetVerticalVelocity(0); } else if (side.Equals(Game1.Side.Bottom)) { int downDirection = 1; int upDirection = -1; if (player.GetVerticalVelocity() > 0) { // player.ManualMoveY(upDirection * player.GetVerticalVelocity()); //player.GetVerticalVelocity() * (-1.0)); double displacement = player.GetRectangle().Bottom - block.GetRectangle().Top; if ((displacement) >= downDirection) { player.ManualMoveY(upDirection * displacement + upDirection); } else { player.ManualMoveY(0); } } player.SetTouchedGround(true); player.SetVerticalVelocity(0); player.ResetEnemyMultiplier(1); /* * player.ManualMoveY(player.GetVerticalVelocity() * (-2)); * plyer.SetVerticalVelocity(0);*/ } } }
public static void HandleCollision(Fireball fireball, IPipe pipe, Game1.Side side) { if (side == Game1.Side.Top) { fireball.Bounce(); } else if (side != Game1.Side.None) { fireball.ChangeState(); } }
public static void HandleCollision(IEnemy enemy, IPipe pipe, Game1.Side side) { if (side.Equals(Game1.Side.Left) || side.Equals(Game1.Side.Right) || side.Equals(Game1.Side.Top)) { enemy.ChangeDirection(); } else { //just keep walking } }
public void CheckGoombaCollisions(List <IBlock> blocks, List <IPipe> pipes, List <IEnemy> goombas, List <IEnemy> koopas) { Game1.Side collisionType = Game1.Side.None; GeneralCollisionDetector generalDetector = new GeneralCollisionDetector(); foreach (Goomba goomba in goombas) { EnemyGravityHandler gravityHandler = new EnemyGravityHandler(goomba); Rectangle currentGoomba = goomba.GetRectangle(); bool goombaIsSupported = false; foreach (Koopa koopa in koopas) { Rectangle currentKoopa = koopa.GetRectangle(); collisionType = generalDetector.DetermineCollision(currentGoomba, currentKoopa); EnemyEnemyCollisionHandler.HandleCollision(goomba, koopa, collisionType); } foreach (IPipe pipe in pipes) { Rectangle currentPipe = pipe.GetRectangle(); collisionType = generalDetector.DetermineCollision(currentGoomba, currentPipe); EnemyPipeCollisionHandler.HandleCollision(goomba, pipe, collisionType); if (collisionType.Equals(Game1.Side.Bottom) || (currentPipe.Top - currentGoomba.Bottom <= 3 && generalDetector.IsAlongSameYAxis(currentGoomba, currentPipe))) { goombaIsSupported = true; } } foreach (IBlock block in blocks) { Rectangle currentBlock = block.GetRectangle(); collisionType = generalDetector.DetermineCollision(currentGoomba, currentBlock); EnemyBlockCollisionHandler.HandleCollision(goomba, block, collisionType); if (collisionType.Equals(Game1.Side.Bottom) || (currentBlock.Top - currentGoomba.Bottom <= 3 && generalDetector.IsAlongSameYAxis(currentGoomba, currentBlock))) { goombaIsSupported = true; } } if (!goombaIsSupported) { gravityHandler.ApplyGravityToEnemy(); } else { goomba.SetGrounded(); } } }
public static void HandleCollision(IItem koopaShell, Game1.Side side) { KoopaShell shell = (KoopaShell)koopaShell; if (shell.isHit) { if (side.Equals(Game1.Side.Left) || side.Equals(Game1.Side.Right)) { shell.ChangeDirection(); } } }
public static void HandleCollision(IItem koopaShell, IEnemy enemy, Game1.Side side) { KoopaShell shell = (KoopaShell)koopaShell; if (shell.isHit) { if (!side.Equals(Game1.Side.None)) { enemy.BeFlipped(); } } }
public void TestMarioOnLeftOfBlockCollisionHandling() { Mario mario = new Mario(new Vector2(101, 100)); FloorBlock block = new FloorBlock(new Vector2(120, 100)); Rectangle marioRect = mario.GetRectangle(); Rectangle blockRect = block.GetRectangle(); Game1.Side collisionType = Game1.Side.Right; MarioBlockCollisionHandler.HandleCollision(mario, block, collisionType); //Assert.AreEqual(102, mario.location.X); }
public void TestMarioOnTopOfBlockCollisionHandling() { Mario mario = new Mario(new Vector2(100, 110)); FloorBlock block = new FloorBlock(new Vector2(100, 100)); Rectangle marioRect = mario.GetRectangle(); Rectangle blockRect = block.GetRectangle(); Game1.Side collisionType = Game1.Side.Bottom; MarioBlockCollisionHandler.HandleCollision(mario, block, collisionType); //Assert.AreEqual(111, mario.location.Y); }
public void TestMarioOnTopOfItemCollision() { Mario mario = new Mario(new Vector2(100, 86)); RedMushroom redMushroom = new RedMushroom(new Vector2(100, 100)); Rectangle marioRect = mario.GetRectangle(); Rectangle redMushroomRect = redMushroom.GetRectangle(); GeneralCollisionDetector generalDetector = new GeneralCollisionDetector(); Game1.Side collisionType = generalDetector.DetermineCollision(marioRect, redMushroomRect); Assert.AreEqual(collisionType, Game1.Side.Bottom); }
public void TestMarioOnBottomOfItemCollision() { Mario mario = new Mario(new Vector2(100, 100)); FireFlower flower = new FireFlower(new Vector2(100, 86)); Rectangle marioRect = mario.GetRectangle(); Rectangle flowerRect = flower.GetRectangle(); GeneralCollisionDetector generalDetector = new GeneralCollisionDetector(); Game1.Side collisionType = generalDetector.DetermineCollision(marioRect, flowerRect); Assert.AreEqual(collisionType, Game1.Side.Top); }
public void TestEnemyOnLeftOfBlockCollisionDetection() { Goomba enemy = new Goomba(new Vector2(100, 100)); FloorBlock block = new FloorBlock(new Vector2(120, 100)); Rectangle enemyRect = enemy.GetRectangle(); Rectangle blockRect = block.GetRectangle(); GeneralCollisionDetector generalDetector = new GeneralCollisionDetector(); Game1.Side collisionType = generalDetector.DetermineCollision(enemyRect, blockRect); Assert.AreEqual(collisionType, Game1.Side.Right); }
public void TestMarioOnBottomOfEnemyCollisionDetector() { Mario mario = new Mario(new Vector2(100, 115)); Goomba enemy = new Goomba(new Vector2(100, 100)); Rectangle marioRect = mario.GetRectangle(); Rectangle enemyRect = enemy.GetRectangle(); GeneralCollisionDetector generalDetector = new GeneralCollisionDetector(); Game1.Side collisionType = generalDetector.DetermineCollision(marioRect, enemyRect); Game1.Side expectedType = Game1.Side.Top; Assert.AreEqual(expectedType, collisionType); }
public void TestMarioOnTopOfBlockCollisionDetector() { Mario mario = new Mario(new Vector2(100, 100)); FloorBlock block = new FloorBlock(new Vector2(100, 110)); Rectangle marioRect = mario.GetRectangle(); Rectangle blockRect = block.GetRectangle(); GeneralCollisionDetector generalDetector = new GeneralCollisionDetector(); Game1.Side collisionType = generalDetector.DetermineCollision(marioRect, blockRect); Assert.AreEqual(collisionType, Game1.Side.Bottom); }
public static void HandleCollision(IPlayer player, IBlock block, Game1.Side side) { if (!player.IsInSpecialAnimationState()) { if (block is BrickBlock && player.GetState().Equals(MarioState.SMALL)) { BrickBlock brickBlock = (BrickBlock)block; brickBlock.ChangeStateWhenSmall(side); } else { block.ChangeState(side); } } }
public void TestMarioOnBottomOfEnemyCollisionHandling() { Mario mario = new Mario(new Vector2(100, 115)); Goomba enemy = new Goomba(new Vector2(100, 100)); Rectangle marioRect = mario.GetRectangle(); Rectangle enemyRect = enemy.GetRectangle(); Game1.Side collisionType = Game1.Side.Top; MarioEnemyCollisionHandler.HandleCollision(mario, enemy, collisionType); bool actualValue = mario.IsDying(); bool expectedValue = true; Assert.AreEqual(expectedValue, actualValue); }
public static void HandleCollision(IItem star, IPipe pipe, Game1.Side side) { Star localStar = (Star)star; int starDisplacement = 3; if (side.Equals(Game1.Side.Left)) { localStar.location.X += starDisplacement; localStar.movingRight = !localStar.movingRight; } else if (side.Equals(Game1.Side.Right)) { localStar.location.X -= starDisplacement; localStar.movingRight = !localStar.movingRight; } }
public void CheckStarCollisions(List <IItem> items, List <IBlock> blocks, List <IPipe> pipes) { Game1.Side collisionType = Game1.Side.None; BlockCollisionDetector generalDetector = new BlockCollisionDetector(); ItemGravityHandler gravityHandler = new ItemGravityHandler(); bool shouldBounce = false; foreach (IItem star in items) { if (star is Star) { Rectangle currentStar = star.GetRectangle(); foreach (IBlock block in blocks) { Rectangle currentBlock = block.GetRectangle(); collisionType = generalDetector.DetermineCollision(currentStar, currentBlock); StarBlockCollisionHanlder.HandleCollision(star, block, collisionType); if (collisionType.Equals(Game1.Side.Bottom)) { shouldBounce = true; } } foreach (IPipe pipe in pipes) { Rectangle currentPipe = pipe.GetRectangle(); collisionType = generalDetector.DetermineCollision(currentStar, currentPipe); StarPipeCollisionHandler.HandleCollision(star, pipe, collisionType); if (collisionType.Equals(Game1.Side.Bottom)) { shouldBounce = true; } } if (shouldBounce) { star.SetGrounded(); } else { gravityHandler.ApplyGravityToItem(star); } } } }
public void ChangeState(Game1.Side side) { if (side.Equals(Game1.Side.Top)) { if (isHit == true) { SoundManager.PlaySound(Game1.breakBlockSound); Rectangle destinationRectangle = new Rectangle(BlockUtility.offScreen, BlockUtility.offScreen, BlockUtility.blockSize, BlockUtility.blockSize); } else { isHit = true; shouldBreak = true; BreakBlock(); } } }
public void TestEnemyOnRightOfBlockCollisionHandling() { IEnemy enemy = new Goomba(new Vector2(110, 100)); Goomba staticEnemy = new Goomba(new Vector2(100, 100)); FloorBlock block = new FloorBlock(new Vector2(100, 100)); Rectangle enemyRect = enemy.GetRectangle(); Rectangle blockRect = block.GetRectangle(); Game1.Side collisionType = Game1.Side.Left; EnemyBlockCollisionHandler.HandleCollision(enemy, block, collisionType); IEnemyState enemyState = enemy.GetState(); IEnemyState expectedState = new GoombaLeftMovingState(staticEnemy); Assert.AreEqual(enemyState.ToString(), expectedState.ToString()); }
public static void HandleCollision(IItem mushroom, IBlock block, Game1.Side side) { RedMushroom localRM; GreenMushroom localGM; if (mushroom is RedMushroom) { localRM = (RedMushroom)mushroom; if (side == Game1.Side.Bottom) { localRM.location.Y += 1; } if (side == Game1.Side.Right) { if (block is UnbreakableBlock) { localRM.movingRight = false; } } else if (side == Game1.Side.Left) { if (block is UnbreakableBlock) { localRM.movingRight = true; } } } if (mushroom is GreenMushroom) { localGM = (GreenMushroom)mushroom; if (side == Game1.Side.Bottom) { localGM.location.Y += 1; } if (side == Game1.Side.Right) { localGM.movingRight = false; } else if (side == Game1.Side.Left) { localGM.movingRight = true; } } }
public void ChangeState(Game1.Side side) { if (side.Equals(Game1.Side.Top)) { if (item.GetType() != typeof(MultiCoin)) { sourceRectangle = new Rectangle(BlockUtility.blockSize * numberOfFrames, 0, BlockUtility.blockSize, BlockUtility.blockSize); hasItem = false; isHit = true; } else if (hitCount > maxHitCount || timer > maxTimer) { sourceRectangle = new Rectangle(BlockUtility.blockSize * numberOfFrames, 0, BlockUtility.blockSize, BlockUtility.blockSize); hasItem = false; isHit = true; } } }
public void CheckFireballCollisions(List <IBlock> blocks, List <IPipe> pipes, List <IEnemy> goombas, List <IEnemy> koopas, List <Fireball> projectiles) { Game1.Side collisionType = Game1.Side.None; GeneralCollisionDetector generalDetector = new GeneralCollisionDetector(); foreach (Fireball fireball in projectiles) { Rectangle currentFireball = fireball.GetRectangle(); foreach (IBlock block in blocks) { Rectangle currentBlock = block.GetRectangle(); collisionType = generalDetector.DetermineCollision(currentBlock, currentFireball); FireballBlockCollisionHandler.HandleCollision(fireball, block, collisionType); } foreach (Koopa koopa in koopas) { Rectangle currentKoopa = koopa.GetRectangle(); collisionType = generalDetector.DetermineCollision(currentKoopa, currentFireball); FireballEnemyCollisionHandler.HandleCollision(fireball, koopa, collisionType); } foreach (Goomba goomba in goombas) { Rectangle currentGoomba = goomba.GetRectangle(); collisionType = generalDetector.DetermineCollision(currentGoomba, currentFireball); FireballEnemyCollisionHandler.HandleCollision(fireball, goomba, collisionType); } foreach (IPipe pipe in pipes) { Rectangle currentPipe = pipe.GetRectangle(); collisionType = generalDetector.DetermineCollision(currentPipe, currentFireball); FireballPipeCollisionHandler.HandleCollision(fireball, pipe, collisionType); } } }