Пример #1
0
        /* Player txt format:
         * *Player*
         * x
         * y
         * sprite-right[0] name
         * sprite-right[1] name
         * sprite-left[0] name
         * sprite-left[1] name
         * jumpr name
         * jumpl name
         * slash r frame 0 name
         * slash r frame 1 name
         * slash l frame 0 name
         * slash l frame 1 name
         * shot [0]
         * shot [1]
         * jump SOUND name
         * slash SOUND name
         * shot SOUND name
         */
        public static void setPlayer(string fPath, ContentManager content, /*SpriteBatch sprites,*/ Player player, int sWidth, int sHeight)
        {
            FileStream   file = new FileStream(fPath, FileMode.Open, FileAccess.Read);
            StreamReader sr   = new StreamReader(file);
            string       line;

            while (!sr.EndOfStream)
            {
                line = sr.ReadLine();
                if (line.Contains("*Player*"))
                {
                    //Read player position
                    float px = (float)Convert.ToDouble(sr.ReadLine());
                    player.position.X = px;

                    float py = (float)Convert.ToDouble(sr.ReadLine());
                    player.position.Y = sHeight - py;

                    //Read player sprites
                    Texture2D[] sprR = { content.Load <Texture2D>(sr.ReadLine()), content.Load <Texture2D>(sr.ReadLine()) };
                    Texture2D[] sprL = { content.Load <Texture2D>(sr.ReadLine()), content.Load <Texture2D>(sr.ReadLine()) };
                    //Texture2D sprR = content.Load<Texture2D>(sr.ReadLine());
                    //Texture2D sprL = content.Load<Texture2D>(sr.ReadLine());

                    Texture2D jumpR = content.Load <Texture2D>(sr.ReadLine());
                    Texture2D jumpL = content.Load <Texture2D>(sr.ReadLine());

                    Texture2D[] slashR = { content.Load <Texture2D>(sr.ReadLine()), content.Load <Texture2D>(sr.ReadLine()) };
                    Texture2D[] slashL = { content.Load <Texture2D>(sr.ReadLine()), content.Load <Texture2D>(sr.ReadLine()) };

                    Texture2D shotR = content.Load <Texture2D>(sr.ReadLine());
                    Texture2D shotL = content.Load <Texture2D>(sr.ReadLine());

                    //Read player sounds
                    SoundEffect jumpSound  = content.Load <SoundEffect>(sr.ReadLine());
                    SoundEffect slashSound = content.Load <SoundEffect>(sr.ReadLine());
                    SoundEffect shotSound  = content.Load <SoundEffect>(sr.ReadLine());

                    //set player sprites/sound
                    player.setBaseSprite(sprR, sprL);
                    player.setJumpSprite(jumpR, jumpL);
                    player.Jumpsound = jumpSound;
                    //set attack sprites/sound
                    SlashAttack s1 = new SlashAttack();
                    s1.setBaseSprite(slashR, slashL);
                    s1.Sound = slashSound;
                    ShotAttack s2 = new ShotAttack();
                    s2.setBaseSprite(shotR, shotL);
                    s2.Sound = shotSound;
                }
            }
            sr.Close();
            file.Close();
        }
Пример #2
0
 //Method for attack button
 public Psprite attackPressed()
 {
     //If not attacking generate attack based on current weapon
     if (!attacking)
     {
         if (cWeapon == Weapon.Pyrokinesis)
         {
             Psprite attack = new SlashAttack();
             if (facing == Facing.Right)
             {
                 attack.position.X = this.position.X + baseR[0].Width;
                 attack.position.Y = this.position.Y;
             }
             else
             {
                 //UPDATE FOR PROPER SCALING
                 attack.position.X = this.position.X - baseR[0].Width - 80;
                 attack.position.Y = this.position.Y;
             }
             attacking = true;
             return(attack);
         }
         else if (cWeapon == Weapon.EnergyShot)
         {
             Psprite attack = new ShotAttack();
             if (facing == Facing.Right)
             {
                 attack.position.X = this.position.X + baseR[0].Width;
                 attack.position.Y = this.position.Y;
                 attack.facing     = Facing.Right;
                 //attack.velocity.X = 225;
             }
             else
             {
                 //UPDATE FOR PROPER SCALING
                 attack.position.X = this.position.X - 40;
                 attack.position.Y = this.position.Y;
                 attack.facing     = Facing.Left;
                 //attack.velocity.X = -225;
             }
             attacking = true;
             return(attack);
         }
     }
     //otherwise return null
     return(null);
 }