Esempio n. 1
0
        /// <summary>
        /// Constructors a new player.
        /// </summary>
        public Bobo(GameScreen screen, Level level, Vector2 position)
        {
            this.level = level;

            LoadContent(screen);

            Reset(position);
        }
Esempio n. 2
0
 /// <summary>
 /// Constructs a new level.
 /// </summary>
 /// <param name="serviceProvider">
 /// The service provider that will be used to construct a ContentManager.
 /// </param>
 /// <param name="fileStream">
 /// A stream containing the tile data.
 /// </param>
 public Level(GameScreen screen, IServiceProvider serviceProvider, Stream fileStream)
 {
     // Create a new content manager to load content used just by this level.
     content = new ContentManager(serviceProvider, "Content");
     mainGameScreen = screen;
     background = Content.Load<Texture2D>("background/sunnysky");
     LoadTiles(fileStream);
 }
Esempio n. 3
0
 public void AddScreen(GameScreen screen)
 {
     screen.IsExiting = false;
     screen.ScreenManager = this;
     if (isInitialized)
     {
         screen.LoadContent();
     }
     screens.Add(screen);
 }
Esempio n. 4
0
 public void Fire(GameScreen screen, Vector2 thePosition, Vector2 theSpeed, Vector2 theDirection, string fireballname)
 {
     Position = thePosition;
     mSpeed = theSpeed;
     mDirection = theDirection;
     LoadContent(screen, fireballname);
 }
Esempio n. 5
0
        /// <summary>
        /// Animates each enemy and allow them to kill the player.
        /// </summary>
        private void UpdateEnemies(GameScreen screen, GameTime gameTime, List<Fireball> fireballs)
        {
            foreach (Enemy enemy in enemies)
            {
                enemy.Update(screen, gameTime, fireballs, player);

                // Touching an enemy instantly hurts the player
                if (enemy.BoundingRectangle.Intersects(Player.BoundingRectangle) && enemy.IsAlive)
                {
                    health -= 10;
                }
                if (health == 0)
                {
                    Lose(enemy, screen);
                }
            }
        }
Esempio n. 6
0
 private bool Lose(Enemy enemy, GameScreen screen)
 {
     screen.isPaused = true;
     isKilled = true;
     OnPlayerKilled(enemy);
     screen.ScreenManager.AddScreen(new LossScreen());
     return true;
 }
Esempio n. 7
0
        /// <summary>
        /// Handles input, performs physics, and animates the player sprite.
        /// </summary>
        /// <remarks>
        /// We pass in all of the input states so that our game is only polling the hardware
        /// once per frame. We also pass the game's orientation because when using the accelerometer,
        /// we need to reverse our motion when the orientation is in the LandscapeRight orientation.
        /// </remarks>
        public void Update(GameScreen screen, GameTime gameTime, KeyboardState keyboardState, List<Enemy> enemies)
        {
            keyboardState = Keyboard.GetState();
            GetInput(keyboardState);

            ApplyPhysics(gameTime);

            if (IsAlive && IsOnGround)
            {
                if (Math.Abs(Velocity.X) - 0.02f > 0)
                {
                    sprite.PlayAnimation(runAnimation);
                }
                else
                {
                    sprite.PlayAnimation(idleAnimation);
                }
            }

            // Clear input.
            movement = 0.0f;
            isJumping = false;
            if (isOnGround)
                numberOfJumps = 0;

            wasStunned = false;

            //Firing component for Bobo
            UpdateFireball(screen, gameTime, keyboardState);
            DoStun(screen, enemies);

            previousKeyboardState = keyboardState;
        }
Esempio n. 8
0
 public Fireball(GameScreen screen ,Level level, string fireballname)
 {
     this.level = level;
     LoadContent(screen, fireballname);
 }
Esempio n. 9
0
 private void ShootFireball(GameScreen screen)
 {
     if (isFiring)
     {
         sprite.PlayAnimation(runAnimation);
         Fireball f = new Fireball(screen, Level, "enemyfire");
         //f.loadContent();
         if ((int)direction == 1)
             f.Fire(screen, new Vector2(Position.X + 10, Position.Y - 25),
                 new Vector2(200, 200), new Vector2(1, 0), "enemyfire");
         else
             f.Fire(screen, new Vector2(Position.X - 25, Position.Y - 25),
                 new Vector2(200, 200), new Vector2(-1, 0), "enemyfire");
         mFireballs.Add(f);
     }
 }
