A base class for all Player ships
Inheritance: ScrollingShooter.GameObject
示例#1
0
        /// <summary>
        /// Updates the seed ship. Ship will move towards the Player and fire bullets when it is close.
        /// </summary>
        /// <param name="elapsedTime">Time since last update.</param>
        public override void Update(float elapsedTime)
        {
            _timer += elapsedTime;

            //Move towards the Player.
            PlayerShip Player         = ScrollingShooterGame.Game.Player;
            Vector2    PlayerPosition = new Vector2(Player.Bounds.Center.X, Player.Bounds.Center.Y);
            Vector2    toPlayer       = PlayerPosition - this._position;

            this._position += toPlayer * (float)((double)elapsedTime * .5);

            switch (_state)
            {
            case SeedState.Closed:
                if (toPlayer.LengthSquared() < 9000)
                {
                    //Close enough, start opening.
                    _timer   = 0f;
                    _opening = true;
                    _state   = SeedState.Opening;
                }
                break;

            case SeedState.Opening:
                if (_timer >= STATE_TIME)
                {
                    //Ready to open or close.
                    _state = (_opening) ? SeedState.Open : SeedState.Closed;
                    _timer = 0f;
                }
                break;

            case SeedState.Open:
                //Fire bullets until we have fired 5 bullets.
                if (firedBullets < NUM_OF_BULLETS_PER_FIRE && _timer >= FIRE_TIME)
                {
                    ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.ToPlayerBullet, _position);
                    firedBullets++;
                }
                else if (firedBullets == NUM_OF_BULLETS_PER_FIRE)
                {
                    //Reset bullet count and start closing.
                    firedBullets = 0;
                    _timer       = 0f;
                    _opening     = false;
                    _state       = SeedState.Opening;
                }
                break;

            case SeedState.Destroyed:
                //Do nothing for now.
                break;

            default:
                throw new Exception("Unknown state!");
            }
        }
示例#2
0
        /// <summary>
        /// Creates new blade projectiles
        /// </summary>
        /// <param name="content">A ContentManager to load content from</param>
        /// <param name="rotation">The rotation that it's at around the Player (0-2*PI)</param>
        /// <param name="Player">Reference back to the Player</param>
        public Blades(uint id, ContentManager content) : base(id)
        {
            this.spriteSheet = content.Load <Texture2D>("Spritesheets/newsh#.shp.000000");

            this.spriteBounds = new Rectangle(148, 67, 43, 35);

            this.Player = ScrollingShooterGame.Game.Player;

            this.BladeTimer = 0;
        }
示例#3
0
        /// <summary>
        /// It's update function that shoots out TurretFireballs if the PlayerShip
        /// is in range.
        /// </summary>
        /// <param name="elapsedTime">Elapsed time of the update.</param>
        public override void Update(float elapsedTime)
        {
            PlayerShip player         = ScrollingShooterGame.Game.Player;
            Vector2    playerPosition = new Vector2(player.Bounds.Center.X, player.Bounds.Center.Y);

            Vector2 toPlayer = playerPosition - this.position;

            turretGunTimer += elapsedTime;

            if (toPlayer.LengthSquared() < 95000)
            {
                toPlayer.Normalize();

                // Unit vector numbers. Should turn evenly in 8 directions.
                if (toPlayer.X > 0.92f)
                {
                    steeringState = TurretSteeringState.Right;
                }
                else if (toPlayer.X < -0.92f)
                {
                    steeringState = TurretSteeringState.Left;
                }
                else if (-toPlayer.Y > 0.92f)
                {
                    steeringState = TurretSteeringState.Top;
                }
                else if (-toPlayer.Y < -0.92f)
                {
                    steeringState = TurretSteeringState.Bottom;
                }
                else if (toPlayer.X > 0.38f && -toPlayer.Y > 0.38f)
                {
                    steeringState = TurretSteeringState.TopRight;
                }
                else if (toPlayer.X > 0.38f && -toPlayer.Y < -0.38f)
                {
                    steeringState = TurretSteeringState.BottomRight;
                }
                else if (toPlayer.X < -0.38f && -toPlayer.Y > 0.38f)
                {
                    steeringState = TurretSteeringState.TopLeft;
                }
                else
                {
                    steeringState = TurretSteeringState.BottomLeft;
                }

                // Turret firing speed can be adjusted here.
                if (turretGunTimer > 1.75f)
                {
                    ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.TurretFireball, position);
                    turretGunTimer = 0f;
                }
            }
        }
示例#4
0
        /// <summary>
        /// Creates new blade projectiles
        /// </summary>
        /// <param name="content">A ContentManager to load content from</param>
        /// <param name="rotation">The rotation that it's at around the player (0-2*PI)</param>
        /// <param name="player">Reference back to the player</param>
        public Blades(uint id, ContentManager content)
            : base(id)
        {
            this.spriteSheet = content.Load<Texture2D>("Spritesheets/newsh#.shp.000000");

            this.spriteBounds = new Rectangle(148, 67, 43, 35);

            this.player = ScrollingShooterGame.Game.player;

            this.BladeTimer = 0;
        }
示例#5
0
        /// <summary>
        /// Updates the Turret
        /// </summary>
        /// <param name="elapsedTime">The in-game time between the previous and current frame</param>
        public override void Update(float elapsedTime)
        {
            // Update the shot timer
            shotDelay += elapsedTime;

            // Sense the Player's position
            PlayerShip Player         = ScrollingShooterGame.Game.Player;
            Vector2    PlayerPosition = new Vector2(Player.Bounds.Center.X, Player.Bounds.Center.Y);

            // Get a vector from our position to the Player's position
            Vector2 toPlayer = PlayerPosition - this.position;

            if (toPlayer.LengthSquared() < 150000)
            {
                // TODO: Figure out why the bullet spawn doesn't always match up perfectly with the cannon barrel

                // We sense the Player's ship!
                // Get a normalized turning vector
                toPlayer.Normalize();

                // Rotate towards them!
                this.alpha = (float)Math.Atan2(toPlayer.Y, toPlayer.X) - MathHelper.PiOver2;

                // If it is time to shoot, fire a bullet towards the Player
                if (shotDelay > 1f)
                {
                    // Rotation Matrix to get the rotated offset vectors
                    Matrix rotMatrix = Matrix.CreateRotationZ(alpha);

                    // Offset vector that adjusts according to which barrel we are using
                    Vector2 offset;

                    // Figure out which barrel we are using and offset it with the toPlayer direction vector
                    if (barrel == 0)
                    {
                        offset = Vector2.Transform(offsetRight, rotMatrix);
                        barrel = 1;
                    }
                    else
                    {
                        offset = Vector2.Transform(offsetLeft, rotMatrix);
                        barrel = 0;
                    }

                    // Spawn the bullet
                    // TODO: Add this to the enemy projectiles list once it's created
                    ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.EnemyBullet, position + offset);

                    // Reset the shot delay
                    shotDelay = 0;
                }
            }
        }
示例#6
0
        /// <summary>
        /// Creates a tracking fireball.
        /// </summary>
        /// <param name="content">Content Manager</param>
        /// <param name="position">Our turrets position</param>
        public TurretFireball(uint id, ContentManager content, Vector2 position)
            : base(id)
        {
            this.spriteSheet = content.Load <Texture2D>("Spritesheets/newshp.shp.000000");

            this.spriteBounds = new Rectangle(193, 88, 21, 21);

            PlayerShip player         = ScrollingShooterGame.Game.Player;
            Vector2    playerPosition = new Vector2(player.Bounds.Center.X, player.Bounds.Center.Y);

            this.velocity = new Vector2(0, 0.5f);

            this.position = position;
        }
