rename bounds to rect

master
Jordan Orelli 4 years ago
parent e7471df15a
commit 3f657da4cd

@ -1,22 +1,22 @@
package math
type Bounds struct {
type Rect struct {
Origin Vec `json:"origin"`
Width int `json:"width"`
Height int `json:"height"`
}
func CreateBounds(width, height int) Bounds {
return Bounds{
func CreateRect(width, height int) Rect {
return Rect{
Origin: Vec{0, 0},
Width: width,
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 &&
v.X < b.Origin.X+b.Width &&
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{
Name: r.name,
Bounds: r.Bounds,
Rect: r.Rect,
Entities: ents,
}
for _, p := range r.players {

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

@ -20,11 +20,11 @@ type World struct {
}
func NewWorld(log *blammo.Log) *World {
bounds := math.CreateBounds(10, 10)
bounds := math.CreateRect(10, 10)
foyer := room{
Log: log.Child("foyer"),
name: "foyer",
Bounds: math.CreateBounds(10, 10),
Rect: bounds,
tiles: make([]tile, bounds.Area()),
players: make(map[string]*player),
}
@ -34,7 +34,7 @@ func NewWorld(log *blammo.Log) *World {
Glyph: 'd',
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{
Log: log,
rooms: []room{foyer},

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

Loading…
Cancel
Save