Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        /// <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));
        }
Ejemplo n.º 3
0
        private void OnBootsCollected(Bobo player)
        {
            //score += Gem.PointValue;

            player.OnBoots();
        }
Ejemplo n.º 4
0
 /// <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();
 }
Ejemplo n.º 5
0
        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);
                }
            }
        }
Ejemplo n.º 6
0
        private void OnBootsCollected(Bobo player)
        {
            //score += Gem.PointValue;

            player.OnBoots();
        }
Ejemplo n.º 7
0
        /// <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);
        }
Ejemplo n.º 8
0
 /// <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();
 }
Ejemplo n.º 9
0
        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;
            }
        }
Ejemplo n.º 10
0
        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);
            }
        }