public void Execute(IGameObject gameObject1, IGameObject gameObject2) { if (gameObject2.GetType() == typeof(HiddenBlock)) { HiddenBlock hiddenBlock = (HiddenBlock)gameObject2; if (!hiddenBlock.Used) { return; } } Goomba2 goomba = (Goomba2)gameObject1; if (!goomba.Alive) { return; } if (gameObject2.GetType() == typeof(LPipeBottom) || gameObject2.GetType() == typeof(LPipeBottomLeft)) { return; } goomba.Location = new Vector2(goomba.Location.X, gameObject2.Location.Y - goomba.Destination.Height); goomba.Velocity = new Vector2(goomba.Velocity.X, GameUtilities.StationaryVelocity); }
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(); }
public void Execute(IGameObject gameObject1, IGameObject gameObject2) { Goomba2 goomba = (Goomba2)gameObject1; if (!goomba.Alive) { return; } if (gameObject2.GetType() == typeof(LPipeBottom) || gameObject2.GetType() == typeof(LPipeBottomLeft)) { return; } int goombaPreY = (int)(goomba.Location.Y - (goomba.Velocity.Y - GameUtilities.SinglePixel)); if (goombaPreY + goomba.Destination.Height <= gameObject2.Location.Y) { return; } else if (goombaPreY > gameObject2.Location.Y + gameObject2.Destination.Height) { return; } if (goomba.Velocity.X > GameUtilities.StationaryVelocity) { goomba.ChangeDirection(); } }
public void Execute(IGameObject gameObject1, IGameObject gameObject2) { IMario mario = (IMario)gameObject1; Goomba2 goomba = (Goomba2)gameObject2; if (mario.State.MarioShape == MarioState.MarioShapeEnums.Dead || mario.IsProtected || !goomba.Alive) { return; } int marioPreY = (int)(mario.Destination.Y - (mario.Velocity.Y - GameUtilities.SinglePixel)); if (marioPreY + mario.Destination.Height < gameObject2.Destination.Y) { ICollisionCommand TopCommand = new MarioGoombaCollisionTop(); TopCommand.Execute(gameObject1, gameObject2); return; } else if (marioPreY > gameObject2.Destination.Y + gameObject2.Destination.Height) { ICollisionCommand BottomCommand = new MarioGoombaCollisionBottom(); BottomCommand.Execute(gameObject1, gameObject2); return; } if (goomba.Alive) { if (mario.State.IsStar == true) { ScoringSystem.PlayerScore(mario.Player).AddPointsForSpecialGoombaHit(gameObject2); goomba.Terminate("RIGHT"); } else { goomba.ChangeDirection(); 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; GameUtilities.GameObjectManager.MarioTransition(mario.State.MarioShape, MarioState.MarioShapeEnums.Small, mario); SoundManager.Instance.PlayPipeSound(); break; } } } }
public void Execute(IGameObject gameObject1, IGameObject gameObject2) { Goomba2 goomba1 = (Goomba2)gameObject1; Horse horse = (Horse)gameObject2; goomba1.Location = new Vector2(goomba1.Location.X + GameUtilities.SinglePixel, goomba1.Location.Y); goomba1.ChangeDirection(); horse.ChangeDirection(); }
public void Execute(IGameObject gameObject1, IGameObject gameObject2) { Goomba2 goomba1 = (Goomba2)gameObject1; if (!goomba1.Alive) { return; } goomba1.Location = new Vector2(goomba1.Location.X, gameObject2.Location.Y - goomba1.Destination.Height); }
public void Execute(IGameObject gameObject1, IGameObject gameObject2) { Goomba2 g = (Goomba2)gameObject1; if (!g.Alive) { return; } g.Location = new Vector2(g.Location.X, gameObject2.Location.Y + gameObject2.Destination.Height); if (g.Velocity.Y > GameUtilities.StationaryVelocity) { g.Velocity = new Vector2(g.Velocity.X, GameUtilities.StationaryVelocity); } }
public void Execute(IGameObject gameObject1, IGameObject gameObject2) { Horse horse1 = (Horse)gameObject1; if (horse1.Alive == false) { return; } Goomba2 goomba2 = (Goomba2)gameObject2; horse1.Location = new Vector2(horse1.Location.X - GameUtilities.SinglePixel, horse1.Location.Y); horse1.ChangeDirection(); goomba2.ChangeDirection(); }
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); }
public void Execute(IGameObject gameObject1, IGameObject gameObject2) { FireBallProjectile fireBall = (FireBallProjectile)gameObject1; Goomba2 enemy = (Goomba2)gameObject2; if (!enemy.Alive) { return; } if (enemy.State.GetType() != typeof(GoombaDeadState)) { fireBall.Terminate(); ScoringSystem.AddPointsForFireballGoombaHit(gameObject2, fireBall.InitiatingPlayer); enemy.Terminate("LEFT"); SoundManager.Instance.PlayKickSound(); } }
public void Execute(IGameObject gameObject1, IGameObject gameObject2) { Goomba2 goomba = (Goomba2)gameObject1; int goombaPreY = (int)(goomba.Location.Y - (goomba.Velocity.Y - GameUtilities.SinglePixel)); if (goombaPreY + goomba.Destination.Height <= gameObject2.Location.Y) { return; } else if (goombaPreY > gameObject2.Location.Y + gameObject2.Destination.Height) { return; } if (goomba.Velocity.X < GameUtilities.StationaryVelocity) { goomba.ChangeDirection(); } }
public void Execute(IGameObject gameObject1, IGameObject gameObject2) { Goomba2 g = (Goomba2)gameObject1; if (!g.Alive) { return; } if (gameObject2.GetType() == typeof(LPipeBottom) || gameObject2.GetType() == typeof(LPipeBottomLeft)) { return; } g.Location = new Vector2(g.Location.X, gameObject2.Location.Y - g.Destination.Height); if (g.Velocity.Y < GameUtilities.StationaryVelocity) { g.Velocity = new Vector2(g.Velocity.X, GameUtilities.StationaryVelocity); } }
public GoombaAliveState(Goomba2 goomba) { StateSprite = EnemySpriteFactory.Instance.CreateGoombaSprite(); this.goomba = goomba; }
public void Execute(IGameObject gameObject1, IGameObject gameObject2) { Goomba2 goomba2 = (Goomba2)gameObject2; goomba2.Location = new Vector2(goomba2.Location.X, gameObject1.Location.Y - gameObject2.Destination.Height - GameUtilities.SinglePixel); }
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); } }
public bool TestMarioEnemyCollisionsGoomba() { bool isSuccess = true; IGameObject marioLeftGoomba = new Mario(new Vector2(40, 52)); IGameObject leftGoomba = new Goomba2(new Vector2(50, 50)); IGameObject marioTopGoomba = new Mario(new Vector2(101, 90)); IGameObject topGoomba = new Goomba2(new Vector2(100, 100)); IGameObject marioRightGoomba = new Mario(new Vector2(160, 153)); IGameObject rightGoomba = new Goomba2(new Vector2(150, 150)); IGameObject marioBottomGoomba = new Mario(new Vector2(200, 210)); IGameObject bottomGoomba = new Goomba2(new Vector2(200, 200)); IGameObject marioNoGoomba = new Mario(new Vector2(0, 100)); IEnemy noCollisionGoomba = new Goomba2(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.Goomba, Object2Side.Top), new MarioKoopaCollisionTop() }, { new Tuple <ObjectType, ObjectType, Object2Side>(ObjectType.Mario, ObjectType.Goomba, Object2Side.Right), new MarioKoopaCollisionRight() }, { new Tuple <ObjectType, ObjectType, Object2Side>(ObjectType.Mario, ObjectType.Goomba, Object2Side.Bottom), new MarioKoopaCollisionBottom() }, { new Tuple <ObjectType, ObjectType, Object2Side>(ObjectType.Mario, ObjectType.Goomba, Object2Side.Left), new MarioKoopaCollisionLeft() } }; AllCollisionHandler testHandler = new AllCollisionHandler(testDictionary); Console.WriteLine("Tests for collision side of Mario-Goomba collisions."); Console.Write("Succesful recognition of left side of Goomba collision: "); Console.WriteLine(AllCollisionHandler.DetermineCollisionSide(marioLeftGoomba.Destination, leftGoomba.Destination) == Object2Side.Left); Console.Write("Succesful recognition of top side of Goomba collision: "); Console.WriteLine(AllCollisionHandler.DetermineCollisionSide(marioTopGoomba.Destination, topGoomba.Destination) == Object2Side.Top); Console.Write("Succesful recognition of right side of Goomba collision: "); Console.WriteLine(AllCollisionHandler.DetermineCollisionSide(marioRightGoomba.Destination, rightGoomba.Destination) == Object2Side.Right); Console.Write("Succesful recognition of bottom side of Goomba collision: "); Console.WriteLine(AllCollisionHandler.DetermineCollisionSide(marioBottomGoomba.Destination, bottomGoomba.Destination) == Object2Side.Bottom); Console.Write("Succesful recognition of no Goomba collision: "); Console.WriteLine(AllCollisionHandler.DetermineCollisionSide(marioNoGoomba.Destination, noCollisionGoomba.Destination) == Object2Side.NoCollision); Console.WriteLine(); testHandler.HandleCollision(marioLeftGoomba, leftGoomba); testHandler.HandleCollision(marioRightGoomba, rightGoomba); testHandler.HandleCollision(marioBottomGoomba, bottomGoomba); testHandler.HandleCollision(marioTopGoomba, topGoomba); testHandler.HandleCollision(marioNoGoomba, noCollisionGoomba); /*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-Goomba collisions."); * Console.Write("Succesful left side of Goomba collision: (38, 52) = ("); * Console.Write(marioLeftGoomba.Location.X); * Console.Write(", "); * Console.Write(marioLeftGoomba.Location.Y); * Console.WriteLine(")"); * isSuccess = isSuccess && (marioLeftGoomba.Destination.X == (int)leftCollisionResult.X && marioLeftGoomba.Destination.Y == (int)leftCollisionResult.Y); * Console.Write("Succesful top side of Goomba collision: (101, 85) = ("); * Console.Write(marioTopGoomba.Location.X); * Console.Write(", "); * Console.Write(marioTopGoomba.Location.Y); * Console.WriteLine(")"); * isSuccess = isSuccess && (marioTopGoomba.Destination.X == (int)topCollisionResult.X && marioTopGoomba.Destination.Y == (int)topCollisionResult.Y); * Console.Write("Succesful right side of Goomba collision: (166, 153) = ("); * Console.Write(marioRightGoomba.Location.X); * Console.Write(", "); * Console.Write(marioRightGoomba.Location.Y); * Console.WriteLine(")"); * isSuccess = isSuccess && (marioRightGoomba.Destination.X == (int)rightCollisionResult.X && marioRightGoomba.Destination.Y == (int)rightCollisionResult.Y); * Console.Write("Succesful bottom side of Goomba collision: (200, 216) = ("); * Console.Write(marioBottomGoomba.Location.X); * Console.Write(", "); * Console.Write(marioBottomGoomba.Location.Y); * Console.WriteLine(")"); * isSuccess = isSuccess && (marioBottomGoomba.Destination.X == (int)bottomCollisionResult.X && marioBottomGoomba.Destination.Y == (int)bottomCollisionResult.Y); * Console.Write("Succesful no Koopa collision: (0, 100) = ("); * Console.Write(marioNoGoomba.Location.X); * Console.Write(", "); * Console.Write(marioNoGoomba.Location.Y); * Console.WriteLine(")"); * isSuccess = isSuccess && (marioNoGoomba.Destination.X == (int)noCollisionResult.X && marioNoGoomba.Destination.Y == (int)noCollisionResult.Y); * Console.WriteLine(); * Console.Write("Mario-Goomba collision tests are successful: "); * Console.WriteLine(isSuccess); * Console.WriteLine(); * * marioLeftGoomba.Draw(spriteBatch); * leftGoomba.Draw(spriteBatch); * marioTopGoomba.Draw(spriteBatch); * topGoomba.Draw(spriteBatch); * marioRightGoomba.Draw(spriteBatch); * rightGoomba.Draw(spriteBatch); * marioBottomGoomba.Draw(spriteBatch); * bottomGoomba.Draw(spriteBatch); * marioNoGoomba.Draw(spriteBatch); * noCollisionGoomba.Draw(spriteBatch); */ return(isSuccess); }