Beispiel #1
0
        /// <summary>
        /// Creates a new SpacewarScreen
        /// </summary>
        public EvolvedScreen(Game game)
            : base(game)
        {
            backdrop = new SceneItem(game, new EvolvedBackdrop(game));
            const float factor = 46;
            backdrop.Center = new Vector3(.5f, .5f, 0);
            backdrop.Scale = new Vector3(16f * factor, 9f * factor, 1f);
            backdrop.Position = new Vector3(-.5f, -.5f, 0);
            nextScene.Add(backdrop, drawScene);

            bullets = new Projectiles(game);
            particles = new Particles(game);

            ship1 = new Ship(game, PlayerIndex.One, SpacewarGame.Players[0].ShipClass, SpacewarGame.Players[0].Skin, new Vector3(SpacewarGame.Settings.Ships[0].StartPosition, 0.0f), bullets, particles);
            ship1.Paused = true;
            ship1.Radius = 15f;
            if (SpacewarGame.Players[0].ShipClass == ShipClass.Pencil)
            {
                ship1.ExtendedExtent[0] = new Vector3(0.0f, 25.0f, 0.0f);
                ship1.ExtendedExtent[1] = new Vector3(0.0f, -25.0f, 0.0f);
            }

            ship2 = new Ship(game, PlayerIndex.Two, SpacewarGame.Players[1].ShipClass, SpacewarGame.Players[1].Skin, new Vector3(SpacewarGame.Settings.Ships[1].StartPosition, 0.0f), bullets, particles);
            ship2.Paused = true;
            ship2.Radius = 15f;
            if (SpacewarGame.Players[1].ShipClass == ShipClass.Pencil)
            {
                ship2.ExtendedExtent[0] = new Vector3(0.0f, 25f, 0.0f);
                ship2.ExtendedExtent[1] = new Vector3(0.0f, -25f, 0.0f);
            }

            nextScene.Add(bullets, drawScene);

            asteroids = new Asteroid[SpacewarGame.GameLevel + 2];

            for (int i = 0; i < SpacewarGame.GameLevel + 2; i++)
            {

                asteroids[i] = new Asteroid(game, random.NextDouble() > .5 ? AsteroidType.Large : AsteroidType.Small, asteroidStarts[i]);
                asteroids[i].Scale = new Vector3(SpacewarGame.Settings.AsteroidScale, SpacewarGame.Settings.AsteroidScale, SpacewarGame.Settings.AsteroidScale);
                asteroids[i].Paused = true;
                asteroids[i].Velocity = (float)random.Next(100) * Vector3.Normalize(new Vector3((float)(random.NextDouble() - .5), (float)(random.NextDouble() - .5), 0));

                nextScene.Add(asteroids[i], drawScene);
            }

            nextScene.Add(ship1, drawScene);
            nextScene.Add(ship2, drawScene);
            //Added after other objects so they draw over the top
            nextScene.Add(particles, drawScene);


            //Sun last so its on top
            sun = new Sun(game, new EvolvedSun(game), new Vector3(-.5f, -.5f, 0));
            nextScene.Add(sun, drawScene);

            //Reset health meters.
            SpacewarGame.Players[0].Health = 5;
            SpacewarGame.Players[1].Health = 5;
        }
Beispiel #2
0
        /// <summary>
        /// Creates a group of projectiles
        /// </summary>
        /// <param name="player">Which player shot the bullet</param>
        /// <param name="position">Start position of projectile</param>
        /// <param name="velocity">Initial velocity of projectile</param>
        /// <param name="angle">Direction projectile is facing</param>
        /// <param name="time">Game time that this projectile was shot</param>
        /// <param name="particles">The particles to add to for effects</param>
        public virtual void Add(PlayerIndex player, Vector3 position, Vector3 velocity, float angle, TimeSpan time, Particles particles)
        {
            ProjectileType projectileType = SpacewarGame.Players[(int)player].ProjectileType;

            Vector3 offset = Vector3.Zero;

            if (SpacewarGame.Players[(int)player].ProjectileType == ProjectileType.DoubleMachineGun)
            {
                //Get a perpendicular vector to the direction of fire to offset the double shot
                offset.X = -velocity.Y;
                offset.Y = velocity.X;
                offset.Normalize();
                offset *= 10.0f;
            }

            for (int i = 0; i < SpacewarGame.Settings.Weapons[(int)projectileType].Burst; i++)
            {
                //If we are not up to max then we can add bullets
                if (Projectile.ProjectileCount[(int)player] < SpacewarGame.Settings.Weapons[(int)projectileType].Max)
                {
                    Add(new Projectile(GameInstance, player, position + velocity * i * .1f + offset, velocity, angle, time, particles));
                    if (offset != Vector3.Zero)
                    {
                        Add(new Projectile(GameInstance, player, position + velocity * i * .1f - offset, velocity, angle, time, particles));
                    }
                }
            }
        }
