Class GameObject
Concrete implementation of IGameObject that works for most use cases.
Inherited Members
Namespace: GoRogue.GameFramework
Assembly: GoRogue.dll
Syntax
public class GameObject : IGameObject, IHasID, IHasLayer, IObjectWithComponents, IPositionable
Remarks
Any component collection implementing the proper interface may be passed in at construction and used as the GoRogueComponents property value, however by default a ComponentCollection is used, and thus will accept components of any type and will properly support ISortedComponent.
Constructors
View SourceGameObject(Point, int, bool, bool, Func<uint>?, IComponentCollection?)
Constructor.
Declaration
public GameObject(Point position, int layer, bool isWalkable = true, bool isTransparent = true, Func<uint>? idGenerator = null, IComponentCollection? customComponentCollection = null)
Parameters
Type | Name | Description |
---|---|---|
Point | position | Position to start the object at. |
int | layer | The layer of of a Map the object is assigned to. |
bool | isWalkable | Whether or not the object is to be considered "walkable", eg. whether or not the square it resides on can be traversed by other, non-walkable objects on the same Map. Effectively, whether or not this object collides. |
bool | isTransparent | Whether or not the object is considered "transparent", eg. whether or not light passes through it for the sake of calculating the FOV of a Map. |
Func<uint> | idGenerator | The function used to generate and return an unsigned integer to use assign to the ID field. Most of the time, you will not need to specify this as the default implementation will be sufficient. See the constructor remarks for details. |
IComponentCollection | customComponentCollection | A custom component collection to use for objects. If not specified, a ComponentCollection is used. Typically you will not need to specify this, as a ComponentCollection is sufficient for nearly all use cases. |
Remarks
idGenerator
is used to generate an ID which is assigned to the ID
field. When null is specified, the constructor simply assigns a random number in range of valid uints. This
is sufficiently distinct for the purposes of placing the objects in an ISpatialMap<T>
implementation, however obviously does NOT guarantee true uniqueness. If uniqueness or some other
implementation is required, override this function to return an appropriate ID. Keep in mind a relatively
high degree of uniqueness is necessary for efficient placement in an ISpatialMap implementation.
GameObject(int, bool, bool, Func<uint>?, IComponentCollection?)
Constructor.
Declaration
public GameObject(int layer, bool isWalkable = true, bool isTransparent = true, Func<uint>? idGenerator = null, IComponentCollection? customComponentCollection = null)
Parameters
Type | Name | Description |
---|---|---|
int | layer | The layer of of a Map the object is assigned to. |
bool | isWalkable | Whether or not the object is to be considered "walkable", eg. whether or not the square it resides on can be traversed by other, non-walkable objects on the same Map. Effectively, whether or not this object collides. |
bool | isTransparent | Whether or not the object is considered "transparent", eg. whether or not light passes through it for the sake of calculating the FOV of a Map. |
Func<uint> | idGenerator | The function used to generate and return an unsigned integer to use assign to the ID field. Most of the time, you will not need to specify this as the default implementation will be sufficient. See the constructor remarks for details. |
IComponentCollection | customComponentCollection | A custom component collection to use for objects. If not specified, a ComponentCollection is used. Typically you will not need to specify this, as a ComponentCollection is sufficient for nearly all use cases. |
Remarks
idGenerator
is used to generate an ID which is assigned to the ID
field. When null is specified, the constructor simply assigns a random number in range of valid uints. This
is sufficiently distinct for the purposes of placing the objects in an ISpatialMap<T>
implementation, however obviously does NOT guarantee true uniqueness. If uniqueness or some other
implementation is required, override this function to return an appropriate ID. Keep in mind a relatively
high degree of uniqueness is necessary for efficient placement in an ISpatialMap implementation.
Properties
View SourceCurrentMap
The current Map which this object resides on. Returns null if the object has not been added to a map. An IGameObject is allowed to reside on only one map.
Declaration
public Map? CurrentMap { get; }
Property Value
Type | Description |
---|---|
Map |
GoRogueComponents
Collection holding components that GoRogue has recorded as being attached to the implementing object.
Declaration
public IComponentCollection GoRogueComponents { get; }
Property Value
Type | Description |
---|---|
IComponentCollection |
ID
ID assigned to this object.
Declaration
public uint ID { get; }
Property Value
Type | Description |
---|---|
uint |
IsTransparent
Whether or not the object is considered "transparent", eg. whether or not light passes through it for the sake of calculating FOV.
Declaration
public bool IsTransparent { get; set; }
Property Value
Type | Description |
---|---|
bool |
IsWalkable
Whether or not the object is to be considered "walkable", eg. whether or not the square it resides on can be traversed by other, non-walkable objects on the same Map. Effectively, whether or not this object collides.
Declaration
public bool IsWalkable { get; set; }
Property Value
Type | Description |
---|---|
bool |
Layer
The layer on which the object should reside. Higher numbers indicate layers closer to the "top".
Declaration
public int Layer { get; }
Property Value
Type | Description |
---|---|
int |
Remarks
This value is typically assumed to remain constant while the object is within a data structure that uses this interface -- if it is modified, that data structure will become out of sync.
Position
The position of the object.
Declaration
public Point Position { get; set; }
Property Value
Type | Description |
---|---|
Point |
Methods
View SourceOnMapChanged(Map?)
Internal use only, do not call manually! Must, at minimum, call SafelySetCurrentMap(IGameObject, ref Map?, Map?, EventHandler<GameObjectCurrentMapChanged>?, EventHandler<GameObjectCurrentMapChanged>?) which will update the CurrentMap field of the IGameObject to reflect the change and fire map added/removed events as appropriate (or provide equivalent functionality).
Declaration
public void OnMapChanged(Map? newMap)
Parameters
Type | Name | Description |
---|---|---|
Map | newMap | New map to which the IGameObject has been added. |
Events
View SourceAddedToMap
Fired when the object is added to a map.
Declaration
public event EventHandler<GameObjectCurrentMapChanged>? AddedToMap
Event Type
Type | Description |
---|---|
EventHandler<GameObjectCurrentMapChanged> |
PositionChanged
Event which should be fired when the object's position changes.
Declaration
public event EventHandler<ValueChangedEventArgs<Point>>? PositionChanged
Event Type
Type | Description |
---|---|
EventHandler<ValueChangedEventArgs<Point>> |
PositionChanging
Event which should be fired right before the object's position changes.
Declaration
public event EventHandler<ValueChangedEventArgs<Point>>? PositionChanging
Event Type
Type | Description |
---|---|
EventHandler<ValueChangedEventArgs<Point>> |
RemovedFromMap
Fired when the object is removed from a map.
Declaration
public event EventHandler<GameObjectCurrentMapChanged>? RemovedFromMap
Event Type
Type | Description |
---|---|
EventHandler<GameObjectCurrentMapChanged> |
TransparencyChanged
Fired when IsTransparent is changed.
Declaration
public event EventHandler<ValueChangedEventArgs<bool>>? TransparencyChanged
Event Type
Type | Description |
---|---|
EventHandler<ValueChangedEventArgs<bool>> |
TransparencyChanging
Fired when IsTransparent is about to be changed.
Declaration
public event EventHandler<ValueChangedEventArgs<bool>>? TransparencyChanging
Event Type
Type | Description |
---|---|
EventHandler<ValueChangedEventArgs<bool>> |
WalkabilityChanged
Fired when IsWalkable is changed.
Declaration
public event EventHandler<ValueChangedEventArgs<bool>>? WalkabilityChanged
Event Type
Type | Description |
---|---|
EventHandler<ValueChangedEventArgs<bool>> |
WalkabilityChanging
Fired when IsWalkable is about to changed.
Declaration
public event EventHandler<ValueChangedEventArgs<bool>>? WalkabilityChanging
Event Type
Type | Description |
---|---|
EventHandler<ValueChangedEventArgs<bool>> |