コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 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);
         }
     }
 }
コード例 #4
0
 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);
             }
         }
     }
 }
コード例 #5
0
 public void AddEntity(Entity.BaseGameEntity ent)
 {
     if (members != null)
     {
         members.Add(ent);
     }
     else
     {
         members = new List <Entity.BaseGameEntity>
         {
             ent
         };
     }
 }