public VVVVVVKeyController(Mario mario) { flip = new FlipCommand(mario); this.mario = mario; commandLibrary = new Dictionary <Keys, ICommands>(); commandLibrary.Add(Keys.W, currentCommand = new FlipCommand(mario)); commandLibrary.Add(Keys.Up, currentCommand = new FlipCommand(mario)); commandLibrary.Add(Keys.S, currentCommand = new FlipCommand(mario)); commandLibrary.Add(Keys.Down, currentCommand = new FlipCommand(mario)); commandLibrary.Add(Keys.A, currentCommand = new LeftCommand(mario)); commandLibrary.Add(Keys.Left, currentCommand = new LeftCommand(mario)); commandLibrary.Add(Keys.D, currentCommand = new RightCommand(mario)); commandLibrary.Add(Keys.Right, currentCommand = new RightCommand(mario)); commandLibrary.Add(Keys.Q, currentCommand = new QuitCommand()); commandLibrary.Add(Keys.R, currentCommand = new ResetSceneCommand()); }
public void PipeMarioCollide(Mario mario, Pipe pipe, List <Pipe> standingPipes) { Rectangle marioRect = mario.state.GetBoundingBox(new Vector2(mario.position.X, mario.position.Y)); Rectangle pipeRect = pipe.GetBoundingBox(); Rectangle intersection = Rectangle.Intersect(marioRect, pipeRect); if (intersection.Height > intersection.Width) { if (marioRect.Right > pipeRect.Left && marioRect.Right < pipeRect.Right) { mario.position.X -= intersection.Width; if (pipe.state.GetType().Equals(new LeftPipeState().GetType())) { pipe.Eat(mario); } } else { mario.position.X += intersection.Width; } } else if (intersection.Height < intersection.Width) { if (marioRect.Bottom > pipeRect.Top && marioRect.Bottom < pipeRect.Bottom) { if (!mario.isJumping) { mario.velocity.Y = 0; } if (intersection.Height > 1) { mario.position.Y -= intersection.Height; } standingPipes.Add(pipe); if (pipe.state.GetType().Equals(new UpPipeState().GetType()) && mario.isCrouch) { pipe.Eat(mario); } } else { mario.position.Y += intersection.Height; } } }
public KeyboardController(Mario mario) { this.mario = mario; commandLibrary = new Dictionary <Keys, ICommands>(); commandLibrary.Add(Keys.W, currentCommand = new UpCommand(mario)); commandLibrary.Add(Keys.X, currentCommand = new RunCommand(mario)); commandLibrary.Add(Keys.Up, currentCommand = new UpCommand(mario)); commandLibrary.Add(Keys.S, currentCommand = new DownCommand(mario)); commandLibrary.Add(Keys.Down, currentCommand = new DownCommand(mario)); commandLibrary.Add(Keys.A, currentCommand = new LeftCommand(mario)); commandLibrary.Add(Keys.Left, currentCommand = new LeftCommand(mario)); commandLibrary.Add(Keys.D, currentCommand = new RightCommand(mario)); commandLibrary.Add(Keys.Right, currentCommand = new RightCommand(mario)); commandLibrary.Add(Keys.B, currentCommand = new ProjectileCommand(mario)); commandLibrary.Add(Keys.Enter, currentCommand = new PauseCommand()); commandLibrary.Add(Keys.Q, currentCommand = new QuitCommand()); commandLibrary.Add(Keys.R, currentCommand = new ResetSceneCommand()); }
public void MarioItemCollide(ICollectable item, Mario mario) { if (item.GetType().Equals(new Star(item.position).GetType())) { mario.isStar = true; game.gameHUD.Score += ValueHolder.itemCollectPoints; if (!mario.isNinja) { SoundManager.PlaySong(SoundManager.songs.star); } } if (item.GetType().Equals(new Ninja(item.position).GetType())) { mario.MakeNinjaMario(); mario.isNinja = true; game.gameHUD.Score += ValueHolder.itemCollectPoints; SoundManager.PlaySong(SoundManager.songs.ninja); } if (item.GetType().Equals(new SuperMushroom(item.position).GetType())) { mario.MakeBigMario(); game.gameHUD.Score += ValueHolder.itemCollectPoints; SoundManager.grow.Play(); game.ach.AchievementAdjustment(AchievementsManager.AchievementType.Mushroom); } if (item.GetType().Equals(new FireFlower(item.position).GetType())) { mario.MakeFireMario(); game.gameHUD.Score += ValueHolder.itemCollectPoints; SoundManager.grow.Play(); } if (item.GetType().Equals(new Coin(item.position).GetType())) { SoundManager.coinCollect.Play(); game.gameHUD.Coins++; game.gameHUD.Score += ValueHolder.coinCollectPoints; } if (item.GetType().Equals(new OneUpMushroom(item.position).GetType())) { SoundManager.oneUp.Play(); game.gameHUD.Lives++; game.ach.AchievementAdjustment(AchievementsManager.AchievementType.Life); } }
public void MarioEnemyCollide(Mario mario, Enemy enemy) { Rectangle marioRect = mario.state.GetBoundingBox(new Vector2(mario.position.X, mario.position.Y)); Rectangle enemyRect = enemy.GetBoundingBox(); Rectangle intersection = Rectangle.Intersect(marioRect, enemyRect); if (intersection.Height > intersection.Width) { if (!mario.isStar) { mario.TakeDamage(); } else { enemy.TakeDamage(); game.gameHUD.Score += ValueHolder.enemyHurtPoints; } } else { if (marioRect.Bottom > enemyRect.Top && marioRect.Bottom < enemyRect.Bottom) { enemy.TakeDamage(); game.ach.AchievementAdjustment(AchievementsManager.AchievementType.Enemy); game.gameHUD.Score += ValueHolder.enemyHurtPoints * game.gameHUD.pointMultiplier; mario.velocity.Y = bounce; game.gameHUD.pointMultiplier++; } else { if (!mario.isStar) { mario.TakeDamage(); } else { enemy.TakeDamage(); game.gameHUD.Score += ValueHolder.enemyHurtPoints; } } } }
public void Gag(Mario mario) { mario.position.X--; }
public void Chew(Mario mario) { mario.position.X++; }
public IdleCommand(Mario mario) { this.mario = mario; }
public UpCommand(Mario mario) { this.mario = mario; }
public RightFallingBigMS(Mario mario) { factory = new SpriteFactory(); Sprite = factory.build(SpriteFactory.sprites.rightFallingMarioBig); this.mario = mario; }
public ThrowingStarCollisionResponder(Mario mario, Game1 game) { this.game = game; this.mario = mario; }
public RunCommand(Mario mario) { this.mario = mario; }
public VVVVVVGroundState(Mario mario, int sign) { this.mario = mario; gravityStrength *= sign; }
public Mario Build(string fileName) { float xCoord = 0, yCoord = 0; StreamReader sr; sr = File.OpenText(Game1.GetInstance().Content.RootDirectory + fileName); string line; while ((line = sr.ReadLine()) != null) { yCoord += spacingIncrement; xCoord = 0; string[] words = line.Split(','); for (int i = 0; i < words.Length; i++) { int events = 1; if (words[i] == "M") { mario = new Mario(new Vector2(xCoord, yCoord)); } if (itemDictionary.ContainsKey(words[i])) { ICollectable item = collectableFactory.build(itemDictionary[words[i]], new Vector2(xCoord, yCoord)); level.levelItems.Add(item); } if (backgroundDictionary.ContainsKey(words[i])) { if (words[i] == "exit") { level.exitPosition = new Vector2(xCoord, yCoord); } else { KeyValuePair <IAnimatedSprite, Vector2> item = new KeyValuePair <IAnimatedSprite, Vector2>(factory.build(backgroundDictionary[words[i]]), new Vector2(xCoord, yCoord)); level.levelBackgroundObjects.Add(item); } } if (blockDictionary.ContainsKey(words[i])) { Block block = blockFactory.build(blockDictionary[words[i]], new Vector2(xCoord, yCoord)); level.levelBlocks.Add(block); } if (enemyDictionary.ContainsKey(words[i])) { Enemy enemy = enemyFactory.build(enemyDictionary[words[i]], new Vector2(xCoord, yCoord)); level.levelEnemies.Add(enemy); } if (pipeDictionary.ContainsKey(words[i])) { Pipe pipe = pipeFactory.build(pipeDictionary[words[i]], new Vector2(xCoord, yCoord)); i++; int exitPiX = int.Parse(words[i]); i++; int exitPiY = int.Parse(words[i]); i++; Pipe exitPipe = pipeFactory.build(pipeDictionary[words[i]], new Vector2((float)exitPiX, (float)exitPiY)); pipe.exitPipe = exitPipe; level.levelPipes.Add(pipe); level.levelPipes.Add(exitPipe); events = 4; } if (words[i] == "V") { level.levelSpikes.Add(new Spike(new Vector2(xCoord, yCoord), false)); } if (words[i] == "^") { level.levelSpikes.Add(new Spike(new Vector2(xCoord, yCoord), true)); } if (words[i] == "t") { level.levelTrampolines.Add(new Trampoline(new Vector2(xCoord, yCoord))); } if (words[i] == "Ch") { level.checkpoint = new Vector2(xCoord, yCoord); } xCoord += spacingIncrement * events; } } return(mario); }
public void Chew(Mario mario) { mario.position.Y--; }
public VVVVVVPadController(Mario mario) { this.mario = mario; }
public FireballCollisionResponder(Mario mario, Game1 game) { this.game = game; this.mario = mario; }
public RightCommand(Mario mario) { this.mario = mario; }
public ProjectileCommand(Mario mario) { this.mario = mario; }
public JumpingState(Mario mario) { this.mario = mario; mario.isJumping = true; }
public void Detect(Mario mario, List <Fireball> levelFireballs, List <ThrowingStar> levelThrowingStars, List <Enemy> levelEnemies, List <Block> levelBlocks, List <ICollectable> levelItems, List <Pipe> levelPipes, List <Spike> levelSpikes, List <Trampoline> levelTrampolines) { standingBlocks = new List <Block>(); standingPipes = new List <Pipe>(); Rectangle marioRect = mario.state.GetBoundingBox(new Vector2(mario.position.X, mario.position.Y)); foreach (Enemy enemy in levelEnemies) { Rectangle enemyRect = enemy.GetBoundingBox(); if (!enemy.isDead && mario.invicibilityFrames == 0) { if (marioRect.Intersects(enemyRect)) { enemyResponder.MarioEnemyCollide(mario, enemy); } } foreach (Fireball fireball in levelFireballs) { if (!enemy.isDead) { Rectangle fireballRect = fireball.GetBoundingBox(); if (fireballRect.Intersects(enemyRect)) { fireballResponder.EnemyFireballCollide(enemy, fireball); } } } foreach (ThrowingStar throwingStar in levelThrowingStars) { if (!enemy.isDead) { Rectangle throwingStarRect = throwingStar.GetBoundingBox(); if (throwingStarRect.Intersects(enemyRect)) { throwingStarResponder.EnemyThrowingStarCollide(enemy, throwingStar); } } } foreach (Block block in levelBlocks) { Rectangle blockRect = block.GetBoundingBox(); if (blockRect.Intersects(enemyRect) && !enemy.isMagic) { blockResponder.EnemyBlockCollide(enemy, block); } } foreach (Enemy otherEnemy in levelEnemies) { Rectangle otherEnemyRect = enemy.GetBoundingBox(); if (otherEnemy != enemy && enemyRect.Intersects(otherEnemyRect) && !enemy.isMagic) { enemyResponder.EnemyEnemyCollide(enemy, otherEnemy); } } foreach (Pipe pipe in levelPipes) { Rectangle pipeRect = pipe.GetBoundingBox(); if (pipeRect.Intersects(enemyRect)) { pipeResponder.PipeEnemyCollide(enemy, pipe); } } } foreach (Pipe pipe in levelPipes) { Rectangle pipeRect = pipe.GetBoundingBox(); if (pipeRect.Intersects(marioRect)) { pipeResponder.PipeMarioCollide(mario, pipe, standingPipes); } } foreach (ICollectable item in levelItems) { Rectangle itemRect = item.GetBoundingBox(); if (marioRect.Intersects(itemRect) && !item.isSpawning) { obtainedItems.Add(item); itemResponder.MarioItemCollide(item, mario); } foreach (Pipe pipe in levelPipes) { Rectangle pipeRect = pipe.GetBoundingBox(); if (pipeRect.Intersects(itemRect)) { pipeResponder.PipeItemCollide(item, pipe); } } } foreach (Block block in levelBlocks) { Rectangle blockRect = block.GetBoundingBox(); if (marioRect.Intersects(blockRect)) { blockResponder.MarioBlockCollide(mario, block, destroyedBlocks, standingBlocks); } foreach (Fireball fireball in levelFireballs) { Rectangle fireballRect = fireball.GetBoundingBox(); if (fireballRect.Intersects(blockRect)) { fireballResponder.BlockFireballCollide(block, fireball); } } foreach (ThrowingStar throwingStar in levelThrowingStars) { Rectangle throwingStarRect = throwingStar.GetBoundingBox(); if (throwingStarRect.Intersects(blockRect)) { throwingStarResponder.BlockThrowingStarCollide(block, throwingStar); } } foreach (ICollectable item in levelItems) { Rectangle itemRect = item.GetBoundingBox(); if (blockRect.Intersects(itemRect) && !item.isSpawning) { blockResponder.ItemBlockCollide(item, block); } } } foreach (Spike spike in levelSpikes) { Rectangle spikeRect = spike.GetBoundingBox(); if (marioRect.Intersects(spikeRect)) { mario.TakeDamage(); } } foreach (Trampoline trampoline in levelTrampolines) { Rectangle trampolineRect = trampoline.GetBoundingBox(); if (marioRect.Intersects(trampolineRect)) { if (mario.physState.GetType().Equals(new VVVVVVAirState(mario, 1).GetType())) { mario.physState = new VVVVVVGroundState(mario, mario.gravityDirection); } mario.physState.Flip(); } } foreach (ICollectable obtainedItem in obtainedItems) { levelItems.Remove(obtainedItem); } foreach (Block destroyedBlock in destroyedBlocks) { levelBlocks.Remove(destroyedBlock); } }
public LeftJumpingBigMS(Mario mario) { factory = new SpriteFactory(); Sprite = factory.build(SpriteFactory.sprites.leftJumpingMarioBig); this.mario = mario; }
public DownCommand(Mario mario) { this.mario = mario; }
public void Gag(Mario mario) { state.Gag(mario); puked = true; }
public DeadFlipGameState(Mario mario) { game = Game1.GetInstance(); this.mario = mario; }
public void Eat(Mario mario, Pipe pipe) { Game1.GetInstance().gameState = new PipeTransitionGameState(PipeTransitionGameState.direction.goIn, pipe); this.mario = mario; }
public GamepadController(Mario mario) { this.mario = mario; }
public void Puke(Mario mario, Pipe pipe) { Game1.GetInstance().gameState = new PipeTransitionGameState(PipeTransitionGameState.direction.comeOut, pipe); this.mario = mario; }
public FallingState(Mario mario) { this.mario = mario; mario.isFalling = true; mario.isJumping = false; }
public void Gag(Mario mario) { mario.position.Y++; }