示例#7
0
        /// <summary>
        /// Draw the SuicideBomber ship on-screen
        /// </summary>
        /// <param name="elapsedTime">The in-game time between the previous and current frame</param>
        /// <param name="spriteBatch">An already initialized SpriteBatch, ready for Draw() commands</param>
        public override void Draw(float elapsedTime, SpriteBatch spriteBatch)
        {
            PlayerShip player         = ScrollingShooterGame.Game.Player;
            Vector2    playerPosition = new Vector2(player.Bounds.Center.X, player.Bounds.Center.Y);
            Vector2    toPlayer       = playerPosition - this.position;
            double     angle          = (2 * Math.PI) - Math.Atan2(toPlayer.X, toPlayer.Y);

            if (toPlayer.LengthSquared() < 90000)
            {
                spriteBatch.Draw(spritesheet, Bounds, spriteBounds[(int)steeringState], Color.White, (float)angle, new Vector2(Bounds.Width / 2, Bounds.Height / 2), SpriteEffects.None, 1f);
            }
            else
            {
                spriteBatch.Draw(spritesheet, Bounds, spriteBounds[(int)steeringState], Color.White);
            }
        }
示例#8
0
        /// <summary>
        /// Updates the Arrow ship
        /// </summary>
        /// <param name="elapsedTime">The in-game time between the previous and current frame</param>
        public override void Update(float elapsedTime)
        {
            gunTimer += elapsedTime;

            // Sense the Player's position
            PlayerShip Player         = ScrollingShooterGame.Game.Player;
            Vector2    PlayerPosition = new Vector2(Player.Bounds.Center.X, Player.Bounds.Center.Y);

            // Get a vector from our position to the Player's position
            Vector2 toPlayer = PlayerPosition - this.position;

            if (toPlayer.LengthSquared() < 20000)
            {
                // We sense the Player's ship!
                // Get a normalized steering vector
                toPlayer.Normalize();

                // Steer towards them!
                this.position += toPlayer * elapsedTime * 120;

                // Change the steering state to reflect our direction
                if (toPlayer.X < -0.5f)
                {
                    steeringState = ArrowSteeringState.Left;
                    //Fire!
                    if (gunTimer > .7f)
                    {
                        ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.ArrowProjectile, position);
                        gunTimer = 0f;
                    }
                }
                else if (toPlayer.X > 0.5f)
                {
                    steeringState = ArrowSteeringState.Right;
                    //Fire!
                    if (gunTimer > .7f)
                    {
                        ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.ArrowProjectile, position);
                        gunTimer = 0f;
                    }
                }
                else
                {
                    steeringState = ArrowSteeringState.Straight;
                }
            }
        }
示例#9
0
        /// <summary>
        /// Updates the LavaFighter ship
        /// </summary>
        /// <param name="elapsedTime">The in-game time between the previous and current frame</param>
        public override void Update(float elapsedTime)
        {
            gunTimer += elapsedTime;

            // Sense the player's position
            PlayerShip player         = ScrollingShooterGame.Game.Player;
            Vector2    playerPosition = new Vector2(player.Bounds.Center.X, player.Bounds.Center.Y);


            // Get a vector from our position to the player's position
            Vector2 toPlayer = playerPosition - this.position;

            this.position.Y += elapsedTime * 100;

            if (toPlayer.LengthSquared() < 60000)
            {
                // We sense the player's ship!
                // Get a normalized steering vector
                toPlayer.Normalize();

                // Change the steering state to reflect our direction
                if (toPlayer.X < -0.5f)
                {
                    steeringState = LavaFighterSteeringState.Left;
                    //Fire!
                    if (gunTimer > .7f)
                    {
                        ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.ToPlayerBullet, position);
                        gunTimer = 0f;
                    }
                }
                else if (toPlayer.X > 0.5f)
                {
                    steeringState = LavaFighterSteeringState.Right;
                    //Fire!
                    if (gunTimer > .7f)
                    {
                        ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.ToPlayerBullet, position);
                        gunTimer = 0f;
                    }
                }
                else
                {
                    steeringState = LavaFighterSteeringState.Straight;
                }
            }
        }
示例#10
0
        /// <summary>
        /// Creates a Eight Ball Shield instance
        /// </summary>
        /// <param name="contentManager">A ContentManager to load content from</param>
        /// <param name="PlayerPosition">A position on the screen</param>
        /// <param name="PlayerShip">A pointer to the current Player ship</param>
        public EightBallShield(uint id, ContentManager contentManager, Vector2 PlayerPosition,
                               PlayerShip PlayerShip) : base(id)
        {
            this.spriteSheet    = contentManager.Load <Texture2D>("Spritesheets/eightballshield");
            this.PlayerPosition = PlayerPosition;
            this.PlayerShip     = PlayerShip;
            this.spriteBounds   = new Rectangle(24, 23, 53, 58);

            //set to 0 for x & y to test
            //don't actually want the shield to deviate from
            // the Player ship's position
            this.velocity = new Vector2(0, 0);

            //test an offset position (ghetto)
            this.position.X = PlayerPosition.X - 25;
            this.position.Y = PlayerPosition.Y - 26;
        }
示例#11
0
        /// <summary>
        /// Updates the Blimp
        /// </summary>
        /// <param name="elapsedTime">The in-game time between the previous and current frame</param>
        public override void Update(float elapsedTime)
        {
            position.Y = ScrollingSpeed * elapsedTime;

            // If the blimp is below 25% health switch the sprite
            if (this.Health / maxHealth < 0.25f)
            {
                state = BlimpState.Below25;
            }

            // If the blimp is at 0 health delete it
            else if (Health == 0)
            {
                ScrollingShooterGame.GameObjectManager.DestroyObject(this.ID);
                return;
            }

            // Move the blimp
            if (position.X - 11 <= 5 || position.X + 69 >= this.screenWidth - 30)
            {
                velocity.X *= -1;
            }
            position.X -= elapsedTime * velocity.X;

            this.gunTimer += elapsedTime;

            if (gunTimer >= 1f)
            {
                // Sense the player's position
                PlayerShip player         = ScrollingShooterGame.Game.Player;
                Vector2    playerPosition = new Vector2(player.Bounds.Center.X, player.Bounds.Center.Y);

                // Get a vector from our position to the player's position
                Vector2 toPlayer = playerPosition - this.position;

                // Shoot the shotgun if the player is within 200 units of the blimp
                if (toPlayer.LengthSquared() < 25000)
                {
                    Vector2 travel = position;
                    travel.X += Bounds.Width / 2;
                    travel.Y += Bounds.Height / 2;
                    ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.BlimpShotgun, travel);
                    gunTimer = 0;
                }
            }
        }
示例#12
0
        /// <summary>
        /// Creates a new bullet that will travel towards the Player's current position.
        /// </summary>
        /// <param name="id">Id for the bullet.</param>
        /// <param name="content">ContentManager to load content with.</param>
        /// <param name="position">Starting position for the bullet.</param>
        public ToPlayerBullet(uint id, ContentManager content, Vector2 position)
            : base(id)
        {
            this.spriteSheet = content.Load <Texture2D>(SPRITESHEET);

            this.spriteBounds = SPRITEBOUNDS;

            this.position = position;

            //Fire at the Player.
            PlayerShip Player         = ScrollingShooterGame.Game.Player;
            Vector2    positionVector = Player.GetPosition() - position;

            positionVector.Normalize();

            this.velocity = positionVector * VELOCITY;
        }