Beispiel #3
0
        public Ship(Game game, PlayerIndex player, ShipClass shipNumber, int shipSkin, Vector3 initialPosition, Projectiles bullets, Particles particles)
            : base(game, new EvolvedShape(game, EvolvedShapes.Ship, player, (int)shipNumber, shipSkin, LightingType.InGame), initialPosition)
        {
            this.player    = player;
            this.bullets   = bullets;
            this.particles = particles;
            this.evolved   = true;

            //Evolved needs scaling
            scale     = new Vector3(SpacewarGame.Settings.ShipScale, SpacewarGame.Settings.ShipScale, SpacewarGame.Settings.ShipScale);
            rotation  = new Vector3(MathHelper.ToRadians(90), 0, 0);
            direction = new Vector3((float)(-Math.Sin(Rotation.Z)), (float)(Math.Cos(Rotation.Z)), 0);

            if (game != null)
            {
                IGraphicsDeviceService graphicsService = (IGraphicsDeviceService)game.Services.GetService(typeof(IGraphicsDeviceService));
                batch = new SpriteBatch(graphicsService.GraphicsDevice);
            }

            if (shipNumber == ShipClass.Pencil)
            {
                extendedExtent = new Vector3[2];
            }
        }
Beispiel #4
0
        private void ReplaceScene(SceneItem sun, Ship one, Ship two, 
            Asteroid[] astr, Particles part, Projectiles proj)
        {
            scene.Remove(this.sun);
            scene.Remove(ship1);
            scene.Remove(ship2);
            this.sun = sun;
            this.ship1 = one;
            this.ship2 = two;

            scene.Add(ship1);
            scene.Add(ship2);
            scene.Add(sun);

            for (int i = 0; i < astr.Length; i++)
            {
                asteroids[i] = astr[0].Copy();
                if(!asteroids[i].Delete)
                    scene.Add(asteroids[i]);
            }

            this.particles = part;
            scene.Add(particles);

            this.bullets = proj;
            scene.Add(bullets);
        }
Beispiel #5
0
        public new Particles Copy()
        {
            Particles retn = new Particles(this.GameInstance);

            retn.acceleration = new Vector3(this.acceleration.X, this.acceleration.Y, this.acceleration.Z);
            retn.center = new Vector3(this.center.X, this.center.Y, this.center.Z);
            //retn.paused = this.paused;
            retn.radius = this.radius;
            retn.rotation = new Vector3(this.rotation.X, this.rotation.Y, this.rotation.Z);
            retn.scale = new Vector3(this.scale.X, this.scale.Y, this.scale.Z);
            foreach (SceneItem item in this)
                retn.Add(item);

            return retn;
        }
Beispiel #6
0
 /// <summary>
 /// Creates a group of projectiles
 /// </summary>
 /// <param name="player">Which player shot the bullet</param>
 /// <param name="position">Start position of projectile</param>
 /// <param name="velocity">Initial velocity of projectile</param>
 /// <param name="angle">Direction projectile is facing</param>
 /// <param name="time">Game time that this projectile was shot</param>
 /// <param name="particles">The particles to add to for effects</param>
 public override void Add(PlayerIndex player, Vector3 position, Vector3 velocity, float angle, TimeSpan time, Particles particles)
 {
     Add(new Projectile(GameInstance, player, position, velocity, angle, time, null));
 }
