entities tickingggg
parent
4496e97515
commit
69902a8009
@ -1,5 +1,20 @@
|
||||
package sim
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/jordanorelli/blammo"
|
||||
)
|
||||
|
||||
// player represents a player character in the simulation
|
||||
type player struct {
|
||||
*blammo.Log
|
||||
sessionID int
|
||||
entityID int
|
||||
}
|
||||
|
||||
func (p *player) update(dt time.Duration) {
|
||||
p.Info("tick")
|
||||
}
|
||||
|
||||
func (p *player) id() int { return p.entityID }
|
||||
|
@ -1,7 +1,25 @@
|
||||
package sim
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/jordanorelli/blammo"
|
||||
)
|
||||
|
||||
type room struct {
|
||||
*blammo.Log
|
||||
name string
|
||||
origin point
|
||||
width int
|
||||
height int
|
||||
tiles []tile
|
||||
}
|
||||
|
||||
func (r *room) update(dt time.Duration) {
|
||||
r.Info("updating room")
|
||||
for _, t := range r.tiles {
|
||||
for _, e := range t.contents {
|
||||
e.update(dt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,30 @@
|
||||
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 []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
|
||||
}
|
||||
|
Loading…
Reference in New Issue