public List<RectangleCollider> fromMap(Vector2 topLeft, Vector2 dimentions,Map map) { Vector2 ss = new Vector2(map.tileSize, map.tileSize); List<RectangleCollider> output = new List<RectangleCollider>(); int tileMinX = ((int)topLeft.X) / map.tileSize; int tileMinY = ((int)topLeft.Y) / map.tileSize; int tileMaxX = (((int)(topLeft.X + dimentions.X)) / map.tileSize); int tileMaxY = (((int)(topLeft.Y + dimentions.Y)) / map.tileSize); if (tileMinX < 0) tileMinX = 0; if (tileMinY < 0) tileMinY = 0; if (tileMaxX >= map.width) tileMaxX = map.width - 1; if (tileMaxY >= map.height) tileMaxY = map.height - 1; for (int i = tileMinX; i <= tileMaxX; i++) { for (int j = tileMinY; j <= tileMaxY; j++) { if (map.tiles[i + (j * map.width)].walkCost == 0) { Vector2 position = new Vector2(i * map.tileSize, j * map.tileSize); output.Add(new RectangleCollider(position, ss)); } } } return output; }
public override bool hit(Map map, Vector2 p) { float hold; Vector2 a = position; Vector2 b = secondPosition; if (a.X > b.X) { hold = a.X; a.X = b.X; b.X = hold; } if (a.Y > b.Y) { hold = a.Y; a.Y = b.Y; b.Y = hold; } List<RectangleCollider> recs = fromMap(a + p, b-a, map); foreach (RectangleCollider re in recs) { if (this.hit(re, p, new Vector2(0, 0))) { return true; } } return false; }
public override bool hit(Map map, Vector2 p) { foreach (Collider colin in within) { if(colin.hit(map,p)) return true; } return false; }
public override bool hit(Map map, Vector2 p) { List<RectangleCollider> recs = fromMap(position + p, dimentions, map); foreach (RectangleCollider re in recs) { if (this.hit(re, p, new Vector2(0, 0))) { return true; } } return false; }
public override bool hit(Map map, Vector2 p) { List<RectangleCollider> recs = fromMap(p + position - new Vector2(radius,radius), new Vector2(2*radius,2*radius), map); foreach (RectangleCollider re in recs) { if (this.hit(re, p, new Vector2(0, 0))) { return true; } } return false; }
public virtual Boolean hits(Map map) { if (collider == null) return false; return collider.hit(map,hitPosition); }
public abstract Boolean hit(Map map, Vector2 p);