public void HandleJump() { Speed.Y = 10; if (IsJumping && AirTime < 25) { AirTime++; if (AirTime == 5) { GameSounds.PlayJumpSound(); } if (CanMoveUp) { Sprite.Position.Y -= Speed.Y; } else { StopJump(); } } else { StopJump(); } }
private void Shoot() { if (Sprite.NumberOfSprites == 1 && LastTimeShooted >= 190) { GameSounds.PlayShootSound(); Texture2D bulletTexture = Factory.CreateTexture("Bullet"); const int yOffset = 10; int xOffset; if (direction == Direction.ToLeft) { xOffset = -bulletTexture.Width; } else { xOffset = Sprite.Texture.Width; } Vector2 bulletPosition = Factory.CreateVector(Sprite.Position.X + xOffset, Sprite.Position.Y + yOffset); Rectangle bulletCollisoionRectangle = Factory.CreateRectangle((int)bulletPosition.X, (int)bulletPosition.Y, bulletTexture.Width, bulletTexture.Height); Sprite sprite = Factory.CreateSprite(bulletTexture, 1, bulletPosition); Bullet bullet = WorldFactory.CreateBullet(sprite, bulletCollisoionRectangle); bullet.direction = direction; ShootedBullets.Add(bullet); LastTimeShooted = 0; } }
public void AddItem(Block Item) { GameSounds.PlayPickSound(); if (Item is MoneySafeKey) { MoneySafeKey doorKey = Item as MoneySafeKey; MoneySafeKey clone = (doorKey.Clone()) as MoneySafeKey; Key = clone; } if (Item is Coin) { Coin coin = Item as Coin; Coin clone = (coin.Clone()) as Coin; AllCoins.Add(clone); } if (Item is Potion) { Potion potion = Item as Potion; Potion clone = (potion.Clone()) as Potion; Potion = clone; } if (Item is MoneySafe) { MoneySafe moneySafe = Item as MoneySafe; MyDiamonds += moneySafe.NumberOfDiamonds; } }
public void DrinkPotion() { if (Inventory.Potion != null) { Speed.X += Inventory.Potion.SpeedAcceleration; Animation.IncreaseSpeed(); Inventory.Potion = null; GameSounds.PlayDrinkSound(); } }
public override void LoadContent() { // Sound Effect if (gameResult == GameResult.Lost) { GameSounds.PlayGameOverSound(); } // Result Image if (gameResult == GameResult.Won) { resultImage = ContentManager.Load <Texture2D>("YouWin"); } else { resultImage = ContentManager.Load <Texture2D>("GameOver"); } textFont = ContentManager.Load <SpriteFont>("DefaultTextFont"); leftMarginGameOver = (Robber2D.ScreenWidth - resultImage.Width) / 2; // Text scoreFont = ContentManager.Load <SpriteFont>("DefaultFont"); CalculateScore(); // Restart canRestart = false; new Handler().PostDelayed(delegate { canRestart = true; }, 2500); }
public void UpdateHealth(Bullet bullet) { GameSounds.PlayHitSound(); Health -= bullet.Damage; }
public override void LoadContent() { // Sound Effect if (gameResult == GameResult.Lost) { GameSounds.PlayGameOverSound(); } // Score scoreFont = ContentManager.Load <SpriteFont>("DefaultFont"); CalculateScore(); // Result Image if (gameResult == GameResult.Won) { resultImage = ContentManager.Load <Texture2D>("YouWin"); } else { resultImage = ContentManager.Load <Texture2D>("GameOver"); } leftMarginGameOver = (Robber2D.ScreenWidth - resultImage.Width) / 2; // Buttons allButtons = new List <Button>(); buttonBorder = ContentManager.Load <Texture2D>("ButtonBorder"); buttonFont = ContentManager.Load <SpriteFont>("ButtonFont"); int leftMarginButton = (Robber2D.ScreenWidth - buttonBorder.Width) / 2; List <string> buttonTitles = new List <string>() { "SAVE SCORE", "BACK", "EXIT" }; int nextYPos = 650; for (int i = 0; i < buttonTitles.Count; i++) { Button button = new Button(buttonBorder, buttonFont) { Text = buttonTitles[i], Position = new Vector2(leftMarginButton, nextYPos) }; allButtons.Add(button); nextYPos += 100; } allButtons[0].Click += SaveScore; allButtons[1].Click += ReturnToMenu; allButtons[2].Click += CloseGame; // Score Logger scoreLogger = new ScoreLogger(); }