Example #1
0
        private bool CollideWith(AnimateSheetSprite other)
        {
            Rectangle myBound    = new Rectangle((int)CentrePos.X - this.ProjectileWidth, (int)CentrePos.Y, ProjectileWidth, ProjectileHeight);
            Rectangle otherBound = new Rectangle((int)other.PixelPosition.X, (int)other.PixelPosition.Y, other.FrameWidth, other.FrameHeight);

            return(myBound.Intersects(otherBound));
        }
 public Projectile(Vector2 userPosition, List<TileRef> projectiletRefs, List<TileRef> explosionRef, int frameWidth, int frameHeight, float layerDepth)
     : base(userPosition, projectiletRefs, frameWidth, frameHeight, layerDepth)
 {
     Target = Vector2.Zero;
         StartPosition = userPosition;
         ProjectileState = PROJECTILE_STATE.STILL;
     explosion = new AnimateSheetSprite(userPosition, explosionRef, frameWidth, FrameHeight, 0.5f);
 }
 public override void follow(AnimateSheetSprite followed)
 {
     if (P != null && delay-- <= 0)
     {
         delay          = DELAYTIME;
         P.TilePosition = TilePosition;
         //P.fire(followed.TilePosition);
         base.follow(followed);
     }
 }
 public override void follow(AnimateSheetSprite followed)
 {
     // only fire towards followed if a stationary sentry
     if (P != null &&
         P.ProjectileState == Projectile.PROJECTILE_STATE.STILL &&
         followed.BoundingRectangle.Intersects(Range))
     {
         P.fire(followed.TilePosition);
     }
     base.follow(followed);
 }
Example #5
0
 public Projectile(Game g, List <TileRef> texture, AnimateSheetSprite rocketExplosion, Vector2 userPosition, int framecount)
     : base(g, userPosition, texture, 64, 64, framecount)
 {
     Target                   = Vector2.Zero;
     myGame                   = g;
     textureCenter            = new Vector2(32, 32);
     explosion                = rocketExplosion;
     explosion.PixelPosition -= textureCenter;
     explosion.Visible        = false;
     StartPosition            = PixelPosition;
     ProjectileState          = PROJECTILE_STATE.STILL;
 }
Example #6
0
        public SuperProjectile(Game game, Vector2 userPosition, List <TileRef> sheetRefs, int frameWidth, int frameHeight, float layerDepth)
            : base(game, userPosition, sheetRefs, frameWidth, frameHeight, layerDepth)
        {
            Target = Vector2.Zero;

            myGame = game;

            explosion = new AnimateSheetSprite(myGame, explosionLocation, new List <TileRef>()
            {
                new TileRef(7, 0, 0),
                new TileRef(8, 0, 0),
                new TileRef(2, 0, 0),
            }, 64, 64, 0f);

            //initialPosition = new Vector2(20, 20);

            //explosion = rocketExplosion;
            //explosion.position -= textureCenter;
            //explosion.Visible = false;

            //StartPosition = position;
            //PixelPosition = initialPosition;
            ProjectileState = PROJECTILE_STATE.STILL;
        }
 public void follow(AnimateSheetSprite followed)
 {
     //MouseState state = Mouse.GetState();
     angleOfRotation = TurnToFace(followed.PixelPosition, PixelPosition, angleOfRotation, 0.01f);
 }
        /// <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)
        {
            // Exit the game.
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // Play sound effect when the player shoots.
            if (Keyboard.GetState().IsKeyDown(Keys.Space) && player1.MySuperProjectile.ProjectileState == SuperProjectile.PROJECTILE_STATE.STILL)
            {
                playerFire.Play();
            }


            #region Handle behaviour between player and sentry.
            foreach (var item in sentries)
            {
                // The following if statement will ensure that the sentry will only carry out it's behaviour if it is still visible.
                if (item.Visible == true)
                {
                    // Follow the player's position.
                    item.Follow(player1);

                    // Ensure the sentry and the player collide if the sentry is still visible.
                    player1.CollisionSentry(item);


                    #region Handle the sentry's projectile colllsions with walls
                    foreach (var wall in projectileColliders)
                    {
                        item.SentrySuperProjectile.WallCollision(wall);
                    }
                    #endregion

                    #region what will happen when a sentry dies.
                    // If the sentry is killed...
                    if (item.Health <= 0)
                    {
                        if (item.Visible == true)
                        {
                            // ...Add to the killcount.
                            killCount++;

                            // Create an explosion where the sentry once was.
                            deathExplosion = new AnimateSheetSprite(this, item.PixelPosition, new List <TileRef>()
                            {
                                new TileRef(0, 0, 0),
                                new TileRef(1, 0, 0),
                                new TileRef(2, 0, 0),
                            }, 64, 64, 0f);
                        }

                        // Make the sentry invisible.
                        item.Visible = false;
                    }
                    #endregion
                }
            }
            #endregion

            #region Handle the player and player projectile's collisions with walls.
            // Ensure that the player collides with locks.
            foreach (Lock collisionLock in locks)
            {
                player1.CollisionLock(collisionLock);
            }

            // Ensure the player projectile collides with walls.
            foreach (var item in projectileColliders)
            {
                player1.MySuperProjectile.WallCollision(item);
            }
            #endregion

            #region  What to do when all sentries have been destroyed.
            if (killCount == sentryCount)
            {
                MediaPlayer.Volume -= 0.4f;

                foreach (Lock item in locks)
                {
                    item.Visible = false;
                }

                gameOverState = true;
            }
            #endregion

            #region Play background music when test timer is up.
            // Play background music.
            //timeSpan -= gameTime.ElapsedGameTime;

            // timeSpan < TimeSpan.Zero
            // Add the above line to the if statement below to test the countdown.

            if (MediaPlayer.Volume != 0.5f)
            {
                MediaPlayer.Play(backgroundMusic);
                MediaPlayer.Volume += 0.5f;
            }
            #endregion

            // What to do when the player reaches the exit tile.
            if (player1.BoundingRectangle.Intersects(exitTile.CollisionField) && player1.Visible == true)
            {
                victoryFanfare.Play();
                player1.Visible = false;
            }


            base.Update(gameTime);
            // TODO: Add your update logic here

            /// <summary>
            /// This is called when the game should draw itself.
            /// </summary>
            /// <param name="gameTime">Provides a snapshot of timing values.</param>
        }