// Update is called once per frame void Update() { if (gen <= 0) { generator = new LevelGenerator(); foreach (GameObject obj in roomObjects) { if (obj == null) { continue; } Destroy(obj); } if (doorObjects != null) { foreach (GameObject obj in doorObjects) { if (obj == null) { continue; } Destroy(obj); } } for (int i = 0; i < 20; i++) { roomObjects[i] = Instantiate(RoomObject, new Vector3(), new Quaternion()); RoomBehaviour behaviour = roomObjects[i].GetComponent <RoomBehaviour>(); behaviour.InitializeRoomGen(); generator.AddRoomDef(behaviour.room); } generator.Debug = pt => Debug(pt); bool b = generator.Generate(); gen = 60; print("Generated: " + !b); foreach (GameObject obj in roomObjects) { if (obj == null) { continue; } RoomBehaviour behaviour = obj.GetComponent <RoomBehaviour>(); Room room = behaviour.room.Room; SpriteRenderer renderer = obj.GetComponent <SpriteRenderer>(); renderer.color = new Color(Random.value * 0.5F + 0.5F, Random.value * 0.5F + 0.5F, Random.value * 0.5F + 0.5F, 1); print(room.Coords1); print(room.Coords2); obj.transform.localScale = new Vector3(room.width / 4F, room.height / 4F, 1); obj.transform.position = new Vector3(room.x + room.width / 2F, room.y + room.height / 2F, 0); print("Placed"); } List <Door> doors = generator.Doors; doorObjects = new GameObject[doors.Count]; uint it = 0; foreach (Door door in generator.Doors) { GameObject obj = doorObjects[it] = Instantiate(DoorObject, new Vector3(), new Quaternion()); obj.transform.localScale = new Vector3(1 / 4F, 1 / 4F, 1); obj.transform.position = new Vector3(door.x + 1 / 2F, door.y + 1 / 2F, 0); float rot = 0; switch (door.Direction) { case EFacing2D.POSX: rot = -90F; break; case EFacing2D.NEGX: rot = 90F; break; case EFacing2D.NEGY: rot = 180F; break; } obj.transform.rotation = Quaternion.Euler(0, 0, rot); it++; } } gen--; }
public void Update(FileParser p) { world = new World(); visualization = new Interface(); levelGen = new LevelGenerator(); player = new Player(); parser = p; messages = new List <string>(); Tuple <int, int> playerPos; Tuple <int, int> exitPos; List <Object> currentTile; List <IDealsDamage> tileDmg; List <NPC> tileNPC; List <IItem> tileItems; List <IItem> inventoryItems; int level = 1; bool quit = false; bool action; ConsoleKeyInfo option; HighScore hS; short itemNum, npcNum; if (keyBinds.Count == 0) { AddKeys(); } messages.Add("Welcome to the game!"); do { exitPos = levelGen.GenerateLevel(world, player, level, parser); playerPos = new Tuple <int, int>(player.X, player.Y); do { // Clear our command flags to update next CommandFlag = Command.None; action = false; tileItems = new List <IItem>(); tileDmg = new List <IDealsDamage>(); tileNPC = new List <NPC>(); currentTile = world.WorldArray[player.X, player.Y]. GetInfo().ToList(); foreach (IItem obj in currentTile.OfType <IItem>()) { tileItems.Add(obj); } foreach (IDealsDamage obj in currentTile.OfType <IDealsDamage>()) { tileDmg.Add(obj); } foreach (IDealsDamage obj in tileDmg) { if (obj is Trap) { if (!(obj as Trap).FallenInto) { obj.OnDetectingPlayer(this); } } if (obj is NPC) { tileNPC.Add(obj as NPC); if (((obj as NPC).Hostile)) { obj.OnDetectingPlayer(this); } } } inventoryItems = player.Inventory.GetInfo().ToList(); if (player.HP <= 0) { break; } visualization.ShowWorld(world, player, level); visualization.ShowStats(world, player); visualization.ShowLegend(world); visualization.ShowMessages(world, messages); visualization.ShowSurrounds (world.GetSurroundingInfo(player)); visualization.ShowOptions(new List <ConsoleKey>(keyBinds.Keys)); messages.Clear(); // Update our input for everything else to use option = Console.ReadKey(); if (keyBinds.TryGetValue(option.Key, out var command)) { CommandFlag |= command; switch (CommandFlag) { case Command.Quit: string wantsQuit; do { visualization.AskQuit(); wantsQuit = Console.ReadLine(); } while ((wantsQuit.ToUpper() != "Y") && (wantsQuit.ToUpper() != "N")); if (wantsQuit.ToUpper() == "Y") { quit = true; } break; case Command.MoveNorth: if (player.MoveNorth()) { playerPos = world.UpdatePlayer(playerPos, player); action = true; messages.Add("You moved NORTH"); } else { messages.Add("You tried to move NORTH." + " But you hit a wall instead"); } break; case Command.MoveSouth: if (player.MoveSouth(world.X)) { playerPos = world.UpdatePlayer(playerPos, player); action = true; messages.Add("You moved SOUTH"); } else { messages.Add("You tried to move SOUTH." + " But you hit a wall instead"); } break; case Command.MoveWest: if (player.MoveWest()) { playerPos = world.UpdatePlayer(playerPos, player); action = true; messages.Add("You moved WEST"); } else { messages.Add("You tried to move WEST." + " But you hit a wall instead"); } break; case Command.MoveEast: if (player.MoveEast(world.Y)) { playerPos = world.UpdatePlayer(playerPos, player); action = true; messages.Add("You moved EAST"); } else { messages.Add("You tried to move EAST." + " But you hit a wall instead"); } break; case Command.AttackNPC: if ((tileNPC.Count > 0)) { if (player.SelectedWeapon != null) { do { visualization.ShowNPCsToAttack( tileNPC); short.TryParse( Console.ReadLine(), out npcNum); } while ((npcNum < 0) || (npcNum > tileItems.Count)); if (npcNum != tileItems.Count) { player.AttackNPC(this, tileNPC[npcNum]); action = true; } } else { messages.Add("You tried to attack an" + " NPC but you don't have a " + "weapon equipped"); } } else { messages.Add("You tried to attack an NPC" + " but there are no NPC in the " + "current tile"); } break; case Command.PickUpItem: if (tileItems.Count > 0) { do { visualization.ShowItems(tileItems, "Pick Up"); short.TryParse( Console.ReadLine(), out itemNum); } while ((itemNum < 0) || (itemNum > tileItems.Count)); if (itemNum != tileItems.Count) { tileItems[itemNum].OnPickUp(this); action = true; } } else { messages.Add("You tried to PICK UP an " + "item but there are no items " + "available to be picked up"); } break; case Command.UseItem: if (inventoryItems.Count > 0) { do { visualization.ShowItems(inventoryItems, "Use"); short.TryParse( Console.ReadLine(), out itemNum); } while ((itemNum < 0) || (itemNum > inventoryItems.Count)); if (itemNum != inventoryItems.Count) { inventoryItems[itemNum].OnUse(this); action = true; } } else { messages.Add("You tried to USE an " + "item but you currently don't have" + " any items in the inventory"); } break; case Command.DropItem: if (inventoryItems.Count > 0) { do { visualization.ShowItems(inventoryItems, "Drop"); short.TryParse( Console.ReadLine(), out itemNum); } while ((itemNum < 0) || (itemNum > inventoryItems.Count)); if (itemNum != inventoryItems.Count) { inventoryItems[itemNum].OnDrop(this); action = true; } } else { messages.Add("You tried to DROP an " + "item but you currently don't have" + " any items in the inventory"); } break; case Command.Information: messages.Add("You sought more info in the " + "elder scrolls"); visualization.ShowInformation(parser); Console.ReadKey(); break; } if (action) { player.LoseHP(1); } } else { Console.WriteLine(); visualization.WrongOption(option.Key.ToString()); Console.ReadKey(); } } while ((!playerPos.Equals(exitPos)) && (!quit) && (player.HP > 0)); if (!quit) { level++; } } while ((player.HP > 0) && (!quit)); if (!quit) { visualization.ShowWorld(world, player, level); visualization.ShowStats(world, player); visualization.ShowLegend(world); visualization.ShowDeath(level); } if (CheckHighScore(level)) { visualization.Success(level); string name = Console.ReadLine(); if (name.Length > 3) { name = name.Substring(0, 3); } hS = new HighScore(name, level); parser.UpdateHighScores(hS); } else { visualization.Failure(level); Console.ReadKey(); } }
public void ChangeLevel(int levelProgress) { environmentList = LevelGenerator.CreateEnviromentList(2); }