示例#13
0
        /// <summary>
        /// Creates a new blimp bullet
        /// </summary>
        /// <param name="content">A ContentManager to load content from</param>
        /// <param name="position">A position on the screen</param>
        public BlimpBullet(uint id, ContentManager content, Vector2 position)
            : base(id)
        {
            this.spriteSheet = content.Load <Texture2D>("Spritesheets/tyrian.shp.000000");

            this.spriteBounds = new Rectangle(203, 56, 13, 14);

            this.position = position;

            // Sense the player's position
            PlayerShip player         = ScrollingShooterGame.Game.Player;
            Vector2    playerPosition = new Vector2(player.Bounds.Center.X, player.Bounds.Center.Y);

            // Get a vector from our position to the player's position
            Vector2 toPlayer = playerPosition - this.position;

            velocity = toPlayer;
        }
        /// <summary>
        /// Creates a Eight Ball Shield instance
        /// </summary>
        /// <param name="contentManager">A ContentManager to load content from</param>
        /// <param name="PlayerPosition">A position on the screen</param>
        /// <param name="PlayerShip">A pointer to the current Player ship</param>
        public EightBallShield(uint id, ContentManager contentManager, Vector2 PlayerPosition,
            PlayerShip PlayerShip)
            : base(id)
        {
            this.spriteSheet = contentManager.Load<Texture2D>("Spritesheets/eightballshield");
            this.PlayerPosition = PlayerPosition;
            this.PlayerShip = PlayerShip;
            this.spriteBounds = new Rectangle(24, 23, 53, 58);

            //set to 0 for x & y to test
            //don't actually want the shield to deviate from
            // the Player ship's position
            this.velocity = new Vector2(0, 0);

            //test an offset position (ghetto)
            this.position.X = PlayerPosition.X - 25;
            this.position.Y = PlayerPosition.Y - 26;
        }
示例#15
0
        /// <summary>
        /// Updates the Standard Baddy.
        /// </summary>
        /// <param name="elapsedTime">Time elapsed</param>
        public override void Update(float elapsedTime)
        {
            dgt += elapsedTime;
            PlayerShip ps = ScrollingShooterGame.Game.Player;
            Vector2    pp = new Vector2(ps.Bounds.Center.X, ps.Bounds.Center.Y);
            Vector2    dp = pp - this.position;

            if (dp.LengthSquared() > 30000)
            {
                dp.Normalize();
                this.position += dp * elapsedTime * 100;
            }
            if (dgt > .75f)
            {
                ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.EBullet, position);
                dgt = 0;
            }
        }
示例#16
0
        /// <summary>
        /// Creates a new instance of the Pincher
        /// </summary>
        /// <param name="content">A ContentManager to load resources with</param>
        /// <param name="position">The position of the Pincher in the game world</param>
        public Pincher(uint id, ContentManager content, Vector2 position)
            : base(id)
        {
            this.position = position;

            spritesheet = content.Load <Texture2D>("Spritesheets/newshg.shp.000000");

            spriteBounds[(int)PincherAnimationFrame.Open].X      = 73;
            spriteBounds[(int)PincherAnimationFrame.Open].Y      = 84;
            spriteBounds[(int)PincherAnimationFrame.Open].Width  = 23;
            spriteBounds[(int)PincherAnimationFrame.Open].Height = 27;

            spriteBounds[(int)PincherAnimationFrame.Mid].X      = 98;
            spriteBounds[(int)PincherAnimationFrame.Mid].Y      = 84;
            spriteBounds[(int)PincherAnimationFrame.Mid].Width  = 21;
            spriteBounds[(int)PincherAnimationFrame.Mid].Height = 27;

            spriteBounds[(int)PincherAnimationFrame.Closed].X      = 124;
            spriteBounds[(int)PincherAnimationFrame.Closed].Y      = 84;
            spriteBounds[(int)PincherAnimationFrame.Closed].Width  = 17;
            spriteBounds[(int)PincherAnimationFrame.Closed].Height = 27;

            frame             = 0;
            animationSequence = new List <PincherAnimationFrame>();
            animationSequence.Add(PincherAnimationFrame.Open);
            animationSequence.Add(PincherAnimationFrame.Mid);
            animationSequence.Add(PincherAnimationFrame.Closed);
            animationSequence.Add(PincherAnimationFrame.Mid);

            //determine the angle

            // Sense the player's position
            PlayerShip player         = ScrollingShooterGame.Game.Player;
            Vector2    playerPosition = new Vector2(player.Bounds.Center.X, player.Bounds.Center.Y);

            // Get a vector from our position to the player's position and normalize it
            angleVector = playerPosition - this.position;

            //normalize the angleVector
            angleVector.Normalize();
            playerPosition.Normalize();

            angle = (float)Math.Acos(Vector2.Dot(playerPosition, angleVector)) - .75f;
        }
        /// <summary>
        /// Factory method for spawning a shield
        /// </summary>
        /// <param name="shieldType">The type of shield to create</param>
        /// <param name="position">Position of the shield in the game world</param>
        /// <param name="PlayerShip">The Player</param>
        /// <returns>The game object id of the projectile</returns>
        public Shield CreateShield(ShieldType shieldType, Vector2 position,
                                   PlayerShip PlayerShip)
        {
            Shield shield;
            uint   id = NextID();

            switch (shieldType)
            {
            case ShieldType.EightBallShield:
                shield = new EightBallShield(id, content, position, PlayerShip);
                break;

            default:
                throw new NotImplementedException("EightBallShield failed.");
            }

            QueueGameObjectForCreation(shield);
            return(shield);
        }
示例#18
0
        /// <summary>
        /// The update method that tracks the players ship to hunt it
        /// down. Parts taken from the PlayerShip class.
        /// </summary>
        /// <param name="elapsedTime"></param>
        public override void Update(float elapsedTime)
        {
            // Sense the player's position
            PlayerShip player         = ScrollingShooterGame.Game.Player;
            Vector2    playerPosition = new Vector2(player.Bounds.Center.X, player.Bounds.Center.Y);

            // Get a vector from our position to the player's position
            Vector2 toPlayer = playerPosition - this.position;

            if (toPlayer.LengthSquared() < 95000)
            {
                toPlayer.Normalize();

                // Seems like 60 is the slowest I can go
                // without jitters. Would like a slower projectile, but I
                // think I will make it just update less.
                this.position += toPlayer * elapsedTime * 60;
            }
        }
示例#19
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create our viewports
            gameViewport  = GraphicsDevice.Viewport;
            worldViewport = new Viewport(0, 0, 768, 720);   // Twice as wide as 16 tiles
            guiViewport   = new Viewport(768, 0, 512, 720); // Remaining space

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            GameObjectManager = new GameObjectManager(Content);

            // TODO: use this.Content to load your game content here
            Player = GameObjectManager.CreatePlayerShip(PlayerShipType.Shrike, new Vector2(300, 300));
            GameObjectManager.CreatePowerup(PowerupType.Fireball, new Vector2(100, 200));

            LevelManager.LoadContent();
            LevelManager.LoadLevel("LavaLevel2");
            GuiManager.LoadContent();
            GameState = GameState.Initializing;
        }
