move!
parent
55d638c7f0
commit
b1cc63e471
@ -1,11 +1,17 @@
|
|||||||
package sim
|
package sim
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// entity is any entity that can be simulated.
|
type Entity struct {
|
||||||
type entity interface {
|
ID int `json:"id"`
|
||||||
id() int
|
Position [2]int `json:"pos"`
|
||||||
|
Glyph rune `json:"glyph"`
|
||||||
|
behavior
|
||||||
|
}
|
||||||
|
|
||||||
|
type behavior interface {
|
||||||
// update is the standard tick function
|
// update is the standard tick function
|
||||||
update(time.Duration)
|
update(time.Duration)
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,6 @@
|
|||||||
package sim
|
package sim
|
||||||
|
|
||||||
// tile is an individual cell within the world simulation. Everything happens
|
|
||||||
// on a tile.
|
|
||||||
type tile struct {
|
type tile struct {
|
||||||
// floor is the surface for the tile. All things sit atop the floor. The
|
|
||||||
// floor informs clients how to draw the tile in the event that the tile's
|
|
||||||
// contents are empty. The floor also determins whether or not the tile is
|
|
||||||
// traversable.
|
|
||||||
floor floor
|
floor floor
|
||||||
|
here *Entity
|
||||||
// contents is all of the entities on this tile. A given tile may have many
|
|
||||||
// entities.
|
|
||||||
contents map[int]entity
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *tile) addEntity(e entity) {
|
|
||||||
if t.contents == nil {
|
|
||||||
t.contents = make(map[int]entity)
|
|
||||||
}
|
|
||||||
t.contents[e.id()] = e
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *tile) removeEntity(id int) entity {
|
|
||||||
if e, here := t.contents[id]; here {
|
|
||||||
delete(t.contents, id)
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
package wire
|
Loading…
Reference in New Issue