//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); }
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) }
public override void Update(GameTime gameTime, CollisionBoard cb) { if (!this.isDestroyed) { this.UpdateProjectiles(gameTime, cb); } // update character in derived enemy/player classes }
public void UpdateProjectiles(GameTime gameTime, CollisionBoard cb) { //Update existing bullets already fired by the character foreach (Projectile projectile in this.projectiles) { projectile.Update(gameTime, cb); } }
// called before configuring a phase static public void Reset() { collisionBoard = new CollisionBoard(ShakeAndBakeGame.graphics.GraphicsDevice.Viewport.Width, ShakeAndBakeGame.graphics.GraphicsDevice.Viewport.Height, ShakeAndBakeGame.player.Width); // clear player bullets user.Projectiles.Clear(); }
//Constructor for GameBoard class static GameBoard() { collisionBoard = new CollisionBoard(ShakeAndBakeGame.graphics.GraphicsDevice.Viewport.Height, ShakeAndBakeGame.graphics.GraphicsDevice.Viewport.Width, ShakeAndBakeGame.player.Width); visibleEnemies = new ObservableCollection <Enemy>(); deadEnemies = new List <Enemy>(); user = new Player(); int width = ShakeAndBakeGame.graphics.GraphicsDevice.Viewport.Width; int height = ShakeAndBakeGame.graphics.GraphicsDevice.Viewport.Height; user.Position = new Vector2((width / 2 - ShakeAndBakeGame.player.Width / 2), height - ShakeAndBakeGame.player.Height); //When enemy is added or removed from collection "updateEnimies" is automatically called visibleEnemies.CollectionChanged += UpdateEnemies; }
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); }
public override void Update(GameTime gameTime, CollisionBoard cb) { base.Update(gameTime, cb); }
public virtual void Update(GameTime gameTime, CollisionBoard cb) { }