public TileMatrix(List <TileBehaviour> tiles) { tiles.Sort(CompareTileCoordinates); var xCoordinates = tiles.Select(t => t.x); var yCoordinates = tiles.Select(t => t.y); var xMax = xCoordinates.Max(); var xMin = xCoordinates.Min(); var yMax = yCoordinates.Max(); var yMin = yCoordinates.Min(); rows = (int)(yMax - yMin); columns = (int)(xMax - xMin); matrix = new TileBehaviour[columns + 1, rows + 1]; yOffset = yMin; xOffset = xMin; for (int x = 0; x <= columns; ++x) { for (int y = 0; y <= rows; ++y) { foreach (var tile in tiles) { if (tile.x - xOffset == x && tile.y - yOffset == y) { matrix [x, y] = tile; } } } } }
/// <summary> /// Initializes the game: creates the board, initializes the score variables, calls to shuffle the bags, emits the first piece and starts the bot, if it's the case /// If the training is activated, plays it too /// </summary> void StartGame() { board = new TileBehaviour[boardWidth, boardHeight]; level = 1; linesCleared = score = pieces = 0; UpdateUIGameStats(); TRG.ShuffleBags(); currentPiece = PieceEmitter.EmitPiece(); startedGame = true; if (playMode != PlayMode.Player) { if (playMode != PlayMode.Training) { if (playMode == PlayMode.Testing) { nextActionsTime = initialCalculationTime; } PlayBot(); } else { geneticAlgorithm.PlayNextGame(); } } }
//Game start and end section public void StartNewGame() { //cleanUpOldGame(); TODO boardTiles = new TileBehaviour[boardWidth, boardHeight]; link = new List <TileBehaviour>(); DeployInitialTileSetup(); }
void BoardSetup(Map map) { rows = map.Height + 2; columns = map.Width + 2; tiles = new TileBehaviour[columns, rows]; GameObject.Find("Main Camera").transform.position = new Vector3(columns / 2, rows / 2, -1); boardHolder = GameObject.Find("Board").transform; tileHolder = boardHolder.Find("Tiles"); playerHolderr = boardHolder.Find("Players"); players = new List <PlayerBehaviour>(); for (int x = 0; x < columns; x++) { for (int y = 0; y < rows; y++) { GameObject instance = Instantiate(tile, new Vector3(x, y, 0f), Quaternion.identity) as GameObject; instance.transform.SetParent(tileHolder); if (x == 0 || x == columns - 1 || y == 0 || y == rows - 1) { instance.GetComponent <TileBehaviour>().SetType(enTileType.Wall, new Color(0, 0, 0)); } tiles[x, y] = instance.GetComponent <TileBehaviour>(); } } }
public void startNewGame() { score = 0; cleanUpOldGame(); boardTiles = new TileBehaviour[boardWidth, boardHeight]; link = new List <TileBehaviour>(); initialSetup(); }
private void cleanUpOldGame() { if (link != null) { link.Clear(); } if (boardTiles != null) { foreach (TileBehaviour tile in boardTiles) { Destroy(tile.transform.gameObject); } boardTiles = null; } }
// Awake is called when the script instance is being loaded private void Awake() { // Load prefabs tilePrefab = Resources.Load <GameObject>("Prefabs/Tile"); playerPrefab = Resources.Load <GameObject>("Prefabs/Player"); goalPrefab = Resources.Load <GameObject>("Prefabs/Goal"); // Instantiate known path finders knownPathFinders = new Dictionary <int, IPathFinder>(); knownPathFinders[Key(PathFindAlg.Dijkstra)] = new DijkstraPathFinder(); knownPathFinders[Key(PathFindAlg.AStar, Heuristic.EuclideanDist)] = new AStarPathFinder(EuclideanDistance); knownPathFinders[Key(PathFindAlg.AStar, Heuristic.EuclideanDist, true)] = new AStarPathFinder(EuclideanDistance, true); knownPathFinders[Key(PathFindAlg.AStar, Heuristic.ManhattanDist)] = new AStarPathFinder(ManhattanDistance); knownPathFinders[Key(PathFindAlg.AStar, Heuristic.ManhattanDist, true)] = new AStarPathFinder(ManhattanDistance, true); knownPathFinders[Key(PathFindAlg.AStar, Heuristic.InverseEuclidean)] = new AStarPathFinder(InverseEuclidean); knownPathFinders[Key(PathFindAlg.AStar, Heuristic.InverseEuclidean, true)] = new AStarPathFinder(InverseEuclidean, true); // References to camera game object and camera component GameObject cameraGameObj = GameObject.FindWithTag("MainCamera"); Camera cameraComponent = cameraGameObj.GetComponent <Camera>(); // Width must be odd if (worldSize.x % 2 == 0) { worldSize.x++; } // Adjust camera to game world cameraComponent.orthographicSize = Mathf.Max(worldSize.x, worldSize.y) / 2; // Initialize matrix of game world elements (by default will be // all empties) world = new TileBehaviour[worldSize.x, worldSize.y]; // Determine tile offsets offset = new Vector2(worldSize.x / 2f - 0.5f, worldSize.y / 2f - 0.5f); }
public void Setup(ushort chunkSize) { tileBehaviours = new TileBehaviour[chunkSize, chunkSize]; for (int x = 0; x < chunkSize; x++) { for (int y = 0; y < chunkSize; y++) { tileBehaviours[x, y] = new GameObject(string.Format("Tile ({0}, {1})", x, y)).AddComponent <TileBehaviour>(); tileBehaviours[x, y].transform.SetParent(transform); tileBehaviours[x, y].transform.localPosition = new Vector2(x, y); tileBehaviours[x, y].gameObject.AddComponent <SpriteRenderer>(); tileBehaviours[x, y].gameObject.AddComponent <BoxCollider2D>().size = new Vector2(1, 1); } } gameObject.name = "Chunk (empty)"; gameObject.SetActive(false); }
//For characters local level navigation public static Vector3?FindPath(TileBehaviour[,] tiles, Vector3 startPosition, Vector3 targetPosition, Vector3 backward) { startPosition.x = (int)startPosition.x; startPosition.y = (int)startPosition.y; startPosition.z = (int)startPosition.z; targetPosition.x = (int)targetPosition.x; targetPosition.y = (int)targetPosition.y; targetPosition.z = (int)targetPosition.z; backward.x = (int)backward.x; backward.y = (int)backward.y; backward.z = (int)backward.z; AGrid grid = new AGrid(tiles, backward); Node startNode = grid.getNode(startPosition, true); Node targetNode = grid.getNode(targetPosition, true); return(FindPath(grid, startNode, targetNode, 0)); }
public Chunk(Layer t_layer, int x, int y) { layer = t_layer; int numberTiles = layer.chunkSize_x * layer.chunkSize_y; int verteciesCount = numberTiles * 4; layer = t_layer; chunkPos_x = x; chunkPos_y = y; grid = new TileBehaviour[layer.chunkSize_x, layer.chunkSize_y]; tileChanges = new bool[layer.chunkSize_x, layer.chunkSize_y]; collisionChanges = new bool[layer.chunkSize_x, layer.chunkSize_y]; //colorChanges = new bool[layer.chunkSize_x, layer.chunkSize_y]; uvChanges = new Vector2[verteciesCount]; textureLayerChanges = new Vector2[verteciesCount]; colorChanges = new Color[verteciesCount]; }
// Awake is called when the script instance is being loaded private void Awake() { // References to camera game object and camera component GameObject cameraGameObj = GameObject.FindWithTag("MainCamera"); Camera cameraComponent = cameraGameObj.GetComponent <Camera>(); // Width must be odd if (worldSize.x % 2 == 0) { worldSize.x++; } // Adjust camera to game world cameraComponent.orthographicSize = Mathf.Max(worldSize.x, worldSize.y) / 2; // Initialize matrix of game world elements (by default will be // all empties) world = new TileBehaviour[worldSize.x, worldSize.y]; // Determine tile offsets offset = new Vector2(worldSize.x / 2f - 0.5f, worldSize.y / 2f - 0.5f); }
// Constructor public TileWorldGraph(TileBehaviour[,] world) { this.world = world; }
public AGrid(TileBehaviour[,] tiles, Vector3 backward) { this.tiles = tiles; this.backward = backward; }