// Removes MObject from this map if it is in there, returning success. public bool Remove(MObject mObject) { if (!_layers[(int)mObject.Layer].Remove(mObject)) { return(false); } mObject.Moved -= OnMObjectMoved; mObject._onMapChanged(null); return(true); }
// Adds given MObject at the given position (Position property of MObject will be // automatically updated, and entity is removed from its current map (if any), if and only if // the Add was successful). Returns false if it can't add. public bool Add(MObject mObject, Coord position) { if (Collides(mObject, position)) { return(false); } if (!_layers[(int)mObject.Layer].Add(mObject, position)) { return(false); } mObject.CurrentMap?.Remove(mObject); mObject.Position = position; // Performs no collision detecttion because its CurrentMap is guaranteed to be null because of above line mObject.Moved += OnMObjectMoved; mObject._onMapChanged(this); return(true); }