You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.1 KiB
Go
63 lines
1.1 KiB
Go
4 years ago
|
package sim
|
||
|
|
||
4 years ago
|
import (
|
||
|
"time"
|
||
|
|
||
4 years ago
|
"github.com/jordanorelli/astro-domu/internal/wire"
|
||
4 years ago
|
"github.com/jordanorelli/blammo"
|
||
|
)
|
||
|
|
||
4 years ago
|
type room struct {
|
||
4 years ago
|
*blammo.Log
|
||
4 years ago
|
name string
|
||
|
origin point
|
||
|
width int
|
||
|
height int
|
||
|
tiles []tile
|
||
|
players map[string]*player
|
||
4 years ago
|
}
|
||
|
|
||
|
func (r *room) update(dt time.Duration) {
|
||
4 years ago
|
for _, p := range r.players {
|
||
|
for _, req := range p.pending {
|
||
4 years ago
|
res := req.Wants.exec(r, p, req.Seq)
|
||
4 years ago
|
p.outbox <- wire.Response{Re: req.Seq, Body: res.reply}
|
||
4 years ago
|
for _, p2 := range r.players {
|
||
|
if p2 == p {
|
||
|
continue
|
||
|
}
|
||
|
p2.outbox <- wire.Response{Body: res.reply}
|
||
|
}
|
||
4 years ago
|
}
|
||
|
p.pending = p.pending[0:0]
|
||
|
}
|
||
|
|
||
4 years ago
|
for _, t := range r.tiles {
|
||
4 years ago
|
if t.here != nil {
|
||
|
t.here.update(dt)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (r *room) allEntities() []Entity {
|
||
|
all := make([]Entity, 0, 4)
|
||
|
for _, t := range r.tiles {
|
||
|
if t.here != nil {
|
||
|
all = append(all, *t.here)
|
||
4 years ago
|
}
|
||
|
}
|
||
4 years ago
|
return all
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
|
func (r *room) addPlayer(p *player) {
|
||
|
r.players[p.name] = p
|
||
|
}
|
||
|
|
||
|
func (r *room) removePlayer(name string) bool {
|
||
|
if _, ok := r.players[name]; ok {
|
||
|
delete(r.players, name)
|
||
|
return true
|
||
|
}
|
||
|
return false
|
||
|
}
|