Exemplo n.º 1
0
        private void ChangeDirection(MobileSprite player, MobileSprite enemy, MobileSprite fireBall, HealthBar enemyHealth,
            bool qkey, bool ekey, bool fkey, ref bool firePlay)
        {
            //Ability to hit enemy
            bool hitAbility; 

            if (qkey)
            {
                //If qkey is pressed, fireball will face left and be left of player
                fireBall.Sprite.CurrentAnimation = "fireleft";
                fireBall.Position = new Vector2((int)player.Position.X - 20, (int)player.Position.Y);
            }
            if (ekey)
            {
                //If ekey is pressed, fireball will face right and be right of player
                fireBall.Sprite.CurrentAnimation = "fireright";
                fireBall.Position = new Vector2((int)player.Position.X + 20, (int)player.Position.Y);
            }

            if (fkey)
            {
                if (fireBall.Sprite.CurrentAnimation == "fireright")
                {
                    //Move the fireball right when fireball is facing right
                    fireBall.Sprite.MoveBy(2, 0);
                }
                else if (fireBall.Sprite.CurrentAnimation == "fireleft")
                {
                    //Move the fireball left when fireball is facing left
                    fireBall.Sprite.MoveBy(-2, 0);
                }
                //Play sound when fireball is fired
                if (firePlay == true)
                {
                    fire.Play();
                    //Allow sound effect to be only played once when fkey is press
                    firePlay = false;
                }
                //Allow fireball to hit enemy when fkey is pressed
                hitAbility = true;
            }
            else
            {
                //Return fireball to default position when fkey is released
                if (fireBall.Sprite.CurrentAnimation == "fireright")
                {
                    fireBall.Position = new Vector2((int)player.Position.X + 20, (int)player.Position.Y);
                }
                if (fireBall.Sprite.CurrentAnimation == "fireleft")
                {
                    fireBall.Position = new Vector2((int)player.Position.X - 20, (int)player.Position.Y);
                }
                //Allow soundeffect to be played again
                firePlay = true;
                //Disallow fireball to hit enemy
                hitAbility = false;
            }

            //Don't allow health to decrease beyond 0
            if (healthSize > Math.Abs(enemyHealth.Health))
            {
                //check if fireball intersect enemy and if hitability is true
                if (fireBall.BoundingBox.Intersects(enemy.BoundingBox) && hitAbility == true)
                {
                    //enemy health decreased
                    enemyHealth.Health--;
                }
            }
        }
Exemplo n.º 2
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //load tiles and fog
            Tile.TileSetTexture = Content.Load<Texture2D>(@"Textures\TileSets\part6_tileset");
            fogOfWar = Content.Load<Texture2D>(@"Textures\FogOfWar");

            //Load title poster
            titleTexture = Content.Load<Texture2D>(@"Textures\Title1");
            //Load font
            text.LoadContent(Content, @"Font\Font");
            credits.LoadContent(Content, @"Font\Font2");
            winnerText.LoadContent(Content, @"Font\Font");
            helpText.LoadContent(Content, @"Font\Font3");

            //Long the song and soundeffect
            battleSong = Content.Load<Song>(@"Sound/Music/BattleTheme");
            fire = Content.Load<SoundEffect>(@"Sound/SoundEffect/Boom");
            cheer = Content.Load<SoundEffect>(@"Sound/SoundEffect/Cheer");

            #region Setup Player One

            princess = Content.Load<Texture2D>(@"Textures\Player");
            myPrincess = new MobileSprite(princess);
            //Set up different varies types of animations
            myPrincess.Sprite.AddAnimation("upstop", 0, 198, 31, 66, 1, 0.1f);
            myPrincess.Sprite.AddAnimation("up", 0, 198, 31, 66, 4, 0.1f);
            myPrincess.Sprite.AddAnimation("leftstop", 0, 66, 31, 66, 1, 0.1f);
            myPrincess.Sprite.AddAnimation("left", 0, 66, 31, 66, 4, 0.1f);
            myPrincess.Sprite.AddAnimation("rightstop", 0, 132, 31, 66, 1, 0.1f);
            myPrincess.Sprite.AddAnimation("right", 0, 132, 31, 66, 4, 0.1f);
            myPrincess.Sprite.AddAnimation("downstop", 0, 0, 31, 66, 1, 0.1f);
            myPrincess.Sprite.AddAnimation("down", 0, 0, 31, 66, 4, 0.1f);
            //Starting animation
            myPrincess.Sprite.CurrentAnimation = "rightstop";
            //Starting position
            myPrincess.Position = new Vector2(15, 15);

            #endregion

            #region Setup Player Two

            princessTwo = Content.Load<Texture2D>(@"Textures\Player2");
            myPrincessTwo = new MobileSprite(princessTwo);
            //Set up different varies types of animation
            myPrincessTwo.Sprite.AddAnimation("upstop", 0, 198, 31, 66, 1, 0.1f);
            myPrincessTwo.Sprite.AddAnimation("up", 0, 198, 31, 66, 4, 0.1f);
            myPrincessTwo.Sprite.AddAnimation("leftstop", 0, 66, 31, 66, 1, 0.1f);
            myPrincessTwo.Sprite.AddAnimation("left", 0, 66, 31, 66, 4, 0.1f);
            myPrincessTwo.Sprite.AddAnimation("rightstop", 0, 132, 31, 66, 1, 0.1f);
            myPrincessTwo.Sprite.AddAnimation("right", 0, 132, 31, 66, 4, 0.1f);
            myPrincessTwo.Sprite.AddAnimation("downstop", 0, 0, 31, 66, 1, 0.1f);
            myPrincessTwo.Sprite.AddAnimation("down", 0, 0, 31, 66, 4, 0.1f);
            //starting animation
            myPrincessTwo.Sprite.CurrentAnimation = "rightstop";
            //Starting position
            myPrincessTwo.Position = new Vector2(600, 300);

            #endregion

            #region Setup FireBall

            fireBall = Content.Load<Texture2D>(@"Textures/FireBall");
            myFireBall = new MobileSprite(fireBall);
            myFireBall.Sprite.AddAnimation("fireleft", 0, 32, 32, 32, 3, 0.1f);
            myFireBall.Sprite.AddAnimation("fireright", 0, 64, 32, 32, 3, 0.1f);


            myFireBallTwo = new MobileSprite(fireBall);
            myFireBallTwo.Sprite.AddAnimation("fireleft", 0, 32, 32, 32, 3, 0.1f);
            myFireBallTwo.Sprite.AddAnimation("fireright", 0, 64, 32, 32, 3, 0.1f);

            #endregion

            #region Setup Health Bar

            mBar = Content.Load<Texture2D>(@"Textures/HealthBar");
            //The max health size equals the width of the health bar
            healthSize = mBar.Width;
            playerOneHealth = new HealthBar(mBar, (int)minDisplayX, (int)(maxDisplayY - mBar.Height), mBar.Width, mBar.Height, Color.Red);
            playerTwoHealth = new HealthBar(mBar, (int)(maxDisplayX - mBar.Width), (int)(maxDisplayY - mBar.Height), mBar.Width, mBar.Height, Color.Blue);

            #endregion

            //Set up Fog of War
            mFogOfWar = new FogOfWar(fogOfWar, 50, 50, 48, 48, 2, 5, 255, 25);
        }