示例#20
0
        /// <summary>
        /// Updates the Panzer2 tank
        /// </summary>
        /// <param name="elapsedTime">In-game time between previous and current frame</param>
        public override void Update(float elapsedTime)
        {
            //Sense the player's position
            PlayerShip player         = ScrollingShooterGame.Game.Player;
            Vector2    playerPosition = new Vector2(player.Bounds.Center.X,
                                                    player.Bounds.Center.Y);

            //Get the vector from Panzer's position to the player's position
            Vector2 toPlayer = playerPosition - this.position;

            if (toPlayer.LengthSquared() < 200000)
            {
                //normalize the vector
                toPlayer.Normalize();
                //update the steering vector pointing to the player
                SteeringState(toPlayer);

                //fire cannon
                FireCannon(elapsedTime);
            }
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create our viewports
            gameViewport  = GraphicsDevice.Viewport;
            worldViewport = new Viewport(0, 0, 768, 720);   // Twice as wide as 16 tiles
            guiViewport   = new Viewport(768, 0, 512, 720); // Remaining space

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Create a basic effect, used with the spritebatch
            basicEffect = new BasicEffect(GraphicsDevice)
            {
                TextureEnabled     = true,
                VertexColorEnabled = true,
            };

            GameObjectManager = new GameObjectManager(Content);

            // TODO: use this.Content to load your game content here
            Player = GameObjectManager.CreatePlayerShip(PlayerShipType.Shrike, new Vector2(300, 300));
            //Player.ApplyPowerup(PowerupType.Fireball);

            LevelManager.LoadContent();
            LevelManager.LoadLevel("lavaLevel2");
            //test out new panzer personality
            int p1 = 100;
            int p2 = 200;

            for (int i = 0; i < 6; i++)
            {
                GameObjectManager.CreateEnemy(EnemyType.Panzer, new Vector2(p1, 100));
                GameObjectManager.CreateEnemy(EnemyType.Panzer2, new Vector2(p2, 100));
                p1 += 100;
                p2 += 100;
            }
            //test out lavabug
            GameObjectManager.CreateEnemy(EnemyType.Lavabug, new Vector2(100, 75));
        }
示例#22
0
        /// <summary>
        /// Updates the Turret
        /// </summary>
        /// <param name="elapsedTime">The in-game time between the previous and current frame</param>
        public override void  Update(float elapsedTime)
        {
            // Update the shot timer
            shotDelay += elapsedTime;

            // Sense the player's position
            PlayerShip player         = ScrollingShooterGame.Game.Player;
            Vector2    playerPosition = new Vector2(player.Bounds.X, player.Bounds.Y);

            // Get a vector from our position to the player's position
            Vector2 toPlayer = playerPosition - this.position;

            if (toPlayer.LengthSquared() < 150000)
            {
                // We sense the player's ship!
                // Get a normalized turning vector
                toPlayer.Normalize();

                // Rotate towards them!
                this.alpha = (float)Math.Atan2(toPlayer.Y, toPlayer.X) - MathHelper.PiOver2;

                // If it is time to shoot, fire a bullet towards the player
                if (shotDelay > 1.5f)
                {
                    // Rotation Matrix to get the rotated offset vectors
                    Matrix rotMatrix = Matrix.CreateRotationZ(alpha);

                    // Offset vector that adjusts according to rotation we are using
                    Vector2 offsetTemp = Vector2.Transform(offset, rotMatrix);

                    // Spawn the bullet
                    ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.EnemyBullet, this.position + offsetTemp, bulletVel * toPlayer);

                    // Reset the shot delay
                    shotDelay = 0;
                }
            }
        }
示例#23
0
        /// <summary>
        /// Updates the Kamakaze ship
        /// </summary>
        /// <param name="elapsedTime">The in-game time between the previous and current frame</param>
        public override void  Update(float elapsedTime)
        {
            // Sense the Player's position
            PlayerShip Player         = ScrollingShooterGame.Game.Player;
            Vector2    PlayerPosition = new Vector2(Player.Bounds.Center.X, Player.Bounds.Center.Y);

            // Get a vector from our position to the Player's position
            Vector2 toPlayer = PlayerPosition - this.position;

            if (toPlayer.LengthSquared() < 90000 && (this.Bounds.Y < Player.Bounds.Y))
            {
                // We sense the Player's ship!
                // Get a normalized steering vector
                toPlayer.Normalize();

                // Steer towards them
                this.position += toPlayer * elapsedTime * 150;

                // Change the steering state to reflect our direction
                if (toPlayer.X < -0.5f)
                {
                    steeringState = DartSteeringState.Left;
                }
                else if (toPlayer.X > 0.5f)
                {
                    steeringState = DartSteeringState.Right;
                }
                else
                {
                    steeringState = DartSteeringState.Straight;
                }
            }
            else
            {
                this.position.Y += elapsedTime * 150;
                steeringState    = DartSteeringState.Straight;
            }
        }
示例#24
0
        /// <summary>
        /// Updates the Lavabug
        /// </summary>
        /// <param name="elapsedTime">The in-game time between the previous and current frame</param>
        public override void Update(float elapsedTime)
        {
            // Sense the player's position
            PlayerShip player         = ScrollingShooterGame.Game.Player;
            Vector2    playerPosition = new Vector2(player.Bounds.Center.X, player.Bounds.Center.Y);

            this.Health -= elapsedTime;//TO DO: this a damage test. REMOVE


            if (this.Health <= 0)
            {
                ScrollingShooterGame.GameObjectManager.CreateEnemy(EnemyType.Lavabug2, new Vector2(800, this.position.Y));
                ScrollingShooterGame.GameObjectManager.CreateEnemy(EnemyType.Lavabug2, new Vector2(0, this.position.Y + 60));
                ScrollingShooterGame.GameObjectManager.DestroyObject(this.ID);
            }

            // Move in front of player
            this.position.Y = 75;
            this.position.X = playerPosition.X;

            //fire at player
            Fire(elapsedTime);
        }
示例#25
0
        /// <summary>
        /// Updates the Mandible
        /// </summary>
        /// <param name="elapsedTime">The in-game time between the previous and current frame</param>
        public override void Update(float elapsedTime)
        {
            // Sense the player's position
            PlayerShip player = ScrollingShooterGame.Game.Player;

            Vector2 playerPosition = new Vector2(player.Bounds.Center.X, player.Bounds.Center.Y);
            Vector2 toPlayer       = playerPosition - this.position;

            Health -= elapsedTime; //TODO: remove this from testing

            // Move in front of player
            if (Health <= 0)
            {
                if (!this.isFired)
                {
                    isFired = true;
                    toPlayer.Normalize();
                    this.position += toPlayer * elapsedTime * 500;
                }
                else
                {
                    this.position.Y += elapsedTime * 500;
                }
            }
            if (!isFired)
            {
                if (isLeft)
                {
                    this.position.X = playerPosition.X - 30;         //change?
                }
                else
                {
                    this.position.X = playerPosition.X + 30;
                }
            }
        }
示例#26
0
        /// <summary>
        /// Creates a new instance of the Orb
        /// </summary>
        /// <param name="content">A ContentManager to load resources with</param>
        /// <param name="position">The position of the Orb in the game world</param>
        public AlienTurretOrb(uint id, ContentManager content, Vector2 position)
            : base(id)
        {
            this.position = position;

            spritesheet = content.Load <Texture2D>("Spritesheets/newshg.shp.000000");

            spriteBounds = new Rectangle(194, 88, 20, 20);

            //determine the angle

            // Sense the player's position
            PlayerShip player         = ScrollingShooterGame.Game.Player;
            Vector2    playerPosition = new Vector2(player.Bounds.Center.X, player.Bounds.Center.Y);

            // Get a vector from our position to the player's position and normalize it
            angleVector = playerPosition - this.position;

            //normalize the angleVector
            angleVector.Normalize();
            playerPosition.Normalize();

            angle = (float)Math.Acos(Vector2.Dot(playerPosition, angleVector)) - .75f;
        }
