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 void AddObject(GameObject obj) { var cellIds = GetIdForObj(obj); foreach (var item in cellIds) { Buckets.Get(item).Add(obj); } }
public override bool Blocks(GameObject other) { if (type == ETileType.WALL || type == ETileType.CRATE) { if (other is Bullet) ((Bullet)other).CheckKill(this); return true; } return false; }
public override bool Blocks(GameObject other) { if (other is Tile) { Tile t = other as Tile; if (t.GetTileType() == ETileType.CRATE) return false; } return owner != other; }
public override bool Blocks(GameObject other) { if (other is Entity) return true; if (other is Bullet) { return !((Bullet)other).CheckKill(this); } return true; }
public override bool Blocks(GameObject other) { if (other is Entity) return true; if (other is Tile) { if(((Tile)other).GetTileType() == ETileType.SPAWN) { ResetHealth(); return false; } } if (other is Bullet) { return !((Bullet)other).CheckKill(this); } return true; }
public bool CheckKill(GameObject obj) { if (obj != owner) { if ( obj is Tile) { Tile t = obj as Tile; if (t.GetTileType() == ETileType.CRATE) { color = Color.Blue; speed *= 0.9f; damage *= 0.8f; return true; } } Dead = true; return true; } return false; }
public virtual bool Blocks(GameObject other) { return false; }
public void AddText(GameObject entity , string text) { Texts.Add(new WorldText() { Entity = entity, Text = text, TimeLeft = 3, Offset = new Vector2(-100 + new Random().Next(100) - 50, -50 + new Random().Next(100) - 50) }); }
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; }
public override bool Blocks(GameObject other) { return base.Blocks(other); }
public GameObject[] GetPossibleColliders(GameObject obj) { var objects = new LinkedList<GameObject>(); var bucketIds = GetIdForObj(obj); foreach (var item in bucketIds) { objects.AddRange(Buckets.Get(item)); } return objects.Distinct().ToArray(); }
public System.Collections.Generic.ICollection<GameObject> GetColliders(GameObject obj) { IList<GameObject> colliders = new LinkedList<GameObject>(); // Get all possible colliders exept myself and bullets colliders.AddRange(collisionCuller.GetPossibleColliders(obj).Where(x => x != obj)); // Add tiles collisions var tileColliders = Map.GetPossibleColliders(obj.GetHitRectangle()); colliders.AddRange(tileColliders); // At last only return those who intersects return colliders.Where(x => x.GetHitRectangle().Intersects(obj.GetHitRectangle()) && (x.Blocks(obj) || obj.Blocks(x))).ToList(); }