public void DrawGUI(SpriteBatch spriteBatch, float DeltaTime, Player CurrentPlayer) { // Aim if (CurrentPlayer.LocalMouse != null) { float AimSize; if (CurrentPlayer.ControlledWorm.CurrentWeapon != null && CurrentPlayer.ControlledWorm.CurrentWeapon.Data.ChargeTime != 0) { AimSize = (CurrentPlayer.ControlledWorm.AccuracyPenalty + (1 - (CurrentPlayer.ControlledWorm.CurrentWeapon.TimeCharging / CurrentPlayer.ControlledWorm.CurrentWeapon.Data.ChargeTime)) * (CurrentPlayer.ControlledWorm.CurrentWeapon.Data.ChargeInaccuracyBonusUncharged) ) / 2.0f; } else { AimSize = (CurrentPlayer.ControlledWorm.AccuracyPenalty) / 2.0f; } AimSize = Math.Min(AimSize, 5); spriteBatch.Draw(ResourceManager.GUI.CursorTexture, new Vector2(CurrentPlayer.LocalMouse.PosX, CurrentPlayer.LocalMouse.PosY), new Rectangle(0, 0, ResourceManager.GUI.CursorTexture.Width, ResourceManager.GUI.CursorTexture.Height), CurrentPlayer.Color, 0, new Vector2(ResourceManager.GUI.CursorTexture.Width / 2, ResourceManager.GUI.CursorTexture.Height / 2), Math.Max(AimSize, 0.1f), SpriteEffects.None, 0); // Draw word coord in cursor position //spriteBatch.DrawString(ResourceManager.Arial, string.Format("{0}, {1}", CurrentPlayer.LocalMouse.PosX + Level.CameraPosition.X, CurrentPlayer.LocalMouse.PosY + Level.CameraPosition.Y), new Vector2(CurrentPlayer.LocalMouse.PosX, CurrentPlayer.LocalMouse.PosY), Color.Orange); } // Hp Bar int HpFillBarPercent = (int)(CurrentPlayer.ControlledWorm.LifeCurrent / CurrentPlayer.ControlledWorm.LifeMaximum * 100); spriteBatch.Draw(ResourceManager.GUI.Bar, new Rectangle((int)CurrentPlayer.LocalGUIPosition.X, (int)CurrentPlayer.LocalGUIPosition.Y, HpFillBarPercent, 8), CurrentPlayer.ColorWithAlpha); spriteBatch.Draw(ResourceManager.GUI.Bar, new Rectangle((int)CurrentPlayer.LocalGUIPosition.X + HpFillBarPercent, (int)CurrentPlayer.LocalGUIPosition.Y, 100 - HpFillBarPercent, 8), new Color(150, 150, 150, 150)); // Magazine capility if (CurrentPlayer.ControlledWorm.CurrentWeapon != null) { float MagazinePrecent; if (!CurrentPlayer.ControlledWorm.CurrentWeapon.Reloading) { MagazinePrecent = (CurrentPlayer.ControlledWorm.CurrentWeapon.Magazine * 1.0f / CurrentPlayer.ControlledWorm.CurrentWeapon.Data.MagazineSize * 100.0f); } else { MagazinePrecent = (CurrentPlayer.ControlledWorm.CurrentWeapon.TimeToReloadEnd / CurrentPlayer.ControlledWorm.CurrentWeapon.Data.ReloadTime * 100); MagazinePrecent = 100 - MagazinePrecent; } spriteBatch.Draw(ResourceManager.GUI.Bar, new Rectangle((int)(CurrentPlayer.LocalGUIPosition.X), (int)(CurrentPlayer.LocalGUIPosition.Y + 10), (int)MagazinePrecent, ResourceManager.GUI.Bar.Height), new Rectangle(0, 0, ResourceManager.GUI.Bar.Width, ResourceManager.GUI.Bar.Height), Color.Gray); spriteBatch.DrawString(ResourceManager.Arial, string.Format("{0} / {1}", CurrentPlayer.ControlledWorm.CurrentWeapon.Magazine, CurrentPlayer.ControlledWorm.CurrentWeapon.Data.MagazineSize), new Vector2(CurrentPlayer.LocalGUIPosition.X, CurrentPlayer.LocalGUIPosition.Y + 10), Color.Black); } // Movement device energy if (CurrentPlayer.ControlledWorm.MovementDevice != null) { int JetpackLength = (int)(CurrentPlayer.ControlledWorm.MovementDevice.Fuel / CurrentPlayer.ControlledWorm.MovementDevice.FuelMaximum * 100.0f); spriteBatch.Draw(ResourceManager.GUI.Bar, new Rectangle((int)CurrentPlayer.LocalGUIPosition.X, (int)CurrentPlayer.LocalGUIPosition.Y + 20, JetpackLength, 8), Color.Cyan); spriteBatch.Draw(ResourceManager.GUI.Bar, new Rectangle((int)CurrentPlayer.LocalGUIPosition.X + JetpackLength, (int)CurrentPlayer.LocalGUIPosition.Y + 20, 100 - JetpackLength, 8), new Color(150, 150, 150, 150)); } }
private int MaxID = 0; // #endregion Fields #region Methods public void AddPlayer(Player NewPlayer) { NewPlayer.ID = MaxID++; Players.Add(NewPlayer.ID, NewPlayer); NewPlayer.Color = PlayerColors[NewPlayer.ID]; NewPlayer.ControlledWorm = new Worm(); NewPlayer.NameOrigin = ResourceManager.NameFont.MeasureString(NewPlayer.Name) / 2; NewPlayer.NameOrigin.Y += 20; Level.InitWorm(NewPlayer.ControlledWorm); Console.WriteLine("{0} joined the game as {1}!", NewPlayer.Name, NewPlayer.Type.ToString()); if (NewPlayer.Type == Player.PlayerType.Local) { if (LocalPlayers < GUIPos.Length) { NewPlayer.LocalGUIPosition = GUIPos[LocalPlayers]; } LocalPlayers++; } }
public void DrawGUIBehindWorm(SpriteBatch spriteBatch, float DeltaTime, Player CurrentPlayer) { // Charging weapon if (CurrentPlayer.ControlledWorm.CurrentWeapon != null && CurrentPlayer.ControlledWorm.CurrentWeapon.Charging) { Vector2 WormScreenPosition = (CurrentPlayer.ControlledWorm.Position - CurrentPlayer.ControlledWorm.Level.CameraPosition); float Distance = (WormScreenPosition - new Vector2(CurrentPlayer.LocalMouse.PosX, CurrentPlayer.LocalMouse.PosY)).Length(); float Angle = CurrentPlayer.ControlledWorm.WeaponAngle + (float)Math.PI / 2; float ChargePercent = CurrentPlayer.ControlledWorm.CurrentWeapon.TimeCharging / CurrentPlayer.ControlledWorm.CurrentWeapon.Data.ChargeTime; spriteBatch.Draw(ResourceManager.GUI.WeaponChargeBar, WormScreenPosition, new Rectangle(0, 0, (int)(ResourceManager.GUI.WeaponChargeBar.Width), (int)(ChargePercent * ResourceManager.GUI.WeaponChargeBar.Height)), Color.White, Angle, new Vector2(ResourceManager.GUI.WeaponChargeBar.Width / 2.0f, 0), new Vector2(1, 1), SpriteEffects.None, 0); } }
public Level(ContentManager GameContent, Game game, string LevelNameString, string LevelDirectory, string[] PlayerStrings, bool AllWeaponEnabled) { LevelName = LevelNameString; EnabledWeapons = AllWeaponEnabled; Content = GameContent; Console.WriteLine("Initializing level"); game.MainWindow.MouseEventButtonDownLeft += new GameWindow.MouseEventHandler(PlayerManager.MouseClickDownLeft); game.MainWindow.MouseEventButtonUpLeft += new GameWindow.MouseEventHandler(PlayerManager.MouseClickUpLeft); game.MainWindow.MouseEventButtonDownRight += new GameWindow.MouseEventHandler(PlayerManager.MouseClickDownRight); game.MainWindow.MouseEventButtonUpRight += new GameWindow.MouseEventHandler(PlayerManager.MouseClickUpRight); game.MainWindow.MouseEventWheelUp += new GameWindow.MouseEventHandler(PlayerManager.MouseWheelUp); game.MainWindow.MouseEventWheelDown += new GameWindow.MouseEventHandler(PlayerManager.MouseWheelDown); ResourceManager.LoadResources(Content); LoadConfiguration(Path.Combine(LevelDirectory, LevelNameString)); using (FileStream fileStream = new FileStream(Path.Combine(new string[] { LevelDirectory, LevelNameString, "Level" } ) + ".png", FileMode.Open)) { Ground = Texture2D.FromStream(game.GraphicsDevice, fileStream); } GroundData = new Color[Ground.Width * Ground.Height]; Ground.GetData<Color>(GroundData); PlayerManager.Level = this; // Parse players foreach (var PlayerString in PlayerStrings) { if (string.IsNullOrEmpty(PlayerString)) continue; Player NewPlayer = new Player(PlayerManager); NewPlayer.Type = Player.PlayerType.Local; string[] Params = PlayerString.Substring(PlayerString.IndexOf('(') + 1, PlayerString.IndexOf(')') - PlayerString.IndexOf('(') - 1).Split(';'); foreach (var Param in Params) { if (Param.StartsWith("name=")) { NewPlayer.Name = Param.Substring(Param.IndexOf('=') + 1); } else if (Param.StartsWith("color=")) { string[] ColorString = Param.Substring(Param.IndexOf('=') + 1).Split(','); NewPlayer.Color = new Microsoft.Xna.Framework.Color(int.Parse(ColorString[0]), int.Parse(ColorString[1]), int.Parse(ColorString[2])); } else if (Param.StartsWith("mouse=")) { IntPtr MouseHandle = (IntPtr)int.Parse(Param.Substring(Param.IndexOf('=') + 1)); NewPlayer.LocalMouse = GameWindow.Instance.Mouses[MouseHandle]; } else if (Param.StartsWith("keyboard=")) { string KeyString = Param.Substring(Param.IndexOf('=') + 1); if (KeyString.StartsWith("W")) { NewPlayer.LocalMoveLeft = Keys.A; NewPlayer.LocalMoveRight = Keys.D; NewPlayer.LocalJump = Keys.W; NewPlayer.LocalShoot = Keys.R; } else if (KeyString.StartsWith("Up")) { NewPlayer.LocalMoveLeft = Keys.Left; NewPlayer.LocalMoveRight = Keys.Right; NewPlayer.LocalJump = Keys.Up; NewPlayer.LocalShoot = Keys.Down; } } else if (Param.StartsWith("weapons=")) { // NYI } } PlayerManager.AddPlayer(NewPlayer); } }