Animating a nice backbuffer. Thank you Casey Muratori of Handmade Hero fame (https://www.youtube.com/watch?v=hNKU8Jiza2g)

This commit is contained in:
Michael Smith
2025-08-07 17:56:59 +02:00
parent 4c224a51ec
commit 5387152a21
4 changed files with 128 additions and 55 deletions

View File

@@ -1,17 +1,40 @@
package gb
import (
"image"
"image/color"
)
const (
ConsoleWidth = 160
ConsoleHeight = 144
)
type Console struct {
Cartridge *Cartridge
front *image.RGBA
}
func NewConsole(path string) (*Console, error) {
cartridge := InsertCartridge(path)
buffer := image.NewRGBA(image.Rect(0, 0, ConsoleWidth, ConsoleHeight))
console := Console{cartridge}
console := Console{Cartridge: cartridge, front: buffer}
return &console, nil
}
func (console *Console) Update(dt uint64) {
console.StepSeconds(dt)
func (console *Console) StepMilliSeconds(ms uint64) {
speed := int(ms / 3)
for y := 0; y < ConsoleHeight; y++ {
for x := 0; x < ConsoleWidth; x++ {
console.front.Set(x, y, color.RGBA{0, uint8(y + speed), uint8(x + speed), 255})
}
}
}
func (console *Console) Buffer() *image.RGBA {
return console.front
}