art.bend checks
raw source on the hub · import 0x3b876eed3a748ea7fba8a7834d3c610b/art.bend as Art
Art: the tile set, and the board as one Image. ==============================================
Bend's Image is a quadtree over a 2^k square, and so is the board. A 16x16 board of 32x32 tiles is a depth-9 image: four levels pick the cell, five more pick the pixel inside its tile.
There are only fourteen tiles on screen at once, so the tile set is drawn once when the game starts and kept in the state. A frame then costs 256 reference counts, not 262144 pixels.
0 hidden 1 flag 2 open, blank 3..10 open, 1 to 8 mines next to it 11 mine 12 the mine that was clicked 13 a flag that was wrong
3 imports
import Base import ./grid.bend as G import ./cell.bend as C
Definitions
def Art.clear source · line 21 · raw
U32
A colour above 0xFFFFFF means "draw the background here".
def Art.pick source · line 24 · raw
@c:Bool -> @a:U32 -> @b:U32 -> U32
def Art.gap source · line 31 · raw
@a:U32 -> @b:U32 -> U32
def Art.font source · line 37 · raw
@+d:U32 -> U32
The 4x6 digit font, one row of four bits per nibble, row 0 lowest.
def Art.ink source · line 48 · raw
@+d:U32 -> U32
The colours Minesweeper has used since 1990.
def Art.raised source · line 59 · raw
@+x:U32 -> @+y:U32 -> U32
An unclicked tile: light on the top and left, dark on the bottom right.
def Art.flat source · line 65 · raw
@x:U32 -> @y:U32 -> U32
A clicked tile: flat, with a grid line along its top and left edge.
def Art.digit_on source · line 72 · raw
@+d:U32 -> @+x:U32 -> @+y:U32 -> Bool
The glyph box is 16x24 at (8, 4), four screen pixels per font pixel. The column and row are clamped before the shift, because an x below 8 wraps to a huge number and U32.shrn counts down its Nat one step at a time.
def Art.mine_on source · line 83 · raw
@+x:U32 -> @+y:U32 -> Bool
A ball with two bars through it, and a highlight on its upper left.
def Art.spark_on source · line 91 · raw
@+x:U32 -> @+y:U32 -> Bool
def Art.cross_on source · line 97 · raw
@+x:U32 -> @+y:U32 -> Bool
The cross drawn over a flag that guarded nothing.
def Art.pole_on source · line 102 · raw
@+x:U32 -> @+y:U32 -> Bool
def Art.cloth_on source · line 112 · raw
@+x:U32 -> @+y:U32 -> Bool
The cloth: widest at the top, down to two pixels at the pole.
def Art.flag_px source · line 117 · raw
@+x:U32 -> @+y:U32 -> U32
def Art.mine_px source · line 121 · raw
@+x:U32 -> @+y:U32 -> U32
def Art.wrong_px source · line 125 · raw
@+x:U32 -> @+y:U32 -> U32
def Art.digit_px source · line 128 · raw
@+code:U32 -> @+x:U32 -> @+y:U32 -> U32
def Art.bg source · line 132 · raw
@+code:U32 -> @+x:U32 -> @+y:U32 -> U32
def Art.fg source · line 137 · raw
@+code:U32 -> @+x:U32 -> @+y:U32 -> U32
def Art.pixel source · line 146 · raw
@+code:U32 -> @+x:U32 -> @+y:U32 -> U32
One pixel of one tile.
def Art.draw source · line 152 · raw
@d:Nat -> @+code:U32 -> @+x:U32 -> @+y:U32 -> Image
Draws one 2^d square. The four quadrants run in parallel, which is also how the quadtree wants to be built.
def Art.tiles source · line 166 · raw
@+scale:Nat -> List<&2, Image>
The whole tile set, drawn once. scale is the tile depth: 5n is 32x32.
def Art.take source · line 182 · raw
@m:Maybe<&2, Image> -> Image
def Art.tile source · line 189 · raw
@ts:List<&2, Image> -> @code:U32 -> Image
def Art.face source · line 194 · raw
@c:0x3b876eed3a748ea7fba8a7834d3c610b/cell.Cell -> @lost:Bool -> @boom:Bool -> U32
Which tile a cell shows. lost turns unflagged mines and bad flags
face up; boom is the one mine the player actually clicked.