示例#27
0
        /// <summary>
        /// Helper method for processing gameobject collisions
        /// </summary>
        void ProcessCollisions()
        {
            // Process collisions
            foreach (CollisionPair pair in GameObjectManager.Collisions)
            {
                GameObject objectA = GameObjectManager.GetObject(pair.A);
                GameObject objectB = GameObjectManager.GetObject(pair.B);

                // Player collisions
                if (objectA.ObjectType == ObjectType.Player || objectB.ObjectType == ObjectType.Player)
                {
                    PlayerShip player   = ((objectA.ObjectType == ObjectType.Player) ? objectA : objectB) as PlayerShip;
                    GameObject collider = (objectA.ObjectType == ObjectType.Player) ? objectB : objectA;

                    // Process powerup collisions
                    switch (collider.ObjectType)
                    {
                    case ObjectType.Powerup:
                        Powerup powerup = collider as Powerup;
                        player.ApplyPowerup(powerup.Type);
                        GameObjectManager.DestroyObject(collider.ID);
                        break;

                    case ObjectType.Enemy:
                        Enemy enemy = collider as Enemy;
                        if (enemy.GetType() == typeof(Kamikaze) || enemy.GetType() == typeof(Mandible) ||
                            enemy.GetType() == typeof(SuicideBomber) || enemy.GetType() == typeof(Mine))
                        {
                            //Player take damage
                            GameObjectManager.DestroyObject(collider.ID);
                            GameObjectManager.CreateExplosion(collider.ID);
                        }
                        break;

                    case ObjectType.EnemyProjectile:
                        Projectile projectile = collider as Projectile;

                        // Damage player
                        player.Health -= projectile.Damage;
                        if (player.Health <= 0)
                        {
                            GameObjectManager.DestroyObject(player.ID);
                            GameObjectManager.CreateExplosion(player.ID);
                        }

                        GameObjectManager.DestroyObject(collider.ID);
                        break;
                    }
                }

                // Player Projectile collisions
                else if (objectA.ObjectType == ObjectType.PlayerProjectile || objectB.ObjectType == ObjectType.PlayerProjectile)
                {
                    Projectile playerProjectile = ((objectA.ObjectType == ObjectType.PlayerProjectile) ? objectA : objectB) as Projectile;
                    GameObject collider         = (objectA.ObjectType == ObjectType.Player) ? objectB : objectA;

                    // Process collisions
                    switch (collider.ObjectType)
                    {
                    case ObjectType.Enemy:
                        Enemy enemy = collider as Enemy;
                        //Enemy take damage
                        enemy.Health -= playerProjectile.Damage;

                        // If health <= 0, kill enemy
                        if (enemy.Health <= 0)
                        {
                            GameObjectManager.DestroyObject(collider.ID);
                            GameObjectManager.CreateExplosion(collider.ID);
                        }
                        // Destroy projectile
                        // Note, if there are special things for the bullet, add them here
                        GameObjectManager.DestroyObject(playerProjectile.ID);
                        break;

                    case ObjectType.Boss:
                        Boss boss = collider as Boss;
                        // Boss take damage
                        boss.Health -= playerProjectile.Damage;

                        // If health <= 0, kill boss
                        if (boss.Health <= 0)
                        {
                            GameObjectManager.DestroyObject(collider.ID);
                            GameObjectManager.CreateExplosion(collider.ID);
                        }
                        // Destroy projectile
                        // Note, if there are special things for the bullet, add them here
                        GameObjectManager.DestroyObject(playerProjectile.ID);
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Constructs a brand new, fully feuled missile ready
        /// to blow some smug pilot to pieces
        /// </summary>
        /// <param name="id">The factory id of this missile</param>
        /// <param name="content">The Content Manager used to get Textures</param>
        /// <param name="position">The position to spawn this missile at</param>
        public Boss_TwinJetMissile(uint id, ContentManager content, Vector2 position)
            : base(id)
        {
            //Set a slight time modifier so that the missiles don't explode all in groups
            //makes it a bit more realistic
            Random timeModifier = new Random((int)(DateTime.Now.Millisecond * id));

            //The sprite sheet containing our missile texture
            this.spriteSheet = content.Load<Texture2D>("Spritesheets/tyrian.shp.000000");

            //The box denoting the sprite texture on the sprite sheet
            this.spriteBounds = new Rectangle(156, 42, 12, 14);

            //Setting the initial velocity of our missile
            this.velocity = new Vector2(0, 1 * MaxSpeed);

            //Setting the initial position of our missile
            this.position = position;

            //Setting the reference to our brave, hopeless hero
            this.player = ScrollingShooterGame.Game.Player;

            //Makes sure that, upon creation, this missile is 'Still Alive'
            this.isAlive = true;

            //Sets the initial rotation to 0
            rotation = 0;

            //Sets the Life timer to the max and applies the modifier
            timerMissileLife = MissileLife + (float)(timeModifier.NextDouble() + timeModifier.Next(-1,1));
        }
示例#29
0
        /// <summary>
        /// Updates the Dart ship
        /// </summary>
        /// <param name="elapsedTime">The in-game time between the previous and current frame</param>
        public override void Update(float elapsedTime)
        {
            if (isAlive == false)
            {
                explosionTimer += elapsedTime;
                if (explosionTimer > 0.05)
                {
                    explosionState = ++explosionState % 12;
                    //if(explosionState>11){ delete object
                    explosionTimer = 0;
                }

                return;
            }

            float velocity = 1;

            // Sense the player's position
            PlayerShip player         = ScrollingShooterGame.Game.Player;
            Vector2    playerPosition = new Vector2(player.Bounds.Center.X, player.Bounds.Center.Y);

            //groupFireTimer += elapsedTime;
            bombTimer  += elapsedTime;
            turboTimer += elapsedTime;
            //once in a while Bomber can turn on extra engine
            if (turboTimer > 7.5f)
            {
                velocity = 2f;
                if (turboTimer > 12f)
                {
                    turboTimer = 0;
                }
            }


            if (playerPosition.X - Bounds.Center.X < -20)
            {
                steeringState    = BomberSteeringState.Left;
                this.position.X -= elapsedTime * 40 * velocity;
            }
            else
            {
                if (playerPosition.X - Bounds.Center.X > 20)
                {
                    steeringState    = BomberSteeringState.Right;
                    this.position.X += elapsedTime * 40 * velocity;
                }
                else
                {
                    steeringState = BomberSteeringState.Straight;
                    if (playerPosition.Y > this.Bounds.Center.Y)
                    {
                        if (bombTimer > 1.5f)
                        {
                            ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.EnemyBomb, position);
                            bombTimer = 0f;
                        }
                    }
                }
            }

            //if (groupFireTimer > (10f * bomberCount) && bombTimer > 1.5f)
            //{
            //    ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.Bomb, position, false);
            //    bombTimer = 0f;
            //    if (groupFireTimer > (13f * bomberCount))
            //    {
            //        groupFireTimer = 0;
            //    }
            //}
            position.Y += elapsedTime * 30 * velocity;
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            player = new ShrikeShip(Content);
        }
示例#31
0
        /// <summary>
        /// Updates the LaserDrone
        /// </summary>
        /// <param name="elapsedTime">The in-game time between the previous and current frame</param>
        public override void Update(float elapsedTime)
        {
            // Sense the Player's position
            PlayerShip Player         = ScrollingShooterGame.Game.Player;
            Vector2    PlayerPosition = new Vector2(Player.Bounds.Center.X, Player.Bounds.Center.Y);

            switch (aiState)
            {
            case AIState.Chasing:
                getInPosition(PlayerPosition, elapsedTime);
                if (Math.Abs(PlayerPosition.X - Bounds.Center.X) < 40 && Bounds.Center.Y < PlayerPosition.Y)
                {
                    //transition to firing state
                    fireTimeRemaining = FIRE_TIME;
                    aiState           = AIState.Firing;
                    currentSpeed      = MAX_MOVE_SPEED * 0.66f;
                    if (droneLaser == null)
                    {
                        droneLaser = (DroneLaser)ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.DroneLaser, Vector2.Zero);
                    }
                    droneLaser.isOn       = true;
                    droneLaser.laserPower = WeaponChargeLevel.Full;
                    droneLaser.updatePosition(position.X + 23, position.Y + 30);
                }
                break;

            case AIState.Firing:
                fireTimeRemaining -= elapsedTime;

                //change to medium charge sprite when halfway depleted
                if (weaponChargeLevel == WeaponChargeLevel.Full && fireTimeRemaining / FIRE_TIME < 0.66)
                {
                    weaponChargeLevel = droneLaser.laserPower = WeaponChargeLevel.Medium;
                }
                else if (weaponChargeLevel == WeaponChargeLevel.Medium && fireTimeRemaining / FIRE_TIME < 0.33)
                {
                    weaponChargeLevel = droneLaser.laserPower = WeaponChargeLevel.Low;
                }

                if (fireTimeRemaining <= 0)
                {
                    //transition to recharging state
                    aiState               = AIState.Recharging;
                    currentSpeed          = MAX_MOVE_SPEED * 0.33f;
                    rechargeTimeRemaining = RECHARGE_TIME;
                    weaponChargeLevel     = WeaponChargeLevel.Low;
                    droneLaser.isOn       = false;
                }

                getInPosition(PlayerPosition, elapsedTime);
                droneLaser.updatePosition(position.X + 23, position.Y + 30);

                break;

            case AIState.Recharging:
                rechargeTimeRemaining -= elapsedTime;

                if (weaponChargeLevel == WeaponChargeLevel.Low && rechargeTimeRemaining / RECHARGE_TIME < 0.66)
                {
                    weaponChargeLevel = WeaponChargeLevel.Medium;
                }
                if (weaponChargeLevel == WeaponChargeLevel.Medium && rechargeTimeRemaining / RECHARGE_TIME < 0.33)
                {
                    weaponChargeLevel = WeaponChargeLevel.Full;
                }

                if (rechargeTimeRemaining <= 0)
                {
                    aiState           = AIState.Chasing;
                    currentSpeed      = MAX_MOVE_SPEED;
                    weaponChargeLevel = WeaponChargeLevel.Full;
                }

                moveAwayFrom(PlayerPosition, elapsedTime);

                break;
            }
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            player = new ShrikeShip(Content);
            //player.ApplyPowerup(Powerups.Fireball);
            //player.ApplyPowerup(Powerups.DroneWave);
            //enemies.Add(new Dart(Content, new Vector2(100, 100)));
            //powerups.Add(new DroneWavePowerup(Content, new Vector2(250, 250)));
            enemies.Add(new Turret(Content, new Vector2(300, 300)));
        }
 private void killPlayer(PlayerShip player)
 {
     //GameObjectManager.DestroyObject(player.ID);
     player.Dead = true;
     player.DeathTimer = 2;
     GameObjectManager.CreateExplosion2(player.ID, 1);
     player.Score -= 100;
 }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create our viewports
            gameViewport = GraphicsDevice.Viewport;
            worldViewport = new Viewport(0, 0, 768, 720); // Twice as wide as 16 tiles
            guiViewport = new Viewport(768, 0, 512, 720); // Remaining space

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            GameObjectManager = new GameObjectManager(Content);

            // TODO: use this.Content to load your game content here
            MediaPlayer.IsRepeating = true;
            Player = GameObjectManager.CreatePlayerShip(PlayerShipType.Shrike, new Vector2(300, 300));
            Player.ApplyPowerup(PowerupType.Default);
            LevelManager.LoadContent();
            GuiManager.LoadContent();
            SplashType = SplashScreenType.GameStart;
            GameState = GameState.Splash;
            loadSplashScreen(new GameStart());
        }
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            // Update according to current game state
            switch (GameState)
            {
                case GameState.Initializing:

                    if (Player == null)
                    {
                        StartGame();
                    }

                    if (!LevelManager.Loading)
                    {
                        GameState = GameState.Gameplay;
                    }
                    break;

                case GameState.Splash:

                    if (!LevelManager.Loading && Keyboard.GetState().IsKeyDown(Keys.Space))
                    {
                        GameState = GameState.Gameplay;
                        //StartGame();
                        Music = LevelManager.CurrentSong;
                        if (Music != null) MediaPlayer.Play(Music);
                    }

                    break;

                case GameState.Gameplay:
                    LevelManager.Update(elapsedTime);
                    GameObjectManager.Update(elapsedTime);
                    ProcessCollisions();

                    if (Player.GetState == PlayerState.Dead)
                    {
                        GameState = ScrollingShooter.GameState.Initializing;
                        GameObjectManager.DestroyObject(Player.ID);
                       Player = null;
                    }

                    break;

                case GameState.Scoring:
                    GuiManager.Update(elapsedTime);
                    if (GuiManager.tallyState == GuiManager.TallyingState.PressSpaceToContinue
                        && Keyboard.GetState().IsKeyDown(Keys.Space))
                    {
                        GameState = GameState.Splash;
                        Music = Splash.Music;
                        if (Music != null) MediaPlayer.Play(Music);
                    }
                    break;

                case GameState.Credits:
                    // TODO: Launch new game when player hits space
                    break;
            }

            base.Update(gameTime);
        }
