Show / Hide Table of Contents

Class GameObject

Concrete implementation of IGameObject that works for most use cases.

Inheritance
object
GameObject
Implements
IGameObject
IHasID
IHasLayer
IObjectWithComponents
IPositionable
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
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 Source

GameObject(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.

View Source

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 Source

CurrentMap

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
View Source

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
View Source

ID

ID assigned to this object.

Declaration
public uint ID { get; }
Property Value
Type Description
uint
View Source

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
View Source

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
View Source

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.

View Source

Position

The position of the object.

Declaration
public Point Position { get; set; }
Property Value
Type Description
Point

Methods

View Source

OnMapChanged(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 Source

AddedToMap

Fired when the object is added to a map.

Declaration
public event EventHandler<GameObjectCurrentMapChanged>? AddedToMap
Event Type
Type Description
EventHandler<GameObjectCurrentMapChanged>
View Source

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>>
View Source

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>>
View Source

RemovedFromMap

Fired when the object is removed from a map.

Declaration
public event EventHandler<GameObjectCurrentMapChanged>? RemovedFromMap
Event Type
Type Description
EventHandler<GameObjectCurrentMapChanged>
View Source

TransparencyChanged

Fired when IsTransparent is changed.

Declaration
public event EventHandler<ValueChangedEventArgs<bool>>? TransparencyChanged
Event Type
Type Description
EventHandler<ValueChangedEventArgs<bool>>
View Source

TransparencyChanging

Fired when IsTransparent is about to be changed.

Declaration
public event EventHandler<ValueChangedEventArgs<bool>>? TransparencyChanging
Event Type
Type Description
EventHandler<ValueChangedEventArgs<bool>>
View Source

WalkabilityChanged

Fired when IsWalkable is changed.

Declaration
public event EventHandler<ValueChangedEventArgs<bool>>? WalkabilityChanged
Event Type
Type Description
EventHandler<ValueChangedEventArgs<bool>>
View Source

WalkabilityChanging

Fired when IsWalkable is about to changed.

Declaration
public event EventHandler<ValueChangedEventArgs<bool>>? WalkabilityChanging
Event Type
Type Description
EventHandler<ValueChangedEventArgs<bool>>

Implements

IGameObject
IHasID
IHasLayer
IObjectWithComponents
IPositionable

Extension Methods

Utility.Yield<T>(T)
GameObjectExtensions.CanMove(IGameObject, Point)
GameObjectExtensions.CanMoveIn(IGameObject, Direction)
GameObjectExtensions.CanSetWalkability(IGameObject, bool)
GameObjectExtensions.CanToggleWalkability(IGameObject)
GameObjectExtensions.SafelySetCurrentMap(IGameObject, ref Map?, Map?, EventHandler<GameObjectCurrentMapChanged>?, EventHandler<GameObjectCurrentMapChanged>?)
  • View Source
In this article
Back to top Generated by DocFX