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); }
private static void CreateItem(IWorld world, string type, float xPosition, float yPosition) { IBlock block = new HiddenBlock(new Vector2(0, 0)); // Get size of an arbitrary block to be size of local collision detection scope int blocksWidth = block.Rectangle.Width;; int blocksHeight = block.Rectangle.Height; int blockIndexX = (int)Math.Floor(xPosition / blocksWidth); int blockIndexY = (int)Math.Floor(yPosition / blocksHeight); block = world.Blocks[blockIndexX].OneBlockLevel[blockIndexY]; if (type.Equals("StaticCoin")) { world.Items.Add(new Coin(new Vector2(xPosition, yPosition), true, new CollectDelegate(ScoreManager.Instance.CollectCoin))); } else if (block is BrickBlock) { BrickBlock brickBlock = block as BrickBlock; brickBlock.AddItem(type); } else if (block is QuestionBlock) { QuestionBlock questionBlock = block as QuestionBlock; questionBlock.AddItem(type); } else if (block is HiddenBlock) { HiddenBlock hiddenBlock = block as HiddenBlock; hiddenBlock.AddItem(type); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.GetComponent <InteractableBlocks>()) { InteractableBlocks block = collision.GetComponent <InteractableBlocks>(); switch (block.type) { case BlockType.Hidden: if (playerRigid.velocity.y > 0) { if (!hasInteractedHidden) { hasInteractedHidden = true; HiddenBlock hidden = collision.GetComponent <HiddenBlock>(); hidden.Interacted(); block.Interacted(player.isGrown); StartCoroutine(hiddenReset()); } } break; default: block.Interacted(player.isGrown); break; } } player.ResetJump(); }
public void Execute(IGameObject gameObject1, IGameObject gameObject2) { if (gameObject2.GetType() == typeof(HiddenBlock)) { HiddenBlock hiddenBlock = (HiddenBlock)gameObject2; if (!hiddenBlock.Used) { return; } } if (gameObject2.GetType() == typeof(LPipeBottom) || gameObject2.GetType() == typeof(LPipeBottomLeft)) { return; } Koopa2 koopa = (Koopa2)gameObject1; if (koopa.State.GetType() == typeof(KoopaSideDeathState)) { return; } koopa.Location = new Vector2(koopa.Location.X, gameObject2.Location.Y - koopa.Destination.Height); koopa.Velocity = new Vector2(koopa.Velocity.X, GameUtilities.StationaryVelocity); }
public void Execute(IGameObject gameObject1, IGameObject gameObject2) { IMario mario = (IMario)gameObject1; if (mario.State.MarioShape == MarioState.MarioShapeEnums.Dead) { return; } if (gameObject2.GetType() == typeof(HiddenBlock)) { HiddenBlock hiddenBlock = (HiddenBlock)gameObject2; if (!hiddenBlock.Used) { return; } } int marioPreY = (int)(mario.Destination.Y - (mario.Velocity.Y - GameUtilities.SinglePixel)); if (marioPreY + mario.Destination.Height <= gameObject2.Destination.Y) { return; } else if (marioPreY > gameObject2.Destination.Y + gameObject2.Destination.Height) { return; } mario.Location = new Vector2(gameObject2.Destination.X + gameObject2.Destination.Width + GameUtilities.SinglePixel, mario.Destination.Y); if (mario.Velocity.X < 0) { mario.Velocity = new Vector2(GameUtilities.StationaryVelocity, mario.Velocity.Y); } }
public void Execute(IGameObject gameObject1, IGameObject gameObject2) { IMario mario = (IMario)gameObject1; if (mario.State.MarioShape == MarioState.MarioShapeEnums.Dead) { return; } if (gameObject2.GetType() == typeof(HiddenBlock)) { HiddenBlock hiddenBlock = (HiddenBlock)gameObject2; if (!hiddenBlock.Used) { return; } } mario.IsInAir = false; mario.Location = new Vector2(mario.Destination.X, gameObject2.Destination.Y - mario.Destination.Height); if (mario.Velocity.Y > 0) { mario.Velocity = new Vector2(mario.Velocity.X, GameUtilities.StationaryVelocity); } }
public void Execute(IGameObject gameObject1, IGameObject gameObject2) { if (gameObject2.GetType() == typeof(HiddenBlock)) { HiddenBlock hiddenBlock = (HiddenBlock)gameObject2; if (!hiddenBlock.Used) { return; } } Star star = (Star)gameObject1; if (star.IsPreparing) { return; } int starPreY = (int)(star.Destination.Y - (star.Velocity.Y - GameUtilities.SinglePixel)); if (starPreY + star.Destination.Height <= gameObject2.Destination.Y) { return; } else if (starPreY > gameObject2.Destination.Y + gameObject2.Destination.Height) { return; } if (star.Velocity.X < GameUtilities.StationaryVelocity) { star.ChangeDirection(); } }
public static void HandleHiddenBlockCollision(IPlayer player, HiddenBlock hiddenBlock, CollisionSide side) { if (hiddenBlock.IsUsed) // If block has been exposed act like a UsedBlock { PlayerBlockRepel(hiddenBlock, player, side); } else if (side == CollisionSide.Bottom && player.PlayerPhysics.IsMovingUp()) // If block is still hidden and mario bumps the bottom of the block { PlayerBlockRepel(hiddenBlock, player, side); hiddenBlock.BeBumped(); hiddenBlock.SpawnItem(); hiddenBlock.BecomeUsed(); } }
public Sprite BuildSprite(BlockType sprite, Vector2 loc) { Sprite toReturn = null; switch (sprite) { case BlockType.exploded: { toReturn = new ExplodingBlock(loc); break; } case BlockType.question: { toReturn = new QuestionBlock(loc); break; } case BlockType.used: { toReturn = new UsedBlock(loc); break; } case BlockType.brick: { toReturn = new BrickBlock(loc); break; } case BlockType.hidden: { toReturn = new HiddenBlock(loc); break; } case BlockType.pipe: { toReturn = new PipeBlock(loc); break; } case BlockType.bridge: { toReturn = new BridgeBlock(loc); break; } } return(toReturn); }
public void Execute(IGameObject gameObject1, IGameObject gameObject2) { if (gameObject2.GetType() == typeof(HiddenBlock)) { HiddenBlock hiddenBlock = (HiddenBlock)gameObject2; if (!hiddenBlock.Used) { return; } } Horse horse = (Horse)gameObject1; if (!horse.Alive) { return; } horse.Location = new Vector2(horse.Location.X, gameObject2.Location.Y - horse.Destination.Height); horse.Velocity = new Vector2(horse.Velocity.X, GameUtilities.StationaryVelocity); }
public void Execute(IGameObject gameObject1, IGameObject gameObject2) { if (gameObject2.GetType() == typeof(HiddenBlock)) { HiddenBlock hiddenBlock = (HiddenBlock)gameObject2; if (!hiddenBlock.Used) { return; } } GreenMushroom greenMushroom = (GreenMushroom)gameObject1; if (greenMushroom.IsPreparing) { return; } greenMushroom.Location = new Vector2(greenMushroom.Location.X, gameObject2.Location.Y - greenMushroom.Destination.Height); greenMushroom.Velocity = new Vector2(greenMushroom.Velocity.X, GameUtilities.StationaryVelocity); }
public void Execute(IGameObject gameObject1, IGameObject gameObject2) { if (gameObject2.GetType() == typeof(HiddenBlock)) { HiddenBlock hiddenBlock = (HiddenBlock)gameObject2; if (!hiddenBlock.Used) { return; } } Star star = (Star)gameObject1; if (star.IsPreparing) { return; } star.Location = new Vector2(star.Location.X, gameObject2.Location.Y - star.Destination.Height); star.Velocity = new Vector2(star.Velocity.X, starBounceVelocity); }
public IEntity AddBlock(XmlNode x, ContentManager content, GraphicsDevice graphics, CollisionDetection collisions) { bool isUnderworld = false; switch (type) { case ("questionblock"): QuestionBlock questionBlock = new QuestionBlock(content, graphics); if (x.HasChildNodes) { for (int m = Constants.ZERO; m < x.ChildNodes.Count; m++) { IEntity childEntity = null; XmlNode y = x.ChildNodes[m]; GetAttributes(y); if (tag.Equals("item")) { childEntity = AddItem(content, graphics); } else if (tag.Equals("block")) { childEntity = AddBlock(y, content, graphics, collisions); } entity = childEntity; SetProperties(collisions); questionBlock.AddContainedItem(childEntity); } } GetAttributes(x); entity = questionBlock; break; case ("floorblock"): isUnderworld = false; entity = new FloorBlock(content, graphics, isUnderworld); break; case ("underworldFloor"): isUnderworld = true; entity = new FloorBlock(content, graphics, isUnderworld); break; case ("glassblock"): GlassBlock glassBlock = new GlassBlock(content, graphics); isGlass = true; if (x.HasChildNodes) { for (int m = Constants.ZERO; m < x.ChildNodes.Count; m++) { IEntity childEntity = null; XmlNode y = x.ChildNodes[m]; GetAttributes(y); if (tag.Equals("block")) { childEntity = AddBlock(y, content, graphics, collisions); } entity = childEntity; SetProperties(collisions); glassBlock.AddContainedItem(childEntity); } } GetAttributes(x); entity = glassBlock; break; case ("brickblock"): isUnderworld = false; BrickBlock brickBlock = new BrickBlock(content, graphics, isUnderworld); if (x.HasChildNodes) { for (int m = Constants.ZERO; m < x.ChildNodes.Count; m++) { IEntity childEntity = null; XmlNode y = x.ChildNodes[m]; GetAttributes(y); if (tag.Equals("item")) { childEntity = AddItem(content, graphics); } else if (tag.Equals("block")) { childEntity = AddBlock(y, content, graphics, collisions); } entity = childEntity; SetProperties(collisions); brickBlock.AddContainedItem(childEntity); } } GetAttributes(x); entity = brickBlock; break; case ("underworldBrick"): Underworld = true; BrickBlock underworldBrickBlock = new BrickBlock(content, graphics, Underworld); if (x.HasChildNodes) { for (int m = Constants.ZERO; m < x.ChildNodes.Count; m++) { IEntity childEntity = null; XmlNode y = x.ChildNodes[m]; GetAttributes(y); if (tag.Equals("item")) { childEntity = AddItem(content, graphics); } else if (tag.Equals("block")) { childEntity = AddBlock(y, content, graphics, collisions); } entity = childEntity; SetProperties(collisions); underworldBrickBlock.AddContainedItem(childEntity); } } GetAttributes(x); entity = underworldBrickBlock; break; case ("warpPipe"): WarpPipe warpPipe = new WarpPipe(content, graphics, ExitPipe, Underworld, MiniGame); if (x.HasChildNodes) { for (int m = Constants.ZERO; m < x.ChildNodes.Count; m++) { IEntity childEntity = null; XmlNode y = x.ChildNodes[m]; GetAttributes(y); if (tag.Equals("enemy")) { childEntity = AddEnemy(content, graphics, peach); } else if (tag.Equals("block")) { childEntity = AddBlock(y, content, graphics, collisions); } entity = childEntity; SetProperties(collisions); warpPipe.AddContainedItem(childEntity); } } GetAttributes(x); entity = warpPipe; break; case ("stairblock"): entity = new StairBlock(content, graphics); break; case ("usedblock"): entity = new UsedBlock(content, graphics); break; case ("hiddenblock"): isUnderworld = false; HiddenBlock hiddenBlock = new HiddenBlock(content, graphics); if (x.HasChildNodes) { for (int m = Constants.ZERO; m < x.ChildNodes.Count; m++) { IEntity childEntity = null; XmlNode y = x.ChildNodes[m]; GetAttributes(y); if (tag.Equals("item")) { childEntity = AddItem(content, graphics); } else if (tag.Equals("block")) { childEntity = AddBlock(y, content, graphics, collisions); } entity = childEntity; SetProperties(collisions); hiddenBlock.AddContainedItem(childEntity); } } GetAttributes(x); entity = hiddenBlock; break; case ("pipe"): entity = new Pipe(content, graphics); break; case ("explodingBlock"): entity = new ExplodingBlock(content, graphics, isGlass); break; case ("exitPipe"): entity = new WarpPipe(content, graphics, ExitPipe, Underworld, MiniGame); break; default: break; } return(entity); }
private static void LoadLevel(XmlReader reader) { Random random = new Random(); string objectType = ""; string objectName = ""; string location = ""; bool typeFlag = false; bool nameFlag = false; bool locationFlag = false; IList <IBlock> blockList = new List <IBlock>(); IList <IEnemy> enemyList = new List <IEnemy>(); IList <IItem> itemList = new List <IItem>(); while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.Name.ToString()) { case "ObjectType": objectType = reader.ReadString(); typeFlag = true; break; case "ObjectName": objectName = reader.ReadString(); nameFlag = true; break; case "Location": location = reader.ReadString(); locationFlag = true; break; } if (typeFlag && nameFlag && locationFlag) { switch (objectType) { case "Player": string[] coordinates = location.Split(' '); Mario.Instance.ConditionState = new SmallMarioState(Mario.Instance); Mario.Instance.Location = new Vector2(Int32.Parse(coordinates[0]), Int32.Parse(coordinates[1])); break; case "Block": switch (objectName) { case "HiddenBlock": string[] blockCoordinates = location.Split(' '); IBlock block = new HiddenBlock(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "HiddenBlockEmpty": blockCoordinates = location.Split(' '); block = new HiddenBlockEmpty(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "HiddenBlockCoin": blockCoordinates = location.Split(' '); block = new HiddenBlockCoin(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "HiddenBlockStar": blockCoordinates = location.Split(' '); block = new HiddenBlockStar(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "BrickBlock": blockCoordinates = location.Split(' '); block = new BrickBlock(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "BrickBlockEmpty": blockCoordinates = location.Split(' '); block = new BrickBlockEmpty(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "ItemBrick": blockCoordinates = location.Split(' '); block = new BrickBlockWithItem(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "ItemBrickCoin": blockCoordinates = location.Split(' '); block = new BrickBlockWithCoin(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "ItemBrickStar": blockCoordinates = location.Split(' '); block = new BrickBlockWithStar(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "QuestionBlock": blockCoordinates = location.Split(' '); block = new QuestionBlock(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "QuestionBlockEmpty": blockCoordinates = location.Split(' '); block = new QuestionBlockEmpty(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "QuestionBlockStar": blockCoordinates = location.Split(' '); block = new QuestionBlockStar(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "QuestionBlockCoin": blockCoordinates = location.Split(' '); block = new QuestionBlockCoin(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "UnbreakableBlock": blockCoordinates = location.Split(' '); block = new UnbreakableBlock(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "UsedBlock": blockCoordinates = location.Split(' '); block = new UsedBlock(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "GroundBlock": blockCoordinates = location.Split(' '); block = new GroundBlock(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "Pipe": blockCoordinates = location.Split(' '); block = new Pipe(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "PipeBottom": blockCoordinates = location.Split(' '); block = new PipeBottom(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; case "WarpPipe": blockCoordinates = location.Split(' '); WarpPipe pipe = new WarpPipe(); pipe.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); switch (pipe.Location.X) { case 1760: pipe.WarpDestination = new Vector2(8000, 384); break; case 8736: pipe.WarpDestination = new Vector2(2080, 352); break; } blockList.Add((IBlock)pipe); break; case "FlagPole": blockCoordinates = location.Split(' '); block = new FlagPole(); block.Location = new Vector2(Int32.Parse(blockCoordinates[0]), Int32.Parse(blockCoordinates[1])); blockList.Add(block); break; } break; case "Enemy": switch (objectName) { case "Goomba": string[] enemyCoordinates = location.Split(' '); IEnemy enemy = new Goomba(); enemy.RowId = random.Next(0, 160); enemy.Location = new Vector2(Int32.Parse(enemyCoordinates[0]), Int32.Parse(enemyCoordinates[1])); enemyList.Add(enemy); break; case "Koopa": enemyCoordinates = location.Split(' '); enemy = new Koopa(); enemy.RowId = random.Next(0, 160); enemy.Location = new Vector2(Int32.Parse(enemyCoordinates[0]), Int32.Parse(enemyCoordinates[1])); enemyList.Add(enemy); break; } break; case "Item": switch (objectName) { case "Coin": string[] itemCoordinates = location.Split(' '); IItem item = new Coin(); item.Location = new Vector2(Int32.Parse(itemCoordinates[0]), Int32.Parse(itemCoordinates[1])); itemList.Add(item); break; case "FireFlower": itemCoordinates = location.Split(' '); item = new FireFlower(); item.Location = new Vector2(Int32.Parse(itemCoordinates[0]), Int32.Parse(itemCoordinates[1])); itemList.Add(item); break; case "OneUpMush": itemCoordinates = location.Split(' '); item = new OneUpMushroom(); item.Location = new Vector2(Int32.Parse(itemCoordinates[0]), Int32.Parse(itemCoordinates[1])); itemList.Add(item); break; case "SuperMush": itemCoordinates = location.Split(' '); item = new SuperMushroom(); item.Location = new Vector2(Int32.Parse(itemCoordinates[0]), Int32.Parse(itemCoordinates[1])); itemList.Add(item); break; case "Star": itemCoordinates = location.Split(' '); item = new Star(); item.Location = new Vector2(Int32.Parse(itemCoordinates[0]), Int32.Parse(itemCoordinates[1])); itemList.Add(item); break; } break; } typeFlag = false; nameFlag = false; locationFlag = false; } } } PlayerLevel.Instance.BlockArray = blockList; PlayerLevel.Instance.EnemyArray = enemyList; PlayerLevel.Instance.ItemArray = itemList; }
public HiddenBlockCommand(HiddenBlock block) { Block = block; }
public HiddenBlockUsedCommand(HiddenBlock block) { hiddenBlock = block; }
public HiddenBlockUpdateCommand(Level level, HiddenBlock gameObject) { this.level = level; block = gameObject; }