Ejemplo n.º 1
0
 /// <summary>
 /// Constructs a new weapon.
 /// </summary>
 /// <param name="owner">The ship that owns this weapon.</param>
 protected Weapon(Ship owner)
 {
     if (owner == null)
     {
         throw new ArgumentNullException("owner");
     }
     this.owner = owner;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs a new rocket-launching weapon.
        /// </summary>
        /// <param name="owner">The ship that owns this weapon.</param>
        public RocketWeapon(Ship owner)
            : base(owner)
        {
            fireDelay = 0.5f;

            // Pick one of the rocket sound variations for this instance.
            if (RandomMath.Random.Next(2) == 0)
                fireSoundEffect = "fire_rocket1";
            else
                fireSoundEffect = "fire_rocket2";
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructs a new mine projectile.
        /// </summary>
        /// <param name="owner">The ship that fired this projectile, if any.</param>
        /// <param name="direction">The initial direction for this projectile.</param>
        public MineProjectile(Ship owner, Vector2 direction)
            : base(owner, direction)
        {
            // set the gameplay data
            this.velocity = initialSpeed * direction;

            // set the collision data
            this.radius = 10f;
            this.mass = 5f;

            // set projectile data
            this.duration = 15f;
            this.damageAmount = 200f;
            this.damageOwner = false;
            this.damageRadius = 80f;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructs a new laser weapon.
        /// </summary>
        /// <param name="owner">The ship that owns this weapon.</param>
        public LaserWeapon(Ship owner)
            : base(owner)
        {
            fireDelay = 0.15f;

            // Pick one of the laser sound variations for this instance.
            switch (RandomMath.Random.Next(3))
            {
                case 0:
                    fireSoundEffect = "fire_laser1";
                    break;
                case 1:
                    fireSoundEffect = "fire_laser2";
                    break;
                case 2:
                    fireSoundEffect = "fire_laser3";
                    break;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Constructs a new projectile.
        /// </summary>
        /// <param name="owner">The ship that fired this projectile.</param>
        /// <param name="direction">The initial direction for this projectile.</param>
        protected Projectile(Ship owner, Vector2 direction)
            : base() 
        {
            // safety-check the parameter
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }

            // apply the parameters
            this.owner = owner;
            this.velocity = direction; // speed will be applied in the subclass

            // initialize the graphics data
            this.position = owner.Position;
            this.rotation = (float)Math.Acos(Vector2.Dot(Vector2.UnitY, direction));
            if (direction.X > 0f)
            {
                this.rotation *= -1f;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructs a new rocket projectile.
        /// </summary>
        /// <param name="owner">The ship that fired this projectile, if any.</param>
        /// <param name="direction">The initial direction for this projectile.</param>
        public RocketProjectile(Ship owner, Vector2 direction)
            : base(owner, direction)
        {
            // set the gameplay data
            this.velocity = initialSpeed * direction;

            // set the collision data
            this.radius = 14f;
            this.mass = 10f;

            // set the projectile data
            this.duration = 4f;
            this.damageAmount = 150f;
            this.damageOwner = false;
            this.damageRadius = 128f;
            this.rotation += MathHelper.Pi;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Draws the gameplay screen.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (networkSession != null)
            {
                // make sure we know what the local ship is
                if ((localShip == null) && (networkSession.LocalGamers.Count > 0))
                {
                    PlayerData playerData = networkSession.LocalGamers[0].Tag
                        as PlayerData;
                    if (playerData.Ship != null)
                    {
                        localShip = playerData.Ship;
                        starfield.Reset(localShip.Position);
                    }
                }

                if (bloomComponent != null)
                {
                    bloomComponent.BeginDraw();
                }

                // draw the world
                if ((world != null) && (localShip != null) && !IsExiting)
                {
                    Vector2 center = new Vector2(
                        localShip.Position.X + ScreenManager.GraphicsDevice.Viewport.X -
                           ScreenManager.GraphicsDevice.Viewport.Width / 2,
                        localShip.Position.Y + ScreenManager.GraphicsDevice.Viewport.Y -
                           ScreenManager.GraphicsDevice.Viewport.Height / 2);
                    starfield.Draw(center);
                    world.Draw(elapsedTime, center);

                    if (bloomComponent != null)
                    {
                        bloomComponent.Draw(gameTime);
                    }
                }

                // draw the user-interface elements of the game (scores, etc.)
                DrawHud((float)gameTime.TotalGameTime.TotalSeconds);
            }

            // If the game is transitioning on or off, fade it out to black.
            if (ScreenState == ScreenState.TransitionOn && (TransitionPosition > 0))
                ScreenManager.FadeBackBufferToBlack(255 - TransitionAlpha);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Construct a new GameplayScreen object.
        /// </summary>
        /// <param name="networkSession">The network session for this game.</param>
        /// <param name="world">The primary gameplay object.</param>
        public GameplayScreen(NetworkSession networkSession, World world)
        {
            // safety-check the parameters
            if (networkSession == null)
            {
                throw new ArgumentNullException("networkSession");
            }
            if (world == null)
            {
                throw new ArgumentNullException("world");
            }

            // apply the parameters
            this.networkSession = networkSession;
            this.world = world;

            // set up the network events
            sessionEndedHandler = new EventHandler<NetworkSessionEndedEventArgs>(
                networkSession_SessionEnded);
            networkSession.SessionEnded += sessionEndedHandler;
            gameEndedHandler = new EventHandler<GameEndedEventArgs>(
                networkSession_GameEnded);
            networkSession.GameEnded += gameEndedHandler;
            gamerLeftHandler = new EventHandler<GamerLeftEventArgs>(
                networkSession_GamerLeft);
            networkSession.GamerLeft += gamerLeftHandler;
                

            // cache the local player's ship object
            if (networkSession.LocalGamers.Count > 0)
            {
                PlayerData playerData = networkSession.LocalGamers[0].Tag as PlayerData;
                if (playerData != null)
                {
                    localShip = playerData.Ship;
                }
            }

            // set the transition times
            TransitionOnTime = TimeSpan.FromSeconds(1.0);
            TransitionOffTime = TimeSpan.FromSeconds(1.0);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Constructs a PlayerData object.
 /// </summary>
 public PlayerData() 
 {
     Ship = new Ship();
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Constructs a new triple-laser weapon.
 /// </summary>
 /// <param name="owner">The ship that owns this weapon.</param>
 public TripleLaserWeapon(Ship owner)
     : base(owner) 
 {
     fireDelay = 0.3f;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Constructs a new mine-laying weapon.
 /// </summary>
 /// <param name="owner">The ship that owns this weapon.</param>
 public MineWeapon(Ship owner)
     : base(owner)
 {
     fireDelay = 2f;         
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Constructs a new double-laser weapon.
 /// </summary>
 /// <param name="owner">The ship that owns this weapon.</param>
 public DoubleLaserWeapon(Ship owner)
     : base(owner) { }
 /// <summary>
 /// Constructs a new double-laser weapon.
 /// </summary>
 /// <param name="owner">The ship that owns this weapon.</param>
 public DoubleLaserWeapon(Ship owner)
     : base(owner)
 {
 }