public GameCoin Clone() { var animatedSprite = CoinSprite.Clone(); var clone = (GameCoin)MemberwiseClone(); clone.CoinSprite = animatedSprite; return(clone); }
public override void Update(GameTime gameTime) { if (_applyPhysics) { if (_xAcceleration != 0f) { _velocity.X += _xAcceleration; _xAcceleration *= _isOnGround ? GroundDragFactor : 0.96f; } base.Update(gameTime); } CoinSprite.Position = Position; CoinSprite.Update(gameTime); }
// Load graphics content for the game public override void Activate() { if (_content == null) { _content = new ContentManager(ScreenManager.Game.Services, "Content"); } _spriteBatch = ScreenManager.SpriteBatch; if (coinsList.Count == 0) { CoinSprite temp = new CoinSprite(_coinPosition); coinsList.Add(temp); } coinsCount = 0; slimeSprite = new SlimeSprite(); // Loads content for gameplay elements foreach (var coin in coinsList) { coin.LoadContent(_content); } slimeSprite.LoadContent(_content); coinPickup = _content.Load <SoundEffect>(coinSoundName); gameMusic = _content.Load <Song>(gameMusicName); MediaPlayer.IsRepeating = true; float roundedMusicVolume = (float)(MediaPlayer.Volume / 4.0); MediaPlayer.Volume = roundedMusicVolume; MediaPlayer.Play(gameMusic); _gameFont = _content.Load <SpriteFont>("gamefont"); // A real game would probably have more content than this sample, so // it would take longer to load. We simulate that by delaying for a // while, giving you a chance to admire the beautiful loading screen. Thread.Sleep(1000); // once the load has finished, we use ResetElapsedTime to tell the game's // timing mechanism that we have just finished a very long frame, and that // it should not try to catch up. //ScreenManager.Game.ResetElapsedTime(); }
// This method checks the GameScreen.IsActive property, so the game will // stop updating when the pause menu is active, or if you tab away to a different application. public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { base.Update(gameTime, otherScreenHasFocus, false); System.Random rand = new System.Random(); // Gradually fade in or out depending on whether we are covered by the pause screen. if (coveredByOtherScreen) { _pauseAlpha = Math.Min(_pauseAlpha + 1f / 32, 1); } else { _pauseAlpha = Math.Max(_pauseAlpha - 1f / 32, 0); } if (IsActive) { float t = (float)gameTime.ElapsedGameTime.TotalSeconds; Vector2 acceleration = new Vector2(0, 30); bool addCoin = false; List <CoinSprite> tempCoinsList = new List <CoinSprite>(); foreach (var coin in coinsList) { ///If the player touches a coin if (!coin.Collected && coin.Bounds.CollidesWith(slimeSprite.Bounds)) { addCoin = true; coinsCount++; coin.Collected = true; coin.Warp(); coinPickup.Play(); } /// If the coin goes beneath the game window if (coin.Position.Y > Constants.GAME_HEIGHT) { Vector2 temp = new Vector2(coin.Position.X, 0); coin.Position = temp; } /// If the coin goes past the right boundary if (coin.Position.X > Constants.GAME_WIDTH) { Vector2 temp = new Vector2(0, coin.Position.Y); coin.Position = temp; } coin.Velocity += acceleration * t; coin.Position += t * coin.Velocity; /// Check to see if the player has gotten enough coins to win if (coinsCount > 9) { //System.Windows.Forms.MessageBoxButtons buttons = System.Windows.Forms.MessageBoxButtons.YesNo; //System.Windows.Forms.DialogResult result; //result = MessageBox.Show("Congrats", "You Won!", (IEnumerable<string>)buttons); } ///Adds a coin randomly in the game window if (addCoin) { CoinSprite tempCoin = new CoinSprite( new Vector2((float)rand.NextDouble() * Constants.GAME_WIDTH, (float)rand.NextDouble() * Constants.GAME_HEIGHT)); tempCoin.LoadContent(_content); if (!(tempCoinsList == null)) { tempCoinsList.Add(tempCoin); } addCoin = false; } } foreach (CoinSprite c in tempCoinsList) { coinsList.Add(c); } tempCoinsList = new List <CoinSprite>(); } }
public Coin(Vector2 position) : base(position) { Sprite = new CoinSprite(this); }