Beispiel #1
0
        public void Update(GameTime gameTime, IUpdatable parent)
        {
            _elapsedTimeSinceLastSpawn += gameTime.ElapsedGameTime.Milliseconds;
            _elapsedTimeSinceStart     += gameTime.ElapsedGameTime.Milliseconds;

            IDrawable parentDrawable = null;

            if (parent is IDrawable)
            {
                parentDrawable = (IDrawable)parent;
            }

            float rotation = Rotation;

            if (parentDrawable != null)
            {
                rotation = parentDrawable.Rotation + Rotation;
            }

            Vector2 position = GetRandomPosition(parentDrawable);

            // remove dead particles
            PruneParticlePool();

            // only create new particles while the emitter is "on" and the
            // duration has not been reached.
            if (_isEmitting && (_elapsedTimeSinceStart < _duration || _duration == -1.0f))
            {
                // time for new spawn
                if (_elapsedTimeSinceLastSpawn > _nextSpawn)
                {
                    // makes sure there is room in the pool for a new particle
                    if (_particlePool.Count < Orion.Core.Settings.Instance.MaxParticlesPerSystem)
                    {
                        _elapsedTimeSinceLastSpawn = 0.0f;
                        _nextSpawn = Settings.SpawnFrequency.GetNextValue();

                        Particle p = new Particle(
                            GetRandomTexture(),
                            position,
                            OrionMath.RotatePointPositive(Settings.StartVelocity.GetNextValue(), Vector2.Zero, rotation),
                            OrionMath.RotatePointPositive(Settings.EndVelocity.GetNextValue(), Vector2.Zero, rotation),
                            Settings.Angle.GetNextValue(),
                            Settings.AngularVelocity.GetNextValue(),
                            Settings.StartColor.GetNextValue(),
                            Settings.EndColor.GetNextValue(),
                            Settings.Alpha.GetNextValue(),
                            Settings.Size.GetNextValue(),
                            Settings.Life.GetNextValue()
                            );
                        _particlePool.Add(p);
                    }
                }
            }

            foreach (Particle p in _particlePool)
            {
                p.Update(gameTime);
            }
        }
Beispiel #2
0
        private Vector2 GetRandomPosition(IDrawable parent)
        {
            float rotation = Rotation;

            if (parent != null)
            {
                rotation = parent.Rotation + Rotation;
            }

            Vector2 relPos = OrionMath.RotatePointPositive(Position, Vector2.Zero, rotation);

            relPos += parent.Position;

            Range <float> xRange = new Range <float>(
                relPos.X + Settings.SpawnRadius.X,
                relPos.X - Settings.SpawnRadius.X,
                Settings.Randomizer);

            Range <float> yRange = new Range <float>(
                relPos.Y + Settings.SpawnRadius.Y,
                relPos.Y - Settings.SpawnRadius.Y,
                Settings.Randomizer);

            return(new Vector2(xRange.GetNextValue(), yRange.GetNextValue()));
        }
Beispiel #3
0
        /// <summary>
        /// Determines how the drawable is drawn to the screen.
        /// </summary>
        /// <param name="spriteBatch">The sprite batch that this drawable will be drawn under.</param>
        /// <param name="parent">The parent drawable.  This value can be null if the drawable
        /// does not have a parent.</param>
        public void Draw(SpriteBatch spriteBatch, IDrawable parent)
        {
            float rotation = Rotation;

            if (parent != null)
            {
                rotation = parent.Rotation + Rotation;
            }

            Vector2 finalPosition = OrionMath.RotatePointPositive(Position, Vector2.Zero, rotation);

            finalPosition += parent.Position;

            if (_renderTarget != null)
            {
                spriteBatch.Draw(
                    _renderTarget,
                    finalPosition,
                    new Rectangle(0, 0, _renderTarget.Width, _renderTarget.Height),
                    Color.White,
                    (float)OrionMath.ToRadians(rotation),
                    new Vector2(_renderTarget.Width / 2, _renderTarget.Height / 2),
                    1.0f,
                    _spriteEffects,
                    0.0f
                    );
            }
        }
Beispiel #4
0
        public virtual void Draw(SpriteBatch spriteBatch, IDrawable parent)
        {
            float rotation = Rotation;

            if (parent != null)
            {
                rotation = parent.Rotation + Rotation;
            }

            Vector2 finalPosition = OrionMath.RotatePointPositive(Position, Vector2.Zero, rotation);

            if (parent != null)
            {
                finalPosition += parent.Position;
            }

            spriteBatch.Draw(
                Texture,
                finalPosition,
                _drawRect,
                new Color(Tint, Alpha),
                (float)OrionMath.ToRadians(rotation),
                Origin,
                Scale,
                SpriteEffects.None,
                0.0f
                );
        }
        private void CalculateEndPoints(Vector2 positionDelta)
        {
            Vector2 pt1 = OrionMath.RotatePointPositive(EndPoint1, Position, Rotation);
            Vector2 pt2 = OrionMath.RotatePointPositive(EndPoint2, Position, Rotation);

            EndPoint1 = pt1 + positionDelta;
            EndPoint2 = pt2 + positionDelta;
        }
        /// <summary>
        /// Determines how the primative is drawn to the screen.
        /// </summary>
        /// <param name="spriteBatch">The sprite batch that this drawable will be drawn under.</param>
        public void Draw(SpriteBatch spriteBatch, IDrawable parent)
        {
            int x = (int)(Position.X - Origin.X);
            int y = (int)(Position.Y - Origin.Y);

            Primitives2D.FillRectangle(
                spriteBatch,
                new Rectangle(x, y, Width, Height),
                FillColor,
                (float)OrionMath.ToRadians(Rotation)
                );

            Vector2 v1 = OrionMath.RotatePointPositive(new Vector2(x, y), Origin, Rotation);
            Vector2 v2 = OrionMath.RotatePointPositive(new Vector2(x + Width, y), Origin, Rotation);
            Vector2 v3 = OrionMath.RotatePointPositive(new Vector2(x + Width, y + Height), Origin, Rotation);
            Vector2 v4 = OrionMath.RotatePointPositive(new Vector2(x, y + Height), Origin, Rotation);

            Primitives2D.DrawLine(spriteBatch, v1, v2, BorderColor, BorderWidth);
            Primitives2D.DrawLine(spriteBatch, v2, v3, BorderColor, BorderWidth);
            Primitives2D.DrawLine(spriteBatch, v3, v4, BorderColor, BorderWidth);
            Primitives2D.DrawLine(spriteBatch, v4, v1, BorderColor, BorderWidth);
        }