public void Draw() { if (player.checkMapDelay > 0 || levelComplete) { FontHandler.AddText(new Text(levelCaptionTop, "levelcaptiontop", Program.cameraPosition - new Vector2(80, 80) + new Vector2(400, 25), 0.8f)); FontHandler.AddText(new Text(levelCaptionBottom, "levelcaptionbottom", Program.cameraPosition - new Vector2(80, 80) + new Vector2(400, 575), 0.8f)); } else { if (!player.dead) { FontHandler.AddText(new Text(levelCaptionTop, "levelcaptiontop", new Vector2(400, 25), 0.8f)); FontHandler.AddText(new Text(levelCaptionBottom, "levelcaptionbottom", new Vector2(400, 575), 0.8f)); } } gameGrid.Draw(); foreach (GameObject g in gameGrid.Grid) { if (g != null) { g.color = new Color4(ambient, ambient, ambient, 1); } } foreach (GameObject g in collisionGameGrid.Grid) { if (g != null) { g.color = new Color4(ambient, ambient, ambient, 1); } } if (!player.dead) { player.Draw(); } EnemyList.ForEach(x => x.Draw()); if (!player.dead) { projectileList.ForEach(x => x.Draw()); particleList.ForEach(x => x.Draw()); lightList.ForEach(x => x.Render()); } collisionGameGrid.Draw(); if (!player.dead) { tileFogList.ForEach(x => x.Draw()); } if (player.dead) { player.Draw(); } if (terminalGame != null && terminalGame.active) { terminalGame.Draw(); } }
public void Build(Window window) { Light.CollisionGrids = new List <GameGrid>(); Light.CollisionGrids.Add(collisionGameGrid); foreach (GameObject g in gameGrid.Grid) { if (g != null) { tileFogList.Add(new TileFog(g.Position, g)); } } foreach (GameObject g in collisionGameGrid.Grid) { if (g != null) { tileFogList.Add(new TileFog(g.Position, g)); } } int j = 0; lightList.ForEach(x => { j++; x.Restart(); string dots = string.Empty; for (int i = 0; i < j; i++) { dots += "."; } window.PrepDraw(); FontHandler.AddText(new Text("LOADING NEXT LEVEL...", "loading", new Vector2(400, 300), 1f)); FontHandler.AddText(new Text("MAKING CYBERPUNK STUFF", "loading2", new Vector2(400, 350), 0.8f)); FontHandler.AddText(new Text(dots, "loading3", new Vector2(400, 400), 0.8f)); FontHandler.Draw(); window.EndDraw(); FontHandler.TextList = new List <Text>(); }); window.PrepDraw(); FontHandler.AddText(new Text("LOADING NEXT LEVEL...", "loading", new Vector2(400, 300), 1f)); FontHandler.AddText(new Text("ADDING CYBERNESS...", "loading2", new Vector2(400, 350), 0.8f)); FontHandler.Draw(); window.EndDraw(); FontHandler.TextList = new List <Text>(); Program.cameraPosition = new Vector2(-800, 0); player.checkMapDelay = 2.5f; }
public static World LoadMap(string file, Window2D window) { World w = new World(); List <Light> lightBuffer = new List <Light>(); StreamReader sr = new StreamReader(GameUtils.GetAppPath() + file); w.Construct(int.Parse(sr.ReadLine()), int.Parse(sr.ReadLine())); w.levelCaptionTop = sr.ReadLine(); w.levelCaptionBottom = sr.ReadLine(); string line = string.Empty; int lightcount = 0; while ((line = sr.ReadLine()) != "END") { if (line.StartsWith("light")) { lightcount++; string[] split = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); lightBuffer.Add(new Light(new Vector2(0, 0), new Color4(byte.Parse(split[1]), byte.Parse(split[2]), byte.Parse(split[3]), 255), int.Parse(split[4]), split[5] == "true")); lightBuffer[lightBuffer.Count - 1].isActivated = split[6] == "true"; if (split.Length > 7) { lightBuffer[lightBuffer.Count - 1].width = int.Parse(split[7]); lightBuffer[lightBuffer.Count - 1].direction = int.Parse(split[8]); lightBuffer[lightBuffer.Count - 1].rotationSpeed = int.Parse(split[9]); } FontHandler.AddText(new Text("LOADING NEXT LEVEL...", "loading", new Vector2(400, 300), 1f)); string dots = string.Empty; for (int i = 0; i < lightcount; i++) { dots += "."; } FontHandler.AddText(new Text("PLUGGING IN THE LIGHTS", "loading2", new Vector2(400, 350), 0.8f)); FontHandler.AddText(new Text(dots, "loading3", new Vector2(400, 400), 0.8f)); window.PrepDraw(); FontHandler.Draw(); window.EndDraw(); FontHandler.TextList = new List <Text>(); } } int x = 0, y = 0; while ((line = sr.ReadLine()) != "END" && line != null) { for (x = 0; x < line.Length; x++) { if (char.IsNumber(line[x])) { byte nr = byte.Parse(line[x].ToString()); Light l = lightBuffer[nr]; l.Position = new Vector2(x * 32, y * 32); w.lightList.Add(l); w.gameGrid.AddTile("floor", x, y); continue; } switch (line[x]) { case '*': w.collisionGameGrid.AddTile("wall", x, y); break; case 'V': w.gameGrid.AddTile("floorv", x, y); w.collisionGameGrid.AddTile("door1", x, y); break; case 'H': w.gameGrid.AddTile("floorh", x, y); w.collisionGameGrid.AddTile("door2", x, y); break; case 'P': w.gameGrid.AddTile("floor", x, y); w.player = new Player("player", new Vector2(x * 32, y * 32)); break; case 'B': w.gameGrid.AddTile("rail", x, y); Light yellow2 = new Light(new Vector2(x * 32, y * 32), Color4.Yellow, 16f, false); yellow2.anglestep = 36f; w.lightList.Add(yellow2); w.EnemyList.Add(new Enemy(new Vector2(x * 32, y * 32), w, true)); w.EnemyList[w.EnemyList.Count - 1].Rotation = 0f; break; case 'W': w.gameGrid.AddTile("floor", x, y); w.EnemyList.Add(new Enemy(new Vector2(x * 32, y * 32), w)); w.EnemyList[w.EnemyList.Count - 1].Rotation = 0f; break; case 'A': w.gameGrid.AddTile("floor", x, y); w.EnemyList.Add(new Enemy(new Vector2(x * 32, y * 32), w)); w.EnemyList[w.EnemyList.Count - 1].Rotation = -90f; break; case 'S': w.gameGrid.AddTile("floor", x, y); w.EnemyList.Add(new Enemy(new Vector2(x * 32, y * 32), w)); w.EnemyList[w.EnemyList.Count - 1].Rotation = 180f; break; case 'D': w.gameGrid.AddTile("floor", x, y); w.EnemyList.Add(new Enemy(new Vector2(x * 32, y * 32), w)); w.EnemyList[w.EnemyList.Count - 1].Rotation = 90f; break; case 'T': w.collisionGameGrid.AddTile("terminal", x, y); w.lightList.Add(new Light(new Vector2((x - 1) * 32, y * 32), Color4.Green, 25f, false)); w.lightList[w.lightList.Count - 1].anglestep = 36f; w.lightList.Add(new Light(new Vector2((x + 1) * 32, y * 32), Color4.Green, 25f, false)); w.lightList[w.lightList.Count - 1].anglestep = 36f; w.lightList.Add(new Light(new Vector2(x * 32, (y - 1) * 32), Color4.Green, 25f, false)); w.lightList[w.lightList.Count - 1].anglestep = 36f; w.lightList.Add(new Light(new Vector2(x * 32, (y + 1) * 32), Color4.Green, 25f, false)); w.lightList[w.lightList.Count - 1].anglestep = 36f; break; case 'O': w.gameGrid.AddTile("off", x, y); Light red = new Light(new Vector2(x * 32, y * 32), Color4.Red, 25f, false); red.anglestep = 36f; w.lightList.Add(red); break; case 'R': w.gameGrid.AddTile("rail", x, y); Light yellow = new Light(new Vector2(x * 32, y * 32), Color4.Yellow, 16f, false); yellow.anglestep = 36f; w.lightList.Add(yellow); break; case 'M': w.collisionGameGrid.AddTile("mask", x, y); break; case 'E': w.gameGrid.AddTile("floor", x, y); Light red2 = new Light(new Vector2(x * 32, y * 32), Color4.Red, 50f, false); red2.anglestep = 36f; red2.isActivated = true; Light green = new Light(new Vector2(x * 32, y * 32), Color4.Green, 50f, false); green.anglestep = 36f; green.isActivated = false; w.lightList.Add(green); w.lightList.Add(red2); break; case ' ': w.gameGrid.AddTile("floor", x, y); break; default: Console.WriteLine("Unrecognized block in map. wtf?"); break; } } y++; } w.Build(window); return(w); }
public void Update(World world, float delta) { if (terminalScreen.Width < 677) { terminalScreen.Width += 8f * 1.97953216374f; } if (terminalScreen.Height < 342) { terminalScreen.Height += 8f; } if (terminalScreen.Width >= 677 && terminalScreen.Height >= 342) { if (!playedsound) { Program.hacking.Play(); playedsound = true; t1 = DateTime.Now; } time += delta * 3.125f; state = (55 / maxTime) * time; float ypos = 40f; if (state > 1) { FontHandler.AddText(new Text(" ONACTIVATE", "line1", terminalScreen.Position - new Vector2(250, ypos), 0.5f, true)); } ypos -= 20; if (state > 2) { FontHandler.AddText(new Text(" [", "line2", terminalScreen.Position - new Vector2(250, ypos), 0.5f, true)); } ypos -= 20; if (state > 3) { FontHandler.AddText(new Text(" SET-POWER-OUTPUT [ DIRECTIONS.ALL, TRUE ]:", "line3", terminalScreen.Position - new Vector2(250, ypos), 0.5f, true)); } ypos -= 20; if (state > 4) { FontHandler.AddText(new Text(" SET-EXPLODER-DEVICE [ STATE-OFF ]:", "line4", terminalScreen.Position - new Vector2(250, ypos), 0.5f, true)); } ypos -= 20; if (state > 5) { FontHandler.AddText(new Text(" ACTIVATE [ BACON-GENERATOR-9000 ]:", "line5", terminalScreen.Position - new Vector2(250, ypos), 0.5f, true)); } ypos -= 20; if (state > 6) { FontHandler.AddText(new Text(" GOOGLE [ KITTENS ]:", "line6", terminalScreen.Position - new Vector2(250, ypos), 0.5f, true)); } ypos -= 20; if (state > 7) { FontHandler.AddText(new Text(" YAHOO [ NOTHING ]:", "line7", terminalScreen.Position - new Vector2(250, ypos), 0.5f, true)); } ypos -= 20; if (state > 8) { FontHandler.AddText(new Text(" SYSTEM-OUT-PRINTLINE [ CYBERPUNK IS AWESOME ]:", "line8", terminalScreen.Position - new Vector2(250, ypos), 0.5f, true)); } ypos -= 20; if (state > 9) { FontHandler.AddText(new Text(" SYSTEM-OUT-PRINTLINE [ GAMEJAMS ARE AWESOME ]:", "line9", terminalScreen.Position - new Vector2(250, ypos), 0.5f, true)); } ypos -= 20; if (state > 10) { FontHandler.AddText(new Text(" WHILE [ TRUE ] DO", "line10", terminalScreen.Position - new Vector2(250, ypos), 0.5f, true)); } ypos -= 20; if (state > 11) { FontHandler.AddText(new Text(" [", "line11", terminalScreen.Position - new Vector2(250, ypos), 0.5f, true)); } ypos -= 20; if (state > 12) { FontHandler.AddText(new Text(" SYSTEM-OUT-PRINTLINE [ YOU ARE AWESOME ]:", "line12", terminalScreen.Position - new Vector2(250, ypos), 0.5f, true)); } ypos -= 20; if (state > 13) { FontHandler.AddText(new Text(" ]", "line13", terminalScreen.Position - new Vector2(250, ypos), 0.5f, true)); } ypos -= 20; if (state > 14) { FontHandler.AddText(new Text(" ]", "line14", terminalScreen.Position - new Vector2(250, ypos), 0.5f, true)); } ypos -= 20; if (state > 15) { FontHandler.AddText(new Text(" TERMINAL: SYSTEM UNLOCKED", "line15", terminalScreen.Position - new Vector2(250, ypos), 0.5f, true)); } ypos -= 20; if (state > 20) { Console.WriteLine((DateTime.Now - t1).TotalMilliseconds); Player.activateBlock(sender, world); this.active = false; FontHandler.TextList = new List <Text>(); } } }
public void Update(float delta, World world) { if (checkMapDelay > 0) { checkMapDelay -= delta; } if (health < maxHealth) { if (!dead) { health += 0.25f; } else { health += 2.5f; } } if (health <= 0) { dead = true; } if (dead) { FontHandler.TextList = new List <Text>(); FontHandler.AddText(new Text("YOU MADE MY DAY, CYBERPUNK", "dead", new Vector2(420, 250), 0.75f)); FontHandler.AddText(new Text("TRY AGAIN", "dead2", new Vector2(400, 350), 0.75f)); FontHandler.AddText(new Text("PRESS SPACE", "dead3", new Vector2(400, 450), 0.75f)); if (world.ambient > 0) { world.ambient -= 0.01f; } this.Rotation = 0; if (GameUtils.GetDistance(Position, new Vector2(400, 300) - Program.cameraPosition) > 2) { Position = GameUtils.MoveTowards(Position, new Vector2(400, 300) - Program.cameraPosition, 150 * delta); } else { Position = new Vector2(400, 300) - Program.cameraPosition; } if (Input.GetState(0).Keyboard[Key.Space] && !Input.GetState(1).Keyboard[Key.Space]) { world.restartMap = true; } } this.world = world; if (IsKeyPressed('E')) { foreach (GameObject g in world.collisionGameGrid.Grid) { if (g != null) { if (g.textureName == "terminal" && GameUtils.GetDistance(g.Position, Position) < 40) { world.terminalGame = new TerminalGame(g); world.inTerminalGame = true; } } } } if (!dead) { this.Rotation = (float)GameUtils.GetRotation(this.Position, Input.GetState(0).MousePosition - new Vector2(80, 80)) + 90; Vector2 bufferposition = Position; if (Input.GetState(0).Mouse.LeftButton&& !Input.GetState(1).Mouse.LeftButton) { float spread = 2.5f; world.projectileList.Add(new Projectile(Position, Rotation + (-spread + ((float)new Random().NextDouble() * (spread * 2))), 10f, 1200, 0)); } if (Input.GetState(0).Keyboard['W']) { //this.sprite.Position = GameUtils.MoveTowards(this.sprite.Position, Input.GetState(0).MousePosition - new Vector2(80, 80), 150 * delta); bufferposition += GameUtils.MoveAlongAngle(-90, Position, 450 * delta) - Position; } if (Input.GetState(0).Keyboard['S']) { //this.sprite.Position = GameUtils.MoveTowards(this.sprite.Position, Input.GetState(0).MousePosition - new Vector2(80, 80), -(150 * delta)); bufferposition += GameUtils.MoveAlongAngle(90, Position, 450 * delta) - Position; } if (Input.GetState(0).Keyboard['A']) { bufferposition += GameUtils.MoveAlongAngle(180, Position, 450 * delta) - Position; } if (Input.GetState(0).Keyboard['D']) { bufferposition += GameUtils.MoveAlongAngle(0, Position, 450 * delta) - Position; } if (GameUtils.GetDistance(Position, bufferposition) < 16) { if (!CheckCollision(bufferposition, world)) { Position = bufferposition; } else { if (!CheckCollision(new Vector2(bufferposition.X, Position.Y), world)) { Position = new Vector2(bufferposition.X, Position.Y); } else { if (!CheckCollision(new Vector2(Position.X, bufferposition.Y), world)) { Position = new Vector2(Position.X, bufferposition.Y); } else { } } } } } if (world.levelComplete) { Program.cameraPosition = GameUtils.MoveTowards(Program.cameraPosition, new Vector2(880, 80), (float)GameUtils.GetDistance(Program.cameraPosition, new Vector2(79, 80)) / 25f); if (world.ambient > 0) { world.ambient -= 0.01f; } foreach (TileFog t in world.tileFogList) { if (t.alpha > 0) { t.alpha -= 0.01f; } } FontHandler.TextList = new List <Text>(); FontHandler.AddText(new Text("LEVEL COMPLETE", "yay!", new Vector2(400, 300), 1f)); if ((float)GameUtils.GetDistance(Program.cameraPosition, new Vector2(880, 80)) < 32) { world.incrementMap = true; } } if (checkMapDelay > 2.5f) { checkMapDelay = 2.5f; } if (!dead && checkMapDelay <= 0 && !world.incrementMap && !world.levelComplete) { foreach (GameObject g2 in world.gameGrid.Grid) { if (g2 != null && GameObject.Contains(Position, g2)) { return; } } world.levelComplete = true; Program.complete.Play(); } }
static void Main(string[] args) { Window2D window = new Window2D(800, 600, true, "Infiltration - Cyberpunk GameJam - By Metaldemon", 800, 600); ContentManager.LoadTexture(GetAppPath() + "\\content\\Floor.png", "floor"); ContentManager.LoadTexture(GetAppPath() + "\\content\\Wall.png", "wall"); ContentManager.LoadTexture(GetAppPath() + "\\content\\Guy.png", "player"); ContentManager.LoadTexture(GetAppPath() + "\\content\\Turret.png", "turret"); ContentManager.LoadTexture(GetAppPath() + "\\content\\Particle.png", "particle"); ContentManager.LoadTexture(GetAppPath() + "\\content\\Terminal.png", "terminal"); ContentManager.LoadTexture(GetAppPath() + "\\content\\FloorOff.png", "off"); ContentManager.LoadTexture(GetAppPath() + "\\content\\FloorOn.png", "on"); ContentManager.LoadTexture(GetAppPath() + "\\content\\Door1.png", "door1"); ContentManager.LoadTexture(GetAppPath() + "\\content\\Door2.png", "door2"); ContentManager.LoadTexture(GetAppPath() + "\\content\\font.png", "font"); ContentManager.LoadTexture(GetAppPath() + "\\content\\terminalscreen.png", "terminalscreen"); ContentManager.LoadTexture(GetAppPath() + "\\content\\FloorV.png", "floorv"); ContentManager.LoadTexture(GetAppPath() + "\\content\\FloorH.png", "floorh"); ContentManager.LoadTexture(GetAppPath() + "\\content\\Maskwall.png", "mask"); ContentManager.LoadTexture(GetAppPath() + "\\content\\Rail.png", "rail"); fire = new Sound(GetAppPath() + "\\content\\audio\\fire.wav"); ouch = new Sound(GetAppPath() + "\\content\\audio\\ouch.wav"); boom = new Sound(GetAppPath() + "\\content\\audio\\boom.wav"); hacking = new Sound(GetAppPath() + "\\content\\audio\\hacking.wav"); complete = new Sound(GetAppPath() + "\\content\\audio\\complete.wav"); hit = new Sound(GetAppPath() + "\\content\\audio\\hit.wav"); fire.Gain = ouch.Gain = boom.Gain = hacking.Gain = complete.Gain = hit.Gain = 0.5f; if (music == null) { FontHandler.AddText(new Text("Loading game...", "loading", new Vector2(400, 300), 1f)); window.PrepDraw(); FontHandler.Draw(); window.EndDraw(); FontHandler.TextList = new List <Text>(); new Thread(_LoadAudio).Start(); } restart: World world = Loader.LoadMap("\\content\\maps\\map00.txt", window); world.map = 00; double totalTime = 0.0; double delta = 0.0; while (window.IsOpen) { Glfw.SwapInterval(false); totalTime += Glfw.GetTime(); delta = (float)Glfw.GetTime(); Glfw.SetTime(0.0); world.Update((float)delta / 3); if (music != null && music.Gain < 0.6f) { music.Gain += 0.0001f; } window.PrepDraw(); if (world.incrementMap || world.restartMap) { int newmap = world.map; if (world.incrementMap) { newmap++; } world.map = newmap; world.incrementMap = false; if (newmap == 15) { while (window.IsOpen) { int ypos = 100; FontHandler.AddText(new Text("THE WINNER IS YOU", "yay1", new Vector2(400, ypos), 0.8f)); ypos += 75; FontHandler.AddText(new Text("YOU COMPLETED THE GAME IN:", "yay2", new Vector2(400, ypos), 0.8f)); ypos += 75; FontHandler.AddText(new Text(Math.Round(totalTime, 2) + " SECONDS", "yay3", new Vector2(400, ypos), 0.8f)); ypos += 75; FontHandler.AddText(new Text("THANK YOU FOR PLAYING THIS GAME", "yay4", new Vector2(400, ypos), 0.8f)); ypos += 75; FontHandler.AddText(new Text("NOW PLAY OTHER CYBERPUNK GAMEJAM GAMES", "yay5", new Vector2(400, ypos), 0.8f)); ypos += 75; FontHandler.AddText(new Text("-METALDEMON", "yay6", new Vector2(400, ypos), 0.8f)); ypos += 75; FontHandler.AddText(new Text("PS: PRESS SPACE TO PLAY AGAIN", "yay7", new Vector2(400, ypos), 0.8f)); ypos += 75; window.PrepDraw(); FontHandler.Draw(); window.EndDraw(); FontHandler.TextList = new List <Text>(); if (Input.GetState(0).Keyboard[Key.Space]) { goto restart; } } Environment.Exit(0); } if (newmap < 10) { world = Loader.LoadMap("\\content\\maps\\map0" + newmap + ".txt", window); } else { world = Loader.LoadMap("\\content\\maps\\map" + newmap + ".txt", window); } world.map = newmap; world.incrementMap = false; continue; } GL.PushMatrix(); { GL.Translate(cameraPosition.X, cameraPosition.Y, 0); world.Draw(); } GL.PopMatrix(); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.OneMinusDstColor, BlendingFactorDest.One); GL.Color4(0, 0, 0, 0.0f); GL.Begin(BeginMode.TriangleFan); GL.Vertex2(400, 300); GL.Color4(1f - (world.player.health / 255f), 0, 0, 0.2f); GL.Vertex2(0, 0); GL.Vertex2(800, 0); GL.Vertex2(800, 600); GL.Vertex2(0, 600); GL.Vertex2(0, 0); GL.End(); GL.Disable(EnableCap.Blend); FontHandler.Draw(); window.EndDraw(); } }