Class GameObjectExtensions
A collection of helpful extension methods for IGameObject instances.
Inherited Members
Namespace: GoRogue.GameFramework
Assembly: GoRogue.dll
Syntax
public static class GameObjectExtensions
Methods
View SourceCanMove(IGameObject, Point)
Returns true if the object can be moved to the location specified; false otherwise.
Declaration
public static bool CanMove(this IGameObject self, Point position)
Parameters
Type | Name | Description |
---|---|---|
IGameObject | self | |
Point | position | The position to check. |
Returns
Type | Description |
---|---|
bool | True if the object can be moved to the specified position; false otherwise. |
Remarks
This function should return false in exactly any case where setting the Position property to the value specified would fail.
CanMoveIn(IGameObject, Direction)
Returns true if the object can move in the given direction; false otherwise.
Declaration
public static bool CanMoveIn(this IGameObject self, Direction direction)
Parameters
Type | Name | Description |
---|---|---|
IGameObject | self | |
Direction | direction | The direction of movement to check. |
Returns
Type | Description |
---|---|
bool | True if the object can be moved in the specified direction; false otherwise |
Remarks
See remarks in documentation for CanMove(IGameObject, Point) for details on when this function should return false.
CanSetWalkability(IGameObject, bool)
Returns true if the object can set its IsWalkable property to the specified value; false otherwise.
Declaration
public static bool CanSetWalkability(this IGameObject self, bool value)
Parameters
Type | Name | Description |
---|---|---|
IGameObject | self | |
bool | value | The new value for walkability to check. |
Returns
Type | Description |
---|---|
bool | True if the object can set its walkability to the given value without violating a map's collision detection, false otherwise. |
Remarks
This returns true unless the new value would violate collision detection rules of a map.
CanToggleWalkability(IGameObject)
Returns true if the object can toggle its IsWalkable property; false otherwise.
Declaration
public static bool CanToggleWalkability(this IGameObject self)
Parameters
Type | Name | Description |
---|---|---|
IGameObject | self |
Returns
Type | Description |
---|---|
bool | True if the object can toggle its walkability without violating a map's collision detection, false otherwise. |
SafelySetCurrentMap(IGameObject, ref Map?, Map?, EventHandler<GameObjectCurrentMapChanged>?, EventHandler<GameObjectCurrentMapChanged>?)
Sets the given map field to the given value, and fires the AddedToMap event and RemovedFromMap event as necessary.
Declaration
public static void SafelySetCurrentMap(this IGameObject self, ref Map? currentMapField, Map? newValue, EventHandler<GameObjectCurrentMapChanged>? addedEvent, EventHandler<GameObjectCurrentMapChanged>? removedEvent)
Parameters
Type | Name | Description |
---|---|---|
IGameObject | self | |
Map | currentMapField | Map field to set. |
Map | newValue | New value to set to the map field. |
EventHandler<GameObjectCurrentMapChanged> | addedEvent | The AddedToMap event for the object whose map is being changed. |
EventHandler<GameObjectCurrentMapChanged> | removedEvent | The RemovedFromMap event for the object whose map is being changed. |
Remarks
This is a convenience function to set the backing field for CurrentMap correctly, ensuring exceptions are handled and that events are fired properly. Generally, this should only be called from within an implementation of OnMapChanged(Map?).
See the implementation of OnMapChanged(Map?) for an example of intended use.