public int PositionToIndex(Entity.BaseGameEntity ent) { int cellX = (int)(ent.GetEntityPosition().X / (partitionSize * 128) / partitionSize); int cellY = (int)(ent.GetEntityPosition().Y / (partitionSize * 128) / partitionSize); return(cellX * numCellsX + cellY); }
public void AddEntity(Entity.BaseGameEntity entity) { int cellX = (int)(entity.GetEntityPosition().X / (partitionSize * 128) / partitionSize); int cellY = (int)(entity.GetEntityPosition().Y / (partitionSize * 128) / partitionSize); //Console.WriteLine("Adding entity to partition: "+ cellX + " " + cellY); entity.SetPartitionCell(cellX, cellY); cells[PositionToIndex(entity)].AddEntity(entity); }
public void ChangeCell(Entity.BaseGameEntity ent) { //Console.WriteLine() if (cells[ent.cellIndex].members != null) { cells[ent.cellIndex].members.Remove(ent); int i = PositionToIndex(ent); if (i >= 0 && i < cellLength) { cells[PositionToIndex(ent)].AddEntity(ent); } } }
public void RemoveEntity(Entity.BaseGameEntity ent) { if (members != null) { for (int i = 0; i < members.Count; i++) { if (members[i].mID == ent.mID) { members.RemoveAt(i); } } } }
public void AddEntity(Entity.BaseGameEntity ent) { if (members != null) { members.Add(ent); } else { members = new List <Entity.BaseGameEntity> { ent }; } }