private void OnEditorPathHighlightEvent(EditorPathHighlightEvent evt) { if (evt.pathIndex == -1) { if (editorPathHighlighted != -1) { glowEffect.Disable(pathsParent.GetChild(editorPathHighlighted).gameObject); editorPathHighlighted = -1; } return; } TDPath path = level.paths[evt.pathIndex]; Vector2 middle = Vector2.zero; for (int i = 0; i < path.Count; ++i) { middle += path[i]; } middle /= path.Count; float xOffset = 5.0f * Screen.width / Screen.height; // Offset a bit from the center of the view, as it's obstructed by the menu. cameraController.FocusOn(new Vector3(middle.x - xOffset, 0, middle.y), 25); glowEffect.Enable(pathsParent.GetChild(editorPathHighlighted = evt.pathIndex).gameObject); }
public void SetPath(TDPath path) { _firetruck.SetPath(path); puttingOutFire = false; SetDestination(GetNextDestination()); }
private IEnumerator PlaceNewPath_EnterState(object input) { editorUI.SetGuidanceMessage(@"Left Click: Place waypoint and create new one Space: Place waypoint and commit path Left Shift: Free movement Escape: Cancel"); inHandWaypoints = new List <Transform>(); inHandPathRenderer = Instantiate(pathRendererPrefab); inHandPathRenderer.transform.parent = pathsParent; inHandWaypoints.Add(GameObject.CreatePrimitive(PrimitiveType.Cube).transform); inHandWaypoints[0].GetComponent <Collider>().isTrigger = true; inHandWaypoints[0].localScale = new Vector3(0.5f, 0.5f, 0.5f); inHandWaypoints[0].parent = inHandPathRenderer.transform; inHandWaypoints[0].gameObject.layer = pathRendererPrefab.gameObject.layer; inHandWaypointMaterial = inHandWaypoints[0].GetComponent <Renderer>().material; Vector3 worldPos = cameraController.ScreenToWorld(Input.mousePosition); inHandWaypoints[0].position = worldPos + new Vector3(0, 0.3f, 0); inHandPathRenderer.positionCount = 1; inHandPathRenderer.SetPosition(0, worldPos + new Vector3(0, 0.05f, 0)); inHandPathRenderer.name = level.paths.Count.ToString(); level.paths.Add(inHandPath = new TDPath()); inHandWaypoints[0].name = "0"; yield return(null); }
private IEnumerator PlaceNewPath_ExitState() { editorUI.SetGuidanceMessage(string.Empty); inHandPathRenderer = null; inHandWaypoints = null; inHandWaypointMaterial = null; inHandPath = null; yield return(null); }
public void SendTruckToTile(EGFiretruck truckToSend, int x, int y) { TDPath truckPath = new TDPath(); TDMap dataMap = _map.Map; truckPath.BuildPath(dataMap, dataMap.GetTile(Mathf.FloorToInt(truckToSend.GetPosition().x), Mathf.FloorToInt(-truckToSend.GetPosition().z)), dataMap.GetTile(x, y)); truckToSend.SetPath(truckPath); truckToSend.SetIdle(false); _dispatcher.AddActiveTruck(truckToSend); }
void SpawnWave(int waveType, int num, int startTime, float freq, TDPath path) { for (int i = 0; i < num; i++) { FollowPath FollowPath = GameObject.Instantiate(UnitsModels[waveType], path.GetPoint(0), Quaternion.identity); FollowPath.startTime = startTime + freq * i; FollowPath.gameObject.SetActive(true); instances.Add(FollowPath.gameObject); LifeIndicator lifeIndicator = FollowPath.gameObject.GetComponentInChildren <LifeIndicator>(); if (lifeIndicator) { Enemy enemyObject = FollowPath.gameObject.GetComponent <Enemy>(); lifeIndicator.root = enemyObject; } } }
public void SetTruckIdle(EGFiretruck truck) { if (truck != null) { _dispatcher.RemoveActiveTruck(truck); _dispatcher.AddIdleTruck(truck); if (truck.returnWhenIdle) { Vector2 fireHouseTilePos = new Vector2(); _map.Map.GetFireHouseCoordinates(out fireHouseTilePos); TDTile start = _map.GetTileForWorldPosition(truck.transform.position); TDTile end = _map.Map.GetTile(Mathf.FloorToInt(fireHouseTilePos.x), Mathf.FloorToInt(fireHouseTilePos.y)); TDPath pathToFirehouse = new TDPath(); pathToFirehouse.BuildPath(_map.Map, start, end); truck.SetPath(pathToFirehouse); } truck.SetIdle(true); } }
// Update is called once per frame void Update() { bool firstRun = true; if (firstRun) { map = _TGMap.getMapData(); firstRun = false; } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (_TGMap.GetComponent<Collider>().Raycast(ray, out hitInfo, Mathf.Infinity)) { int x = Mathf.FloorToInt(hitInfo.point.x / _TGMap.tileSize); int z = Mathf.FloorToInt(hitInfo.point.z / _TGMap.tileSize); currentTileCoord.x = x; currentTileCoord.z = z; selectionCube.transform.position = currentTileCoord * _TGMap.tileSize; } else { } if (Input.GetMouseButtonDown(0)) { occupy = map.getTile((int)playerSelectedCoord.x, (int)playerSelectedCoord.z); if (map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z).getOccupied() == 1) { playerSelected = true; Debug.Log("Player Selected" + map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z)); playerSelectedCoord = new Vector3(currentTileCoord.x, 0, currentTileCoord.z); } else if (map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z).getOccupied() == 0 && playerSelected == true) { playerSelected = false; Debug.Log("Player Moved New coord: " + map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z)); Debug.Log("Player Moved Old coord: " + map.getTile((int)playerSelectedCoord.x, (int)playerSelectedCoord.z)); path = checkPath(map, map.getTile((int)playerSelectedCoord.x, (int)playerSelectedCoord.z), 7); if (path != null) { Debug.Log(path); Debug.Log(path.path[0]); moving = path.path.Count - 1; } } } if(Input.GetMouseButtonDown(1)) { if (map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z).getOccupied() == 2) { opponent = map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z); attacker = map.getTile((int)playerSelectedCoord.x, (int)playerSelectedCoord.z); float hitRoll = Random.Range(0, 10); float cover = 0; //cover calculations Debug.Log(opponent.x + "And" + attacker.x + "ys = " + opponent.y + "And " + attacker.y); Debug.Log("Neighbors: " + map.getTile(opponent.findNeighbors()[0]).getType() + ", " + map.getTile(opponent.findNeighbors()[1]).getType() + ", " + map.getTile(opponent.findNeighbors()[2]).getType() + ", " + map.getTile(opponent.findNeighbors()[3]).getType()); //Left cover if ((opponent.x > attacker.x && map.getTile(opponent.findNeighbors()[1]).getType() == 3)&& !((Mathf.Abs(opponent.x-attacker.x) == 1 && (map.getTile(attacker.findNeighbors()[0]).getType() == 3)) || map.getTile(attacker.findNeighbors()[3]).getType() == 3)) { Debug.Log("Covered! Left"); cover = 2; } //Right Cover else if (opponent.x < attacker.x && map.getTile(opponent.findNeighbors()[2]).getType() == 3 && !((Mathf.Abs(opponent.x - attacker.x) == 1 && (map.getTile(attacker.findNeighbors()[0]).getType() == 3)) || map.getTile(attacker.findNeighbors()[3]).getType() == 3)) { Debug.Log("Covered! Right"); cover = 2; } //Down Cover else if (opponent.y > attacker.y && map.getTile(opponent.findNeighbors()[0]).getType() == 3 && !((Mathf.Abs(opponent.y - attacker.y) == 1 && (map.getTile(attacker.findNeighbors()[1]).getType() == 3)) || map.getTile(attacker.findNeighbors()[2]).getType() == 3)) { Debug.Log("Covered! Down"); cover = 2; } //Up Cover else if (opponent.y < attacker.y && map.getTile(opponent.findNeighbors()[3]).getType() == 3 && !((Mathf.Abs(opponent.y - attacker.y) == 1 && (map.getTile(attacker.findNeighbors()[1]).getType() == 3)) || map.getTile(attacker.findNeighbors()[2]).getType() == 3)) { Debug.Log("Covered! Up"); cover = 2; } Debug.Log("Cover Bonus! " + cover); //hit Debug.Log("HitRoll = " + hitRoll); if((hitRoll - (cover * 3)) > 1) //90% base, -30 for half, -60 for fullcover { opponent.getEnemy().setHealth(opponent.getEnemy().getHealth() - 3); Debug.Log("Hit! Health: " + opponent.getEnemy().getHealth()); } else { } if(opponent.getEnemy().getHealth() <= 0) { opponent.setOccupied(0); } _TGMap.UpdateGraphics(); } } if (moving >= 0) { TDTile next = (TDTile)path.getPath()[moving]; Debug.Log(moving); occupy.removePlayer(); map.setTile(next.position, 1, 1); map.setTile(occupy.position, 1, 0); occupy.switchPlayers(next); occupy = next; _TGMap.UpdateGraphics(); moving -= 1; } }
public void SetPath(TDPath path) { this.path = path; }