Esempio 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);
            }
        }
Esempio n. 11
0
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, GameScreen screen)
        {
            // Stop running when the game is paused or before turning around.
            if (screen.isPaused)
            {
                sprite.PlayAnimation(idleAnimation);
            }
            else
            {
                sprite.PlayAnimation(runAnimation);
            }

            // Draw facing the way the enemy is moving.
            if (IsAlive)
            {
                SpriteEffects flip = direction > 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
                sprite.Draw(gameTime, spriteBatch, Position, flip);
                    foreach (Fireball f in mFireballs)
                        if (!f.isDead)
                            f.Draw(gameTime, spriteBatch);
            }
            else
            if (waitDieTime > 0)
            {
                // Wait for some amount of time.
                waitDieTime = Math.Max(0.0f, waitDieTime - (float)gameTime.ElapsedGameTime.TotalSeconds);
                SpriteEffects flip = direction > 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
                sprite.Draw(gameTime, spriteBatch, Position, flip);
            }
        }
Esempio n. 12
0
        private void UpdateFireball(GameScreen screen, GameTime gameTime, KeyboardState keyboardState)
        {
            foreach (Fireball f in mFireballs)
                f.Update(gameTime);

            if (keyboardState.IsKeyDown(Keys.Space) == true && previousKeyboardState.IsKeyDown(Keys.Space) == false)
            {
                isFiring = true;
                ShootFireball(screen);
            }
        }
Esempio n. 13
0
 private void ShootFireball(GameScreen screen)
 {
     if (isFiring && (numFireBalls > 0))
     {
         sprite.PlayAnimation(fireAnimation);
         Fireball f = new Fireball(screen,Level, "");
         //f.loadContent();
         if (flip == SpriteEffects.FlipHorizontally)
             f.Fire(screen, new Vector2(Position.X + 10, Position.Y - 25),
                 new Vector2(200, 200), new Vector2(1, 0), "");
         else
             f.Fire(screen, new Vector2(Position.X - 25, Position.Y - 25),
                 new Vector2(200, 200), new Vector2(-1, 0), "");
         mFireballs.Add(f);
         numFireBalls--;
     }
 }
Esempio n. 14
0
 private void DoStun(GameScreen screen, List<Enemy> Enemies)
 {
     foreach (Enemy E in Enemies){
         if (this.BoundingRectangle.Intersects(E.BoundingRectangle) && E.IsAlive)
         {
             sprite.PlayAnimation(dieAnimation);
             //this.velocity = new Vector2(-200, 8000);
             wasStunned = true;
         }
     }
 }
Esempio n. 15
0
 /// <summary>
 /// Allows the game component to perform any initialization it needs to before starting
 /// to run.  This is where it can query for any required services and load content.
 /// </summary>
 public void loadContent(GameScreen screen)
 {
     this.LoadContent();
 }
Esempio n. 16
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;
            }
        }
Esempio n. 17
0
        public void LoadContent(GameScreen screen, string fireballname)
        {
            // Calculate bounds within texture size.
            /*int width = (int)(sprite.Width * 0.35);
            int left = (sprite.Width - width) / 2;
            int height = (int)(sprite.Height * 0.7);
            int top = sprite.Height - height;
            localBounds = new Rectangle(0, 0, sprite.Width, sprite.Height);*/
            //------------------------end
            if (fireballname == "enemyfire")
            {
                sprite = Level.Content.Load<Texture2D>("Sprites/Enemy/enemyfire");
            }
            else
            {
                if (mDirection.X < 0)
                    sprite = Level.Content.Load<Texture2D>("Sprites/Bobo/fireball");
                else
                    sprite = Level.Content.Load<Texture2D>("Sprites/Bobo/fireball2");
            }

            localBounds = new Rectangle(0, 0, sprite.Width, sprite.Height);
        }
