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); } }
public override void Update(MainGameState game, float time) { float xPlayerDiff = game.CurrentPlayer.X - X; float zPlayerDiff = game.CurrentPlayer.Z - Z; if (xPlayerDiff * xPlayerDiff + zPlayerDiff * zPlayerDiff < 1f) { last = this; ShouldBeRemoved = true; Sounds.PickupCrate.Play(); CopyWorld(game); } }
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 static void ClearCheckPoints() { last = null; }