Beispiel #7
0
        /// <summary>
        /// Cretes a new projectile
        /// </summary>
        /// <param name="game">Instance of the game</param>
        /// <param name="player">Which player it came from</param>
        /// <param name="position">The start position</param>
        /// <param name="velocity">The start velocity</param>
        /// <param name="angle">The direction its facing</param>
        /// <param name="time">The time the projectile was fired</param>
        public Projectile(Game game, PlayerIndex player, Vector3 position, Vector3 velocity, float angle, TimeSpan time, Particles particles)
            : base(game)
        {
            this.player = player;
            this.velocity = velocity;
            this.position = position;

            projectileCount[(int)player]++;

            if (SpacewarGame.GameState == GameState.PlayEvolved)
            {
                projectileType = (int)SpacewarGame.Players[(int)player].ProjectileType;

                this.particles = particles;

                endTime = time.TotalSeconds + SpacewarGame.Settings.Weapons[projectileType].Lifetime;
                thrust = Vector3.Multiply(Vector3.Normalize(velocity), SpacewarGame.Settings.Weapons[projectileType].Acceleration);
                radius = 2;

                damage = SpacewarGame.Settings.Weapons[projectileType].Damage;

                if (SpacewarGame.GameState == GameState.PlayEvolved)
                {
                    shape = new BasicEffectShape(GameInstance, BasicEffectShapes.Projectile, projectileType, LightingType.InGame);

                    //Evolved needs scaling
                    scale.X =
                    scale.Y =
                    scale.Z = SpacewarGame.Settings.BulletScale;

                    rotation.X = MathHelper.ToRadians(90);
                    rotation.Y = 0;
                    rotation.Z = (float)angle;
                }
            }
            else
            {
                //Build up a retro weapon
                damage = 5; //One shot kill
                projectileType = (int)ProjectileType.Peashooter;
                radius = 1;

                endTime = time.TotalSeconds + 2.0;
                acceleration = Vector3.Zero;
            }

            //Play 'shoot' sound
            switch (projectileType)
            {
                case (int)ProjectileType.Peashooter:
                    Sound.PlayCue(Sounds.PeashooterFire);
                    break;

                case (int)ProjectileType.MachineGun:
                    Sound.PlayCue(Sounds.MachineGunFire);
                    break;

                case (int)ProjectileType.DoubleMachineGun:
                    Sound.PlayCue(Sounds.DoubleMachineGunFire);
                    break;

                case (int)ProjectileType.Rocket:
                    Sound.PlayCue(Sounds.RocketExplode);
                    break;

                case (int)ProjectileType.BFG:
                    Sound.PlayCue(Sounds.BFGFire);
                    break;
            }
        }
Beispiel #8
0
 /// <summary>
 /// Creates a group of projectiles
 /// </summary>
 /// <param name="player">Which player shot the bullet</param>
 /// <param name="position">Start position of projectile</param>
 /// <param name="velocity">Initial velocity of projectile</param>
 /// <param name="angle">Direction projectile is facing</param>
 /// <param name="time">Game time that this projectile was shot</param>
 /// <param name="particles">The particles to add to for effects</param>
 public override void Add(PlayerIndex player, Vector3 position, Vector3 velocity, float angle, TimeSpan time, Particles particles)
 {
     Add(new Projectile(GameInstance, player, position, velocity, angle, time, null));
 }
Beispiel #9
0
        /// <summary>
        /// Creates a group of projectiles
        /// </summary>
        /// <param name="player">Which player shot the bullet</param>
        /// <param name="position">Start position of projectile</param>
        /// <param name="velocity">Initial velocity of projectile</param>
        /// <param name="angle">Direction projectile is facing</param>
        /// <param name="time">Game time that this projectile was shot</param>
        /// <param name="particles">The particles to add to for effects</param>
        public virtual void Add(PlayerIndex player, Vector3 position, Vector3 velocity, float angle, TimeSpan time, Particles particles)
        {
            ProjectileType projectileType = SpacewarGame.Players[(int)player].ProjectileType;

            Vector3 offset = Vector3.Zero;

            if (SpacewarGame.Players[(int)player].ProjectileType == ProjectileType.DoubleMachineGun)
            {
                //Get a perpendicular vector to the direction of fire to offset the double shot
                offset.X = -velocity.Y;
                offset.Y = velocity.X;
                offset.Normalize();
                offset *= 10.0f;
            }

            for (int i = 0; i < SpacewarGame.Settings.Weapons[(int)projectileType].Burst; i++)
            {
                //If we are not up to max then we can add bullets
                if (Projectile.ProjectileCount[(int)player] < SpacewarGame.Settings.Weapons[(int)projectileType].Max)
                {
                    Add(new Projectile(GameInstance, player, position + velocity * i * .1f + offset, velocity, angle, time, particles));
                    if (offset != Vector3.Zero)
                    {
                        Add(new Projectile(GameInstance, player, position + velocity * i * .1f - offset, velocity, angle, time, particles));
                    }
                }
            }
        }
