Пример #1
0
 /// <summary>
 /// Allows the game to run logic such as updating the world,
 /// checking for collisions, gathering input, and playing audio.
 /// </summary>
 /// <param name="gameTime">Provides a snapshot of timing values.</param>
 protected override void Update(GameTime gameTime)
 {
     GameTime = gameTime;
     if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
     {
         Exit();
     }
     EntityManager.Update();
     Input.Update();
     EnemySpawner.Update();
     PlayerStatus.Update();
     base.Update(gameTime);
 }
Пример #2
0
        static void HandleCollisions()
        {
            // handle collisions between enemies
            for (int i = 0; i < enemies.Count; i++)
            {
                for (int j = i + 1; j < enemies.Count; j++)
                {
                    if (IsColliding(enemies[i], enemies[j]))
                    {
                        enemies[i].HandleCollision(enemies[j]);
                        enemies[j].HandleCollision(enemies[i]);
                    }
                }
            }

            // handle collisions between bullets and enemies
            for (int i = 0; i < enemies.Count; i++)
            {
                for (int j = 0; j < bullets.Count; j++)
                {
                    if (IsColliding(enemies[i], bullets[j]))
                    {
                        enemies[i].WasShot();
                        bullets[j].IsExpired = true;
                    }
                }
            }

            // handle collisions between the player and enemies
            for (int i = 0; i < enemies.Count; i++)
            {
                if (enemies[i].IsActive && IsColliding(PlayerShip.Instance, enemies[i]))
                {
                    PlayerShip.Instance.Kill();
                    enemies.ForEach(x => x.WasShot());
                    bullets.ForEach(p => p.IsExpired = true);
                    EnemySpawner.Reset();
                    break;
                }
            }
        }
Пример #3
0
        public void Kill()
        {
            EntityManager.Reset();
            EnemySpawner.Reset();
            //framesUntilRespawn = 60;
            PlayerStatus.RemoveLife();
            PlayerStatus.ResetMultiplier();
            if (PlayerStatus.Lives == 0)
            {
                PlayerStatus.GameOver();
                GameManager.PauseGame(300, true);
            }
            framesUntilRespawn = PlayerStatus.IsGameOver ? 300 : 120;
            var yellow = new Color(0.8f, 0.8f, 0.4f);

            for (var i = 0; i < 1200; i++)
            {
                var speed         = 18f * (1f - 1 / rand.NextFloat(1f, 10f));
                var particleColor = Color.Lerp(Color.White, yellow, rand.NextFloat(0, 1));
                var state         = new ParticleState(rand.NextVector2(speed, speed), ParticleType.None);

                GameRoot.ParticleManager.CreateParticle(Art.LineParticle, Position, particleColor, 60, new Vector2(0.7f, 0.7f), state);
            }
        }