public override Vector2i Draw(MainGameState game) { Vector2i v = base.Draw(game); toPerformWhileNoPP.Add(() => TextureTools.BlitString(TextureTools.Font, 4, 5, new Vector2i(v.X - TextureTools.MeasureString(Name, 4, 5).X / 2, v.Y - 6), Name, game.Game.Screen)); return(v); }
private void DrawAmmo(Gun gun) { int realGunAmmo = (gun.Ammo - 1); float endPosition = MainClass.ScreenWidth / 2 + 15 * 2.5f; for (int j = 0; j < realGunAmmo / 10 + 1; ++j) { float startPosition; int yStart = MainClass.ScreenHeight - 19 - (gun.AmmoTexture.Height + 1) * (realGunAmmo / 10 - j + 1); if (j == 0) { startPosition = MainClass.ScreenWidth / 2 + 15 * 2.5f - (realGunAmmo % 10) * (gun.AmmoTexture.Width + 1); } else { startPosition = MainClass.ScreenWidth / 2 + 15 * 2.5f - 9 * (gun.AmmoTexture.Width + 1); } for (int i = (int)startPosition; i < endPosition; i += gun.AmmoTexture.Width + 1) { gun.AmmoTexture.Blit(new Rectanglei(0, 0, gun.AmmoTexture.Width, gun.AmmoTexture.Height), new Vector2i(i, yStart), Game.Game.Screen); } } if (gun.MagazinesLeft > 0) { string magString = "X" + gun.MagazinesLeft.ToString(); int yStartMagazineCounter = MainClass.ScreenHeight - 19 - (gun.AmmoTexture.Height + 1); float xStartMagazineCounter = MainClass.ScreenWidth / 2 + 15 * 2.5f - 9 - (magString.Length * 5) * (gun.AmmoTexture.Width + 1); TextureTools.BlitString(TextureTools.Font, 4, 5, new Vector2i((int)xStartMagazineCounter, yStartMagazineCounter), magString, Game.Game.Screen); } }
public ServerRequestState(MainClass game) : base(game) { Glfw.Enable(GlfwEnableCap.MouseCursor); Label ip = new Label("ENTER SERVER IP:", Game); ip.Position = new Vector2i(game.Screen.Width / 2 - TextureTools.MeasureString(ip.Text, 4, 5).X / 2, 10); Gui.Add(ip); Label username = new Label("ENTER USERNAME:"******"ENTER SERVER PORT:", Game); portLabel.Position = new Vector2i(game.Screen.Width / 2 - TextureTools.MeasureString(portLabel.Text, 4, 5).X / 2, 70); Gui.Add(portLabel); TextBox bSP = new TextBox(game); bSP.Position = new Vector2i(game.Screen.Width / 2 - bSP.Image.Width / 2, 20); #if DEBUG bSP.Text = "127.0.0.1"; #endif Gui.Add(bSP); TextBox bUname = new TextBox(game); bUname.Position = new Vector2i(game.Screen.Width / 2 - bSP.Image.Width / 2, 50); #if DEBUG bUname.Text = "ANTONIJN"; #endif Gui.Add(bUname); TextBox bPort = new TextBox(game); bPort.Position = new Vector2i(game.Screen.Width / 2 - bPort.Image.Width / 2, 80); #if DEBUG bPort.Text = "25565"; #endif Gui.Add(bPort); Button bMP = new Button(game, "JOIN"); bMP.Position = new Vector2i(game.Screen.Width / 2 - bMP.Image.Width / 2, 100); bMP.MouseClicked += (sender, e) => Game.CurrentGameState = new MainGameState(Game, bSP.Text, bUname.Text, int.Parse(bPort.Text)); Gui.Add(bMP); Button backButton = new Button(game, "BACK"); backButton.Position = new Vector2i(game.Screen.Width / 2 - backButton.Image.Width / 2, 120); backButton.MouseClicked += (sender, e) => Game.CurrentGameState = new MenuState(Game); Gui.Add(backButton); }
public override void Draw() { Game.Screen.Fill((x, y) => { if (x < 10 || y < 10 || x >= MainClass.ScreenWidth - 10 || y >= MainClass.ScreenHeight - 10) { return(0xFF0066ff); } return(0xFF00ccff); }); TextureTools.BlitString(TextureTools.Font, 4, 5, new Vector2i(20), new string(onScreen.ToArray()), Game.Screen); foreach (UIElement element in Gui) { element.Draw(); } }
public void LoadLevel(int level) { CheckPoint.ClearCheckPoints(); CurrentLevel = -level; if (level > 0 && level < 4) { Blocks.Clear(); Enemies.Clear(); Crates.Clear(); SpecialLocations.Clear(); HealthPacks.Clear(); Projectiles.Clear(); DroppedWeapons.Clear(); Texture2D tex = TextureTools.LoadTexture(IsServer, "level" + level + ".gif", new Rectanglei(0, 0, 64, 64)); BlockGrid = new Block[tex.Width, tex.Height]; WorldWidth = tex.Width; WorldHeight = tex.Height; List <Action> enemyAdditions = new List <Action>(); for (int x = 0; x < tex.Width; ++x) { int xReal = tex.Width - x - 1; for (int z = 0; z < tex.Height; ++z) { Color c = tex.Get(x, z); switch (c) { case 0xFFFF0000: Blocks.Add(new Block(xReal, z, TextureTools.TextureWall1)); BlockGrid [xReal, z] = Blocks.Last(); break; case 0xFF0000FF: Blocks.Add(new Block(xReal, z, TextureTools.TextureWall2)); BlockGrid [xReal, z] = Blocks.Last(); break; case 0xFFFFFF00: if (!MainGameState.IsServer) { Blocks.Add(new Door(xReal, z, TextureTools.TextureDoor1, TextureTools.TextureDoor1Upper, TextureTools.TextureDoor1Lower)); BlockGrid [xReal, z] = Blocks.Last(); } break; case 0xFF333333: { int xRealCopy = xReal; int zCopy = z; enemyAdditions.Add(() => { for (int i = 0; i < 2; ++i) { while (true) { float offsetX = ((float)MainClass.Random.NextDouble() - .5f); float offsetZ = ((float)MainClass.Random.NextDouble() - .5f); Enemy e = new Enemy(xRealCopy + offsetX, zCopy + offsetZ); if (BlockGrid [(int)e.X, (int)e.Z] == null) { Enemies.Add(e); break; } } } }); } break; case 0xFF666666: { int xRealCopy = xReal; int zCopy = z; enemyAdditions.Add(() => { for (int i = 0; i < 4; ++i) { while (true) { float offsetX = ((float)MainClass.Random.NextDouble() - .5f); float offsetZ = ((float)MainClass.Random.NextDouble() - .5f); Enemy e = new Enemy(xRealCopy + offsetX, zCopy + offsetZ); if (BlockGrid [(int)e.X, (int)e.Z] == null) { Enemies.Add(e); break; } } } }); } break; case 0xFF999999: { int xRealCopy = xReal; int zCopy = z; enemyAdditions.Add(() => { for (int i = 0; i < 6; ++i) { while (true) { float offsetX = ((float)MainClass.Random.NextDouble() - .5f); float offsetZ = ((float)MainClass.Random.NextDouble() - .5f); Enemy e = new Enemy(xRealCopy + offsetX, zCopy + offsetZ); if (BlockGrid [(int)e.X, (int)e.Z] == null) { Enemies.Add(e); break; } } } }); } break; case 0xFFCCCCCC: { int xRealCopy = xReal; int zCopy = z; enemyAdditions.Add(() => { for (int i = 0; i < 8; ++i) { while (true) { float offsetX = ((float)MainClass.Random.NextDouble() - .5f); float offsetZ = ((float)MainClass.Random.NextDouble() - .5f); Enemy e = new Enemy(xRealCopy + offsetX, zCopy + offsetZ); if (BlockGrid [(int)e.X, (int)e.Z] == null) { Enemies.Add(e); break; } } } }); } break; case 0xFFFFFFFF: if (!IsServer) { if (CurrentPlayer == null) { CurrentPlayer = new Player(this, xReal, z, "LOCAL"); } else { CurrentPlayer.Position = new Vector2(xReal, z); } } Spawn = new Vector2i(xReal, z); break; case 0xFF00FF00: Crates.Add(new AmmoCrate(xReal + .5f, z + .5f)); break; case 0xFFFF00FF: HealthPacks.Add(new HealthPack(xReal + .5f, z + .5f)); break; case 0xFF00FFFF: if (!MainGameState.IsServer) { Projectiles.Add(new CheckPoint(xReal + .5f, z + .5f)); } break; case 0xFF808080: SpecialLocations.Add(new Vector2i(xReal, z)); break; } } } foreach (Action a in enemyAdditions) { a(); } } else { CurrentLevel = short.MinValue; Game.CurrentGameState = new PlotScreen(Game, "So we meet at last.", (sender, e) => { Game.CurrentGameState = this; Glfw.Disable(GlfwEnableCap.MouseCursor); }, (sender, e) => { Game.CurrentGameState = new PlotScreen(Game, "I have a confession to make now.\n\n" + "The guys in suits, those weren't the bad guys. Or at least, you wouldn't have thought they were the bad guys.\n" + "You see, you just killed a whole lot of your own people. Yes, you did.\n\n" + "You had the key of that first room you were in in your pocket, but you couldn't remember after some of my people drugged you.", (sender1, e1) => { Game.CurrentGameState = this; Glfw.Disable(GlfwEnableCap.MouseCursor); }, (sender1, e1) => { Game.CurrentGameState = new PlotScreen(Game, "I'm the bad guy. Bye bye.", (sender2, e2) => { Game.CurrentGameState = this; Glfw.Disable(GlfwEnableCap.MouseCursor); }, (sender2, e2) => { Game.CurrentGameState = new DeathState(this, false); }); }); }); } }
public override void Draw() { CurrentPlayer.AtCrossHair = null; // clear screen Game.Screen.Fill((x, y) => { float xFromCenter = x - MainClass.ScreenWidth / 2f; float yFromCenter = y - MainClass.ScreenHeight / 2f; float xModelSpace = xFromCenter / yFromCenter * 0.5f; float zModelSpace = Math.Abs(1f / yFromCenter) * (MainClass.ScreenHeight / 2f); if (zModelSpace >= 0f && zModelSpace < WallsDisappearAt) { float xModelSpaceBackup = xModelSpace; if (yFromCenter < 0) { // ceiling xModelSpace = CurrentPlayer.CosWorldRotation * xModelSpace + CurrentPlayer.SinWorldRotation * zModelSpace; zModelSpace = CurrentPlayer.SinWorldRotation * xModelSpaceBackup - CurrentPlayer.CosWorldRotation * zModelSpace; xModelSpace -= CurrentPlayer.X; zModelSpace -= CurrentPlayer.Z; float s = MakePositive(zModelSpace % 1f); float t = MakePositive(xModelSpace % 1f); return(TextureTools.TextureCeiling2.Get((int)(s * 16), (int)(t * 16))); } { // floor xModelSpace = CurrentPlayer.CosWorldRotation * xModelSpace - CurrentPlayer.SinWorldRotation * zModelSpace; zModelSpace = CurrentPlayer.SinWorldRotation * xModelSpaceBackup + CurrentPlayer.CosWorldRotation * zModelSpace; xModelSpace += CurrentPlayer.X; zModelSpace += CurrentPlayer.Z; float s = MakePositive(zModelSpace % 1f); float t = MakePositive(xModelSpace % 1f); return(TextureTools.TextureFloor1.Get((int)(s * 16), (int)(t * 16))); } } return(0xFF000000); }); // clear zbuffer Game.ZBuffer.Fill((x, y) => { float yFromCenter = y - MainClass.ScreenHeight / 2f; float z = 1f - (1f / Math.Abs(yFromCenter)); if (z < 0f) { z = 0f; } return(z); }); lock (MultiplayerClient.WorldMutex) { foreach (Block b in Blocks) { b.Draw(this); } } foreach (Enemy e in Enemies) { e.Draw(this); } foreach (Projectile p in Projectiles) { p.Draw(this); } foreach (DroppedWeapon dw in DroppedWeapons) { dw.Draw(this); } lock (MultiplayerClient.PlayerMutex) { foreach (Player p in OtherPlayers) { p.Draw(this); } } foreach (AmmoCrate crate in Crates.Where(c => c.Enabled)) { crate.Draw(this); } foreach (HealthPack hp in HealthPacks.Where(h => h.Enabled)) { hp.Draw(this); } PostProcess(); lock (ChatMutex) { int chatLine = Game.Screen.Height - 50; foreach (Tuple <DateTime, string> chat in Chat) { TextureTools.BlitString(TextureTools.Font, 4, 5, new Vector2i(10, chatLine), chat.Item2, Game.Screen); chatLine -= 6; } Chat = Chat.Where(ch => DateTime.Now - ch.Item1 < new TimeSpan(0, 0, 10)).Take(10).ToList(); } TextureTools.BlitString(TextureTools.Font, 4, 5, new Vector2i(10, Game.Screen.Height - 50 + 6), new string(onScreen.ToArray()), Game.Screen); if (!IsMultiplayer) { TextureTools.BlitString(TextureTools.Font, 4, 5, new Vector2i(1), "CHECKPOINTS LEFT: " + Projectiles.Count(x => x is CheckPoint), Game.Screen); } CurrentPlayer.Draw(); }
public override void Draw() { TextureTools.BlitString(TextureTools.Font, 4, 5, Position, Text, Game.Screen); }
public override void Draw() { base.Draw(); TextureTools.BlitString(TextureTools.Font, 4, 5, Position + new Vector2i(Image.Width / 2, Image.Height / 2) - TextureTools.MeasureString(Text, 4, 5) / 2, Text, Game.Screen); }
public AreYouSure(MainGameState maingame) : base(maingame.Game) { Glfw.Enable(GlfwEnableCap.MouseCursor); Label deadLabel = new Label("ARE YOU SURE YOU WANT TO QUIT?", Game); deadLabel.Position = new Vector2i(Game.Screen.Width, Game.Screen.Height) / 2 - TextureTools.MeasureString(deadLabel.Text, 4, 5) / 2; Gui.Add(deadLabel); Button yes = new Button(Game, "YES"); yes.Position = new Vector2i(Game.Screen.Width / 2 - yes.Image.Width - 15, Game.Screen.Height / 2 + 30); yes.MouseClicked += (sender, e) => { Game.CurrentGameState = new MenuState(Game); }; Gui.Add(yes); Button no = new Button(Game, "NO"); no.Position = new Vector2i(Game.Screen.Width / 2 + 15, Game.Screen.Height / 2 + 30); no.MouseClicked += (sender, e) => { Game.CurrentGameState = maingame; Glfw.Disable(GlfwEnableCap.MouseCursor); }; Gui.Add(no); mainGame = maingame; }
public DeathState(MainGameState game, bool respawn) : base(game.Game) { Glfw.Enable(GlfwEnableCap.MouseCursor); Label deadLabel = new Label("YOU DEADED", Game); deadLabel.Position = new Vector2i(Game.Screen.Width, Game.Screen.Height) / 2 - TextureTools.MeasureString(deadLabel.Text, 4, 5) / 2; Gui.Add(deadLabel); if (respawn) { Button bSP = new Button(Game, "RESPAWN"); bSP.Position = new Vector2i(Game.Screen.Width / 2 - bSP.Image.Width / 2, Game.Screen.Height / 2 + 30); bSP.MouseClicked += (sender, e) => { CheckPoint.Restore(game); Game.CurrentGameState = game; Glfw.Disable(GlfwEnableCap.MouseCursor); }; Gui.Add(bSP); } else { Button bSP = new Button(Game, "QUIT"); bSP.Position = new Vector2i(Game.Screen.Width / 2 - bSP.Image.Width / 2, Game.Screen.Height / 2 + 30); bSP.MouseClicked += (sender, e) => { Game.CurrentGameState = new MenuState(Game); }; Gui.Add(bSP); } }