示例#36
0
        /// <summary>
        /// Updates the Green Goblin ship
        /// </summary>
        /// <param name="elapsedTime">The in-game time between the previous and current frame</param>
        public override void Update(float elapsedTime)
        {
            // Sense the Player's position
            PlayerShip Player         = ScrollingShooterGame.Game.Player;
            Vector2    PlayerPosition = new Vector2(Player.Bounds.Center.X, Player.Bounds.Center.Y);

            gunTimer += elapsedTime;

            // Get the distance between the Player and this along the X axis
            float PlayerDistance = Math.Abs(PlayerPosition.X - this.position.X);

            // Make sure the Player is within range
            if (PlayerDistance < 60 && gunTimer > 0.20 && PlayerPosition.Y > (this.position.Y + 30))
            {
                ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.EnemyFlameball, position);
                gunTimer = 0;
            }

            //Ship flies from top to bottom
            this.position.Y += 1;

            // If the ship hasn't reached the turning point
            if (diagCount < diagFlightLength)
            {
                //If the ship has just been created
                if (0 == steeringState.CompareTo(GreenGoblinSteeringState.Straight))
                {
                    this.position.X += 2;
                    steeringState    = GreenGoblinSteeringState.Right;
                    diagCount++;
                }

                // If the ship is going right
                else if (0 == steeringState.CompareTo(GreenGoblinSteeringState.Right))
                {
                    this.position.X += 2;
                    diagCount++;
                }

                // If the ship is going left
                else if (0 == steeringState.CompareTo(GreenGoblinSteeringState.Left))
                {
                    this.position.X -= 2;
                    diagCount++;
                }
            }

            // Once diagonal motion has reach its length, switch directions
            else if (diagCount == diagFlightLength)
            {
                // If going right, switch to left
                if (0 == steeringState.CompareTo(GreenGoblinSteeringState.Right))
                {
                    this.position.X -= 1;
                    steeringState    = GreenGoblinSteeringState.Left;
                    diagCount        = 0;
                    diagFlightLength = rand.Next(20, 150);
                }

                // If going left, switch to right
                else if (0 == steeringState.CompareTo(GreenGoblinSteeringState.Left))
                {
                    this.position.X += 1;
                    steeringState    = GreenGoblinSteeringState.Right;
                    diagCount        = 0;
                    diagFlightLength = rand.Next(20, 150);
                }
            }

            else
            {
                steeringState = GreenGoblinSteeringState.Straight;
            }
        }
