33 lines
543 B
Go
33 lines
543 B
Go
|
package world
|
||
|
|
||
|
import "sync"
|
||
|
|
||
|
// Entity represents an entity within the world.
|
||
|
type Entity struct {
|
||
|
t int // Type
|
||
|
x, y, z int
|
||
|
|
||
|
sync.RWMutex
|
||
|
}
|
||
|
|
||
|
// NewEntity returns a new Entity.
|
||
|
func NewEntity(t int) *Entity {
|
||
|
return &Entity{t: t}
|
||
|
}
|
||
|
|
||
|
// Is returns whether the Entity matches the specified type.
|
||
|
func (e *Entity) Is(t int) bool {
|
||
|
e.RLock()
|
||
|
defer e.RUnlock()
|
||
|
|
||
|
return e.t == t
|
||
|
}
|
||
|
|
||
|
// Coordinates returns the position of the entity.
|
||
|
func (e *Entity) Coordinates() (x, y, z int) {
|
||
|
e.RLock()
|
||
|
defer e.RUnlock()
|
||
|
|
||
|
return e.x, e.y, e.z
|
||
|
}
|