/// <summary> /// Removes a character from the game scene, usually when logging out /// </summary> /// <param name="player"></param> public void RemoveCharacter(PlayerCharacter player) { PlayerCharacterSprite toRemove = new PlayerCharacterSprite(_content, player, _camera); foreach (PlayerCharacterSprite sprite in _characterSprites) { if (player == sprite.PlayerCharacter) { toRemove = sprite; } } _characterSprites.Remove(toRemove); }
/// <summary> /// adds a character into the game scene. Expected when a player logs in to the game /// </summary> /// <param name="player">player to be added</param> public void AddCharacter(PlayerCharacter player) { PlayerCharacterSprite sprite = new PlayerCharacterSprite(_content, player, _camera) { IsVisible = true, Texture = _content.Load <Texture2D>("Images/Characters/base"), Width = 48, Height = 48, Size = new Point(48, 48), Location = new Point(player.X, player.Y), PlayerCharacter = player, InGame = true, }; sprite.HealthBar.SetHP(player.Health, player.MaxHealth); _characterSprites.Add(sprite); }
public override void Initialise(ContentManager content) { Texture2D baseCharacterTexture = content.Load <Texture2D>("Images/Characters/base"); Controls = new List <Control>(); for (int i = 0; i < 3; i++) { _charBox[i] = new Rect() { Name = "rectCharacterBorder" + i, BackColor = Color.White, Size = new Point(200, 200), BorderThickness = 2, BorderColor = Color.Red }; Controls.Add(_charBox[i]); } _charBox[1].Location = new Point(GameClient.WIDTH / 2 - (_charBox[1].Size.X / 2), GameClient.HEIGHT / 2 - (_charBox[1].Size.Y / 2) - 50); _charBox[0].Location = new Point(_charBox[1].Location.X - (_charBox[1].Size.X + (_charBox[1].Size.X / 2)), _charBox[1].Location.Y); _charBox[2].Location = new Point(_charBox[1].Location.X + (_charBox[1].Size.X + (_charBox[1].Size.X / 2)), _charBox[1].Location.Y); for (int i = 0; i < 3; i++) { _lblCharNames[i] = new Label() { Name = "lblCharName" + i, BackColor = Color.White, FrontColor = Color.Red, Font = GameClient.DEFAULT_FONT, Location = new Point(_charBox[i].Location.X + (_charBox[i].Size.X / 2), _charBox[i].Destination.Top - (int)GameClient.DEFAULT_FONT.MeasureString(" ").Y - 10), }; Controls.Add(_lblCharNames[i]); _lblCharLvls[i] = new Label() { Name = "lblCharLvl" + i, BackColor = Color.White, FrontColor = Color.Red, Font = GameClient.DEFAULT_FONT, Location = new Point(_charBox[i].Destination.Right, _charBox[i].Destination.Bottom - (int)GameClient.DEFAULT_FONT.MeasureString(" ").Y - 2), }; Controls.Add(_lblCharLvls[i]); _btnPlayChar[i] = new Button() { IsVisible = false, Name = "btnPlayChar" + i, BackColor = Color.Red, FrontColor = Color.White, Font = GameClient.GW2_FONT, Text = "Play", Size = new Point((int)GameClient.GW2_FONT.MeasureString("Create").X + 10, (int)GameClient.GW2_FONT.MeasureString("Create").Y + 10), Location = new Point(_charBox[i].Destination.Left + (_charBox[i].Size.X / 2) - ((int)GameClient.GW2_FONT.MeasureString("Create").X / 2), _charBox[i].Destination.Bottom + 10) }; _btnPlayChar[i].OnClick += btnPlayChar_OnClick; Controls.Add(_btnPlayChar[i]); _btnDeleteChar[i] = new Button() { IsVisible = false, Name = "btnDeleteChar" + i, BackColor = Color.Red, FrontColor = Color.White, Font = GameClient.GW2_FONT, Text = "Delete", Size = new Point((int)GameClient.GW2_FONT.MeasureString("Create").X + 10, (int)GameClient.GW2_FONT.MeasureString("Create").Y + 10), Location = new Point(_charBox[i].Destination.Left + (_charBox[i].Size.X / 2) - ((int)GameClient.GW2_FONT.MeasureString("Create").X / 2), _btnPlayChar[i].Destination.Bottom + 10) }; _btnDeleteChar[i].OnClick += btnDeleteChar_OnClick; Controls.Add(_btnDeleteChar[i]); _btnCreateChar[i] = new Button() { IsVisible = true, Name = "btnCreateChar" + i, BackColor = Color.Red, FrontColor = Color.White, Font = GameClient.GW2_FONT, Text = "Create", Size = new Point((int)GameClient.GW2_FONT.MeasureString("Create").X + 10, (int)GameClient.GW2_FONT.MeasureString("Create").Y + 10), Location = new Point(_charBox[i].Destination.Left + (_charBox[i].Size.X / 2) - ((int)GameClient.GW2_FONT.MeasureString("Create").X / 2), _charBox[i].Destination.Bottom + 10) }; _btnCreateChar[i].OnClick += btnCreateChar_OnClick; Controls.Add(_btnCreateChar[i]); _characterSprites[i] = new PlayerCharacterSprite(content, null, null) { IsVisible = true, Width = 48, Height = 48, Size = new Point(48, 48), Location = new Point(_charBox[i].Destination.Left + (_charBox[i].Size.X / 2) - 24, _charBox[i].Destination.Top + (_charBox[i].Size.Y / 2) - 24), Texture = baseCharacterTexture }; } }
public override void Initialise(ContentManager content) { //creating all the controls and adding them to the list to be updated/drawn. _characterSprite = new PlayerCharacterSprite(content, null, null); Texture2D baseCharacterTexture = content.Load <Texture2D>("Images/Characters/base"); Controls = new List <Control>(); _charBox = new Rect() { Name = "rectCharacterBorder", BackColor = Color.White, Size = new Point(200, 200), BorderThickness = 2, BorderColor = Color.Red }; Controls.Add(_charBox); _charBox.Location = new Point(GameClient.WIDTH / 2 - (_charBox.Size.X / 2), GameClient.HEIGHT / 2 - (_charBox.Size.Y / 2) - 50); _btnCreateChar = new Button() { IsVisible = true, Name = "btnCreateChar", BackColor = Color.Red, FrontColor = Color.White, Font = GameClient.GW2_FONT, Text = "Create", Size = new Point((int)GameClient.GW2_FONT.MeasureString("Create").X + 10, (int)GameClient.GW2_FONT.MeasureString("Create").Y + 10), Location = new Point(_charBox.Destination.Left + (_charBox.Size.X / 2) - ((int)GameClient.GW2_FONT.MeasureString("Create").X) - 10, _charBox.Destination.Bottom + 10) }; _btnCreateChar.OnClick += _btnCreateChar_OnClick; Controls.Add(_btnCreateChar); _btnBack = new Button() { IsVisible = true, Name = "btnBack", BackColor = Color.Red, FrontColor = Color.White, Font = GameClient.GW2_FONT, Text = "Back", Size = new Point((int)GameClient.GW2_FONT.MeasureString("Back").X + 10, (int)GameClient.GW2_FONT.MeasureString("Back").Y + 10), Location = new Point(_charBox.Destination.Left + (_charBox.Size.X / 2) + 10, _charBox.Destination.Bottom + 10) }; _btnBack.OnClick += _btnBack_OnClick; Controls.Add(_btnBack); _btnMale = new Button() { IsVisible = true, Name = "btnMale", BackColor = Color.Red, FrontColor = Color.White, Font = GameClient.GW2_FONT, Text = "Male", Size = new Point((int)GameClient.GW2_FONT.MeasureString("Male").X + 10, (int)GameClient.GW2_FONT.MeasureString("Male").Y + 10), Location = new Point(_charBox.Destination.Left + (_charBox.Size.X / 2) - ((int)GameClient.GW2_FONT.MeasureString("Male").X) - 20, _charBox.Destination.Top - 20 - (int)GameClient.GW2_FONT.MeasureString("Male").Y) }; _btnMale.OnClick += _btnMale_OnClick; Controls.Add(_btnMale); _btnFemale = new Button() { IsVisible = true, Name = "btnFemale", BackColor = Color.Red, FrontColor = Color.White, Font = GameClient.GW2_FONT, Text = "Female", Size = new Point((int)GameClient.GW2_FONT.MeasureString("Female").X, (int)GameClient.GW2_FONT.MeasureString("Female").Y + 10), Location = new Point(_charBox.Destination.Left + (_charBox.Size.X / 2) + 10, _charBox.Destination.Top - 20 - (int)GameClient.GW2_FONT.MeasureString("Female").Y) }; _btnFemale.OnClick += _btnFemale_OnClick; Controls.Add(_btnFemale); _characterSprite = new PlayerCharacterSprite(content, null, null) { IsVisible = true, Width = 48, Height = 48, Size = new Point(48, 48), Location = new Point(_charBox.Destination.Left + (_charBox.Size.X / 2) - 24, _charBox.Destination.Top + (_charBox.Size.Y / 2) - 24), Texture = baseCharacterTexture }; _txtCharacterName = new TextBox() { Name = "txtCharacterName", Text = "", BackColor = Color.White, FrontColor = Color.Black, BorderColor = Color.Black, BorderThickness = 2, CharacterLimit = 20, Font = GameClient.DEFAULT_FONT, Size = new Point(300, (int)GameClient.DEFAULT_FONT.MeasureString(" ").Y + 10), Location = new Point((GameClient.WIDTH / 2) - 150, _btnFemale.Destination.Top - ((int)GameClient.DEFAULT_FONT.MeasureString(" ").Y + 20)), SpacesAllowed = false, NumbersAllowed = true, SpecialCharactersAllowed = false }; _txtCharacterName.OnClick += Control_OnClick; Controls.Add(_txtCharacterName); _lblCharacter = new Label() { Name = "lblCharacter", BackColor = Color.White, FrontColor = Color.Red, Font = GameClient.DEFAULT_FONT, Text = "Name", Location = new Point(_txtCharacterName.Location.X, _txtCharacterName.Destination.Top - (int)GameClient.DEFAULT_FONT.MeasureString("Name").Y - 10), Size = new Point((int)GameClient.DEFAULT_FONT.MeasureString("Name").X, (int)GameClient.DEFAULT_FONT.MeasureString("Name").Y), IsVisible = true }; Controls.Add(_lblCharacter); _lblError = new Label() { Name = "lblError", BackColor = Color.White, FrontColor = Color.Red, Font = GameClient.DEFAULT_FONT_BOLD, Text = "", Location = new Point(GameClient.WIDTH / 2, _btnBack.Destination.Bottom + (int)GameClient.DEFAULT_FONT.MeasureString("Name").Y), Size = new Point((int)GameClient.DEFAULT_FONT.MeasureString("").X, (int)GameClient.DEFAULT_FONT.MeasureString("").Y), IsVisible = false }; Controls.Add(_lblError); playerCharacter = new PlayerCharacter() { Gender = Gender.MALE }; _characterSprite.PlayerCharacter = playerCharacter; }