rename bounds to rect

master
Jordan Orelli 4 years ago
parent e7471df15a
commit 3f657da4cd

@ -1,22 +1,22 @@
package math package math
type Bounds struct { type Rect struct {
Origin Vec `json:"origin"` Origin Vec `json:"origin"`
Width int `json:"width"` Width int `json:"width"`
Height int `json:"height"` Height int `json:"height"`
} }
func CreateBounds(width, height int) Bounds { func CreateRect(width, height int) Rect {
return Bounds{ return Rect{
Origin: Vec{0, 0}, Origin: Vec{0, 0},
Width: width, Width: width,
Height: height, Height: height,
} }
} }
func (b Bounds) Area() int { return b.Width * b.Height } func (b Rect) Area() int { return b.Width * b.Height }
func (b Bounds) Contains(v Vec) bool { func (b Rect) Contains(v Vec) bool {
return v.X >= b.Origin.X && return v.X >= b.Origin.X &&
v.X < b.Origin.X+b.Width && v.X < b.Origin.X+b.Width &&
v.Y >= b.Origin.Y && v.Y >= b.Origin.Y &&

@ -92,7 +92,7 @@ func (s *SpawnPlayer) exec(r *room, p *player, seq int) result {
} }
welcome.Rooms[r.name] = wire.Room{ welcome.Rooms[r.name] = wire.Room{
Name: r.name, Name: r.name,
Bounds: r.Bounds, Rect: r.Rect,
Entities: ents, Entities: ents,
} }
for _, p := range r.players { for _, p := range r.players {

@ -11,7 +11,7 @@ import (
type room struct { type room struct {
*blammo.Log *blammo.Log
name string name string
math.Bounds math.Rect
tiles []tile tiles []tile
players map[string]*player players map[string]*player
} }

@ -20,11 +20,11 @@ type World struct {
} }
func NewWorld(log *blammo.Log) *World { func NewWorld(log *blammo.Log) *World {
bounds := math.CreateBounds(10, 10) bounds := math.CreateRect(10, 10)
foyer := room{ foyer := room{
Log: log.Child("foyer"), Log: log.Child("foyer"),
name: "foyer", name: "foyer",
Bounds: math.CreateBounds(10, 10), Rect: bounds,
tiles: make([]tile, bounds.Area()), tiles: make([]tile, bounds.Area()),
players: make(map[string]*player), players: make(map[string]*player),
} }
@ -34,7 +34,7 @@ func NewWorld(log *blammo.Log) *World {
Glyph: 'd', Glyph: 'd',
behavior: doNothing{}, behavior: doNothing{},
} }
log.Info("created foyer with bounds: %#v having width: %d height: %d area: %d", foyer.Bounds, foyer.Width, foyer.Height, foyer.Area()) log.Info("created foyer with bounds: %#v having width: %d height: %d area: %d", foyer.Rect, foyer.Width, foyer.Height, foyer.Area())
return &World{ return &World{
Log: log, Log: log,
rooms: []room{foyer}, rooms: []room{foyer},

@ -6,7 +6,7 @@ import (
// Room represents a 2-dimensional coordinate space. // Room represents a 2-dimensional coordinate space.
type Room struct { type Room struct {
Name string `json:"name"` Name string `json:"name"`
math.Bounds `json:"bounds"` math.Rect `json:"bounds"`
Entities map[int]Entity `json:"entities"` Entities map[int]Entity `json:"entities"`
} }

Loading…
Cancel
Save