From 5bdcccd3d117548a14ad037cf7209aefb7f3b258 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Wed, 4 Nov 2020 03:56:40 +0000 Subject: [PATCH] cleaning up entity creation --- internal/sim/room.go | 12 ++++++++++++ internal/sim/world.go | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/internal/sim/room.go b/internal/sim/room.go index 7bfeda6..f89e5a8 100644 --- a/internal/sim/room.go +++ b/internal/sim/room.go @@ -37,6 +37,18 @@ func (r *room) playerAvatars() map[string]int { return all } +func (r *room) addEntity(e *entity) bool { + t := r.getTile(e.Position) + if t == nil { + return false + } + if t.here != nil { + return false + } + t.here = e + return true +} + func (r *room) addPlayer(p *player) { r.players[p.name] = p } diff --git a/internal/sim/world.go b/internal/sim/world.go index 52dd56d..e880440 100644 --- a/internal/sim/world.go +++ b/internal/sim/world.go @@ -38,16 +38,43 @@ func newWorld(log *blammo.Log) *world { tiles: make([]tile, bounds.Area()), players: make(map[string]*player), } - foyer.tiles[55].here = &entity{ - ID: 777, + + foyer.addEntity(&entity{ + ID: -1, Position: math.Vec{5, 5}, Glyph: 'd', behavior: doNothing{}, + }) + + foyer.addEntity(&entity{ + ID: -2, + Position: math.Vec{9, 0}, + Glyph: '+', + behavior: doNothing{}, + }) + + foyer.addEntity(&entity{ + ID: -3, + Position: math.Vec{9, 1}, + Glyph: '-', + behavior: doNothing{}, + }) + + hall := room{ + Log: log.Child("hall"), + name: "hall", + Rect: math.CreateRect(20, 4), + tiles: make([]tile, bounds.Area()), + players: make(map[string]*player), } + log.Info("created foyer with bounds: %#v having width: %d height: %d area: %d", foyer.Rect, foyer.Width, foyer.Height, foyer.Area()) return &world{ - Log: log, - rooms: map[string]*room{"foyer": &foyer}, + Log: log, + rooms: map[string]*room{ + "foyer": &foyer, + "hall": &hall, + }, done: make(chan bool), inbox: make(chan Request), connect: make(chan connect),