Exemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            // update the orientation each frame
            if (velocity.LengthSquared() > 0)
            {
                orientation = velocity.ToAngle();
            }

            // update position of bullet each frame using pixel/second
            position += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;

            // if bullet moves out of the screen destroy it
            if (!GameRoot.Viewport.Bounds.Contains(position.ToPoint()))
            {
                isExpired = true;

                ParticleState state;
                for (int i = 0; i < 15; i++)
                {
                    state = new ParticleState()
                    {
                        velocity         = rand.NextVector2(0, 150),
                        type             = ParticleType.Bullet,
                        lengthMultiplier = 1
                    };
                    GameRoot.ParticleManager.CreateParticle(Art.LineParticle, position, Color.LightBlue, 0.6f, 1, state);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Kill the enemy
        /// </summary>
        public void WasShot()
        {
            // applying variation to pitch so that the explosion sound is a bit different every time
            Sound.Explosion.Play(0.5f, rand.NextFloat(-0.2f, 0.2f), 0);
            isExpired = true;

            float hue1   = rand.NextFloat(0, 6);
            float hue2   = (hue1 + rand.NextFloat(0, 2)) % 6f;
            Color color1 = ColorUtil.HSVToColor(hue1, 0.5f, 1);
            Color color2 = ColorUtil.HSVToColor(hue2, 0.5f, 1);

            for (int i = 0; i < 120; i++)
            {
                // 10 step speed variation
                float speed = 400f * (1f - 1 / rand.NextFloat(1f, 10f));
                var   state = new ParticleState()
                {
                    velocity         = rand.NextVector2(speed, speed),
                    type             = ParticleType.Enemy,
                    lengthMultiplier = 1
                };

                Color color = Color.Lerp(color1, color2, rand.NextFloat(0, 1));
                GameRoot.ParticleManager.CreateParticle(Art.LineParticle, position, color, 2f, 1.5f, state);
            }
        }
Exemplo n.º 3
0
        public void WasShot()
        {
            hitpoints--;
            if (hitpoints <= 0)
            {
                isExpired = true;
            }

            float     hue          = (float)((3 * GameRoot.GameTime.TotalGameTime.TotalSeconds) % 6);
            Color     color        = ColorUtil.HSVToColor(hue, 0.25f, 1);
            const int numParticles = 150;
            float     startOffset  = rand.NextFloat(0, MathHelper.TwoPi / numParticles);

            for (int i = 0; i < numParticles; i++)
            {
                Vector2 sprayVel = MathUtil.FromPolar(MathHelper.TwoPi * i / numParticles + startOffset, rand.NextFloat(8, 16));
                Vector2 pos      = position + 2f * sprayVel;
                var     state    = new ParticleState()
                {
                    velocity         = sprayVel * 90,
                    lengthMultiplier = 1,
                    type             = ParticleType.IgnoreGravity
                };

                GameRoot.ParticleManager.CreateParticle(Art.LineParticle, pos, color, 2.5f, 1.5f, state);
            }
        }
Exemplo n.º 4
0
        public void Kill()
        {
            PlayerStatus.RemoveLife();

            if (!PlayerStatus.IsGameOver)
            {
                timeUntilRespawn = 3;
            }
            else
            {
                PlayerStatus.EndSession();
            }

            // Particles
            Color yellow = new Color(0.8f, 0.8f, 0.4f);

            for (int i = 0; i < 1200; i++)
            {
                float speed = 700 * (1f - 1 / rand.NextFloat(1f, 10f));
                Color color = Color.Lerp(Color.White, yellow, rand.NextFloat(0, 1));
                var   state = new ParticleState()
                {
                    velocity         = rand.NextVector2(speed, speed),
                    type             = ParticleType.None,
                    lengthMultiplier = 1
                };

                GameRoot.ParticleManager.CreateParticle(Art.LineParticle, position, color, 3, 1.5f, state);
            }
        }
Exemplo n.º 5
0
        public static ParticleState GetRandom(float minVel, float maxVel)
        {
            var state = new ParticleState();

            state.velocity         = rand.NextVector2(minVel, maxVel);
            state.type             = ParticleType.None;
            state.lengthMultiplier = 1;

            return(state);
        }
Exemplo n.º 6
0
        public override void Update(GameTime gameTime)
        {
            var entities = EntityManager.GetNearbyEntities(position, areaOfEffectRadius);

            foreach (Entity entity in entities)
            {
                if (entity is Enemy && !(entity as Enemy).IsActive)
                {
                    continue;
                }

                if (entity is Bullet)
                {
                    entity.velocity += (entity.position - position).ScaleTo(12f);
                }
                else
                {
                    var dPos   = position - entity.position;
                    var length = dPos.Length();

                    entity.velocity += dPos.ScaleTo(MathHelper.Lerp(150f, 0, length / 250f));
                }
            }

            // The black holes spray some orbiting particles. The spray toggles on and off every quarter second.
            if ((GameRoot.GameTime.TotalGameTime.Milliseconds / 250) % 2 == 0)
            {
                Vector2 sprayVel = MathUtil.FromPolar(sprayAngle, rand.NextFloat(12, 15));
                Color   color    = ColorUtil.HSVToColor(5, 0.5f, 0.8f);              // light purple
                Vector2 pos      = position + 2f * new Vector2(sprayVel.Y, -sprayVel.X) + rand.NextVector2(4, 8);
                var     state    = new ParticleState()
                {
                    velocity         = sprayVel,
                    lengthMultiplier = 1,
                    type             = ParticleType.Enemy
                };

                GameRoot.ParticleManager.CreateParticle(Art.LineParticle, pos, color, 3, 1.5f, state);
            }

            // rotate the spray direction
            sprayAngle -= MathHelper.TwoPi / 50f;
        }