コード例 #1
0
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

            if (coveredByOtherScreen)
            {
                pauseAlpha = Math.Min(pauseAlpha + 1f / 32, 1);
            }
            else
            {
                pauseAlpha = Math.Max(pauseAlpha - 1f / 32, 0);
            }

            seconds += gameTime.ElapsedGameTime.TotalSeconds;

            if (seconds > 5.0 && !collisionOn)
            {
                collisionOn = true;
            }

            if (IsActive)
            {
                spaceShip.Update(gameTime, ScreenManager.GraphicsDevice.Viewport.Width, ScreenManager.GraphicsDevice.Viewport.Height);

                foreach (var asteroid in asteroids)
                {
                    asteroid.Update(gameTime);

                    if (asteroid.Bounds.CollidesWith(spaceShip.Bounds) && collisionOn)
                    {
                        explosion.PlaceExplosion(spaceShip.Position);
                        ScreenManager.RemoveScreen(this);
                        ScreenManager.Game.Components.Remove(shootingStar);
                        ScreenManager.AddScreen(new BackgroundScreen(), null);
                        ScreenManager.AddScreen(new LoseScreen(), null);
                    }
                }

                foreach (var coin in coins)
                {
                    if (!coin.Collected && coin.Bounds.CollidesWith(spaceShip.Bounds))
                    {
                        pickup.PlaceParticle(coin.Bounds.Center);
                        coin.Collected = true;
                        coinsLeft--;
                        coinPickup.Play();
                    }
                }
                if (coinsLeft < 1)
                {
                    ScreenManager.RemoveScreen(this);
                    ScreenManager.Game.Components.Remove(shootingStar);
                    ScreenManager.AddScreen(new BackgroundScreen(), null);
                    ScreenManager.AddScreen(new WinScreen(), null);
                }
            }
        }
コード例 #2
0
        public override void Draw(GameTime gameTime)
        {
            // This game has a blue background. Why? Because!
            ScreenManager.GraphicsDevice.Clear(ClearOptions.Target, Color.CornflowerBlue, 0, 0);

            // Our player and enemy are both actually just text strings.
            var spriteBatch = ScreenManager.SpriteBatch;

            _spriteBatch.Begin();
            _spriteBatch.Draw(background, Vector2.Zero, new Rectangle(0, 0, 626, 374), Color.White, 0, Vector2.Zero, 1.5f, SpriteEffects.None, 0);
            if (exit)
            {
                exitSprite.Draw(gameTime, _spriteBatch);
                if (!exploded)
                {
                    exploded = true;
                    explosion.PlaceExplosion(exitSprite.position);
                }
            }
            foreach (var coin in coins)
            {
                coin.Draw(gameTime, _spriteBatch);
            }
            _spriteBatch.End();

            _spriteBatch.Begin();
            batSprite.Draw(gameTime, _spriteBatch);
            _spriteBatch.End();

            _spriteBatch.Begin();
            _spriteBatch.DrawString(bangers, $"Coins Collected: {coinsCollected} / 10", new Vector2(2, 2), Color.Gold);
            _spriteBatch.End();



            // If the game is transitioning on or off, fade it out to black.
            if (TransitionPosition > 0 || _pauseAlpha > 0)
            {
                float alpha = MathHelper.Lerp(1f - TransitionAlpha, 1f, _pauseAlpha / 2);

                ScreenManager.FadeBackBufferToBlack(alpha);
            }
        }
コード例 #3
0
        public override void Draw(GameTime gameTime)
        {
            ScreenManager.GraphicsDevice.Clear(Color.ForestGreen);

            var _spriteBatch = ScreenManager.SpriteBatch;
            //If it isn't shaking make it the identity matrix
            Matrix shakeTransform = Matrix.Identity;

            if (is_hit_by_bush)
            {
                shakeTransform = Matrix.CreateTranslation(20 * MathF.Sin(elapsed_text_time * 1000), 20 * MathF.Cos(elapsed_text_time * 1000), 0);
            }

            // TODO: Add your drawing code here
            _spriteBatch.Begin(transformMatrix: shakeTransform);

            if (current_round_time < 1.5)
            {
                _spriteBatch.DrawString(font, "Hole 3", new Vector2(775, 500), Color.Gold);
            }

            //Draw class objects
            disc.Draw(_spriteBatch);
            foreach (Bush bush in bushes)
            {
                bush.Draw(gameTime, _spriteBatch);
            }
            foreach (Tree tree in trees)
            {
                tree.Draw(gameTime, _spriteBatch);
            }

            //Had to rotate by another 90 degrees (radians) because arrow sprite was draw straight north in the sprite (rather then where the unit circle starts)
            _spriteBatch.Draw(windArrow, new Vector2(1375, 64), null, Color.White, windAngle + (float)(Math.PI / 2.0), new Vector2(16, 16), 1f, SpriteEffects.None, 1);
            _spriteBatch.DrawString(high_score_font, "WIND", new Vector2(1325, 120), Color.Red);
            _spriteBatch.DrawString(high_score_font, "Hole 3", new Vector2(1820, 1040), Color.Gold);

            #region High Score Drawing
            _spriteBatch.DrawString(high_score_font, current_round_time.ToString("n3") + " seconds", new Vector2(2, 2), Color.Gold);
            _spriteBatch.DrawString(high_score_font, "Total Time: " + past_high_score.ToString("n3") + " seconds", new Vector2(1500, 2), Color.Gold);
            #endregion

            //Obstacle/winning logic, disables input either way and the resets player
            if (is_hit_by_bush)
            {
                if (elapsed_text_time < 1.5)
                {
                    input_enabled = false;
                    _spriteBatch.DrawString(font, "BONK!", new Vector2(800, 500), Color.Red);
                    elapsed_text_time += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    GamePad.SetVibration(0, 0.5f, 0.5f);
                    bushParticleSystem.PlaceExplosion(disc.Position);
                }
                else
                {
                    elapsed_text_time = 0f;
                    disc.Position     = new Vector2(1800, 5);
                    input_enabled     = true;
                    is_hit_by_bush    = false;
                    GamePad.SetVibration(0, 0, 0);
                    current_round_time = 0.0f;
                }
            }
            if (is_in_basket)
            {
                basket.DrawWin(gameTime, _spriteBatch);
                if (elapsed_text_time < 1.5)
                {
                    input_enabled = false;
                    _spriteBatch.DrawString(font, "CHAINS!", new Vector2(800, 500), Color.Orange);
                    elapsed_text_time += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    GamePad.SetVibration(0, 0.5f, 0.5f);
                    high_score_time = current_round_time;
                    basketParticleSystem.PlaceExplosion(new Vector2(basket.Bounds.X + basket.Bounds.Width / 2, basket.Bounds.Y + basket.Bounds.Height / 2));
                }
                else
                {
                    elapsed_text_time = 0f;
                    disc.Position     = new Vector2(1800, 5);
                    input_enabled     = true;
                    is_in_basket      = false;
                    GamePad.SetVibration(0, 0, 0);
                    current_round_time = 0.0f;

                    switch_holes = true;

                    /*//generate a new wind each time the player wins
                     * windAngle = (float)(rand.NextDouble() * 2 * Math.PI);
                     * windDirection = new Vector2((float)Math.Cos(windAngle), (float)Math.Sin(windAngle));
                     *
                     * //Update particle enginer for new wind
                     * windParticleSystem.Source = GetWindSourceRect();
                     * windParticleSystem.WindDirection = windDirection;*/
                }
            }
            else
            {
                basket.Draw(_spriteBatch); //Just draw the normal basket
            }
            _spriteBatch.End();
            base.Draw(gameTime);
        }