예제 #1
0
        //Updates the
        public override void Update(GameTime gameTime, CollisionBoard cb)
        {
            cb.RemoveFromBucketIfExists(this);

            //Move Enemy to new position in its set path
            position = path.NextPoint();

            // random shake effect for bosses, just to add variety right now (move to appropriate classes later)
            if (this is MidBoss)
            {
                position.X = position.X + (float)Util.randDouble(1, 25);
            }
            else if (this is FinalBoss)
            {
                position.X = position.X + (float)Util.randDouble(1, 50);
            }

            // enemy went off screen without dying, so destroy it
            if (position.Y > ShakeAndBakeGame.graphics.GraphicsDevice.Viewport.Height)
            {
                isDestroyed = true;
                return;
            }

            cb.FillBucket(this);

            //Fire a new projectile if firerate field will allow
            this.FireProjectile();

            base.Update(gameTime, cb);
        }
예제 #2
0
        public override void Update(GameTime gameTime, CollisionBoard cb)
        {
            if (position.Y + this.sprite.Height < 0 ||
                position.Y > ShakeAndBakeGame.graphics.GraphicsDevice.Viewport.Height)
            {
                IsDestroyed = true;
                return;
            }

            //Before updating position, remove current bucket position on collision board
            cb.RemoveFromBucketIfExists(this);

            //Update the position of the projectile based off of its spritePath
            position = path.NextPoint();

            //Tell the event handler that the projectile has moved and thus it needs to check if it has hit an enemy or player
            RaisePropertyChanged("Projectile_Position_Changed");

            //Fill bucket on collision board
            cb.FillBucket(this);

            if (this.GetType().Equals(typeof(EnemyBullet)))
            {
            }
            else if (this.GetType().Equals(typeof(PlayerBullet)))
            {
                HashSet <GameObject> collidedEnemies = cb.GetObjectsCollided(this, typeof(Enemy));
                HashSet <GameObject> collidedBullets = cb.GetObjectsCollided(this, typeof(EnemyBullet));

                foreach (Enemy go in collidedEnemies)
                {
                    if (go.IsDestroyed)
                    {
                        continue;
                    }

                    /* TODO: Replace this with a function which does damage instead of instant kill */
                    go.IsDestroyed   = true;
                    this.IsDestroyed = true;
                }

                if (!this.IsDestroyed)
                {
                    foreach (EnemyBullet go in collidedBullets)
                    {
                        if (go.IsDestroyed)
                        {
                            continue;
                        }

                        /* TODO: Replace this with a function which does damage instead of instant kill */
                        go.IsDestroyed   = true;
                        this.IsDestroyed = true;
                    }
                }
            }

            //cb.GetObjectsCollided(this, GameObject)
        }
예제 #3
0
        //MultiThread this Method call
        static public void UpdateBoard(GameTime gameTime)
        {
            user.Update(gameTime, collisionBoard);
            //Call update on all our visible enemies, this will automatically update their projectiles as well
            for (int j = 0; j < visibleEnemies.Count; j++)
            {
                Enemy enemy = visibleEnemies[j];
                if (enemy.IsDestroyed)
                {
                    visibleEnemies.RemoveAt(j);
                    deadEnemies.Add(enemy);
                    collisionBoard.RemoveFromBucketIfExists(enemy);
                    continue;
                }

                if (!enemy.IsDestroyed)
                {
                    enemy.Update(gameTime, collisionBoard);
                }
            }

            //Check if player bullets destroyed
            for (int i = 0; i < user.Projectiles.Count; i++)
            {
                Projectile p = user.Projectiles[i];
                if (p.IsDestroyed)
                {
                    user.Projectiles.RemoveAt(i);
                    collisionBoard.RemoveFromBucketIfExists(p);
                    continue;
                }
            }

            //check deadEnimies list to see if they have any projectiles left on the board
            for (int i = 0; i < deadEnemies.Count; i++)
            {
                Enemy enemy = deadEnemies[i];
                enemy.Update(gameTime, collisionBoard);
                if (enemy.Projectiles.Count == 0)
                {
                    deadEnemies.RemoveAt(i);
                }
            }
        }
