// 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 updateClock() (dt float32) { t := nimble.Now() if lastTime > 0 { dt = float32(t - lastTime) } else { dt = 0 } lastTime = t return }
// Draw the teletype contents on the given PixMap. func Draw(pm nimble.PixMap) { var r *[]byte = nil if displayCursor && math.Mod(nimble.Now(), 1) >= 0.5 { r = lastLine() } if r != nil { *r = append(*r, 0) } draw(pm, teletypeDisplay[:]) if r != nil { *r = (*r)[:len(*r)-1] } }