// Draw the "fall" view onto the given PixMap. func Draw(pm nimble.PixMap, invaders []Invader) { if pm.Width() != background.Width() || pm.Height() != background.Height() { panic("fall.Draw: pm and background differ in size") } drawDot := false time := nimble.Now() if time-lastDotTime >= dotTimeInterval { lastDotTime = time drawDot = true } pm.Copy(0, 0, &background) xScale := float32(pm.Width() - tickHalfWidth) // Avoid clipping tic on right side yScale := float32(pm.Height() - tickHalfHeight) // Avoid clippling tic on bottom xOffset := float32(0) yOffset := float32(0) for _, inv := range invaders { x := int32(inv.Amplitude*xScale + xOffset) y := int32(inv.Progress*yScale + yOffset) r := nimble.Rect{ Left: x - tickHalfWidth, Top: y - tickHalfHeight, Right: x + tickHalfWidth, Bottom: y + tickHalfHeight, } pm.DrawRect(r, inv.Color) background.DrawRect(r, nimble.Black) if drawDot { if doty := r.Top - 1; background.Contains(x, doty) { background.SetPixel(x, doty, inv.Color) } } } }
func DrawMenuBar(pm nimble.PixMap, menuBar []*Menu) { // Draw menu x := int32(0) for _, m := range menuBar { m.Draw(pm, x, 0) w, _ := m.TabSize() x += w } h := menuFont.Height() pm.DrawRect(nimble.Rect{Top: 0, Left: x, Bottom: h, Right: pm.Width()}, backgroundColor) pm.DrawRect(nimble.Rect{Top: h, Left: x, Bottom: h + 1, Right: pm.Width()}, separatorColor) }