예제 #1
0
        public static ParticleState GetRandom(float minVel, float maxVel)
        {
            var state = new ParticleState
            {
                Velocity = rand.NextVector2(minVel, maxVel),
                Type = ParticleType.None,
                LengthMultiplier = 1
            };

            return state;
        }
        public static ParticleState GetRandom(float minVel, float maxVel)
        {
            var state = new ParticleState
            {
                Velocity         = rand.NextVector2(minVel, maxVel),
                Type             = ParticleType.None,
                LengthMultiplier = 1
            };

            return(state);
        }
예제 #3
0
        private void ParticleExplosion(Vector2 position)
        {
            float hue1 = _gameRef.Rand.NextFloat(0, 6);
            float hue2 = (hue1 + _gameRef.Rand.NextFloat(0, 2)) % 6f;
            Color color1 = ColorUtil.HSVToColor(hue1, 0.5f, 1);
            Color color2 = ColorUtil.HSVToColor(hue2, 0.5f, 1);

            for (int j = 0; j < 50; j++)
            {
                float speed = 18f * (1f - 1 / _gameRef.Rand.NextFloat(1f, 10f));
                var state = new ParticleState()
                {
                    Velocity = _gameRef.Rand.NextVector2(speed, speed),
                    Type = ParticleType.Enemy,
                    LengthMultiplier = 1f
                };

                Color color = Color.Lerp(color1, color2, _gameRef.Rand.NextFloat(0, 1));

                _gameRef.ParticleManager.CreateParticle(_gameRef.LineParticle, position,
                    color, 190, 1.5f, state);
            }
        }
예제 #4
0
        public void TakeDamage(float damage)
        {
            _health -= damage;

            if (_health < 0)
            {
                float hue1 = GameRef.Rand.NextFloat(0, 6);
                float hue2 = (hue1 + GameRef.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 < 5000; i++)
                {
                    float speed = 18f * (1f - 1 / GameRef.Rand.NextFloat(1f, 10f));
                    var state = new ParticleState()
                    {
                        Velocity = GameRef.Rand.NextVector2(speed, speed),
                        Type = ParticleType.Enemy,
                        LengthMultiplier = 1f
                    };

                    Color color = Color.Lerp(color1, color2, GameRef.Rand.NextFloat(0, 1));

                    GameRef.ParticleManager.CreateParticle(GameRef.LineParticle, new Vector2(Position.X, Position.Y - Size.Y / 2f),
                        color, 190, 1.5f, state);
                }

                IsAlive = false;
            }
        }
예제 #5
0
        public override bool Intersects(Entity entity)
        {
            foreach (var collisionBox in CollisionBoxes)
            {
                var collisionConvexPolygon = collisionBox as CollisionConvexPolygon;

                if (collisionConvexPolygon == null)
                    return base.Intersects(entity);

                foreach (var entityCollisionBox in entity.CollisionBoxes)
                {
                    if (entityCollisionBox.Intersects(collisionBox))
                    {
                        var bullet = entity as BaseBullet;

                        if (bullet != null)
                        {
                            _collisionBoxesHp[collisionConvexPolygon] -= bullet.Power;

                            if (_collisionBoxesHp[collisionConvexPolygon] <= 0)
                            {
                                float hue1 = GameRef.Rand.NextFloat(0, 6);
                                float hue2 = (hue1 + GameRef.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++)
                                {
                                    float speed = 18f * (1f - 1 / GameRef.Rand.NextFloat(1f, 10f));
                                    var state = new ParticleState()
                                    {
                                        Velocity = GameRef.Rand.NextVector2(speed, speed),
                                        Type = ParticleType.Enemy,
                                        LengthMultiplier = 1f
                                    };

                                    Color color = Color.Lerp(color1, color2, GameRef.Rand.NextFloat(0, 1));

                                    GameRef.ParticleManager.CreateParticle(GameRef.LineParticle, bullet.Position,
                                        color, 190, 1.5f, state);
                                }

                                Split(collisionConvexPolygon);
                            }
                        }

                        _color = HitColor;
                        _changeColorTimer = new TimeSpan(0, 0, 0, 0, 40);

                        return true;
                    }
                }
            }
            return false;
        }
예제 #6
0
        public void Hit()
        {
            if (!IsInvincible)
            {
                _lives--;
                _deadSound.Play();

                var yellow = new Color(0.8f, 0.8f, 0.4f);

                for (int i = 0; i < 1200; i++)
                {
                    float speed = 18f * (1f - 1 / GameRef.Rand.NextFloat(1f, 10f));
                    Color color = Color.Lerp(Color.White, yellow, GameRef.Rand.NextFloat(0, 1));
                    var state = new ParticleState()
                    {
                        Velocity = GameRef.Rand.NextVector2(speed, speed),
                        Type = ParticleType.None,
                        LengthMultiplier = 1
                    };

                    GameRef.ParticleManager.CreateParticle(GameRef.LineParticle, Position, color, 190, 1.5f, state);
                }

                _timeBeforeRespawn = Config.PlayerTimeBeforeRespawn;
                IsInvincible = true;
                CollisionBoxes.Add(_shieldCollisionCircle);
            }
        }