move!
parent
55d638c7f0
commit
b1cc63e471
@ -1,11 +1,17 @@
|
||||
package sim
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// entity is any entity that can be simulated.
|
||||
type entity interface {
|
||||
id() int
|
||||
type Entity struct {
|
||||
ID int `json:"id"`
|
||||
Position [2]int `json:"pos"`
|
||||
Glyph rune `json:"glyph"`
|
||||
behavior
|
||||
}
|
||||
|
||||
type behavior interface {
|
||||
// update is the standard tick function
|
||||
update(time.Duration)
|
||||
}
|
||||
|
@ -1,30 +1,6 @@
|
||||
package sim
|
||||
|
||||
// tile is an individual cell within the world simulation. Everything happens
|
||||
// on a tile.
|
||||
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
|
||||
|
||||
// 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
|
||||
here *Entity
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
package wire
|
Loading…
Reference in New Issue