public void SpawnTile () { var x = PuzzleTileHex.GetRandomTile(this); x.MakeDraggable(); x.Name = $"tile_{tileID++}"; x.Position = spawnCoord.Position(); board.AddChild(x); }
void LoadLevel (int number) { currentLevel = number; //GODOT: how on earth do I load a text file? //var resource = GD.Load($"res://Levels/{number}.txt"); //this took 30mins to figure out. every operation is different than the //C# BCL version and the docs are not helpful var f = new File(); f.Open($"res://Levels/{number}.txt", (int)File.ModeFlags.Read); var lines = new System.Collections.Generic.List<string>(); while(!f.EofReached()) { lines.Add(f.GetLine()); } //var lines = System.IO.File.ReadAllLines(System.IO.Path.Combine("Levels", $"{number}.txt")); var boardDef = lines[0].Split('|'); int boardSize = int.Parse(boardDef[0]); if (boardDef.Length == 6) { TileColor = new Color(boardDef[1]); if (string.IsNullOrEmpty(boardDef[2])) { StaticTileColor = TileColor.Darkened(0.2f); } else { StaticTileColor = new Color(boardDef[2]); } BoardColor = new Color(boardDef[3]); if (string.IsNullOrEmpty(boardDef[4])) { BackgroundColor = Colors.Black; } else { BackgroundColor = new Color(boardDef[4]); } LineHighlightColor = new Color(boardDef[5]); } else { TileColor = new Color("e017c2"); StaticTileColor = TileColor.Darkened(0.2f); BoardColor = new Color("bdf0ec"); BackgroundColor = Colors.Black; LineHighlightColor = Colors.Yellow; } VisualServer.SetDefaultClearColor(BackgroundColor); CreateLevel(boardSize); for (int i = 1; i < lines.Count; i++) { var line = lines[i]; if (string.IsNullOrWhiteSpace(line)) { continue; } int commaIdx = line.IndexOf(','); int q = int.Parse(line.Substring(0,commaIdx)); var pipeIdx = line.IndexOf('|'); int r = int.Parse(line.Substring(commaIdx + 1, pipeIdx - commaIdx - 1)); int[] desc = new int[6]; for (int j = 0; j < 6; j++) { desc[j] = line[pipeIdx+ 1+j] - '0'; } //offset due to the map we're using to figure out positions int offset = Math.Max(0, 4 - boardSize); var coord = new HexCoord(q, r - offset); var tile = new PuzzleTileHex { LineDescriptions = desc, Position = coord.Position() }; tile.IsStatic = true; map.SetCell(new CellInfo(coord, tile)); board.AddChild(tile); tile.CalculatePaths(this, coord); } var c = TileColor; c.a = 0.6f; hexCursor.Modulate = c; Rescale(); }
public void ResetTile(PuzzleTileHex tile) => SnapTileToCell(tile, spawnCoord);
public void SnapTileToCell (PuzzleTileHex tile, HexCoord coord) { snapTween.InterpolateProperty(tile, "position", null, coord.Position(), 0.1f, Tween.TransitionType.Cubic, Tween.EaseType.Out, 0); snapTween.Start(); }