package types type Rect struct { X, Y, W, H int } type RectFill struct { Top, Bottom, Left, Right, TopLeft, TopRight, BottomLeft, BottomRight, Body interface{} } func NewRect(x, y, w, h int) *Rect { return &Rect{x, y, w, h} } func (r *Rect) Blit(fillage RectFill, layer Putable) { if fillage.Body != "" { for i := r.X + 1; i < r.X+r.W; i++ { for j := r.Y + 1; j < r.Y+r.H; j++ { layer.Put(i, j, fillage.Body) //lii.Put(i, j, "X"); } } } for i := r.X + 1; i < r.X+r.W; i++ { layer.Put(i, r.Y, fillage.Top) //lii.Put(i, Y-1, "Q"); layer.Put(i, r.Y+r.H, fillage.Bottom) //lii.Put(i, Y+H, "H"); } for j := r.Y + 1; j < r.Y+r.H; j++ { layer.Put(r.X, j, fillage.Left) //lii.Put(X-1, j, "U"); layer.Put(r.X+r.W, j, fillage.Right) //lii.Put(X+W, j, "M"); } layer.Put(r.X, r.Y, fillage.TopLeft) //lii.Put(X-1, Y-1, "T"); layer.Put(r.X, r.Y+r.H, fillage.BottomLeft) //lii.Put(X-1, Y+H, "q"); layer.Put(r.X+r.W, r.Y, fillage.TopRight) //lii.Put(X+W, Y-1, "L"); layer.Put(r.X+r.W, r.Y+r.H, fillage.BottomRight) } func (self *Rect) Intersects(other *Rect) bool { if self.X <= (other.X+other.W) && (self.X+self.W) >= other.X && self.Y <= (other.Y+other.Y) && (self.Y+self.H) >= other.Y { return true } return false } func (r *Rect) InBounds (c Coords) bool { return c.X >= r.X && c.X <= (r.X + r.W -1) && c.Y >= r.Y && c.Y <= (r.Y + r.H -1) }