doodle/level/grid.go
Noah Petherbridge e1cbff8c3f Add Palette Window and Palette Support to Edit Mode
* Add ui.Window to easily create reusable windows with titles.
* Add a palette window (panel) to the right edge of the Edit Mode.
  * Has Radio Buttons listing the colors available in the palette.
* Add palette support to Edit Mode so when you draw pixels, they take
  on the color and attributes of the currently selected Swatch in your
  palette.
* Revise the on-disk format to better serialize the Palette object to
  JSON.
* Break Play Mode: collision detection fails because the Grid key
  elements are now full Pixel objects (which retain their Palette and
  Swatch properties).
  * The Grid will need to be re-worked to separate X,Y coordinates from
    the Pixel metadata to just test "is something there, and what is
    it?"
2018-08-10 17:19:47 -07:00

28 lines
501 B
Go

package level
import (
"git.kirsle.net/apps/doodle/render"
)
// Grid is a 2D grid of pixels in X,Y notation.
type Grid map[*Pixel]interface{}
// Exists returns true if the point exists on the grid.
func (g *Grid) Exists(p *Pixel) bool {
if _, ok := (*g)[p]; ok {
return true
}
return false
}
// Draw the grid efficiently.
func (g *Grid) Draw(e render.Engine) {
for pixel := range *g {
color := pixel.Swatch.Color
e.DrawPoint(color, render.Point{
X: pixel.X,
Y: pixel.Y,
})
}
}