Beispiel #10
0
        private void ReplaceScene(SceneItem sun, Ship one, Ship two,
            Particles part, Projectiles proj)
        {
            scene.Remove(this.sun);
            scene.Remove(ship1);
            scene.Remove(ship2);
            this.sun = sun;
            this.ship1 = one;
            this.ship2 = two;

            scene.Add(ship1);
            scene.Add(ship2);
            scene.Add(sun);

            this.particles = part;
            if(particles != null)
                scene.Add(particles);

            this.bullets = proj;
            scene.Add(bullets);
        }
Beispiel #11
0
        /// <summary>
        /// Cretes a new projectile
        /// </summary>
        /// <param name="game">Instance of the game</param>
        /// <param name="player">Which player it came from</param>
        /// <param name="position">The start position</param>
        /// <param name="velocity">The start velocity</param>
        /// <param name="angle">The direction its facing</param>
        /// <param name="time">The time the projectile was fired</param>
        public Projectile(Game game, PlayerIndex player, Vector3 position, Vector3 velocity, float angle, TimeSpan time, Particles particles)
            : base(game)
        {
            this.player   = player;
            this.velocity = velocity;
            this.position = position;

            projectileCount[(int)player]++;

            if (SpacewarGame.GameState == GameState.PlayEvolved)
            {
                projectileType = (int)SpacewarGame.Players[(int)player].ProjectileType;

                this.particles = particles;

                endTime = time.TotalSeconds + SpacewarGame.Settings.Weapons[projectileType].Lifetime;
                thrust  = Vector3.Multiply(Vector3.Normalize(velocity), SpacewarGame.Settings.Weapons[projectileType].Acceleration);
                radius  = 2;

                damage = SpacewarGame.Settings.Weapons[projectileType].Damage;

                if (SpacewarGame.GameState == GameState.PlayEvolved)
                {
                    shape = new BasicEffectShape(GameInstance, BasicEffectShapes.Projectile, projectileType, LightingType.InGame);

                    //Evolved needs scaling
                    scale.X         =
                        scale.Y     =
                            scale.Z = SpacewarGame.Settings.BulletScale;

                    rotation.X = MathHelper.ToRadians(90);
                    rotation.Y = 0;
                    rotation.Z = (float)angle;
                }
            }
            else
            {
                //Build up a retro weapon
                damage         = 5; //One shot kill
                projectileType = (int)ProjectileType.Peashooter;
                radius         = 1;

                endTime      = time.TotalSeconds + 2.0;
                acceleration = Vector3.Zero;
            }

            //Play 'shoot' sound
            switch (projectileType)
            {
            case (int)ProjectileType.Peashooter:
                Sound.PlayCue(Sounds.PeashooterFire);
                break;

            case (int)ProjectileType.MachineGun:
                Sound.PlayCue(Sounds.MachineGunFire);
                break;

            case (int)ProjectileType.DoubleMachineGun:
                Sound.PlayCue(Sounds.DoubleMachineGunFire);
                break;

            case (int)ProjectileType.Rocket:
                Sound.PlayCue(Sounds.RocketExplode);
                break;

            case (int)ProjectileType.BFG:
                Sound.PlayCue(Sounds.BFGFire);
                break;
            }
        }
Beispiel #12
0
        public Ship(Game game, PlayerIndex player, ShipClass shipNumber, int shipSkin, Vector3 initialPosition, Projectiles bullets, Particles particles)
            : base(game, new EvolvedShape(game, EvolvedShapes.Ship, player, (int)shipNumber, shipSkin, LightingType.InGame), initialPosition)
        {
            this.player = player;
            this.bullets = bullets;
            this.particles = particles;
            this.evolved = true;

            //Evolved needs scaling
            scale = new Vector3(SpacewarGame.Settings.ShipScale, SpacewarGame.Settings.ShipScale, SpacewarGame.Settings.ShipScale);
            rotation = new Vector3(MathHelper.ToRadians(90), 0, 0);
            direction = new Vector3((float)(-Math.Sin(Rotation.Z)), (float)(Math.Cos(Rotation.Z)), 0);

            if (game != null)
            {
                IGraphicsDeviceService graphicsService = (IGraphicsDeviceService)game.Services.GetService(typeof(IGraphicsDeviceService));
                batch = new SpriteBatch(graphicsService.GraphicsDevice);
            }

            if (shipNumber == ShipClass.Pencil)
                extendedExtent = new Vector3[2];
        }