/// <summary>
        /// Initializes a new instance of the <see cref="Sprite"/> class.
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <param name="texture">
        /// The texture.
        /// </param>
        /// <param name="initialFrame">
        /// The initial frame.
        /// </param>
        /// <param name="frameCount">
        /// The frame count.
        /// </param>
        /// <param name="collisionRadius">
        /// The collision radius.
        /// </param>
        /// <param name="simulationState">
        /// The simulation state.
        /// </param>
        internal Sprite(
            long id, 
            Texture2D texture, 
            Rectangle initialFrame, 
            int frameCount, 
            int collisionRadius, 
            EntityState simulationState)
        {
            this.Id = id;
            this.Texture = texture;
            this.InitialFrame = initialFrame;
            this.collisionRadius = collisionRadius;

            this.frames.Add(initialFrame);

            for (int x = 1; x < frameCount; x++)
            {
                this.frames.Add(
                    new Rectangle(
                        initialFrame.X + (initialFrame.Width * x), 
                        initialFrame.Y, 
                        initialFrame.Width, 
                        initialFrame.Height));
            }

            this.SimulationState = simulationState;
            this.DisplayState = (EntityState)simulationState.Clone();
            this.PrevDisplayState = (EntityState)simulationState.Clone();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Asteroid"/> class.
 /// </summary>
 /// <param name="id">
 /// The id.
 /// </param>
 /// <param name="texture">
 /// The texture.
 /// </param>
 /// <param name="initialFrame">
 /// The initial frame.
 /// </param>
 /// <param name="frameCount">
 /// The frame count.
 /// </param>
 /// <param name="collisionRadius">
 /// The collision radius.
 /// </param>
 /// <param name="simulationState">
 /// The simulation state.
 /// </param>
 internal Asteroid(
     long id, 
     Texture2D texture, 
     Rectangle initialFrame, 
     int frameCount, 
     int collisionRadius, 
     EntityState simulationState)
     : base(id, texture, initialFrame, frameCount, collisionRadius, simulationState)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Enemy"/> class.
 /// </summary>
 /// <param name="id">
 /// The id.
 /// </param>
 /// <param name="texture">
 /// The texture.
 /// </param>
 /// <param name="initialFrame">
 /// The initial frame.
 /// </param>
 /// <param name="frameCount">
 /// The frame count.
 /// </param>
 /// <param name="collisionRadius">
 /// The collision radius.
 /// </param>
 /// <param name="simulationState">
 /// The simulation state.
 /// </param>
 /// <param name="path">
 /// The path.
 /// </param>
 internal Enemy(
     long id, 
     Texture2D texture, 
     Rectangle initialFrame, 
     int frameCount, 
     int collisionRadius, 
     EntityState simulationState, 
     int path)
     : base(id, texture, initialFrame, frameCount, collisionRadius, simulationState)
 {
     this.Path = path;
 }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Shot"/> class.
 /// </summary>
 /// <param name="id">
 /// The id.
 /// </param>
 /// <param name="texture">
 /// The texture.
 /// </param>
 /// <param name="initialFrame">
 /// The initial frame.
 /// </param>
 /// <param name="frameCount">
 /// The frame count.
 /// </param>
 /// <param name="collisionRadius">
 /// The collision radius.
 /// </param>
 /// <param name="simulationState">
 /// The simulation state.
 /// </param>
 /// <param name="firedById">
 /// The fired by id.
 /// </param>
 /// <param name="firedByPlayer">
 /// The fired by player.
 /// </param>
 internal Shot(
     long id, 
     Texture2D texture, 
     Rectangle initialFrame, 
     int frameCount, 
     int collisionRadius, 
     EntityState simulationState, 
     long firedById, 
     bool firedByPlayer)
     : base(id, texture, initialFrame, frameCount, collisionRadius, simulationState)
 {
     this.FiredByPlayer = firedByPlayer;
     this.FiredById = firedById;
 }
        /// <summary>
        /// The select random entity state.
        /// </summary>
        /// <returns>
        /// </returns>
        public EntityState SelectRandomEntityState()
        {
            var physicsState = new EntityState
                {
                    Position =
                        new Vector2(
                        this.randomNumberGenerator.Next(0, this.PlayerAreaLimit.Width), 
                        this.randomNumberGenerator.Next(this.PlayerAreaLimit.Top, this.PlayerAreaLimit.Bottom))
                };

            return physicsState;
        }
 /// <summary>
 /// The reset asteroid state.
 /// </summary>
 /// <param name="newState">
 /// The new state.
 /// </param>
 public void ResetAsteroidState(EntityState newState)
 {
     this.SimulationState = newState;
     this.DisplayState = (EntityState)this.SimulationState.Clone();
     this.PrevDisplayState = (EntityState)this.SimulationState.Clone();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Particle"/> class.
 /// </summary>
 /// <param name="id">
 /// The id.
 /// </param>
 /// <param name="texture">
 /// The texture.
 /// </param>
 /// <param name="initialFrame">
 /// The initial frame.
 /// </param>
 /// <param name="frameCount">
 /// The frame count.
 /// </param>
 /// <param name="collisionRadius">
 /// The collision radius.
 /// </param>
 /// <param name="simulationState">
 /// The simulation state.
 /// </param>
 /// <param name="acceleration">
 /// The acceleration.
 /// </param>
 /// <param name="maxSpeed">
 /// The max speed.
 /// </param>
 /// <param name="duration">
 /// The duration.
 /// </param>
 /// <param name="initialColor">
 /// The initial color.
 /// </param>
 /// <param name="finalColor">
 /// The final color.
 /// </param>
 public Particle(
     long id, 
     Texture2D texture, 
     Rectangle initialFrame, 
     int frameCount, 
     int collisionRadius, 
     EntityState simulationState, 
     Vector2 acceleration, 
     float maxSpeed, 
     int duration, 
     Color initialColor, 
     Color finalColor)
     : base(id, texture, initialFrame, frameCount, collisionRadius, simulationState)
 {
     this.initialDuration = duration;
     this.remainingDuration = duration;
     this.acceleration = acceleration;
     this.initialColor = initialColor;
     this.maxSpeed = maxSpeed;
     this.finalColor = finalColor;
 }
        /// <summary>
        /// The select random entity state.
        /// </summary>
        /// <returns>
        /// </returns>
        public EntityState SelectRandomEntityState()
        {
            var physicsState = new EntityState();
            bool physicsStateIsOk = true;
            int tryCount = 0;

            physicsState.Rotation = MathHelper.ToRadians(this.randomNumberGenerator.Next(0, 360));

            do
            {
                physicsStateIsOk = true;
                Vector2 velocity = Vector2.Zero;

                switch (this.randomNumberGenerator.Next(0, 2))
                {
                    case 0:
                        physicsState.Position = new Vector2(
                            -this.screenPadding.Left, 
                            this.randomNumberGenerator.Next(0, this.resolutionManager.DisplayViewport.Height));

                        velocity = new Vector2(
                            this.randomNumberGenerator.Next(0, 50), this.randomNumberGenerator.Next(0, 100) - 50);
                        break;

                    case 1:
                        physicsState.Position = new Vector2(
                            this.resolutionManager.DisplayViewport.Width, 
                            this.randomNumberGenerator.Next(0, this.resolutionManager.DisplayViewport.Height));

                        velocity = new Vector2(
                            this.randomNumberGenerator.Next(0, 50) - 50, this.randomNumberGenerator.Next(0, 100) - 50);
                        break;

                    case 2:
                        physicsState.Position =
                            new Vector2(
                                this.randomNumberGenerator.Next(0, this.resolutionManager.DisplayViewport.Width), 
                                -this.screenPadding.Top);

                        velocity = new Vector2(
                            this.randomNumberGenerator.Next(0, 100) - 50, this.randomNumberGenerator.Next(0, 50));
                        break;
                }

                velocity.Normalize();
                velocity *= this.randomNumberGenerator.Next((int)this.minAsteroidSpeed, (int)this.maxAsteroidSpeed);
                physicsState.Velocity = velocity;

                foreach (Asteroid asteroid in this.asteroids.Values)
                {
                    if (
                        asteroid.Bounds.Intersects(
                            new Rectangle(
                                (int)physicsState.Position.X, 
                                (int)physicsState.Position.Y, 
                                this.initialAsteroidFrame.Width, 
                                this.initialAsteroidFrame.Height)))
                    {
                        physicsStateIsOk = false;
                    }
                }

                tryCount++;
                if ((tryCount > 5) && physicsStateIsOk == false)
                {
                    physicsState.Position = new Vector2(-500, -500);
                    physicsStateIsOk = true;
                }
            }
            while (physicsStateIsOk == false);

            return physicsState;
        }