public CharacterSelector(Dictionary <string, Texture2D> textures, Texture2D Background, Vector2 pos)
 {
     setupCharcaters(textures);
     CurrentSelected = characters.First().Value;
     _background     = Background;
     Selecting       = false;
 }
        private void setupCharcaters(Dictionary <string, Texture2D> textures)
        {
            Vector2 choicePos = new Vector2(10, 10);

            foreach (var item in textures)
            {
                Texture2D          tx = item.Value;
                CharacterSelection c  = new CharacterSelection(item.Value, choicePos);
                characters.Add(item.Key, c);
                choicePos += new Vector2(c.size.X + 10, 0);
            }
        }
        public void Update(Player p)
        {
            // if the Esc key is pressed then we are hanging up
            if (InputEngine.IsKeyPressed(Keys.Escape))
            {
                Selecting = !Selecting;
            }

            if (Selecting)
            {
                AudioManager.Play(ref _backingTrackPlayer, "backingTrack");
                // If selecting iterate over the characters in
                // the Dictionary and see if one is selected
                // Note we only update the characters to catch a
                // Mouse press if we are in selection mode
                foreach (var character in characters)
                {
                    character.Value.Update();
                    if (character.Value.Selected)
                    {
                        CurrentSelected = character.Value;
                    }
                    // Reset the character selected value as
                    // we have captured the selction in Current Selected
                    character.Value.Selected = false;
                }
                // When done set the player texture
                p.Image = CurrentSelected.Texture;
            }
            // If not selecting then check player
            else
            {
                if (_backingTrackPlayer != null)
                {
                    if (_backingTrackPlayer.State == SoundState.Playing)
                    {
                        _backingTrackPlayer.Stop();
                        _backingTrackPlayer = null;
                    }
                }
            }
        }
예제 #4
0
        // This static method must be called after the class is added as a game component
        public static void SetupCharacterMenu()
        {
            Vector2 pos = new Vector2(50, 50);
            // Draw 5 badges per row
            int ColCount = 5;

            foreach (KeyValuePair <string, CharacterSelection> entry in Characters)
            {
                entry.Value.Position = pos;
                if (ColCount-- > 1)
                {
                    pos += new Vector2(entry.Value.Texture.Width + 10, 0);
                }
                else
                {
                    ColCount = 5;
                    pos     += new Vector2(-pos.X + 50, entry.Value.Texture.Height + 10);
                }
            }
            current = Characters.First().Value;
        }
예제 #5
0
 public override void Update(GameTime gameTime)
 {
     if (InputEngine.IsKeyPressed(Keys.C))
     {
         HudUp = !HudUp;
     }
     if (HudUp)
     {
         foreach (KeyValuePair <string, CharacterSelection> entry in Characters)
         {
             entry.Value.Visible = true;
         }
         // Change up current Selection if another is selected
         var found = Characters.FirstOrDefault(c => c.Value.Selected && c.Value.Name != current.Name).Value;
         // if changed
         if (found != null)
         {
             // Find the player
             var p = Game.Components.FirstOrDefault(c => c.GetType() == typeof(Player));
             // Update the current Selection
             current.Selected = false;
             current          = found;
             // Update the player texture
             if (p != null)
             {
                 CharacterSelection projectile = new CharacterSelection(Game, current.Texture, Vector2.Zero, current.Name);
                 ((Player)p).Projectiles.Enqueue(projectile);
             }
         }
     }
     else
     {
         foreach (KeyValuePair <string, CharacterSelection> entry in Characters)
         {
             entry.Value.Visible = false;
         }
     }
     base.Update(gameTime);
 }