示例#37
0
        /// <summary>
        /// Create a new instance of a Photon projectile
        /// </summary>
        /// <param name="id">Obj id</param>
        /// <param name="content">A ContentManager to load resources with</param>
        /// <param name="position">The position of the Photon projectile in the game world</param>
        public Photon(uint id, ContentManager content, Vector2 position)
            : base(id)
        {
            this.position    = position;
            this.velocity    = new Vector2(150);
            this.spriteSheet = content.Load <Texture2D>("Spritesheets/accessories");
            spriteBounds     = new Rectangle[10];
            player           = ScrollingShooterGame.Game.Player;
            photonStateTimer = 0;
            homing           = true;

            spriteBounds[(int)PhotonState.One].X      = 108;
            spriteBounds[(int)PhotonState.One].Y      = 3;
            spriteBounds[(int)PhotonState.One].Width  = 9;
            spriteBounds[(int)PhotonState.One].Height = 7;

            spriteBounds[(int)PhotonState.Two].X      = 96;
            spriteBounds[(int)PhotonState.Two].Y      = 2;
            spriteBounds[(int)PhotonState.Two].Width  = 9;
            spriteBounds[(int)PhotonState.Two].Height = 9;

            spriteBounds[(int)PhotonState.Three].X      = 83;
            spriteBounds[(int)PhotonState.Three].Y      = 1;
            spriteBounds[(int)PhotonState.Three].Width  = 11;
            spriteBounds[(int)PhotonState.Three].Height = 11;

            spriteBounds[(int)PhotonState.Four].X      = 71;
            spriteBounds[(int)PhotonState.Four].Y      = 1;
            spriteBounds[(int)PhotonState.Four].Width  = 11;
            spriteBounds[(int)PhotonState.Four].Height = 11;

            spriteBounds[(int)PhotonState.Five].X      = 59;
            spriteBounds[(int)PhotonState.Five].Y      = 1;
            spriteBounds[(int)PhotonState.Five].Width  = 11;
            spriteBounds[(int)PhotonState.Five].Height = 11;

            spriteBounds[(int)PhotonState.Six].X      = 47;
            spriteBounds[(int)PhotonState.Six].Y      = 1;
            spriteBounds[(int)PhotonState.Six].Width  = 11;
            spriteBounds[(int)PhotonState.Six].Height = 11;

            spriteBounds[(int)PhotonState.Seven].X      = 35;
            spriteBounds[(int)PhotonState.Seven].Y      = 1;
            spriteBounds[(int)PhotonState.Seven].Width  = 11;
            spriteBounds[(int)PhotonState.Seven].Height = 11;

            spriteBounds[(int)PhotonState.Eight].X      = 23;
            spriteBounds[(int)PhotonState.Eight].Y      = 1;
            spriteBounds[(int)PhotonState.Eight].Width  = 11;
            spriteBounds[(int)PhotonState.Eight].Height = 11;

            spriteBounds[(int)PhotonState.Nine].X      = 11;
            spriteBounds[(int)PhotonState.Nine].Y      = 1;
            spriteBounds[(int)PhotonState.Nine].Width  = 11;
            spriteBounds[(int)PhotonState.Nine].Height = 11;

            spriteBounds[(int)PhotonState.Ten].X      = 0;
            spriteBounds[(int)PhotonState.Ten].Y      = 0;
            spriteBounds[(int)PhotonState.Ten].Width  = 10;
            spriteBounds[(int)PhotonState.Ten].Height = 13;

            photonState = PhotonState.One;
        }
        /// <summary>
        /// Factory method for spawning a shield
        /// </summary>
        /// <param name="shieldType">The type of shield to create</param>
        /// <param name="position">Position of the shield in the game world</param>
        /// <param name="PlayerShip">The Player</param>
        /// <returns>The game object id of the projectile</returns>
        public Shield CreateShield(ShieldType shieldType, Vector2 position,
            PlayerShip PlayerShip)
        {
            Shield shield;
            uint id = NextID();

            switch (shieldType)
            {
                case ShieldType.EightBallShield:
                    shield = new EightBallShield(id, content, position, PlayerShip);
                    break;
                default:
                    throw new NotImplementedException("EightBallShield failed.");
            }

            shield.ObjectType = ObjectType.Shield;
            QueueGameObjectForCreation(shield);
            return shield;
        }
        /// <summary>
        /// Clear all of the Queues, lists, and Dictionarys and readd the Player
        /// This reloads the level while maintaining the player's score, lives, and powerups.
        /// </summary>
        /// <param name="player">The player</param>
        public void Reset(PlayerShip player)
        {
            gameObjects.Clear();

            createdGameObjects.Clear();
            destroyedGameObjects.Clear();

            boundingBoxes.Clear();
            scrollingObjects.Clear();
            projectileObjects.Clear();
            verticalAxis.Clear();

            verticalOverlaps.Clear();
            collisions.Clear();

            QueueGameObjectForCreation(player);
        }
示例#40
0
        private Vector2 toPlayer; //vector from Photon pos to player pos

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Create a new instance of a Photon projectile
        /// </summary>
        /// <param name="id">Obj id</param>
        /// <param name="content">A ContentManager to load resources with</param>
        /// <param name="position">The position of the Photon projectile in the game world</param>
        public Photon(uint id, ContentManager content, Vector2 position)
            : base(id)
        {
            this.position = position;
            this.velocity = new Vector2(150);
            this.spriteSheet = content.Load<Texture2D>("Spritesheets/accessories");
            spriteBounds = new Rectangle[10];
            player = ScrollingShooterGame.Game.Player;
            photonStateTimer = 0;
            homing = true;

            spriteBounds[(int)PhotonState.One].X = 108;
            spriteBounds[(int)PhotonState.One].Y = 3;
            spriteBounds[(int)PhotonState.One].Width = 9;
            spriteBounds[(int)PhotonState.One].Height = 7;

            spriteBounds[(int)PhotonState.Two].X = 96;
            spriteBounds[(int)PhotonState.Two].Y = 2;
            spriteBounds[(int)PhotonState.Two].Width = 9;
            spriteBounds[(int)PhotonState.Two].Height = 9;

            spriteBounds[(int)PhotonState.Three].X = 83;
            spriteBounds[(int)PhotonState.Three].Y = 1;
            spriteBounds[(int)PhotonState.Three].Width = 11;
            spriteBounds[(int)PhotonState.Three].Height = 11;

            spriteBounds[(int)PhotonState.Four].X = 71;
            spriteBounds[(int)PhotonState.Four].Y = 1;
            spriteBounds[(int)PhotonState.Four].Width = 11;
            spriteBounds[(int)PhotonState.Four].Height = 11;

            spriteBounds[(int)PhotonState.Five].X = 59;
            spriteBounds[(int)PhotonState.Five].Y = 1;
            spriteBounds[(int)PhotonState.Five].Width = 11;
            spriteBounds[(int)PhotonState.Five].Height = 11;

            spriteBounds[(int)PhotonState.Six].X = 47;
            spriteBounds[(int)PhotonState.Six].Y = 1;
            spriteBounds[(int)PhotonState.Six].Width = 11;
            spriteBounds[(int)PhotonState.Six].Height = 11;

            spriteBounds[(int)PhotonState.Seven].X = 35;
            spriteBounds[(int)PhotonState.Seven].Y = 1;
            spriteBounds[(int)PhotonState.Seven].Width = 11;
            spriteBounds[(int)PhotonState.Seven].Height = 11;

            spriteBounds[(int)PhotonState.Eight].X = 23;
            spriteBounds[(int)PhotonState.Eight].Y = 1;
            spriteBounds[(int)PhotonState.Eight].Width = 11;
            spriteBounds[(int)PhotonState.Eight].Height = 11;

            spriteBounds[(int)PhotonState.Nine].X = 11;
            spriteBounds[(int)PhotonState.Nine].Y = 1;
            spriteBounds[(int)PhotonState.Nine].Width = 11;
            spriteBounds[(int)PhotonState.Nine].Height = 11;

            spriteBounds[(int)PhotonState.Ten].X = 0;
            spriteBounds[(int)PhotonState.Ten].Y = 0;
            spriteBounds[(int)PhotonState.Ten].Width = 10;
            spriteBounds[(int)PhotonState.Ten].Height = 13;

            photonState = PhotonState.One;
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            GameObjectManager = new GameObjectManager(Content);

            // TODO: use this.Content to load your game content here
            player = GameObjectManager.CreatePlayerShip(PlayerShipType.Shrike, new Vector2(300, 300));
            player.ApplyPowerup(PowerupType.Fireball);

            // Create a Green Goblin enemy
            GameObjectManager.CreateEnemy(EnemyType.GreenGoblin, new Vector2(200, -150));
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create our viewports
            gameViewport = GraphicsDevice.Viewport;
            worldViewport = new Viewport(0, 0, 768, 720); // Twice as wide as 16 tiles
            guiViewport = new Viewport(768, 0, 512, 720); // Remaining space

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Create a basic effect, used with the spritebatch
            basicEffect = new BasicEffect(GraphicsDevice)
            {
                TextureEnabled = true,
                VertexColorEnabled = true,
            };

            GameObjectManager = new GameObjectManager(Content);

            // TODO: use this.Content to load your game content here
            Player = GameObjectManager.CreatePlayerShip(PlayerShipType.Shrike, new Vector2(300, 300));
            //Player.ApplyPowerup(PowerupType.Fireball);

            LevelManager.LoadContent();
            LevelManager.LoadLevel("lavaLevel2");
            //test out new panzer personality
            int p1 = 100;
            int p2 = 200;
            for (int i = 0; i < 6; i++)
            {
                GameObjectManager.CreateEnemy(EnemyType.Panzer, new Vector2(p1, 100));
                GameObjectManager.CreateEnemy(EnemyType.Panzer2, new Vector2(p2, 100));
                p1 += 100;
                p2 += 100;
            }
            //test out lavabug
            GameObjectManager.CreateEnemy(EnemyType.Lavabug, new Vector2(100, 75));
        }
