steel-lord/entity/entity.go

104 lines
1.9 KiB
Go
Raw Normal View History

2019-06-28 16:37:33 -07:00
package entity
import (
2019-07-17 20:05:05 -07:00
"steel/interfaces"
2019-06-28 16:37:33 -07:00
"github.com/kettek/goro"
)
2019-07-17 20:05:05 -07:00
2019-06-28 16:37:33 -07:00
type Entity struct {
2019-07-17 20:05:05 -07:00
x, y int
rune rune
style goro.Style
name string
flags uint
2019-06-28 16:37:33 -07:00
}
2019-07-17 20:05:05 -07:00
// NewEntity returns an interface to a new populated Entity.
2019-07-24 21:04:21 -07:00
func NewEntity(x int, y int, r rune, style goro.Style, name string, flags uint) interfaces.Entity {
2019-06-28 16:37:33 -07:00
return &Entity{
2019-07-17 20:05:05 -07:00
x: x,
y: y,
rune: r,
style: style,
2019-07-24 21:04:21 -07:00
name: name,
flags: flags,
2019-06-28 16:37:33 -07:00
}
2019-07-17 20:05:05 -07:00
}
// Move moves the entity by a given amount.
func (e *Entity) Move(x, y int) {
e.x += x
e.y += y
}
// X returns the entity's X value.
func (e *Entity) X() int {
return e.x
}
// SetX sets the entity's x value
2019-07-17 20:05:05 -07:00
func (e *Entity) SetX(x int) {
e.x = x
}
// Y returns the entity's Y value.
func (e *Entity) Y() int {
return e.y
}
// SetY sets the entity's Y value
func (e *Entity) SetY(y int) {
e.y = y
}
// Rune returns the entity's rune.
func (e *Entity) Rune() rune {
return e.rune
}
// SetRune sets the entity's rune.
func (e *Entity) SetRune(r rune) {
e.rune = r
}
// Style returns the entity's style.
func (e *Entity) Style() goro.Style {
return e.style
}
// SetStyle sets the entity's style.
func (e *Entity) SetStyle(style goro.Style) {
e.style = style
}
// Name gets the entity's name.
func (e *Entity) Name() string {
return e.name
}
// SetName sets the entity's name.
func (e *Entity) SetName(n string) {
e.name = n
}
// Flags gets the entity's flags.
func (e *Entity) Flags() uint {
return e.flags
}
// SetFlags sets the entity's flags.
func (e *Entity) SetFlags(f uint) {
e.flags = f
}
// FindEntityAtLocation finds and returns the first entity at x and y matching the provided flags. If none exists, it returns nil.
func FindEntityAtLocation(entities []interfaces.Entity, x, y int, checkMask uint, matchFlags uint) interfaces.Entity {
for _, e := range entities {
if (e.Flags()&checkMask) == matchFlags && e.X() == x && e.Y() == y {
return e
}
}
return nil
2019-07-17 20:05:05 -07:00
}