GameObject SpawnTile(Vector3 spawnPosition, int x, int y, Boolean active) { if (tile) { GameObject newTile = Instantiate(tile, spawnPosition, Quaternion.identity) as GameObject; newTile.transform.localScale = newTile.transform.localScale * tileSize; ClickableTile clickTile = newTile.GetComponent <ClickableTile>(); if (clickTile) { clickTile.tileX = x; clickTile.tileY = y; } newTile.transform.parent = transform; newTile.SetActive(active); if (!active) { newTile.SetActive(true); newTile.transform.localScale = new Vector3(newTile.transform.localScale.x, 4.0f, newTile.transform.localScale.z); newTile.AddComponent <Rigidbody>().useGravity = false; Destroy(newTile.GetComponent <ClickableTile>()); //newTile.GetComponent<MeshRenderer>().enabled = true; } return(newTile); } return(null); }
void GenerateMapVisual() { for (int x = 0; x < mapSizeX; x++) { for (int y = 0; y < mapSizeY; y++) { TileType tt = tileTypes[tiles[x, y]]; GameObject go = Instantiate(tt.tileVisualPrefab, new Vector3(x, y, 0), Quaternion.identity); ClickableTile ct = go.GetComponent <ClickableTile>(); ct.tileX = x; ct.tileY = y; ct.map = this; // if tileType is a machine type, store it in my machines list if (tt.name == "machine") { Machine machine = go.GetComponent <Machine>(); machines.Add(machine); } } } }
public FoodCounter(TileLocation location) { Tile = new ClickableTile("2/table2", location, true, EatFood, 2); FoodTile = new ClickableTile("transparent", location, true, 3); _foods = new List <Food>(); World.Subscribe(EventSubscription.Create <FoodDelivered>((f) => { _foods.Add(f.Food); FoodTile.TextureName = "2/food"; }, this)); }
public void PinPointTile(ClickableTile tile) { //TeleportCursorToTile(tile.GetTileCoordX(), tile.GetTileCoordY()); currentPositionX = tile.GetTileCoordX(); currentPositionY = tile.GetTileCoordY(); SetCursorPosition(); }
public void CheckVisibleTiles() { GameObject DrawLine = GameObject.Find("LineRenderer"); DrawLine drawLine = DrawLine.GetComponent <DrawLine> (); visibleTiles = new List <Node>(); drawLine.skillDistance = 20; GameObject Player = GameObject.Find(selecterPlayer); PlayableCharacter player = Player.GetComponent <PlayableCharacter> (); // player.VisibleNodes = null; GameObject[] Tiles = GameObject.FindGameObjectsWithTag("Hex"); foreach (GameObject tile in Tiles) { ClickableTile clickableTile = tile.GetComponent <ClickableTile> (); bool allowed = drawLine.CalculateLine(player.PlayerClass.TileX, player.PlayerClass.TileY, clickableTile.tileX, clickableTile.tileY); if (allowed) { // clickableTile.hexVisible = true; visibleTiles.Add(graph[clickableTile.tileX, clickableTile.tileY]); } else { // clickableTile.hexVisible = false; } } player.VisibleNodes = visibleTiles; }
private int CalcuatePathValue(List <Node> path) { int value, resultingValue = 0, numCapturedTiles = 0; //Step through path, tally each captured for (int steps = 0; steps < path.Count; steps++) { Node node = path[steps]; ClickableTile tile = map.tiles[node.pos.x, node.pos.y]; int sum = tile.GetValue() + steps; if (sum % 10 == 0) { numCapturedTiles += tile.GetValue() / 10; } //last node in path, check what final value will be if (steps == path.Count - 1) { if (sum % 10 == 0) { resultingValue = 1; } else { resultingValue = sum; } } } // Values increase as captured tiles increase and resulting values decrease value = numCapturedTiles - resultingValue; return(value); }
public void CalculateDistanceToTargets(int startPointX, int startPointY) { Vector3 startLoc = new Vector3(); Vector3 endLoc = new Vector3(); startLoc.y = startPointY; startLoc.z = startPointX - (startPointY - (Mathf.Abs(startPointY) % 2)) / 2; startLoc.x = -startLoc.y - startLoc.z; GameObject[] PlayersAlive = GameObject.FindGameObjectsWithTag("Player"); foreach (GameObject Player in PlayersAlive) { PlayableCharacter player = Player.GetComponent <PlayableCharacter> (); endLoc.y = player.PlayerClass.TileY; endLoc.z = player.PlayerClass.TileX - (player.PlayerClass.TileY - (Mathf.Abs(player.PlayerClass.TileY) % 2)) / 2; endLoc.x = -endLoc.y - endLoc.z; int distance = (int)(Mathf.Abs(startLoc.x - endLoc.x) + Mathf.Abs(startLoc.y - endLoc.y) + Mathf.Abs(startLoc.z - endLoc.z)) / 2; if (distance <= range) { GameObject Tile = GameObject.Find("Hex_" + player.PlayerClass.TileX + "_" + player.PlayerClass.TileY); ClickableTile tile = Tile.GetComponent <ClickableTile> (); GameObject HighlightTiles = GameObject.Find("_Scripts"); HighlightTiles highlightTiles = HighlightTiles.GetComponent <HighlightTiles> (); highlightTiles.tileX = tile.tileX; highlightTiles.tileY = tile.tileY; highlightTiles.ShowHoveringTileSkill(); } } }
public void ShowTilesThatInTrapRange(int startX, int startY) { Vector3 ret = new Vector3(); Vector3 retTarget = new Vector3(); ret.y = startY; ret.z = startX - (startY - (Mathf.Abs(startY) % 2)) / 2; ret.x = -ret.y - ret.z; GameObject[] ClickableTiles = GameObject.FindGameObjectsWithTag("Hex"); foreach (GameObject v in ClickableTiles) { ClickableTile clickableTile = v.GetComponent <ClickableTile> (); retTarget.y = clickableTile.tileY; retTarget.z = clickableTile.tileX - (clickableTile.tileY - (Mathf.Abs(clickableTile.tileY) % 2)) / 2; retTarget.x = -retTarget.y - retTarget.z; int d = (int)((Mathf.Abs(ret.x - retTarget.x) + Mathf.Abs(ret.y - retTarget.y) + Mathf.Abs(ret.z - retTarget.z)) / 2); if (d <= skillRange && clickableTile.hexVisible && map.UnitCanEnterTile(clickableTile.tileX, clickableTile.tileY) == true && d != 0) { Material[] mat = clickableTile.GetComponent <Renderer>().materials; mat[1] = hoverMaterialAllowed; clickableTile.GetComponent <Renderer>().materials = mat; clickableTile.rangeTargetted = true; clickableTile.canAttack = true; clickableTile.willTakeHit = false; // tileX = clickableTile.tileX; // tileY = clickableTile.tileY; } else { clickableTile.rangeTargetted = false; } } }
// Use this for initialization void Start() { timeRemaining = TIMES[type]; currentJobIsDone = false; calledWorker = false; trays = new List <GameObject>(); if (type == "MARKER") { Job job1 = new Job(); Job job2 = new Job(); Job job3 = new Job(); jobs.Add(job1); jobs.Add(job2); //jobs.Add(job3); Debug.Log("Starting with " + jobs.Count + " jobs"); InstantiateTrays(); } ct = GetComponent <ClickableTile>(); worker = ct.map.selectedUnit.GetComponent <Unit>(); tileX = ct.tileX; tileY = ct.tileY; mapSizeX = ct.map.mapSizeX; mapSizeY = ct.map.mapSizeY; SetOrientation(); }
void GenerateMapVisual() { for (int x = 0; x < mapSizeX; x++) { for (int y = 0; y < mapSizeX; y++) { TileType tt = tileTypes[tiles[x, y]]; GameObject go = (GameObject)Instantiate(tt.tileVisualPrefab, new Vector3(x, y, 0), Quaternion.identity); ClickableTile ct = go.GetComponent <ClickableTile>(); if (ct.grass != null) { graph[x, y].grass = go.transform.GetChild(0).gameObject; graph[x, y].burntGrass = go.transform.GetChild(1).gameObject; graph[x, y].cutGrass = go.transform.GetChild(2).gameObject; } if (ct.holdsTraps) { int checkTrapNum = Random.Range(0, 1); if (ct.traps[checkTrapNum] != null) { graph[x, y].trap = ct.traps[checkTrapNum]; } // graph[x,y].uncovered = true; Debug.Log("assign trap" + checkTrapNum); } ct.tileX = x; ct.tileY = y; ct.map = this; ct.myNode = graph[x, y]; graph[x, y].myTile = ct; } } }
// Start is called before the first frame update void Start() { Builders.HexagonalMapBuilder builder = new Builders.HexagonalMapBuilder(); List <MapTile> mapTiles = builder.Create(new Data.DefaultDataProvider(), _tileContainer.transform); foreach (MapTile tile in mapTiles) { if (tile.Walkable) { ClickableTile clickableTile = tile.gameObject.AddComponent <ClickableTile>(); clickableTile.OnClick.AddListener(OnTileClicked); } } /* * MapTile from = mapTiles.Find(t => t.X == 7 && t.Y == 3); * MapTile to = mapTiles.Find(t => t.X == 6 && t.Y == 7); * * var path = PathFinding.AStar.GetPath(from, to); * * Debug.Log("tiles: " + path.Count); * * for( int i = 0; i < path.Count; i++ ) * { * ((MapTile)path[i]).SetTintColor((i == 0 || i == path.Count - 1) ? Color.green : Color.red); * }*/ }
//spawn prefabs void GenerateMapVisuals() { for (int x = 0; x < mapSizeX; x++) { for (int y = 0; y < mapSizeY; y++) { TileType tt = tileTypes[tiles[x, y]]; switch (tiles[x, y]) { case 2: go = Instantiate(tt.tileVisualPrefab, new Vector3(x, y, -0.45f), Quaternion.Euler(0, 180, 0)); break; case 3: go = Instantiate(tt.tileVisualPrefab, new Vector3(x, y, 0f), Quaternion.Euler(0, 180, 0)); break; case 4: go = Instantiate(tt.tileVisualPrefab, new Vector3(x, y, 0f), Quaternion.Euler(0, 180, 0)); break; default: go = Instantiate(tt.tileVisualPrefab, new Vector3(x, y, 0f), Quaternion.Euler(0, 180, 0)); break; } ClickableTile ct = go.GetComponent <ClickableTile> (); ct.tileX = x; ct.tileY = y; ct.map = this; } } }
void HitEnemy() { GameObject CardDropArea = GameObject.Find("CardDropArea"); DropZone dropZone = CardDropArea.GetComponent <DropZone>(); GameObject[] Enemies = GameObject.FindGameObjectsWithTag("Enemy"); foreach (GameObject Enemy in Enemies) { BaseEnemy enemy = Enemy.GetComponent <BaseEnemy> (); GameObject Tile = GameObject.Find("Hex_" + enemy.TileX + "_" + enemy.TileY); ClickableTile tile = Tile.GetComponent <ClickableTile> (); if (tile.willTakeHit) { enemy.Recentlyhit = true; HealthBar enemyHpBar = enemy.GetComponent <HealthBar> (); //TODO //if lauseke johonkin, joka tarkistaa onko kyseess' physDMG vai magic DMG enemyHpBar.CurHealth -= (dropZone.damage / enemy.HpPointsMax) * (100 * (enemy.PhysDmgReduction + enemy.MagicDmgReduction)); enemyHpBar.SetHealthBarEnemy(); enemyHpBar.parentName = Enemy.name; enemyHpBar.KillUnit(); tile.willTakeHit = false; } } }
public void EstablishNewTile(ClickableTile newTile) { gameObject.transform.position = new Vector3(newTile.GetTileCoordX(), newTile.GetTileCoordY(), gameObject.transform.position.z); newTile.AssignUnit(this); originTile = newTile; TireUnit(); }
public void ShowTilesCanBereached() { //Init(); Unit uni = selectedUnit; for (int i = uni.tileY - 1; i < uni.tileY + 2; i++) { for (int j = uni.tileX - 1; j < uni.tileX + 2; j++) { ClickableTile ct = FindTile(j, i); if (ct == null) { continue; } if (ct.mask == null) { continue; } //Debug.LogError(uni.remainingMovement + "___" + CostToEnterTile(uni.tileX, uni.tileY, j, i)); bool canEnter = uni.remainingMovement - CostToEnterTile(uni.tileX, uni.tileY, j, i) >= 0 ? true : false; if (canEnter) { ct.mask.SetActive(true); if (i == uni.tileY && j == uni.tileX) { ct.mask.SetActive(false); } } } } }
void GenerateMapVisual() { // Debug.Log("GenerateMapVisual"); for (int x = 0; x < mapSizeX; x++) { for (int y = 0; y < mapSizeY; y++) { float xPos = x * xOffset; if (y % 2 == 1) { xPos += xOffset / 2f; } TileType tt = tileTypes[tiles[x, y]]; GameObject go = (GameObject)Instantiate(tt.tileVisualPrefab, new Vector3(xPos, y * zOffset, 0), new Quaternion(0, 180, 0, 0)); ClickableTile ct = go.GetComponent <ClickableTile>(); ct.tileX = x; ct.tileY = y; ct.map = this; go.name = "Hex_" + x + "_" + y; go.transform.SetParent(this.transform); go.tag = "Hex"; // go.isStatic = true; } } }
private void Start() { troop_Txt.color = Base.baseColor; origin = Base.TileList[0]; MoveToDestination(raidedBaseIndex); }
public int GetTileValue(Coord target) { ClickableTile ct = tiles[target.x, target.y]; int value = ct.GetValue(); //Debug.Log("Tile value at " + target + " is " + value); return(value); }
///<summary> /// Sets tile visible with colorfader enabled ///</summary> private void HighlightTile(int x, int y) { GameObject t = GameObject.Find("Tile" + x + "-" + y); ClickableTile ct = t.GetComponent<ClickableTile>(); ct.Enabled = true; ct.GetComponent<Renderer>().enabled = true; ct.GetComponent<ColorFader>().IsEnabled = true; }
public void MoveToDestination(int baseIndex) { GeneratePathfindingGraph(); GeneratePathToBase(baseIndex); nextPosition = path[0]; }
private void UpdateInformation() { currentTile = map.tiles[unit.pos.x, unit.pos.y]; currentNode = map.nodes[unit.pos.x, unit.pos.y]; currentValue = currentTile.GetValue(); availableTiles = unit.GetAvailableTileOptions(currentNode, unit.GetMoveSpeed()); paths.Clear(); sortedPaths.Clear(); }
public void SetTile(int x, int y, TileType type) { if (x <= 1 || x >= mWidth - 2 || y <= 1 || y >= mHeight - 2) { return; } tiles[x, y] = type; if (type == TileType.Block) { tilesSprites[x, y] = Instantiate <SpriteRenderer>(tilePrefab); tilesSprites[x, y].transform.parent = transform; tilesSprites[x, y].gameObject.layer = 8; tilesSprites[x, y].transform.position = position + new Vector3(cTileSize * x, cTileSize * y, 10.0f); DamageHandler damage = tilesSprites[x, y].gameObject.GetComponent <DamageHandler>(); damage.x = x; damage.y = y; damage.mapdata = this; ClickableTile clickedthis = tilesSprites[x, y].gameObject.GetComponent <ClickableTile>(); clickedthis.TileX = x; clickedthis.TileY = y; mGrid[x, y] = 0; AutoTile(type, x, y); tilesSprites[x, y].enabled = true; } else if (type == TileType.OneWay) { tilesSprites[x, y] = Instantiate <SpriteRenderer>(tilePrefab); tilesSprites[x, y].transform.parent = transform; tilesSprites[x, y].gameObject.layer = 8; tilesSprites[x, y].transform.position = position + new Vector3(cTileSize * x, cTileSize * y, 10.0f); DamageHandler damage = tilesSprites[x, y].gameObject.GetComponent <DamageHandler>(); damage.x = x; damage.y = y; damage.mapdata = this; mGrid[x, y] = 1; tilesSprites[x, y].enabled = true; tilesSprites[x, y].transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); tilesSprites[x, y].transform.eulerAngles = new Vector3(0.0f, 0.0f, 0.0f); tilesSprites[x, y].sprite = mDirtSprites[2]; } else { mGrid[x, y] = 1; } AutoTile(type, x - 1, y); AutoTile(type, x + 1, y); AutoTile(type, x, y - 1); AutoTile(type, x, y + 1); }
// public bool dig(int x,int y){ // //if the spot is already empty, do nothing // if(tiles[x,y] == 0){ // return false; // } // //if (Game_Manager.instance.digLeft > 0 && isDiggable (x, y)) { // if (isDiggable (x, y)) { // // // //print ("click"); // GameObject go = Instantiate (tileTypes [0].tileVisualPrefab, new Vector3 (x, y, 0), Quaternion.identity); // tiles [x, y] = 0; //// Game_Manager.instance.digLeft--; // emptyLocations.Add(new Vector3(x,y,0)); // Game_Manager.instance.updateText (); // return true; // } //// else if (Game_Manager.instance.digLeft == 0) { //// print ("You've used up all the digging power for this round!"); //// return false; //// } // else { // print ("This tile is not diggable."); // return false; // } // } public IEnumerator dig(GameObject toDestory) { //if the spot is already empty, do nothing ClickableTile script = toDestory.GetComponent <ClickableTile>(); int x = script.tileX; int y = script.tileY; if (tiles[x, y] == 0) { yield break; } if (is_digging) { print("Already digging another tile!!!!!!"); yield break; } //if (Game_Manager.instance.digLeft > 0 && isDiggable (x, y)) { if (isDiggable(x, y)) { is_digging = true; yield return(new WaitForSeconds(digging_time)); if (script.tileIndex == 1) { Game_Manager.instance.tileNumbers [0]++; } if (script.tileIndex == 2) { Game_Manager.instance.tileNumbers [1]++; } if (script.tileIndex == 3) { Game_Manager.instance.tileNumbers [2]++; } Destroy(toDestory); GameObject go = Instantiate(tileTypes [0].tileVisualPrefab, new Vector3(x, y, 0), Quaternion.identity); tiles [x, y] = 0; movement_costs [x, y] = 1; // Game_Manager.instance.digLeft--; emptyLocations.Add(new Vector3(x, y, 0)); Game_Manager.instance.updateText(); } // else if (Game_Manager.instance.digLeft == 0) { // print ("You've used up all the digging power for this round!"); // return false; // } else { print("This tile is not diggable."); yield return(null); } is_digging = false; }
public void MoveToOrigin() { origin = map.tileMap[nextPosition.positionX, nextPosition.positionY]; GeneratePathfindingGraph(); GeneratePathToBase(Base.baseIndex); nextPosition = path[0]; }
public void ShowTilesThatCanBeHit() { GameObject Tile = GameObject.Find("Hex_" + tileX + "_" + tileY); ClickableTile tile = Tile.GetComponent <ClickableTile>(); Material[] mat = tile.GetComponent <Renderer>().materials; mat[1] = hoverMaterialAllowed; tile.GetComponent <Renderer>().materials = mat; tile.willTakeHit = false; }
public void ShowTilesThatWillBeHitSkill() { GameObject Tile = GameObject.Find("Hex_" + tileX + "_" + tileY); ClickableTile tile = Tile.GetComponent <ClickableTile>(); Material[] mat = tile.GetComponent <Renderer>().materials; mat[1] = materialWillBeHit; tile.GetComponent <Renderer>().materials = mat; tile.willTakeHit = true; }
public void AllowTargetable(bool allow) { if (IsDead) { ClickableTile.ShowArea(false); return; } ClickableTile.ShowArea(allow); }
private void DeselectTile(ClickableTile tile) { if (tile == null) { return; } tile.movable = false; tile.GetComponent <Image>().color = Color.white; }
public void OnTileClicked(ClickableTile t) { if (tileSelectionMode) { tileSelectionCallback(t.x, t.y); } else { ((GambitModel)GambitModel.instance).TryMovePlayer(t.x, t.y); } }
public void CreateBaseTile(WorldObject obj) { CreateWorldSpaceObject(obj, "Base", 0); ClickableTile tile = Instantiate(clickableTilePrefab); tile.transform.position = obj.gameSpaceObject.transform.position + new Vector3(0, 0, 10); tile.transform.parent = transform; tile.x = obj.x; tile.y = obj.y; }