예제 #4
0
        public override void Update(GameTime gameTime, CollisionBoard cb)
        {
            //Remove player's collision bucket before update
            cb.RemoveFromBucketIfExists(this);

            base.Update(gameTime, cb);

            KeyboardState state = Keyboard.GetState();//gets the state of the keyboard and checks the combos as follows

            //utilizes the left control as the switch between speed modes essentially halving the speed when pressed.
            if (state.IsKeyDown(Keys.S))
            {
                GameBoard.GameSpeed = 1;
            }
            if (state.IsKeyUp(Keys.S))
            {
                GameBoard.GameSpeed = 2;
            }
            //Spacebar fires user projectile
            if (state.IsKeyDown(Keys.Space))
            {
                FireProjectile();
            }

            //variables to hold calculations preventing redundant calculations
            float xChange = (float)(Velocity * Acceleration);
            float yChange = (float)(Velocity * Acceleration);


            //down right
            if (state.IsKeyDown(Keys.Right) && state.IsKeyDown(Keys.Down) && !(state.IsKeyDown(Keys.Left)) && !(state.IsKeyDown(Keys.Up)))
            {
                //looking into better computation for diagonal cause this moves farther than it should
                this.position.X = Position.X + xChange;
                this.position.Y = Position.Y + yChange;

                //if result is out of the window undo the change in position
                if (!isInWindow())
                {
                    if (!IsInWindowHeight())
                    {
                        this.position.Y = Position.Y - yChange;
                    }
                    if (!IsInWindowWidth())
                    {
                        this.position.X = Position.X - xChange;
                    }
                }
            }
            //up right
            if (state.IsKeyDown(Keys.Right) && state.IsKeyDown(Keys.Up) && !(state.IsKeyDown(Keys.Left)) && !(state.IsKeyDown(Keys.Down)))
            {
                //looking into better computation for diagonal cause this moves farther than it should
                this.position.X = Position.X + xChange;
                this.position.Y = Position.Y - yChange;

                //if result is out of the window undo the change in position
                if (!isInWindow())
                {
                    if (!IsInWindowHeight())
                    {
                        this.position.Y = Position.Y + yChange;
                    }
                    if (!IsInWindowWidth())
                    {
                        this.position.X = Position.X - xChange;
                    }
                }
            }
            //right
            if (state.IsKeyDown(Keys.Right) && !(state.IsKeyDown(Keys.Up)) && !(state.IsKeyDown(Keys.Down)) && !(state.IsKeyDown(Keys.Left)))
            {
                this.position.X = Position.X + xChange;

                //if result is out of the window undo the change in position
                if (!isInWindow())
                {
                    this.position.X = Position.X - xChange;
                }
            }
            //left down
            if (state.IsKeyDown(Keys.Left) && state.IsKeyDown(Keys.Down) && !(state.IsKeyDown(Keys.Up)) && !(state.IsKeyDown(Keys.Right)))
            {
                //looking into better computation for diagonal cause this moves farther than it should
                this.position.X = Position.X - xChange;
                this.position.Y = Position.Y + yChange;

                //if result is out of the window undo the change in position
                if (!isInWindow())
                {
                    if (!IsInWindowHeight())
                    {
                        this.position.Y = Position.Y - yChange;
                    }
                    if (!IsInWindowWidth())
                    {
                        this.position.X = Position.X + xChange;
                    }
                }
            }
            //left up
            if (state.IsKeyDown(Keys.Left) && state.IsKeyDown(Keys.Up) && !(state.IsKeyDown(Keys.Down)) && !(state.IsKeyDown(Keys.Right)))
            {
                //looking into better computation for diagonal cause this moves farther than it should
                this.position.X = Position.X - xChange;
                this.position.Y = Position.Y - yChange;

                //if result is out of the window undo the change in position
                if (!isInWindow())
                {
                    if (!IsInWindowHeight())
                    {
                        this.position.Y = Position.Y + yChange;
                    }
                    if (!IsInWindowWidth())
                    {
                        this.position.X = Position.X + xChange;
                    }
                }
            }
            //left
            if (state.IsKeyDown(Keys.Left) && !(state.IsKeyDown(Keys.Up)) && !(state.IsKeyDown(Keys.Down)) && !(state.IsKeyDown(Keys.Right)))
            {
                this.position.X = Position.X - xChange;

                //if result is out of the window undo the change in position
                if (!isInWindow())
                {
                    this.position.X = Position.X + xChange;
                }
            }
            //up
            if (state.IsKeyDown(Keys.Up) && !(state.IsKeyDown(Keys.Left)) && !(state.IsKeyDown(Keys.Right)) && !(state.IsKeyDown(Keys.Down)))
            {
                this.position.Y = Position.Y - yChange;

                //if result is out of the window undo the change in position
                if (!isInWindow())
                {
                    this.position.Y = Position.Y + yChange;
                }
            }
            //down
            if (state.IsKeyDown(Keys.Down) && !(state.IsKeyDown(Keys.Left)) && !(state.IsKeyDown(Keys.Right)) && !(state.IsKeyDown(Keys.Up)))
            {
                this.position.Y = Position.Y + yChange;

                //if result is out of the window undo the change in position
                if (!isInWindow())
                {
                    this.position.Y = Position.Y - yChange;
                }
            }

            //Update collision board
            cb.FillBucket(this);
        }