private void UpdateFireball(GameScreen screen, GameTime gameTime, Bobo player) { foreach (Fireball f in mFireballs) { f.Update(gameTime); if (player.BoundingRectangle.Intersects(f.BoundingRectangle) && !f.isDead) { f.Die(); level.Health -= 10; } } if (waitFire > 0) { waitFire = Math.Max(0.0f, waitFire - (float)gameTime.ElapsedGameTime.TotalSeconds); } else { if ((((int)direction == 1 && Position.X < player.Position.X) || (int)direction == -1 && Position.X > player.Position.X) && ((int)Math.Floor(Position.Y / Tile.height) == (int)Math.Floor(player.Position.Y / Tile.height))) { isFiring = true; ShootFireball(screen); } waitFire = 0.8f; } }
/// <summary> /// Instantiates a player, puts him in the level, and remembers where to put him when he is resurrected. /// </summary> private Tile LoadStartTile(int x, int y) { if (Player != null) { throw new NotSupportedException("A level may only have one starting point."); } start = RectangleExtensions.GetBottomCenter(GetBounds(x, y)); player = new Bobo(mainGameScreen, this, start); return(new Tile(null, TileCollision.Passable)); }
private void OnBootsCollected(Bobo player) { //score += Gem.PointValue; player.OnBoots(); }
/// <summary> /// Called when this gem has been collected by a player and removed from the level. /// </summary> /// <param name="collectedBy"> /// The player who collected this gem. Although currently not used, this parameter would be /// useful for creating special powerup gems. For example, a gem could make the player invincible. /// </param> public void OnCollected(Bobo collectedBy) { //collectedSound.Play(); }
public void Update(GameScreen screen, GameTime gameTime, List <Fireball> fireballs, Bobo player) { float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; if (IsAlive) { // Calculate tile position based on the side we are walking towards. float posX = Position.X + localBounds.Width / 2 * (int)direction; int tileX = (int)Math.Floor(posX / Tile.width) - (int)direction; int tileY = (int)Math.Floor(Position.Y / Tile.height); if (waitTime > 0) { // Wait for some amount of time. waitTime = Math.Max(0.0f, waitTime - (float)gameTime.ElapsedGameTime.TotalSeconds); if (waitTime <= 0.0f) { // Then turn around. direction = (FaceDirection)(-(int)direction); } } else { // If we are about to run into a wall or off a cliff, start waiting. if (Level.GetCollision(tileX + (int)direction, tileY - 1) == TileCollision.Impassable || Level.GetCollision(tileX + (int)direction, tileY) == TileCollision.Passable) { waitTime = MaxWaitTime; } else { if (enemy == "enemy") { // Move in the current direction. Vector2 velocity = new Vector2((int)direction * MoveSpeed * elapsed, 0.0f); position = position + velocity; } else { waitTime = Math.Min(0.0f, waitTime - elapsed); if (-1.3f < waitTime && waitTime < -1.0f) { if (flip == 1) { direction = (FaceDirection)(-(int)direction); } flip = 0; } else { if (flip == 0) { flip = 1; direction = (FaceDirection)(-(int)direction); } // Move in the current direction. Vector2 velocity = new Vector2((int)direction * MoveSpeed * elapsed, 0.0f); position = position + velocity; } } } foreach (Fireball f in fireballs) { if (this.BoundingRectangle.Intersects(f.BoundingRectangle) && !f.isDead) { OnEnemyKilled(f); level.AddScore(100); f.Die(); } } } if (enemy == "enemy") { UpdateFireball(screen, gameTime, player); } } }
/// <summary> /// Instantiates a player, puts him in the level, and remembers where to put him when he is resurrected. /// </summary> private Tile LoadStartTile(int x, int y) { if (Player != null) throw new NotSupportedException("A level may only have one starting point."); start = RectangleExtensions.GetBottomCenter(GetBounds(x, y)); player = new Bobo(mainGameScreen, this, start); return new Tile(null, TileCollision.Passable); }
public void Update(GameScreen screen, GameTime gameTime, List<Fireball> fireballs, Bobo player) { float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; if (IsAlive) { // Calculate tile position based on the side we are walking towards. float posX = Position.X + localBounds.Width / 2 * (int)direction; int tileX = (int)Math.Floor(posX / Tile.width) - (int)direction; int tileY = (int)Math.Floor(Position.Y / Tile.height); if (waitTime > 0) { // Wait for some amount of time. waitTime = Math.Max(0.0f, waitTime - (float)gameTime.ElapsedGameTime.TotalSeconds); if (waitTime <= 0.0f) { // Then turn around. direction = (FaceDirection)(-(int)direction); } } else { // If we are about to run into a wall or off a cliff, start waiting. if (Level.GetCollision(tileX + (int)direction, tileY - 1) == TileCollision.Impassable || Level.GetCollision(tileX + (int)direction, tileY) == TileCollision.Passable) { waitTime = MaxWaitTime; } else { if (enemy == "enemy") { // Move in the current direction. Vector2 velocity = new Vector2((int)direction * MoveSpeed * elapsed, 0.0f); position = position + velocity; } else { waitTime = Math.Min(0.0f, waitTime - elapsed); if (-1.3f < waitTime && waitTime < -1.0f) { if (flip == 1) direction = (FaceDirection)(-(int)direction); flip = 0; } else { if (flip == 0) { flip = 1; direction = (FaceDirection)(-(int)direction); } // Move in the current direction. Vector2 velocity = new Vector2((int)direction * MoveSpeed * elapsed, 0.0f); position = position + velocity; } } } foreach (Fireball f in fireballs) if (this.BoundingRectangle.Intersects(f.BoundingRectangle) && !f.isDead) { OnEnemyKilled(f); level.AddScore(100); f.Die(); } } if(enemy == "enemy") UpdateFireball(screen, gameTime, player); } }