public void Initialize() { IGameObject Mushroom = new Mushroom(DefaultSpawn); IGameObject FireFlower = new FireFlower(DefaultSpawn); IGameObject Coin = new Coin(DefaultSpawn); IGameObject OneUp = new OneUp(DefaultSpawn); IGameObject Star = new Star(DefaultSpawn); AllItems.Add(Mushroom); AllItems.Add(FireFlower); AllItems.Add(Coin); AllItems.Add(OneUp); AllItems.Add(Star); }
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 Trigger() { if (Used) { return; } IGameObject newObject = null; switch (hiddenItem) { case ItemType.Flower: newObject = new FireFlower(new Vector2(Location.X, Location.Y - 2)); SoundManager.Instance.PlayMushStarSound(); break; case ItemType.UpMushroom: newObject = new UpMushroom(new Vector2(Location.X, Location.Y - 16)); SoundManager.Instance.PlayMushStarSound(); break; case ItemType.SuperMushroom: newObject = new SuperMushroom(new Vector2(Location.X, Location.Y - 16)); SoundManager.Instance.PlayMushStarSound(); break; case ItemType.Star: newObject = new Star(new Vector2(Location.X, Location.Y - 16)); SoundManager.Instance.PlayMushStarSound(); break; default: coinAnimation.StartAnimation(); CoinSystem.Instance.AddCoin(); ScoringSystem.AddPointsForCoin(this); break; } if (newObject != null) { GameObjectManager.itemList.Add(newObject); } stateMachine.BeTriggered(); }
public override void SpawnItem() { if (Mario.Instance.ConditionState is SmallMarioState) { IItem powerup = new SuperMushroom { Location = new Vector2(Location.X, Location.Y - SpriteUtility.Instance.BLOCK_UNIT) }; PlayerLevel.Instance.ItemArray.Add(powerup); } else { IItem powerup = new FireFlower { Location = new Vector2(Location.X, Location.Y - SpriteUtility.Instance.BLOCK_UNIT) }; PlayerLevel.Instance.ItemArray.Add(powerup); } }
public CollisionMarioFireFlowerTests() : base() { tangible1 = new Mario(); tangible2 = new FireFlower(); collisions = new List <Tuple <ITangibleState, PhysicsBundle, ITangibleState, PhysicsBundle, Collider.CollisionFrom> >() { // mario FireFlower above collision Tuple.Create <ITangibleState, PhysicsBundle, ITangibleState, PhysicsBundle, Collider.CollisionFrom>( new SIdleLeftBigMario((Mario)tangible1), new PhysicsBundle(40, 0, 0, 1), new SFireFlowerIdle((FireFlower)tangible2), new PhysicsBundle(40, 5), WindowsGame2.Collider.CollisionFrom.Below), Tuple.Create <ITangibleState, PhysicsBundle, ITangibleState, PhysicsBundle, Collider.CollisionFrom>( new SIdleLeftBigMario((Mario)tangible1), new PhysicsBundle(40, 5, 0, -1), new SFireFlowerIdle((FireFlower)tangible2), new PhysicsBundle(40, 0), WindowsGame2.Collider.CollisionFrom.Above), Tuple.Create <ITangibleState, PhysicsBundle, ITangibleState, PhysicsBundle, Collider.CollisionFrom>( new SIdleLeftBigMario((Mario)tangible1), new PhysicsBundle(40, 0, -1), new SFireFlowerIdle((FireFlower)tangible2), new PhysicsBundle(45, 0), WindowsGame2.Collider.CollisionFrom.Left), Tuple.Create <ITangibleState, PhysicsBundle, ITangibleState, PhysicsBundle, Collider.CollisionFrom>( new SIdleLeftBigMario((Mario)tangible1), new PhysicsBundle(40, 0, 1), new SFireFlowerIdle((FireFlower)tangible2), new PhysicsBundle(45, 0), WindowsGame2.Collider.CollisionFrom.Right), Tuple.Create <ITangibleState, PhysicsBundle, ITangibleState, PhysicsBundle, Collider.CollisionFrom>( new SIdleLeftBigMario((Mario)tangible1), new PhysicsBundle(0, 0), new SFireFlowerIdle((FireFlower)tangible2), new PhysicsBundle(40, 0), WindowsGame2.Collider.CollisionFrom.None), }; }
public override void SpawnItem() { SoundFactory.Instance.PlaySoundEffect("SOUND_POWERUP_APPEARS"); if (Mario.Instance.ConditionState is SmallMarioState) { IItem powerup = new SuperMushroom { Location = new Vector2(Location.X, Location.Y - SpriteUtility.Instance.BLOCK_UNIT) }; Level.PlayerLevel.Instance.ItemArray.Add(powerup); } else { IItem powerup = new FireFlower { Location = new Vector2(Location.X, Location.Y - SpriteUtility.Instance.BLOCK_UNIT) }; Level.PlayerLevel.Instance.ItemArray.Add(powerup); } }
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 static void InfiniteLevelLoad(Game myGame) { enemyList = new List <IEnemy>(); itemList = new List <IItem>(); blockList = new List <IBlock>(); bgList = new List <IBg>(); String[] levelFile = new String[two] { "InfiniteLevel-1.txt", "InfiniteLevel-2.txt" }; int file = 0; StreamReader File = new StreamReader(Path.Combine(Directory.GetCurrentDirectory(), "Content", "Levels", levelFile[file])); String inComingLine; int posRow = zero; while (!File.EndOfStream) { inComingLine = File.ReadLine(); String[] target = inComingLine.Split(','); int posCol = zero; while (posCol < target.Length) { if (target[posCol].Equals("brick")) { IBlock block = new Brick(myGame, posCol, posRow); blockList.Add(block); } else if (target[posCol].Equals("crack")) { IBlock block = new Crack(myGame, posCol, posRow); blockList.Add(block); } else if (target[posCol].Equals("diamond")) { IBlock block = new Diamond(myGame, posCol * stdSpriteSize, posRow * stdSpriteSize); blockList.Add(block); } else if (target[posCol].Equals("question")) { IBlock block = new Question(myGame, posCol, posRow); blockList.Add(block); } else if (target[posCol].Equals("questionRedM")) { Question block = new Question(myGame, posCol, posRow); block.contain = Utility.items.redM; blockList.Add(block); } else if (target[posCol].Equals("questionFireF")) { Question block = new Question(myGame, posCol, posRow); block.contain = Utility.items.flower; blockList.Add(block); } else if (target[posCol].Equals("questionCoin")) { Question block = new Question(myGame, posCol, posRow); block.contain = Utility.items.coin; blockList.Add(block); } else if (target[posCol].Equals("questionGreenM")) { Question block = new Question(myGame, posCol, posRow); block.contain = Utility.items.greenM; blockList.Add(block); } else if (target[posCol].Equals("questionBat")) { Question block = new Question(myGame, posCol, posRow); block.contain = Utility.items.bat; blockList.Add(block); } else if (target[posCol].Equals("used")) { IBlock block = new Used(myGame, posCol, posRow); blockList.Add(block); } else if (target[posCol].Equals("invisible")) { IBlock block = new Invisible(myGame, posCol, posRow); blockList.Add(block); } else if (target[posCol].Equals("standardPipe")) { Pipe block = new Pipe(myGame, posCol, posRow); blockList.Add(block); IEnemy enemy = new PiranhaPlant(myGame, block.drawLoc.X, block.drawLoc.Y); enemyList.Add(enemy); } else if (target[posCol].Equals("pipeNeck")) { IBlock block = new PipeNeck(myGame, posCol, posRow); blockList.Add(block); } else if (target[posCol].Equals("coin")) { IItem item = new Coin(myGame, posCol * stdSpriteSize, posRow * stdSpriteSize); itemList.Add(item); } else if (target[posCol].Equals("star")) { IItem item = new Star(myGame, posCol * stdSpriteSize, posRow * stdSpriteSize); itemList.Add(item); } else if (target[posCol].Equals("flower")) { IItem item = new FireFlower(myGame, posCol * stdSpriteSize, posRow * stdSpriteSize); itemList.Add(item); } else if (target[posCol].Equals("redMushroom")) { IItem item = new RedMushroom(myGame, posCol * stdSpriteSize, posRow * stdSpriteSize); itemList.Add(item); } else if (target[posCol].Equals("greenMushroom")) { IItem item = new GreenMushroom(myGame, posCol * stdSpriteSize, posRow * stdSpriteSize); itemList.Add(item); } else if (target[posCol].Equals("goomba")) { IEnemy enemy = new Goomba(myGame, posCol, posRow); enemyList.Add(enemy); } else if (target[posCol].Equals("koopa")) { IEnemy enemy = new Koopa(myGame, posCol, posRow); enemyList.Add(enemy); } else if (target[posCol].Equals("oneCloud")) { IBg bg = new Bg(myGame, myGame.oneCloudBgElement, posCol, posRow); bgList.Add(bg); } else if (target[posCol].Equals("threeClouds")) { IBg bg = new Bg(myGame, myGame.threeCloudsBgElement, posCol, posRow); bgList.Add(bg); } else if (target[posCol].Equals("oneBush")) { IBg bg = new Bg(myGame, myGame.oneBushBgElement, posCol, posRow); bgList.Add(bg); } else if (target[posCol].Equals("threeBushes")) { IBg bg = new Bg(myGame, myGame.threeBushesBgElement, posCol, posRow); bgList.Add(bg); } else if (target[posCol].Equals("smallMountain")) { IBg bg = new Bg(myGame, myGame.smallMountainBgElement, posCol, posRow); bgList.Add(bg); } else if (target[posCol].Equals("bigMountain")) { IBg bg = new Bg(myGame, myGame.bigMountainBgElement, posCol, posRow); bgList.Add(bg); } posCol++; } posRow++; } File.Close(); if (file < two) { File = new StreamReader(Path.Combine(Directory.GetCurrentDirectory(), "Content", "Levels", levelFile[file])); file++; } else { file = zero; } IComparer <IBlock> blockComp = new BlockComparer <IBlock>(); IComparer <IItem> itemComp = new ItemComparer <IItem>(); IComparer <IEnemy> enemyComp = new EnemyComparer <IEnemy>(); blockList.Sort(blockComp); itemList.Sort(itemComp); enemyList.Sort(enemyComp); }