void FullCheck() { bool gotIt = false; Crossroad tempCrossroad = new Crossroad(); Crossroad previousCrossroad = null; tempCrossroad.location = player; foreach(Crossroad c in decisions) { if(tempCrossroad.location == c.location) { tempCrossroad.currentDirection = c.currentDirection; previousCrossroad = c; break; } } if(player.x<7 && SingleCheck(new Vector2(player.x+1, player.y))) {//check right if(!gotIt && tempCrossroad.CheckStage(Direction.Right)) { gotIt = true; player.x++; tempCrossroad.currentDirection = Direction.Right; } } if(player.x>0 && SingleCheck(new Vector2(player.x-1, player.y))) {//check left if(!gotIt && tempCrossroad.CheckStage(Direction.Left)) { gotIt = true; player.x--; tempCrossroad.currentDirection = Direction.Left; } } if(player.y<7 && SingleCheck(new Vector2(player.x, player.y+1))) {//check down if(!gotIt && tempCrossroad.CheckStage(Direction.Down)) { gotIt = true; player.y++; tempCrossroad.currentDirection = Direction.Down; } } if(player.y>0 && SingleCheck(new Vector2(player.x, player.y-1))) {//check up if(!gotIt && tempCrossroad.CheckStage(Direction.Up)) { gotIt = true; player.y--; tempCrossroad.currentDirection = Direction.Up; } } if(!gotIt) { player = new Vector2(-1,-1); tempCrossroad.currentDirection = Direction.None; } if(previousCrossroad!=null) { previousCrossroad.currentDirection = tempCrossroad.currentDirection; } else { decisions.Add(tempCrossroad); } //Debug.Log("andei para " + player); path.Add(player); if(player==end) { madeIt = true; } }
public Unit(Crossroad spawn, Vector2 offset, Vector2 movement, float speed, int tier, Texture2D textureLiving, Texture2D textureDead, int value, int maxHP) : this(spawn, offset, movement, speed, tier, textureLiving, textureDead, value, maxHP, 0) { }
private void SetupMap(Texture2D texColorKey) { mMap = new DefenderMap(texColorKey); #region TowerDefence Final Version Map Crossroad x1 = new Crossroad(0, 0); Crossroad x2 = new Crossroad(200, 200); Crossroad x3 = new Crossroad(520, 280); Crossroad x4 = new Crossroad(540, 80); Crossroad x5 = new Crossroad(960, 40); Crossroad x6 = new Crossroad(1000, 200); Crossroad x7 = new Crossroad(900, 300); Crossroad x8 = new Crossroad(860, 520); Crossroad x9 = new Crossroad(1200, 620); Crossroad x10 = new Crossroad(1400, 500); Crossroad x11 = new Crossroad(1720, 320); Crossroad x12 = new Crossroad(1880, 380); Crossroad x13 = new Crossroad(1940, 520); Crossroad x14 = new Crossroad(1780, 600); Crossroad x15 = new Crossroad(1580, 780); Crossroad x16 = new Crossroad(1800, 880); Crossroad x17 = new Crossroad(1880, 1160); Crossroad x18 = new Crossroad(1600, 1200); Crossroad x19 = new Crossroad(1740, 1420); Crossroad x20 = new Crossroad(1460, 1560); Crossroad x21 = new Crossroad(1180, 1560); Crossroad x22 = new Crossroad(1000, 1800); Crossroad x23 = new Crossroad(720, 1940); Crossroad x24 = new Crossroad(600, 1760); Crossroad x25 = new Crossroad(720, 1580); Crossroad x26 = new Crossroad(600, 1400); Crossroad x27 = new Crossroad(420, 1560); Crossroad x28 = new Crossroad(340, 1660); Crossroad x29 = new Crossroad(80, 1560); Crossroad x30 = new Crossroad(200, 1280); Crossroad x31 = new Crossroad(400, 1220); Crossroad x32 = new Crossroad(360, 840); Crossroad x33 = new Crossroad(60, 780); Crossroad x34 = new Crossroad(280, 460); Crossroad end = new Crossroad(1800, 1800); Crossroads = new CrossroadList(x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, x29, x30, x31, x32, x33, x34, end); Spawns = new CrossroadList(x1); #region connections x1.Connections.Add(x2); x2.Connections.Add(x3); x2.Connections.Add(x34); x3.Connections.Add(x4); x4.Connections.Add(x5); x5.Connections.Add(x6); x6.Connections.Add(x7); x7.Connections.Add(x8); x8.Connections.Add(x9); x9.Connections.Add(x10); x10.Connections.Add(x11); x11.Connections.Add(x12); x12.Connections.Add(x13); x13.Connections.Add(x14); x14.Connections.Add(x15); x15.Connections.Add(x16); x16.Connections.Add(x17); x17.Connections.Add(x18); x18.Connections.Add(x19); x19.Connections.Add(x20); x20.Connections.Add(end); x34.Connections.Add(x33); x33.Connections.Add(x32); x32.Connections.Add(x31); x31.Connections.Add(x30); x30.Connections.Add(x29); x29.Connections.Add(x28); x28.Connections.Add(x27); x27.Connections.Add(x26); x26.Connections.Add(x25); x25.Connections.Add(x24); x24.Connections.Add(x23); x23.Connections.Add(x22); x22.Connections.Add(x21); x21.Connections.Add(x20); #endregion #endregion // Debug cross road structure //System.Xml.Serialization.XmlSerializer xml = new System.Xml.Serialization.XmlSerializer(typeof(CrossroadList)); //xml.Serialize(System.IO.File.OpenWrite("crossroads.xml"), Crossroads); Paths = new Paths(Spawns.PathCount + Crossroads.PathCount); Paths.CalculatePaths(Crossroads); Paths.CalculatePaths(Spawns); MapBaseArea = new Rectangle(end.X - 30 + TileSize / 2, end.Y - 30 + TileSize / 2, 60, 60); }
private void PlaceRoad() { if (Input.GetMouseButtonDown(0)) { if (_CurrentRoad == null) { _CurrentRoad = IsTargetingRoadEnd(); _CurrentCrossRoad = IsTargetingCrossRoad(); if (_CurrentRoad) { _RoadEnd = _CurrentRoad.GetClickedRoadEnd(Camera.main.ScreenToWorldPoint(_CurrentMousePos)); _CurrentRoad.DisableColliders(); } else if (_CurrentCrossRoad) { _CurrentCrossRoad.GetComponent <CircleCollider2D>().enabled = false; } else { GameObject road = Instantiate(_RoadBP[_LaneCount]); _CurrentRoad = road.GetComponentInChildren <Road>(); Vector2[] points = new Vector2[2] { Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero }; _CurrentRoad.endpoints = points; _RoadEnd = 1; } } } if (Input.GetMouseButtonUp(0)) { Road otherRoad = IsTargetingRoadEnd(); Crossroad crossroad = IsTargetingCrossRoad(); if (_CurrentRoad) { _CurrentRoad.EnableColliders(); } if (_CurrentCrossRoad) { _CurrentCrossRoad.GetComponent <CircleCollider2D>().enabled = true; } if (otherRoad && !_CurrentCrossRoad) { _CurrentRoad.ConnectRoad(otherRoad, otherRoad.GetClickedRoadEnd(Camera.main.ScreenToWorldPoint(_CurrentMousePos)), _RoadEnd); } if (crossroad && !_CurrentCrossRoad && _CurrentRoad) { _CurrentRoad.ConnectRoad(crossroad, _RoadEnd); } _CurrentRoad = null; _CurrentCrossRoad = null; } if (Input.GetMouseButtonDown(1) && !_CurrentRoad) { _CurrentRoad = IsTargetingRoadEnd(); if (!_CurrentRoad) { _CurrentRoad = IsTargetingRoadMesh(); } if (_CurrentRoad) { _CurrentRoad.DisconnectEndPoints(); Destroy(_CurrentRoad.gameObject); _CurrentRoad = null; } } }
public RoadSegment(Crossroad start, Crossroad end) { setStart(start); setEnd(end); width = 0.5f; }
void FullCheck() { bool gotIt = false; Crossroad tempCrossroad = new Crossroad(); Crossroad previousCrossroad = null; tempCrossroad.location = player; foreach (Crossroad c in decisions) { if (tempCrossroad.location == c.location) { tempCrossroad.currentDirection = c.currentDirection; previousCrossroad = c; break; } } if (player.x < 7 && SingleCheck(new Vector2(player.x + 1, player.y))) { //check right if (!gotIt && tempCrossroad.CheckStage(Direction.Right)) { gotIt = true; player.x++; tempCrossroad.currentDirection = Direction.Right; } } if (player.x > 0 && SingleCheck(new Vector2(player.x - 1, player.y))) { //check left if (!gotIt && tempCrossroad.CheckStage(Direction.Left)) { gotIt = true; player.x--; tempCrossroad.currentDirection = Direction.Left; } } if (player.y < 7 && SingleCheck(new Vector2(player.x, player.y + 1))) { //check down if (!gotIt && tempCrossroad.CheckStage(Direction.Down)) { gotIt = true; player.y++; tempCrossroad.currentDirection = Direction.Down; } } if (player.y > 0 && SingleCheck(new Vector2(player.x, player.y - 1))) { //check up if (!gotIt && tempCrossroad.CheckStage(Direction.Up)) { gotIt = true; player.y--; tempCrossroad.currentDirection = Direction.Up; } } if (!gotIt) { player = new Vector2(-1, -1); tempCrossroad.currentDirection = Direction.None; } if (previousCrossroad != null) { previousCrossroad.currentDirection = tempCrossroad.currentDirection; } else { decisions.Add(tempCrossroad); } //Debug.Log("andei para " + player); path.Add(player); if (player == end) { madeIt = true; } }
public UnitTypeWave(EUnitType unitType, Crossroad spawn, int numUnits, int tileSize, float interval) : base(unitType, spawn, numUnits, tileSize, interval) { }
public static bool areRoadsIntersects(Crossroad cr00, Crossroad cr01, Crossroad cr10, Crossroad cr11, float width) { bool lineIntersection = ccw(cr00, cr10, cr11) != ccw(cr01, cr10, cr11) && ccw(cr00, cr01, cr10) != ccw(cr00, cr01, cr11); if (lineIntersection) { return(true); } Vector2[] rs0StartPoints = getRoadOffsetVectors(cr00, cr01, width); Vector2[] rs0EndPoints = getRoadOffsetVectors(cr01, cr00, width); Vector2[] rs1StartPoints = getRoadOffsetVectors(cr10, cr11, width); Vector2[] rs1EndPoints = getRoadOffsetVectors(cr11, cr10, width); for (int rs0SPoint = 0; rs0SPoint < rs0StartPoints.Length; rs0SPoint++) { for (int rs0EPoint = 0; rs0EPoint < rs0EndPoints.Length; rs0EPoint++) { for (int rs1SPoint = 0; rs1SPoint < rs1StartPoints.Length; rs1SPoint++) { for (int rs1EPoint = 0; rs1EPoint < rs1EndPoints.Length; rs1EPoint++) { if (areLinesIntersects(rs0StartPoints[rs0SPoint], rs0EndPoints[rs0EPoint], rs1StartPoints[rs1SPoint], rs1EndPoints[rs1EPoint])) { return(true); } } } } } return(false); }
public static bool isUnderWaterline(Crossroad crossroad, CityGenerator cityGenerator) { return(cityGenerator.getPointHeight(crossroad.x, crossroad.y) <= cityGenerator.terrainGenerator.meshGenerator.scaleHeight(cityGenerator.waterlineHeight)); }
// Line segment intersection algorithm by Bryce Boe // More info: http://bryceboe.com/2006/10/23/line-segment-intersection-algorithm/ protected static bool ccw(Crossroad A, Crossroad B, Crossroad C) { return((C.y - A.y) * (B.x - A.x) > (B.y - A.y) * (C.x - A.x)); }
public static Vector2 getIntersectionPoint(Crossroad a, Crossroad b, Crossroad c, Crossroad d) { float x12 = a.x - b.x; float x34 = c.x - d.x; float y12 = a.y - b.y; float y34 = c.y - d.y; float f = x12 * y34 - y12 * x34; if (Math.Abs(f) < 0.01) { return(Vector2.zero); } else { float tmp0 = a.x * b.y - a.y * b.x; float tmp1 = c.x * d.y - c.y * d.x; return(new Vector2((tmp0 * x34 - tmp1 * x12) / f, (tmp0 * y34 - tmp1 * y12) / f)); } }
public void ConnectRoad(Crossroad other, int nodeToRemove) { other.transform.position = _EndPoints[nodeToRemove].pos; other.GetComponent <Crossroad>().ConnectRoad(_EndPoints[nodeToRemove]); other.GetComponent <Crossroad>().UpdateCrossroad(true); }