示例#43
0
        /// <summary>
        /// Updates the blade spinner
        /// </summary>
        /// <param name="elapsedTime">The in-game time between the previous and current frame</param>
        public override void Update(float elapsedTime)
        {
            //If the spinner is dead do nothing
            if (state == spinnerState.dead)
            {
                return;
            }

            //"Sense" the player ship
            PlayerShip player = ScrollingShooterGame.Game.Player;

            //-40 is so the Spinner actually covers the ship instead of menacing its back right corner
            Vector2 playerPosition = new Vector2(player.Bounds.Center.X - 40, player.Bounds.Center.Y - 40);
            // Get a vector from our position to the player's position
            Vector2 toPlayer = playerPosition - this.position;

            //Conditionals to keep the spinner on screen by adjusting the patrol vector
            //A switch statement may be more efficient
            if (horDir == flightDirection.positive && this.position.X > 725)
            {
                horDir = flightDirection.negative;
            }
            else if (horDir == flightDirection.negative && this.position.X < 25)
            {
                horDir = flightDirection.positive;
            }
            if (vertDir == flightDirection.negative && this.position.Y < 25)
            {
                vertDir = flightDirection.positive;
            }
            else if (vertDir == flightDirection.positive && this.position.Y > 400)
            {
                vertDir = flightDirection.negative;
            }
            patrolVector.X = ((int)horDir * 50);
            patrolVector.Y = ((int)vertDir) * 5;
            //End of conditionals to stay on screen


            //Determine if the player is "seen"
            if (toPlayer.LengthSquared() < 30000 && state != spinnerState.dying)
            {
                //if seen attack player
                state = spinnerState.attacking;
            }
            else if (state != spinnerState.dying)
            {
                state = spinnerState.flying;
            }

            switch (state)
            {
            case spinnerState.flying:
                //normalize the patrol vector
                patrolVector.Normalize();

                //move
                this.position += patrolVector * elapsedTime * 250;
                break;

            case spinnerState.attacking:
                // Get a normalized steering vector
                toPlayer.Normalize();

                // Steer towards them
                this.position += toPlayer * elapsedTime * 125;
                break;

            case spinnerState.dying:
                //No movement while dying
                break;
            }

            //Collision detection?

            /*
             * if(state==spinnerState.attacking)
             * {
             *     if(hitPlayer)
             *          damage player
             *
             *    if(hitProjectile)
             *    {
             *          take a little damage
             *          if(hp==0)
             *              state==spinnerState.dying;
             *     }
             * }
             * else if(state==spinnerState.flying)
             *{
             *      if(hitPorjectile)
             *      {
             *          take more damage
             *          if(hp==0)
             *              state==spinnerState.dying;
             *      }
             *      if(hitPlayer)
             *      {
             *          //Should never happen
             *          damage player a little
             *          state = spinnerState.dying;
             *      }
             *}
             * else if(state==spinnerState.dying)
             *{
             *      if(hit Object)
             *      {
             *          do "med" damage
             *      }
             *}
             */
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            GameObjectManager = new GameObjectManager(Content);

            // TODO: use this.Content to load your game content here
            player = GameObjectManager.CreatePlayerShip(PlayerShipType.Shrike, new Vector2(300, 300));
            GameObjectManager.CreatePowerup(PowerupType.Fireball, new Vector2(100, 200));
            //player.ApplyPowerup(PowerupType.Fireball);

            tilemap = Content.Load<Tilemap>("Tilemaps/example");
            for (int i = 0; i < tilemap.GameObjectGroupCount; i++)
            {
                for (int j = 0; j < tilemap.GameObjectGroups[i].GameObjectData.Count(); j++ )
                {
                    GameObjectData goData = tilemap.GameObjectGroups[i].GameObjectData[j];
                    Vector2 position = new Vector2(goData.Position.Center.X, goData.Position.Center.Y);
                    GameObject go;

                    switch (goData.Category)
                    {
                        case "Powerup":
                            go = GameObjectManager.CreatePowerup((PowerupType)Enum.Parse(typeof(PowerupType), goData.Type), position);
                            goData.ID = go.ID;
                            break;

                        case "Enemy":
                            go = GameObjectManager.CreateEnemy((EnemyType)Enum.Parse(typeof(EnemyType), goData.Type), position);
                            goData.ID = go.ID;
                            break;
                    }
                }
            }
            tilemap.Scrolling = true;

            GameObjectManager.CreateEnemy(EnemyType.Cobalt, new Vector2(200, 200));
        }
 public void StartGame()
 {
     Player = GameObjectManager.CreatePlayerShip(PlayerShipType.Shrike, new Vector2(300, 300));
 }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create our viewports
            gameViewport = GraphicsDevice.Viewport;
            worldViewport = new Viewport(0, 0, 768, 720); // Twice as wide as 16 tiles
            guiViewport = new Viewport(768, 0, 512, 720); // Remaining space

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            GameObjectManager = new GameObjectManager(Content);

            // TODO: use this.Content to load your game content here
            Player = GameObjectManager.CreatePlayerShip(PlayerShipType.Shrike, new Vector2(300, 300));
            GameObjectManager.CreatePowerup(PowerupType.Fireball, new Vector2(100, 200));
            //Player.ApplyPowerup(PowerupType.Fireball);

            LevelManager.LoadContent();
            LevelManager.LoadLevel("crystalland");
            GuiManager.LoadContent();
            GameState = GameState.Initializing;
        }
 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
     #if TEST
     IsMouseVisible = true;
     #endif
     // Create a new SpriteBatch, which can be used to draw textures.
     spriteBatch = new SpriteBatch(GraphicsDevice);
     // TODO: use this.Content to load your game content here
     player = new ShrikeShip(Content);
     GUIHealthBar hBar1 = new GUIHealthBar(Content, new Vector2(GraphicsDevice.Viewport.Width-10-150,10), 100, 100);
     GUIHealthBar hBar2 = new GUIHealthBar(Content, new Vector2(10, 10), 100, 100);
     gManager.Add(hBar1);
     gManager.Add(hBar2);
     player.ApplyPowerup(Powerups.Fireball);
 }