Esempio n. 18
0
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, GameScreen screen)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(background, Vector2.Zero, null, Color.White, 0.0f, Vector2.Zero, 1.5f, SpriteEffects.None, 0.0f);
            spriteBatch.End();

            float start = (float)(Height * Tile.height / 1.0365); //1x = 2
            Matrix cameraTransform = Matrix.CreateTranslation(0.0f, cameraPosition-start, 0f);
            if (!screen.isPaused)
            {

                if (isBeginning == true || gameTime.TotalGameTime.TotalSeconds < 11 || !player.ScrollON)
                {
                    //cameraTransform = Matrix.CreateTranslation(0.0f, -start, 0.0f);
                    isBeginning = false;

                }
                else
                {
                    ScrollCamera(spriteBatch.GraphicsDevice.Viewport, gameTime);
                    cameraTransform = Matrix.CreateTranslation(0.0f, cameraPosition - start, 0.0f);
                }
            }

                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, cameraTransform);
                DrawTiles(spriteBatch);
                foreach (PowerUp pu in powerups)
                    pu.Draw(gameTime, spriteBatch);

                Player.Draw(gameTime, spriteBatch);

                // Draw enemys
                foreach (Enemy enemy in enemies)
                {
                    if (enemy.IsAlive == true)
                        enemy.Draw(gameTime, spriteBatch, screen);
                }
                spriteBatch.End();
        }
Esempio n. 19
0
 public void RemoveScreen(GameScreen screen)
 {
     if (isInitialized)
     {
         screen.UnloadContent();
     }
     screens.Remove(screen);
     screensToUpdate.Remove(screen);
 }
Esempio n. 20
0
 public void Update(GameScreen screen, GameTime gameTime, KeyboardState keyboardState)
 {
     keyboardState = Keyboard.GetState();
     mainGameScreen = screen;
     if (isKilled == false)
     {
         Player.Update(screen, gameTime, keyboardState, enemies);
         UpdateEnemies(screen, gameTime, player.fireballs);
         UpdatePowers(gameTime);
     }
     if (Player.Position.Y > Height * Tile.height - cameraPosition)
     {
         if (!lost)
             lost = Lose(null, screen);
     }
     if (ReachedExit)
     {
         // Animate the time being converted into points.
         int seconds = (int)Math.Round(gameTime.ElapsedGameTime.TotalSeconds * 100.0f) - 11;
         score += seconds * 2;
     }
     //// The player has reached the exit if they are standing on the ground and
     //// his bounding rectangle contains the center of the exit tile. They can only
     //// exit when they have collected all of the gems.
     //if (Player.IsAlive &&
     //    Player.IsOnGround &&
     //    Player.BoundingRectangle.Contains(exit))
     //{
     //    OnExitReached(screen);
     //}
 }
Esempio n. 21
0
 public void QuitToScreen(GameScreen screen)
 {
     int length = screens.Count;
     for (int i = length - 1; i >= 0; --i)
     {
         if (screens[i].bgSong != null)
             MediaPlayer.Stop();
         screens.Remove(screens[i]);
     }
     length = screensToUpdate.Count;
     UnloadContent();
     for (int i = length - 1; i >= 0; --i)
     {
         screensToUpdate.Remove(screensToUpdate[i]);
     }
     AddScreen(screen);
 }
Esempio n. 22
0
        /// <summary>
        /// Loads the player sprite sheet and sounds.
        /// </summary>
        public void LoadContent(GameScreen screen)
        {
            // Load animated textures.
            //spriteBatch = new SpriteBatch(screen.ScreenManager.GraphicsDevice);

            idleAnimation = new Animation(screen.ScreenManager.Game.Content.Load<Texture2D>("Sprites/Bobo/idle"), 0.1f, true);
            runAnimation = new Animation(screen.ScreenManager.Game.Content.Load<Texture2D>("Sprites/Bobo/running"), 0.1f, true);
            jumpAnimation = new Animation(screen.ScreenManager.Game.Content.Load<Texture2D>("Sprites/Bobo/jumping"), 0.1f, false);
            dieAnimation = new Animation(screen.ScreenManager.Game.Content.Load<Texture2D>("Sprites/Bobo/dead"), 0.1f, false);
            fireAnimation = new Animation(screen.ScreenManager.Game.Content.Load<Texture2D>("Sprites/Bobo/firing"), 0.1f, false);

            // Calculate bounds within texture size.
            int width = (int)(idleAnimation.FrameWidth * 1);
            int left = (idleAnimation.FrameWidth - width) / 2;
            int height = (int)(idleAnimation.FrameWidth * 1);
            int top = idleAnimation.FrameHeight - height;
            localBounds = new Rectangle(left, top, width, height);

            // Load Fireballs
            foreach (Fireball f in mFireballs)
                f.loadContent(screen);
        }