//RANDOM MOVE void SpawnMinionBehaviour3(Minion minion, bool isLastMinion) { //MATEIXA ESTRUCTURA QUE "FORWARD MOVE" PERO INSTANTIAN UN MINION AMB UN ALTRE COMPORTAMENT spawn1 = GameObject.Find("Hex_0_" + RandomInt(firstSpawnPoint, lastSpawnPoint)); HexInfo spawn1Hex = spawn1.GetComponentInChildren <HexInfo>(); MinionMovementRandom minionScript = minion3.GetComponent <MinionMovementRandom>(); ColorComponents colorComponents = minion3.GetComponent <ColorComponents>(); colorComponents.lastMinionInWave = isLastMinion; minionScript.ActualHex = spawn1Hex; //BuildMinion(minion); colorComponents.cyanComponent = minion.cyanQuantity; colorComponents.magentaComponent = minion.magentaQuantity; colorComponents.yellowComponent = minion.yellowQuantity; cyanQuantity = 0; magentaQuantity = 0; yellowQuantity = 0; if (MobileBuild) { minionScript.speed = minion.speed * incrementPerMobilBuild; } else { minionScript.speed = minion.speed; } Instantiate(minion3, spawn1.transform.position, minion3.transform.rotation); }
public void MoveAnt(AntInfo ant, HexInfo hex) { var oldHex = ant.Hex; oldHex.HasAnt = false; hex.HasAnt = true; ant.Hex = hex; ant.LastLocation = oldHex.Coordinates; // move ant ant.Ant.transform.DOMove(Master.MasterHex.CalculatePosition(hex.Coordinates.x, hex.Coordinates.y), Master.CoreGameLoopFrequency).SetEase(Ease.Linear); // move food if ant is carrying if (ant.Food != null) { ant.Food.transform.DOMove(Master.MasterHex.CalculatePosition(hex.Coordinates.x, hex.Coordinates.y), Master.CoreGameLoopFrequency).SetEase(Ease.Linear); } // uncomment this if you want to see where the ants have been //Master.MasterHex.HighlightHex(hex.Coordinates, Color.green); ant.Energy--; // spend energy ant.LastTurn = Master.GameTurn; hex.LastTouched = Master.GameTurn; }
void ResetHexagonColorValues(HexInfo ActualHex) { ActualHex.HexColor = 'W'; ActualHex.transform.localScale = new Vector3(1, 1, 1); ActualHex.GetComponent <Renderer>().material.mainTexture = buildManagerInstance.defaultTexture; ActualHex.ColorDensity = 0; }
void ClickableSpace(){ for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { GameObject Hex_go = GameObject.Find ("Hex_" + x + "_" + y); HexInfo ActualHex = Hex_go.GetComponentInChildren<HexInfo> (); MeshRenderer ActualHexRend = ActualHex.GetComponent<MeshRenderer>(); for (int i = 0; i < 6; i++) { if (ActualHex.neigbours [i] != null) { if (ActualHex.neigbours [i].Nucli ) { ActualHex.Clickable = true; ActualHexRend.material.mainTexture = null; } for(int j=0;j<6;j++){ if (ActualHex.neigbours [i].neigbours [j]!= null) { if (ActualHex.neigbours [i].neigbours [j].Nucli) { ActualHex.Clickable = true; ActualHexRend.material.mainTexture = null; } } } } } } } }
public override void Execute(HexInfo hexInfo, PositionInfo positionInfo, CameraInfo camInfo, SelectionController selectionController) { if (Input.GetMouseButtonUp(1) || selectionController.SelectedUnit == null) { DebugLogger.Log(LogLevel.Informational, "Complete unit movement.", GetType()); if (selectionController.SelectedUnit != null) { selectionController.SelectedUnit.SetHexPath(hexInfo.HexPath); // Process this unit's moves this.callback(hexInfo.HexMap.DoUnitMoves(selectionController.SelectedUnit, hexInfo)); // Reset pathfinding guideline // TODO: autoselect the next unit (if there is one)? //hexInfo.HexPath = selectionController.SelectedUnit.GetHexPath(); } MarkComplete(); return; } // We have a selected unit // Look at the hex under our mouse // Is this a different hex than before (or we don't already have a path) if (hexInfo.HexPath == null || hexInfo.CurrentHex != hexInfo.PreviousHex) { // Do a pathfinding search to that hex hexInfo.HexPath = QPath.QPath.FindPath <Hex>(hexInfo.HexMap, selectionController.SelectedUnit, selectionController.SelectedUnit.Hex, hexInfo.CurrentHex, Hex.CostEstimate); } }
void MovementRecte() { Vector3 dir = target.position - transform.position; float distanceThisFrame = speed * Time.deltaTime; //EVITA QUE DETECTI COLISIÓ DE COLOR DESPRÉS DE PASSAR PEL HEX if (dir.magnitude < maxDist && dir.magnitude > minDist) { neutralHex = false; } else if (dir.magnitude < minDist) { neutralHex = true; ActualHex = NextHex; } if (dir.magnitude <= distanceThisFrame) { NextHex = ActualHex.neigbours [3]; if (NextHex == null) { Destroy(gameObject); return; } target = NextHex.gameObject.transform; } transform.Translate(dir.normalized * distanceThisFrame, Space.World); }
public static string HomeDirection(this HexInfo hex) { if (hex.HomeInfo.Distance == 0) { return("?"); } var direction = string.Empty; if (hex.HomeInfo.Coordinates.y < hex.Coordinates.y) { direction += "n"; } if (hex.HomeInfo.Coordinates.y > hex.Coordinates.y) { direction += "s"; } if (hex.HomeInfo.Coordinates.x < hex.Coordinates.x) { direction += "w"; } if (hex.HomeInfo.Coordinates.x > hex.Coordinates.x) { direction += "e"; } return(direction); }
HexInfo GetNeighbourByPosition(NeighbourPosition position, HexInfo ActualHex) { HexInfo retVal = null; switch (position) { case NeighbourPosition.Left: retVal = GetLeftNeighbour (ActualHex); break; case NeighbourPosition.UpLeft: retVal = GetUpLeftNeighbour (ActualHex); break; case NeighbourPosition.UpRight: retVal = GetUpRightNeighbour(ActualHex); break; case NeighbourPosition.Right: retVal = GetRightNeighbour (ActualHex); break; case NeighbourPosition.DownRight: retVal = GetDownRightNeighbour(ActualHex); break; case NeighbourPosition.DownLeft: retVal = GetDownLeftNeighbour (ActualHex); break; default: break; } return retVal; }
public void TilePopup(HexInfo inf) { if (buyPannel.activeSelf && Info.gameObject.GetComponent <BaseHex>() == null) { buyPannel.SetActive(false); } tileInfoPannel.SetActive(true); Name.text = inf.tileType; Info.text = inf.tileInfo; if (inf.team != 0) { Team.text = "Team: " + inf.team.ToString(); } else { Team.text = ""; } if (inf.movementCost != 0) { Movement.text = "Movement Cost: " + inf.movementCost.ToString() + " Unit's"; } else { Movement.text = "Cant Pass"; } }
/// <summary> /// Returns hex info at a particular location /// </summary> /// <param name="coords"></param> /// <returns></returns> public HexInfo GetHexInfoAt(Vector2Int coords, bool noColor) { // bounds check if (coords.x < 0 || coords.x >= GridWidth) { return(null); } if (coords.y < 0 || coords.y >= GridHeight) { return(null); } HexInfo info; if (HexDataDictionary.TryGetValue(coords, out info)) { return(info); } var hex = GetHexAt(coords, noColor); if (hex == null) { return(null); } var hexInfo = new HexInfo(coords) { IsRock = hex.GetComponent <Hex>().NeverPathable }; HexDataDictionary.Add(coords, hexInfo); return(hexInfo); }
void Update() { if (EventSystem.current.IsPointerOverGameObject()) { return; } ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hitInfo)) { ourHitObject = hitInfo.collider.transform.gameObject; if (ourHitObject.tag != "Hex") { return; } if (Input.GetMouseButtonDown(0)) { HexInfo hexInfoObject = ourHitObject.GetComponentInChildren <HexInfo>(); if (!hexInfoObject.Clickable) { return; } if (MoneyManager.Pigment > 0) { if (hexInfoObject != null) { MeshRenderer mr = ourHitObject.GetComponentInChildren <MeshRenderer>(); if (ColorInHand == 'C' && hexInfoObject.HexColor != 'C') { FindObjectOfType <AudioManager>().Play("Pop1"); hexInfoObject.HexColor = 'C'; hexInfoObject.SetColorTo(CyanTex); MoneyManager.Pigment -= colorCost; } else if (ColorInHand == 'M' && hexInfoObject.HexColor != 'M') { FindObjectOfType <AudioManager>().Play("Pop2"); hexInfoObject.HexColor = 'M'; hexInfoObject.SetColorTo(MagentaTex); MoneyManager.Pigment -= colorCost; } else if (ColorInHand == 'Y' && hexInfoObject.HexColor != 'Y') { FindObjectOfType <AudioManager>().Play("Pop3"); hexInfoObject.HexColor = 'Y'; hexInfoObject.SetColorTo(YellowTex); MoneyManager.Pigment -= colorCost; } } } } } }
//custom editor for HexInfo values void hexEditor(HexInfo hex) { if (hex != null) { GUILayout.BeginHorizontal(); GUILayout.Space(15); GUILayout.BeginVertical(); GUILayout.Label("Color"); GUILayout.Label("Height"); GUILayout.Label("Path"); GUILayout.Label("Path ID"); GUILayout.Label("Start"); GUILayout.Label("End"); GUILayout.EndVertical(); GUILayout.BeginVertical(); hex.color = EditorGUILayout.IntField(hex.color); hex.height = EditorGUILayout.FloatField(hex.height); hex.path = EditorGUILayout.Toggle(hex.path); hex.pathId = EditorGUILayout.IntField(hex.pathId); hex.start = EditorGUILayout.Toggle(hex.start); hex.end = EditorGUILayout.Toggle(hex.end); GUILayout.EndVertical(); GUILayout.EndHorizontal(); } }
// Use this for initialization private void Start() { hexInfo = new HexInfo { HexMap = GameObject.FindObjectOfType <HexMap>(), LineRenderer = transform.GetComponentInChildren <LineRenderer>() }; hexInfo.CurrentHex = MouseToHex(); positionInfo = new PositionInfo { lastMousePosition = Input.mousePosition }; cameraInfo = new CameraInfo { MouseDragThreshold = 1 }; selectionController = GameObject.FindObjectOfType <SelectionController>(); // A list of Mouse Behaviors which run every frame. constantBehaviors = new List <IMouseBehavior> { new ScrollZoom() }; }
void FillNeighbours(){ for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { GameObject Hex_go = GameObject.Find ("Hex_" + x + "_" + y); HexInfo ActualHex = Hex_go.GetComponentInChildren<HexInfo> (); ActualHex.neigbours = new HexInfo[6]; for (int i = (int)NeighbourPosition.Left; i < (int)NeighbourPosition.NumPositions; i++) { HexInfo neighbour = GetNeighbourByPosition ((NeighbourPosition)i, ActualHex); if (neighbour != null) { ActualHex.neigbours [i] = neighbour; } } } } }
public void TryGetTowerLocation(Vector3 position, Tower tower) { HexCoordinates hex = TryGetHexCoordinateFromWorldPosition(position, out bool success); if (success) { HexInfo info = cellInfo[hex]; success = !info.Occupied && info.Reachable; if (success) { HexInfo closestHex = info; List <HexInfo> available = hex.GetStraightLinesOfLength(2).Where(h => cellInfo.ContainsKey(h) && cellInfo[h].Filled).Select(n => cellInfo[n]).ToList(); int minHexDistance = 100; float minPhysicalDistance = 100; foreach (HexInfo i in available) { int dist = HexCoordinates.Distance(hex, i.Coordinates); if (dist < minHexDistance) { float pDist = Vector2.Distance(i.PhysicalCoordinates, position); minHexDistance = dist; minPhysicalDistance = pDist; closestHex = i; } else if (dist == minHexDistance) { float pDist = Vector2.Distance(i.PhysicalCoordinates, position); if (pDist < minPhysicalDistance) { minPhysicalDistance = pDist; closestHex = i; } } } success = minHexDistance < 100; if (success) { Vector3 diff = closestHex.PhysicalCoordinates - info.PhysicalCoordinates; Vector3 posRot = info.PhysicalCoordinates + (diff / 2f) + (0.5f * (minHexDistance - 1) * InnerRadius) * diff.normalized; posRot.z = Vector2.SignedAngle(Vector2.down, diff); tower.Height = minHexDistance; tower.gameObject.SetActive(true); tower.transform.position = new Vector3(posRot.x, posRot.y, -0.5f); tower.transform.rotation = Quaternion.Euler(0, 0, posRot.z); tower.GridPosition = info.Coordinates; } } } if (!success) { tower.gameObject.SetActive(false); } }
void setPath(HexInfo hex) { hex.color = hex.path ? baseColor : pathColor; hex.height = hex.path ? baseHeight : pathHeight; hex.path = !hex.path; hex.pathId = nextPathPoint; nextPathPoint++; }
public void SetHexInfo(HexInfo info) { MyHexInfo.HexColor = info.HexColor; MyHexInfo.SpriteName = info.SpriteName; Sprite MySprite = Resources.Load <Sprite>(info.SpriteName); this.gameObject.GetComponent <SpriteRenderer>().sprite = MySprite; }
void setBase(HexInfo hex) { hex.color = hex.path ? baseColor : pathColor; hex.height = hex.path ? baseHeight : pathHeight; hex.path = !hex.path; hex.pathId = 0; nextPathPoint--; hex.nextPositions = 0; //new List<Vector2>(); }
void MovementS() { Vector3 dir = target.position - transform.position; float distanceThisFrame = speed * Time.fixedDeltaTime; //EVITA QUE DETECTI COLISIÓ DE COLOR DESPRÉS DE PASSAR PEL HEX if (dir.magnitude < maxDist && dir.magnitude > minDist) { neutralHex = false; } else if (dir.magnitude < minDist) { neutralHex = true; ActualHex = NextHex; } if (dir.magnitude <= distanceThisFrame) { if (counter == 0) { NextHex = ActualHex.neigbours [4]; transform.Rotate(1, 60, 1); counter = 1; } else if (counter == 1) { NextHex = ActualHex.neigbours [3]; transform.Rotate(1, -60, 1); counter = 2; } else if (counter == 2) { NextHex = ActualHex.neigbours [2]; transform.Rotate(1, -60, 1); counter = 3; } else { NextHex = ActualHex.neigbours [3]; transform.Rotate(1, 60, 1); counter = 0; } if (NextHex == null) { Destroy(gameObject); return; } target = NextHex.gameObject.transform; } transform.Translate(dir.normalized * distanceThisFrame, Space.World); }
public void ClearHex(HexInfo hexInfo) { var hex = Master.MasterHex.GetHexAt(hexInfo.Coordinates).GetComponent <Hex>(); if (hex.NeverPathable) { hex.NeverPathable = false; hex.ChangeColor(DefaultColor); hexInfo.IsRock = false; } }
void createMap(){ hexLines = new HexLine[height]; for (int i = 0; i < height; i ++) { hexLines[i] = new HexLine(); hexLines[i].columns = new HexInfo[width]; } for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { float xPos = x * xOffset; if (y % 2 == 1) { xPos += xOffset/2; } //Instantiate hex GameObject Hex_go; if (x >= 3) Hex_go = (GameObject)Instantiate (hexprefab3, new Vector3 (xPos, 0, y * zOffset), Quaternion.identity); else Hex_go = (GameObject)Instantiate (hexprefab1, new Vector3 (xPos, 0, y * zOffset), Quaternion.identity); HexInfo hexInfo = Hex_go.GetComponentInChildren<HexInfo> (); hexInfo.x = x; hexInfo.y = y; hexInfo.Nucli = false; hexInfo.ColorDensity = 0; hexInfo.Clickable = true; hexInfo.map = this; hexInfo.HexColor = 'W'; hexLines [y].columns [x] = hexInfo; //Rename hexes with coordenate names Hex_go.name = "Hex_" + x + "_" + y; //Group hexes in a GameObject parent called "Hex" Hex_go.transform.SetParent (this.transform); Hex_go.isStatic = true; if (x < 3) hexInfo.Clickable = false; } } }
HexInfo GetLeftNeighbour(HexInfo ActualHex) { HexInfo retVal = null; if (ActualHex.x > 0) { retVal = ActualHex.map.hexLines[ActualHex.y].columns[ActualHex.x-1]; } return retVal; }
HexInfo GetRightNeighbour(HexInfo ActualHex) { HexInfo retVal = null; if (ActualHex.x < Map.width - 1) { retVal = ActualHex.map.hexLines [ActualHex.y].columns [ActualHex.x + 1]; } return(retVal); }
HexInfo GetRightNeighbour() { HexInfo retVal = null; if (x < Map.width - 1) { //retVal = map.hexLines [x + 1].columns [y]; retVal = map.hexLines [y].columns [x + 1]; } return(retVal); }
//Map.heith o Map.widht -1 ???? HexInfo GetLeftNeighbour() { HexInfo retVal = null; if (x > 0) { // retVal = map.hexLines[x - 1].columns[y]; retVal = map.hexLines[y].columns[x - 1]; } return(retVal); }
HexInfo GetDownLeftNeighbour(HexInfo ActualHex){ HexInfo retVal=null; if (ActualHex.y % 2 == 0 && ActualHex.x > 0 && ActualHex.y > 0) { retVal = ActualHex.map.hexLines [ActualHex.y - 1].columns [ActualHex.x - 1]; } else if (ActualHex.y % 2 == 1) { retVal = ActualHex.map.hexLines [ActualHex.y-1].columns [ActualHex.x]; } return retVal; }
public TargetContext(Transform transform, List <HexInfo> targets, List <HexInfo> workedHexInfos, int oil, int wood, int water, int food) { this.self = transform; cityTile = targets[0]; targets.RemoveAt(0); this.targets = targets; this.workedHexInfos = workedHexInfos; this.oil = oil; this.wood = wood; this.water = water; this.food = food; }
HexInfo GetUpLeftNeighbour(HexInfo ActualHex){ HexInfo retVal = null; if (ActualHex.y % 2 == 0 && ActualHex.x > 0 ) { retVal = ActualHex.map.hexLines [ActualHex.y+1].columns [ActualHex.x-1]; } else if (ActualHex.y % 2 == 1 && ActualHex.y < Map.height -1) { retVal = ActualHex.map.hexLines [ActualHex.y+1].columns [ActualHex.x]; } return retVal; }
HexInfo GetUpRightNeighbour(HexInfo ActualHex) { HexInfo retVal = null; if (ActualHex.y % 2 == 0) { retVal = ActualHex.map.hexLines [ActualHex.y + 1].columns [ActualHex.x]; } else if (ActualHex.y % 2 == 1 && ActualHex.x < Map.width - 1 && ActualHex.y < Map.height - 1) { retVal = ActualHex.map.hexLines [ActualHex.y + 1].columns [ActualHex.x + 1]; } return(retVal); }
HexInfo GetDownRightNeighbour(HexInfo ActualHex){ HexInfo retVal=null; if (ActualHex.y % 2 == 0 && ActualHex.y > 0) { retVal = ActualHex.map.hexLines [ActualHex.y-1].columns [ActualHex.x]; } else if (ActualHex.y % 2 == 1 && ActualHex.x < Map.width-1 ) { retVal = ActualHex.map.hexLines[ActualHex.y - 1].columns[ActualHex.x + 1]; } return retVal; }
public MapInfo LoadMap() { Debug.Log("LoadMap Start"); MapInfo mapinfo = new MapInfo(); XmlDocument xmlFile = new XmlDocument(); xmlFile.Load("test.xml"); XmlNode mapSize = xmlFile.SelectSingleNode("MapInfo/MapSize"); string mapSizeString = mapSize.InnerText; string[] sizes = mapSizeString.Split( ' ' ); int mapSizeX = mapinfo.MapSizeX = int.Parse(sizes[0]); int mapSizeY = mapinfo.MapSizeY = int.Parse(sizes[1]); int mapSizeZ = mapinfo.MapSizeZ = int.Parse(sizes[2]); XmlNodeList hexes = xmlFile.SelectNodes("MapInfo/Hex"); foreach(XmlNode hex in hexes) { string mapposStr = hex["MapPos"].InnerText; string[] mapposes = mapposStr.Split( ' ' ); int MapPosX = int.Parse(mapposes[0]); int MapPosY = int.Parse(mapposes[1]); int MapPosZ = int.Parse(mapposes[2]); string passableStr = hex["Passable"].InnerText; bool passable = passableStr == "True"; HexInfo info = new HexInfo(); info.MapPosX = MapPosX; info.MapPosY = MapPosY; info.MapPosZ = MapPosZ; info.Passable = passable; mapinfo.HexInfos.Add(info); } return mapinfo; }