Exemplo n.º 1
0
 public void ReLoadSpatialHash()
 {
     EntitySpatialHash.Clear();
     foreach (EntityObject e in Entities)
     {
         EntitySpatialHash[e.Position] = e;
     }
 }
Exemplo n.º 2
0
 public EntityObject TryGetEntityHash(Vector2 position)
 {
     if (EntitySpatialHash.ContainsKey(position))
     {
         return(EntitySpatialHash[position]);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 3
0
        public void CheckEntityChange(EntityObject e)
        {
            Vector2 new_position = e.Position + e.FacingPosition;

            if (e.RequestMovement)
            {
                bool in_map = new_position.X >= 0 && new_position.Y >= 0 &&
                              new_position.X < Current.TileMapWidth && new_position.Y < Current.TileMapHeight;
                if (in_map && !CollisionGridTest(new_position))
                {
                    //Request Movement
                    CheckStepOn(e, new_position);
                    MovingEntities[e.Id] = e.Position;
                    e.Position           = new_position;
                    e.Timer = e.TimerResetValue;
                    EntitySpatialHash[e.Position] = e;
                }
                e.RequestMovement = false;
            }
            if (e.RequestMovementComplete)
            {
                e.RequestMovementComplete = false;
                Debug.WriteLine("Remove entity");
                EntitySpatialHash.Remove(MovingEntities[e.Id]);
                MovingEntities.Remove(e.Id);
            }
            if (e.RequestInteract)
            {
                EntityObject entity = TryGetEntityHash(new_position);
                if (entity != null)
                {
                    entity.Interact(EventTrigger.Interact, e);
                }
                e.RequestInteract = false;
            }
        }