Ejemplo n.º 1
0
        private void SpawnShip(int number)
        {
            Player player;
            SpriteSheet spriteSheet;
            string bulletImageFilename;
            double bulletImageScale;
            Color bulletImageTransparentColor;
            string infoBarShipImageFilename;
            Color infoBarShipImageTransparentColor;
            Point scoreCardDisplayPosition;
            if (number == 1)
            {
                player = this.player1;
                bulletImageFilename = Configuration.Ships.Model1.BulletImageFilename;
                bulletImageScale = Configuration.Ships.Model1.BulletImageScale;
                bulletImageTransparentColor = Configuration.Ships.Model1.BulletImageTransparentColor;
                infoBarShipImageFilename = Configuration.Ships.Model1.InfoBarShipImageFilename;
                infoBarShipImageTransparentColor = Configuration.Ships.Model1.InfoBarShipImageTransparentColor;
                scoreCardDisplayPosition = new Point(Configuration.InfoBarPosition.X + Configuration.InfoBar.Player1ScoreCardDisplayPosition.X, Configuration.InfoBarPosition.Y + Configuration.InfoBar.Player1ScoreCardDisplayPosition.Y);
                spriteSheet = new SpriteSheet(Configuration.Ships.Model1.SpriteSheet.Filename, Configuration.Ships.Model1.SpriteSheet.TransparentColor, Configuration.Ships.Model1.SpriteSheet.Size, Configuration.Ships.Model1.SpriteSheet.RotationDegreesPerFrame, Configuration.Ships.Model1.SpriteSheet.FirstFrameDirectionDegrees, Configuration.Ships.Model1.SpriteSheet.RotationAnimationDelay, Configuration.Ships.Model1.SpriteSheet.CannonBarrelLength, Configuration.Ships.Model1.SpriteSheet.ForwardThrusterEngineLength, Configuration.Ships.Model1.SpriteSheet.ReverseThrusterEngineLength);
            }
            else
            {
                player = this.player2;
                bulletImageFilename = Configuration.Ships.Model2.BulletImageFilename;
                bulletImageScale = Configuration.Ships.Model2.BulletImageScale;
                bulletImageTransparentColor = Configuration.Ships.Model2.BulletImageTransparentColor;
                infoBarShipImageFilename = Configuration.Ships.Model2.InfoBarShipImageFilename;
                infoBarShipImageTransparentColor = Configuration.Ships.Model2.InfoBarShipImageTransparentColor;
                scoreCardDisplayPosition = new Point(Configuration.InfoBarPosition.X + Configuration.InfoBar.Player2ScoreCardDisplayPosition.X, Configuration.InfoBarPosition.Y + Configuration.InfoBar.Player2ScoreCardDisplayPosition.Y);

                spriteSheet = new SpriteSheet(Configuration.Ships.Model2.SpriteSheet.Filename, Configuration.Ships.Model2.SpriteSheet.TransparentColor, Configuration.Ships.Model2.SpriteSheet.Size, Configuration.Ships.Model2.SpriteSheet.RotationDegreesPerFrame, Configuration.Ships.Model2.SpriteSheet.FirstFrameDirectionDegrees, Configuration.Ships.Model2.SpriteSheet.RotationAnimationDelay, Configuration.Ships.Model2.SpriteSheet.CannonBarrelLength, Configuration.Ships.Model2.SpriteSheet.ForwardThrusterEngineLength, Configuration.Ships.Model2.SpriteSheet.ReverseThrusterEngineLength);
            }

            Point spawnPosition = GetSafeSpawnPosition(player.Ship);

            // Start the creation special effects.
            this.particleSystem.Particles.Add(player.CreationEffect.Create(new Point(spawnPosition.X + spriteSheet.FrameSize.Width / 2, spawnPosition.Y + spriteSheet.FrameSize.Height / 2)));

            Bitmap bulletImage = new Bitmap(bulletImageFilename);
            Surface bulletSurface = new Surface(bulletImage).Convert(Video.Screen, true, false);
            bulletSurface = bulletSurface.CreateScaledSurface(bulletImageScale);
            bulletSurface.Transparent = true;
            bulletSurface.TransparentColor = bulletImageTransparentColor;

            Bitmap infoBarShipImage = new Bitmap(infoBarShipImageFilename);
            Surface infoBarShipSurface = new Surface(infoBarShipImage).Convert(Video.Screen, true, false);
            infoBarShipSurface.Transparent = true;
            infoBarShipSurface.TransparentColor = infoBarShipImageTransparentColor;

            if (player.Ship != null)
                player.Ship.Dispose();

            player.Ship = new Ship(player, spriteSheet, spawnPosition, bulletSurface, infoBarShipSurface);

            if (player.ScoreCard == null)
                player.ScoreCard = new ScoreCard(player, scoreCardDisplayPosition);

            this.particleSystem.Add(player.Ship);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new Ship instance.
        /// </summary>
        /// <param name="player">
        /// The player who owns the ship.
        /// </param>
        /// <param name="spriteSheet">
        /// The Ship's rotational sprite sheet.
        /// </param>
        /// <param name="startingScreenPosition">
        /// The Ship's starting screen position.
        /// </param>
        /// <param name="bulletSurface">
        /// The surface for bullets fired by this ship.
        /// </param>
        /// <param name="infoBarShipSurface">
        /// The surface that is displayed as the identifying icon in the
        /// InfoBar.
        /// </param>
        public Ship(Player player, SpriteSheet spriteSheet, Point startingScreenPosition, Surface bulletSurface, Surface infoBarShipSurface)
            : base(spriteSheet.AnimatedSprite)
        {
            this.player = player;
            this.spriteSheet = spriteSheet;

            // This is for the ship picture in the InfoBar.
            this.shipPhotoSurface = infoBarShipSurface;

            this.topSpeed = Configuration.Ships.TopSpeed;
            this.shields = Configuration.Ships.Shields.Power;

            this.X = startingScreenPosition.X;
            this.Y = startingScreenPosition.Y;
            this.Velocity = new Vector();
            this.Life = -1; // Infinite life span.

            // Our next scheduled respawn time (i.e. never).
            this.respawnTime = DateTime.MinValue;

            this.speedLimiter = new SpeedLimit(this.topSpeed);

            this.forwardThruster = new Thruster(this, false, Configuration.Ships.Thrusters.Forward.SoundFilename, Configuration.Ships.Thrusters.Forward.Power, spriteSheet.ForwardThrusterEngineLength, Configuration.Ships.Thrusters.Forward.ExhaustConeDeg, Configuration.Ships.Thrusters.Forward.ParticleMinColor, Configuration.Ships.Thrusters.Forward.ParticleMaxColor);

            this.reverseThruster = new Thruster(this, true, Configuration.Ships.Thrusters.Reverse.SoundFilename, Configuration.Ships.Thrusters.Reverse.Power, spriteSheet.ReverseThrusterEngineLength, Configuration.Ships.Thrusters.Reverse.ExhaustConeDeg, Configuration.Ships.Thrusters.Reverse.ParticleMinColor, Configuration.Ships.Thrusters.Reverse.ParticleMaxColor);

            this.cannon = new Cannon(this, spriteSheet.CannonBarrelLength, bulletSurface, Configuration.Ships.Cannon.Power, Configuration.Ships.Cannon.Cooldown, Configuration.Ships.Cannon.MuzzleSpeed, Configuration.Bullets.Life);

            this.spawnTime = DateTime.Now;
        }