private IList<int> GetIdForObj(GameObject obj) { var bucketsObjIsIn = new LinkedList<int>(); Vector2 min = new Vector2( obj.GetPosition().X - (obj.GetMaxRadius()), obj.GetPosition().Y - (obj.GetMaxRadius())); Vector2 max = new Vector2( obj.GetPosition().X + (obj.GetMaxRadius()), obj.GetPosition().Y + (obj.GetMaxRadius())); float width = Cols; //TopLeft AddBucket(min, width, bucketsObjIsIn); //TopRight AddBucket(new Vector2(max.X, min.Y), width, bucketsObjIsIn); //BottomRight AddBucket(new Vector2(max.X, max.Y), width, bucketsObjIsIn); //BottomLeft AddBucket(new Vector2(min.X, max.Y), width, bucketsObjIsIn); return bucketsObjIsIn; }
public bool RayCast(GameObject origin, GameObject target) { var segment = new Segment(origin.GetPosition(), target.GetPosition()); for (int y = 0; y < Map.getTileMap().GetLength(0); y++) { for (int x = 0; x < Map.getTileMap().GetLength(1); x++) { if (Map.getTileMap()[x, y].GetTileType() != ETileType.WALL) // && Map.getTileMap()[x, y].GetType() != ETileType.CREATE) continue; if (segment.Collide(Map.getTileMap()[x, y].GetRecHit())) return false; } } // Should enemies block raycast? foreach (var enemy in Enemies.Where(x => x != origin)) { if (segment.Collide(enemy.GetHitRectangle())) return false; } return true; }