public static void OnHubGUI() { if (m_level == null || m_layout == null) { m_level = GameObject.FindObjectOfType <Level>(); return; } Editing = EditorGUILayout.Toggle("Editing", Editing); GUI.enabled = m_layout.Dirty; if (GUILayout.Button("Save")) { string path = EditorUtility.SaveFilePanelInProject("Save Level", "newlevel", "xml", "Save levels in \"Resources/Levels\"!"); m_layout.Serialise(path); } GUI.enabled = true; if (GUILayout.Button("Load")) { string path = EditorUtility.OpenFilePanel("Open Level", Application.dataPath + "/Resources/Levels", "xml"); if (!string.IsNullOrEmpty(path)) { m_layout = LevelLayout.Deserialise(path); Level.Instance.LoadFromLayout(m_layout); } } }
public LevelLayout Generate() { #region DEBUG float startTime = 0; if (BigBoss.Debug.logging(Logs.LevelGenMain)) { BigBoss.Debug.printHeader(Logs.LevelGenMain, "Generating Level: " + Depth); startTime = Time.realtimeSinceStartup; } #endregion Layout = new LevelLayout() { Random = Rand }; Container = new LayoutObjectContainer(); Log("Mod Rooms", false, GenerateRoomShells, ModRooms); Log("Cluster", true, ClusterRooms); Log("Place Rooms", true, PlaceRooms); Log("Confirm Connection", true, ConfirmConnection); Log("Place Stairs", true, PlaceStairs); Log("Confirm Edges", true, ConfirmEdges); #region DEBUG if (BigBoss.Debug.logging()) { BigBoss.Debug.w(Logs.LevelGenMain, "Generate Level took: " + (Time.realtimeSinceStartup - startTime)); Container.ToLog(Logs.LevelGenMain); BigBoss.Debug.printFooter(Logs.LevelGenMain, "Generating Level: " + Depth); } #endregion Layout.Grids.PutAll(Container.GetGrid()); return(Layout); }
public void InputtingRawDataReturnsBoardDataObject() { var rawData = "01" + "10"; var height = 2; var width = 2; var converter = new BinaryToBoardLayoutConverter(); var expectedData = new LevelLayout { new Tile(1, 1, TileState.Empty), new Tile(2, 1, TileState.Wall), new Tile(1, 2, TileState.Wall), new Tile(2, 2, TileState.Empty) }; expectedData.Append(new Tile(1, 1, TileState.Empty)); var boardData = converter.Convert(height, width, rawData); for (int i = 0; i < expectedData.Count; i++) { Assert.Equal(expectedData[i].X, boardData[i].X); Assert.Equal(expectedData[i].Y, boardData[i].Y); Assert.Equal(expectedData[i].State, boardData[i].State); } }
public void TestAdjacencyCheck(int x1, int y1, int x2, int y2, bool expected) { Vector2Int loc1 = new Vector2Int(x1, y1); Vector2Int loc2 = new Vector2Int(x2, y2); Assert.AreEqual(LevelLayout.AreAdjacent(loc1, loc2), expected); }
public void BuildLevelLayout(LevelLayout layout) { BuildBackground(layout.Width, layout.Height); BuildBlockingTiles(layout.BlockingTiles); BuildMoveableTiles(layout.MoveableTiles); }
private void GenerateMainPath(LevelData levelData, LevelLayout levelLayout) { int enterDirection = 0; var selectedPos = IntPair.CreatePair(levelData.StartingRoomCoordinates.x, levelData.StartingRoomCoordinates.y); while (selectedPos.x < LevelSize.x) { var selectedRoomConnection = SelectRoomConnectionType(enterDirection, selectedPos.y); if (selectedRoomConnection.SelectedRoomConnectionAttribute == null) { throw new Exception("Couldn't select any room. Make sure your room inventory has sufficient combinations"); } levelLayout.AddRoomAttribute(selectedPos.x, selectedPos.y, selectedRoomConnection.SelectedRoomConnectionAttribute); levelLayout.MainPath.Add(selectedPos.Clone()); enterDirection = selectedRoomConnection.ExitDirection; switch (selectedRoomConnection.ExitDirection) { case 1: selectedPos.y--; break; case 2: selectedPos.y++; break; case 3: selectedPos.x++; break; } } selectedPos.x--; levelData.EndRoomCoordinate = selectedPos.Clone(); }
public LevelLayout Convert(int height, int width, string rawData) { var returnData = new LevelLayout(); var x = 1; var y = 1; foreach (var c in rawData) { var isWall = c switch { '0' => TileState.Empty, '1' => TileState.Wall, _ => throw new InvalidLevelDataFormatException() }; returnData.Add(new Tile(x, y, isWall)); if (x < width) { x++; } else if (x == width) { x = 1; y++; } } if (returnData.Count != height * width) { throw new InsufficientLevelDataException(); } return(returnData); } }
// Use this for initialization void Start() { _playerObject = GameObject.Find("Player"); _player = _playerObject.GetComponent <Player>(); _levelLayoutObject = GameObject.Find("BackTiles"); _levelLayout = _levelLayoutObject.GetComponent <LevelLayout>(); }
public Level(Container2D <GridSpace> spaces, LevelLayout layout, Theme theme, System.Random rand) { _array = spaces.Array; LoadRoomMaps(layout); UpStartPoint = layout.UpStart; DownStartPoint = layout.DownStart; Random = rand; }
// Use this for initialization void Start() { _levelLayoutObject = GameObject.Find("BackTiles"); _levelLayout = _levelLayoutObject.GetComponent <LevelLayout>(); _compileObject = GameObject.Find("Compile"); _compile = _compileObject.GetComponent <Compile>(); }
private void AnimateMove() { float interpolationValue = 1.0f - (m_actionTimer / m_moveSeconds); Vector3 current = LevelLayout.TilePosToWorldVec3(m_tilePos); Vector3 target = LevelLayout.TilePosToWorldVec3(m_moveTargetPos); transform.position = Vector3.Lerp(current, target, interpolationValue); }
private void Start() { grid = LevelLayout.GetInstance(); foreach (Transform child in transform) { grid.AddEntity(child.gameObject); } }
public Level(LevelLayout layout, BaseValueAndColorGenerator valueAndColorGenerator, Condition winCondition, Condition loseCondition, BaseMergeRule mergeRule, BaseMergeEffect mergeEffect) : this(layout) { this.valueAndColorGenerator = valueAndColorGenerator; this.winCondition = winCondition; this.loseCondition = loseCondition; this.mergeRule = mergeRule; this.mergeRule.Initialize(this.valueAndColorGenerator); this.mergeEffect = mergeEffect; }
public static void OnEnable() { m_level = GameObject.FindObjectOfType <Level>(); if (m_level != null) { m_level.Start(); } m_layout = new LevelLayout(); m_layout.Init(100, 100); }
public override LevelLayout ProvideLevelLayout() { Map_String_Builder builder = new Map_String_Builder(m_size_of_chunk_array_, m_size_of_chunk_, m_vertex_amount_min_max_); m_current_map = builder.string_map_getter(); //give result LevelLayout result = new LevelLayout(m_current_map, m_size_of_chunk_array_.x * m_size_of_chunk_.x); return(result); }
public Level(int width, int height, int pacStartX, int pacStartY, Direction pacStartDirection, List <Ghost> ghosts, LevelLayout layout) { Width = width; Height = height; PacStartX = pacStartX; PacStartY = pacStartY; PacStartDirection = pacStartDirection; Ghosts = ghosts; Layout = layout; }
public void TestAddRoom(int x, int y) { LevelLayout layout = new LevelLayout(); Vector2Int location = new Vector2Int(x, y); IRoom room = layout.AddRoom(location); Assert.AreEqual(location, room.Position); Assert.AreEqual(room, layout.GetRoom(location)); }
void Start() { levelLayoutObject = GameObject.Find("BackTiles"); levelLayout = levelLayoutObject.GetComponent <LevelLayout>(); _compileObject = GameObject.Find("Compile"); _compile = _compileObject.GetComponent <Compile>(); _playerObject = GameObject.Find("Player"); _player = _playerObject.GetComponent <Player>(); }
public void Start() { s_instance = this; m_raycastHit = new LevelGridRaycastHit(); m_meshRenderer = GetComponent <MeshRenderer>(); LevelLayout layout = LevelLayout.Deserialise(@"C:\Unity\Squad\Assets\Resources\Levels\newlevel.xml"); LoadFromLayout(layout); }
public static LevelLayout Deserialise(string path) { LevelLayout newLayout = new LevelLayout(); using (TextReader tr = new StreamReader(path)) { using (JsonReader reader = new JsonTextReader(tr)) { int tileCount = 0; while (reader.Read()) { if (reader.TokenType == JsonToken.PropertyName) { if (reader.Value.ToString() == "size_x") { reader.Read(); if (int.TryParse(reader.Value.ToString(), out newLayout.m_levelSizeX)) { newLayout.m_contents = new bool[newLayout.m_levelSizeX][]; } } if (reader.Value.ToString() == "size_y") { reader.Read(); if (int.TryParse(reader.Value.ToString(), out newLayout.m_levelSizeY)) { for (int x = 0; x < newLayout.m_levelSizeX; x++) { newLayout.m_contents[x] = new bool[newLayout.m_levelSizeY]; } } } // Categories if (reader.Value.ToString() == "blocked") { reader.Read(); int x = tileCount / newLayout.m_levelSizeX; int y = tileCount % newLayout.m_levelSizeX; bool.TryParse(reader.Value.ToString(), out newLayout.m_contents[x][y]); tileCount++; } } } } } return(newLayout); }
void Start() { _level = GameObject.Find("BackTiles"); _levelLayout = _level.GetComponent <LevelLayout>(); _compileObject = GameObject.Find("Compile"); _compile = _compileObject.GetComponent <Compile>(); _repeatObject = GameObject.Find("Repeat"); _repeat = _repeatObject.GetComponent <RepeatCommand>(); moveSpeed = _StandardSpeed; }
void GenerateLevel(int depth) { LevelGenerator gen = new LevelGenerator(); gen.Theme = GetTheme(); gen.Depth = depth; gen.Rand = new System.Random(_levelSeeds[depth]); LevelLayout layout = gen.Generate(); Container2D <GridSpace> spaces = Builder.GeneratePrototypes(layout); Level level = new Level(spaces, layout, gen.Theme, gen.Rand); _levels[depth] = level; }
public void TestConnectRoomsMissingBoth() { LevelLayout layout = new LevelLayout(); Vector2Int loc1 = Vector2Int.zero; Vector2Int loc2 = Vector2Int.right; try { layout.ConnectRooms(loc1, loc2); Assert.Fail("Both null rooms should have thrown an exception"); } catch (ArgumentOutOfRangeException) { } }
public void RunningOutOfLivesResultsInAGameOver() { var data = new LevelLayout { new Tile(1, 1, TileState.Empty) }; var sim = new Game(3, new Engine(new Level(1, 1, 1, 1, Direction.Right, new List <Ghost>(), data), new KeyInput(), new ConsoleOutput(), new GameTimer()), new LevelSet(), new ConsoleOutput()); sim.Lives = 0; sim.StartGame(); Assert.True(sim.GameOver); }
void Start() { _playerObject = GameObject.Find("Player"); _player = _playerObject.GetComponent <Player>(); _levelLayoutObject = GameObject.Find("BackTiles"); _levelLayout = _levelLayoutObject.GetComponent <LevelLayout>(); _compileObject = GameObject.Find("Compile"); _compile = _compileObject.GetComponent <Compile>(); _repeatObject = GameObject.Find("Repeat"); _repeat = _repeatObject.GetComponent <RepeatCommand>(); }
public void LoadFromLayout(LevelLayout layout) { m_grid = new LevelGrid(m_cellSize, 100, 100); m_walls = new Walls(m_grid, layout); m_grid.RebuildGraphs(); m_grid.RebuildMeshes(); CreateGridObject(); m_gridObject.transform.position = new Vector3(m_grid.GridStart.x, m_grid.GridStart.y, -1.0f); }
public void TestCount() { LevelLayout layout = new LevelLayout(); Assert.AreEqual(layout.Count, 0); layout.AddRoom(new Vector2Int(0, 0)); Assert.AreEqual(layout.Count, 1); layout.AddRoom(new Vector2Int(0, 1)); layout.AddRoom(new Vector2Int(0, 2)); layout.AddRoom(new Vector2Int(0, 3)); Assert.AreEqual(layout.Count, 4); }
public void GameCanInitialiseGameBoardWithGivenBoardData() { var boarddata = new LevelLayout { new Tile(1, 1, TileState.Wall), new Tile(2, 1, TileState.Empty), new Tile(1, 2, TileState.Empty), new Tile(2, 2, TileState.Wall) }; var board = new Level(2, 2, 1, 1, Direction.Right, new List <Ghost>(), boarddata); var game = new Engine(board, new KeyInput(), new ConsoleOutput(), new GameTimer()); Assert.Equal(board, game.Level); }
private void LoadRoomMaps(LevelLayout layout) { foreach (LayoutObject room in layout.Rooms) { var roomMap = new MultiMap <GridSpace>(); RoomMaps.Add(roomMap); foreach (Value2D <GenSpace> floor in room.Grids) { int x = floor.x + room.ShiftP.x; int y = floor.y = room.ShiftP.y; roomMap[x, y] = _array[x, y]; roomMapping[x, y] = roomMap; } } }
public void PacmanCanOnlyMoveIfNotCollidingWithWall(TileState isWall, int x) { var boarddata = new LevelLayout { new Tile(1, 1, TileState.Empty), new Tile(2, 1, isWall) }; var board = new Level(2, 1, 1, 1, Direction.Right, new List <Ghost>(), boarddata); var game = new Engine(board, new KeyInput(), new ConsoleOutput(), new GameTimer()); game.UpdateBoard(); Assert.Equal(x, game.Pacman.X); Assert.Equal(1, game.Pacman.Y); }
public bool CreateNewLevel(string name, LevelType levelType, LevelLayout layout, WorldInfo worldinfo) { Level l = new Level(); l.LevelLayout = layout; l.Palette = levelType.InGameID; switch (levelType.InGameID) { case 1: l.GraphicsBank = 0x08; l.ClearValue = 0x90; break; case 2: l.GraphicsBank = 0x10; l.ClearValue = 0x90; break; case 3: l.GraphicsBank = 0x6C; l.ClearValue = 0x90; break; case 4: l.GraphicsBank = 0x06; l.ClearValue = 0x90; break; case 5: l.GraphicsBank = 0x58; l.ClearValue = 0x90; break; case 6: l.GraphicsBank = 0x58; l.ClearValue = 0x90; break; case 7: l.GraphicsBank = 0x5C; l.ClearValue = 0x90; break; case 8: l.GraphicsBank = 0x3E; l.ClearValue = 0x80; break; case 9: l.GraphicsBank = 0x30; l.ClearValue = 0x90; break; case 10: l.GraphicsBank = 0x34; l.ClearValue = 0x90; break; case 11: l.GraphicsBank = 0x6E; l.ClearValue = 0x90; break; case 12: l.GraphicsBank = 0x18; l.ClearValue = 0x90; break; case 13: l.GraphicsBank = 0x38; l.ClearValue = 0x90; break; case 14: l.GraphicsBank = 0x1C; l.ClearValue = 0x90; break; } l.Guid = Guid.NewGuid(); l.Length = 0x0A; l.Type = levelType.InGameID; l.Music = 0x00; l.Time = 300; l.PaletteEffect = 0; l.InvincibleEnemies = false; l.VineBlocked = false; l.XStart = 0x00; l.YStart = 0x14; for(int j = 0; j < l.Height; j++) { for(int i = 0; i < l.Width; i++) { l.LevelData[i, j] = (byte) l.ClearValue; } } LevelInfo li = new LevelInfo() { Name = name, LevelGuid = l.Guid, WorldGuid = worldinfo.WorldGuid, LevelType = l.Type, Layout = l.LevelLayout }; Levels.Add(li); levelLookup.Add(l.Guid, li); if (l.Save()) { if (LevelAdded != null) LevelAdded(this, new TEventArgs<LevelInfo>(li)); } return true; }
public bool Load(string filename) { XDocument xDoc; string[] levelData = null; string[] compressData = null; SpriteData.Clear(); Pointers.Clear(); try { xDoc = XDocument.Load(filename); } catch { return false; } XElement level = xDoc.Element("level"); foreach (var a in level.Attributes()) { switch (a.Name.LocalName) { case "layout": LevelLayout = (LevelLayout)Enum.Parse(typeof(LevelLayout), a.Value, true); break; case "guid": Guid = a.Value.ToGuid(); break; case "type": Type = a.Value.ToInt(); break; case "clearvalue": ClearValue = a.Value.ToInt(); break; case "graphicsbank": GraphicsBank = a.Value.ToInt(); break; case "music": Music = a.Value.ToInt(); break; case "length": Length = a.Value.ToInt(); break; case "time": Time = a.Value.ToInt(); break; case "xstart": XStart = a.Value.ToInt(); break; case "ystart": YStart = a.Value.ToInt(); break; case "invincibleenemies": InvincibleEnemies = a.Value.ToBoolean(); break; case "vineblocked": VineBlocked = a.Value.ToBoolean(); break; case "paletteeffect": PaletteEffect = a.Value.ToInt(); break; case "palette": Palette = a.Value.ToInt(); break; case "scrolltype": ScrollType = a.Value.ToInt(); break; case "animationtype": AnimationType = a.Value.ToInt(); break; case "startaction": StartAction = a.Value.ToInt(); break; case "leveldata": levelData = a.Value.Split(','); break; case "compresseddata": compressData = a.Value.Split(','); break; case "challengeleveltype": ChallengeType = a.Value.ToInt(); break; case "specialleveltype": SpecialLevelType = a.Value.ToInt(); break; case "misc1": MiscByte1 = a.Value.ToInt(); break; case "misc2": MiscByte2 = a.Value.ToInt(); break; case "misc3": MiscByte3 = a.Value.ToInt(); break; case "tempprojeffects": ProjectileBlocksTemporary = a.Value.ToBoolean(); break; case "rhythm": RhythmPlatforms = a.Value.ToBoolean(); break; case "dpadtiles": DpadTiles = a.Value.ToBoolean(); break; } } int xPointer = 0, yPointer = 0; int[] tileCount = new int[256]; foreach (var c in levelData) { LevelData[xPointer, yPointer] = (byte)c.ToInt(); tileCount[c.ToInt()]++; xPointer++; if (xPointer >= Width) { xPointer = 0; yPointer++; if (yPointer > Height) break; } } int highestTileCount = -1; for (int i = 0; i < 256; i++) { if (tileCount[i] > highestTileCount) { highestTileCount = MostCommonTile = i; } } foreach (var x in level.Elements()) { switch (x.Name.LocalName) { case "spritedata": foreach (var spr in x.Elements("sprite")) { Sprite s = new Sprite(); s.LoadFromElement(spr); SpriteData.Add(s); } break; case "pointers": foreach (var ptr in x.Elements("pointer")) { LevelPointer p = new LevelPointer(); p.LoadFromElement(ptr); Pointers.Add(p); } break; case "settings": Settings.LoadFromElement(x); break; } } return true; }