almost everything working for nicebadge

- missing logo image
- cmd to generate logo image
This commit is contained in:
Daniel Esteban 2026-04-17 18:43:42 +02:00
parent 8a746c30d5
commit b3363a7fd7
16 changed files with 268 additions and 194 deletions

View file

@ -1,78 +1,6 @@
//go:build gopher_badge //go:build !gopher_badge && !pybadge
// +build gopher_badge // +build !gopher_badge,!pybadge
package main package main
import ( func Accel3D() {}
"time"
"tinygo.org/x/tinydraw"
"tinygo.org/x/tinyfont"
"tinygo.org/x/tinyfont/freesans"
)
func Accel3D() {
display.FillScreen(colorWhite)
tinydraw.Rectangle(&display, 50, 16, 260, 16, colorBlack)
tinydraw.Rectangle(&display, 50, 56, 260, 16, colorBlack)
tinydraw.Rectangle(&display, 50, 96, 260, 16, colorBlack)
tinyfont.WriteLine(&display, &freesans.Regular12pt7b, 20, 180, "MOVE the Gopher to see", colorBlack)
tinyfont.WriteLine(&display, &freesans.Regular12pt7b, 32, 200, "the accelerometer in", colorBlack)
tinyfont.WriteLine(&display, &freesans.Regular12pt7b, 90, 220, "action.", colorBlack)
tinyfont.WriteLine(&display, &freesans.Regular24pt7b, 4, 40, "X:", colorBlack)
tinyfont.WriteLine(&display, &freesans.Regular24pt7b, 4, 80, "Y:", colorBlack)
tinyfont.WriteLine(&display, &freesans.Regular24pt7b, 4, 120, "Z:", colorBlack)
x, y, z := accel.ReadRawAcceleration()
for {
if !btnA.Get() || !btnB.Get() {
break
}
x, y, z = accel.ReadRawAcceleration()
x = x / 250
y = y / 250
z = z / 250
if x > 128 {
x = 128
}
if y > 128 {
y = 128
}
if z > 128 {
z = 128
}
if x < -128 {
x = -128
}
if y < -128 {
y = -128
}
if z < -128 {
z = -128
}
display.FillRectangle(51, 22, 258, 6, colorWhite)
display.FillRectangle(51, 62, 258, 6, colorWhite)
display.FillRectangle(51, 102, 258, 6, colorWhite)
if x < 0 {
display.FillRectangle(179+x, 22, -x, 6, colorRed)
} else {
display.FillRectangle(179, 22, x, 6, colorRed)
}
if y < 0 {
display.FillRectangle(179+y, 62, -y, 6, colorGreen)
} else {
display.FillRectangle(179, 62, y, 6, colorGreen)
}
if z < 0 {
display.FillRectangle(179+z, 102, -z, 6, colorBlue)
} else {
display.FillRectangle(179, 102, z, 6, colorBlue)
}
println("X:", x, "Y:", y, "Z:", z)
time.Sleep(50 * time.Millisecond)
}
}

78
accel3d_gopherbadge.go Normal file
View file

@ -0,0 +1,78 @@
//go:build gopher_badge
// +build gopher_badge
package main
import (
"time"
"tinygo.org/x/tinydraw"
"tinygo.org/x/tinyfont"
"tinygo.org/x/tinyfont/freesans"
)
func Accel3D() {
display.FillScreen(colorWhite)
tinydraw.Rectangle(&display, 50, 16, 260, 16, colorBlack)
tinydraw.Rectangle(&display, 50, 56, 260, 16, colorBlack)
tinydraw.Rectangle(&display, 50, 96, 260, 16, colorBlack)
tinyfont.WriteLine(&display, &freesans.Regular12pt7b, 20, 180, "MOVE the Gopher to see", colorBlack)
tinyfont.WriteLine(&display, &freesans.Regular12pt7b, 32, 200, "the accelerometer in", colorBlack)
tinyfont.WriteLine(&display, &freesans.Regular12pt7b, 90, 220, "action.", colorBlack)
tinyfont.WriteLine(&display, &freesans.Regular24pt7b, 4, 40, "X:", colorBlack)
tinyfont.WriteLine(&display, &freesans.Regular24pt7b, 4, 80, "Y:", colorBlack)
tinyfont.WriteLine(&display, &freesans.Regular24pt7b, 4, 120, "Z:", colorBlack)
x, y, z := accel.ReadRawAcceleration()
for {
if !btnA.Get() || !btnB.Get() {
break
}
x, y, z = accel.ReadRawAcceleration()
x = x / 250
y = y / 250
z = z / 250
if x > 128 {
x = 128
}
if y > 128 {
y = 128
}
if z > 128 {
z = 128
}
if x < -128 {
x = -128
}
if y < -128 {
y = -128
}
if z < -128 {
z = -128
}
display.FillRectangle(51, 22, 258, 6, colorWhite)
display.FillRectangle(51, 62, 258, 6, colorWhite)
display.FillRectangle(51, 102, 258, 6, colorWhite)
if x < 0 {
display.FillRectangle(179+x, 22, -x, 6, colorRed)
} else {
display.FillRectangle(179, 22, x, 6, colorRed)
}
if y < 0 {
display.FillRectangle(179+y, 62, -y, 6, colorGreen)
} else {
display.FillRectangle(179, 62, y, 6, colorGreen)
}
if z < 0 {
display.FillRectangle(179+z, 102, -z, 6, colorBlue)
} else {
display.FillRectangle(179, 102, z, 6, colorBlue)
}
println("X:", x, "Y:", y, "Z:", z)
time.Sleep(50 * time.Millisecond)
}
}

View file

@ -13,6 +13,11 @@ import (
qrcode "github.com/skip2/go-qrcode" qrcode "github.com/skip2/go-qrcode"
) )
var (
advOptY = int16(24)
advOptHeight = int16(10)
)
func adventure() { func adventure() {
quit := false quit := false
s := 0 s := 0
@ -23,9 +28,14 @@ func adventure() {
talk := false talk := false
opinion := 0 opinion := 0
selected := int16(0) selected := int16(0)
//released := true
if displayWidth <= 240 {
advOptY = 54
advOptHeight = 20
}
for { for {
println(s) println("SCENE", s)
scene(s) scene(s)
selected = 0 selected = 0
score += s score += s
@ -71,23 +81,21 @@ func adventure() {
return return
} }
tinydraw.FilledCircle(&display, 10, displayHeight-28+10*selected, 3, colorWhite) tinydraw.FilledCircle(&display, 10, displayHeight-advOptY-4+advOptHeight*selected, 3, colorWhite)
//released = true
for { for {
getInput()
/*if released && !btnUp.Get() && selected > 0 { if selected > 0 && ((!buttonsOldState[buttonLeft] && buttonsState[buttonLeft]) ||
tinydraw.FilledCircle(&display, 10, displayHeight-28+10*selected, 3, colorBlack) (!buttonsOldState[buttonUp] && buttonsState[buttonUp])) {
tinydraw.FilledCircle(&display, 10, displayHeight-4-advOptY+advOptHeight*selected, 3, colorBlack)
selected-- selected--
tinydraw.FilledCircle(&display, 10, displayHeight-28+10*selected, 3, colorWhite) tinydraw.FilledCircle(&display, 10, displayHeight-4-advOptY+advOptHeight*selected, 3, colorWhite)
} } else if selected < 2 && ((!buttonsOldState[buttonRight] && buttonsState[buttonRight]) ||
(!buttonsOldState[buttonDown] && buttonsState[buttonDown])) {
if released && !btnDown.Get() && selected < 2 { tinydraw.FilledCircle(&display, 10, displayHeight-4-advOptY+advOptHeight*selected, 3, colorBlack)
tinydraw.FilledCircle(&display, 10, displayHeight-28+10*selected, 3, colorBlack)
selected++ selected++
tinydraw.FilledCircle(&display, 10, displayHeight-28+10*selected, 3, colorWhite) tinydraw.FilledCircle(&display, 10, displayHeight-4-advOptY+advOptHeight*selected, 3, colorWhite)
} } else if !buttonsOldState[buttonA] && buttonsState[buttonA] {
if released && !btnA.Get() {
if selected == 0 { if selected == 0 {
s = sceneData[s].sceneA s = sceneData[s].sceneA
if s == 1 { if s == 1 {
@ -113,19 +121,12 @@ func adventure() {
} }
break break
} }
} else if goBack() {
quit = true
break
} }
if btnA.Get() && btnUp.Get() && btnDown.Get() {
released = true
} else {
released = false
}
if !btnB.Get() {
return
}*/
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)
} }
if quit { if quit {
break break
@ -136,33 +137,59 @@ func adventure() {
func scene(s int) { func scene(s int) {
display.FillScreen(colorWhite) display.FillScreen(colorWhite)
ss := splitBefore(sceneData[s].description) ss := splitBefore(sceneData[s].description, 0)
for i := int16(0); i < int16(len(ss)); i++ { for i := int16(0); i < int16(len(ss)); i++ {
tinyfont.WriteLine(&display, &freemono.Regular9pt7b, 6, 6+i*16, ss[i], colorBlack) if displayWidth <= 240 {
tinyfont.WriteLine(&display, &proggy.TinySZ8pt7b, 6, 16+i*10, ss[i], colorBlack)
} else {
tinyfont.WriteLine(&display, &freemono.Regular9pt7b, 6, 16+i*16, ss[i], colorBlack)
}
} }
display.FillRectangle(0, displayHeight-33, displayWidth, 33, colorBlack) display.FillRectangle(0, displayHeight-advOptY-9, displayWidth, advOptY+9, colorBlack)
tinyfont.WriteLine(&display, &proggy.TinySZ8pt7b, 20, displayHeight-24, sceneData[s].optionA, colorWhite)
tinyfont.WriteLine(&display, &proggy.TinySZ8pt7b, 20, displayHeight-14, sceneData[s].optionB, colorWhite)
tinyfont.WriteLine(&display, &proggy.TinySZ8pt7b, 20, displayHeight-4, sceneData[s].optionC, colorWhite)
tinydraw.Circle(&display, 10, displayHeight-28, 4, colorWhite) // OPTION A
tinydraw.Circle(&display, 10, displayHeight-18, 4, colorWhite) ss = splitBefore(sceneData[s].optionA, 3)
tinydraw.Circle(&display, 10, displayHeight-8, 4, colorWhite) tinyfont.WriteLine(&display, &proggy.TinySZ8pt7b, 20, displayHeight-advOptY, ss[0], colorWhite)
if len(ss) > 1 {
tinyfont.WriteLine(&display, &proggy.TinySZ8pt7b, 20, displayHeight-advOptY+10, ss[1], colorWhite)
}
// OPTION B
ss = splitBefore(sceneData[s].optionB, 3)
tinyfont.WriteLine(&display, &proggy.TinySZ8pt7b, 20, displayHeight-advOptY+advOptHeight, ss[0], colorWhite)
if len(ss) > 1 {
tinyfont.WriteLine(&display, &proggy.TinySZ8pt7b, 20, displayHeight-advOptY+advOptHeight+10, ss[1], colorWhite)
}
// OPTION C
ss = splitBefore(sceneData[s].optionC, 3)
tinyfont.WriteLine(&display, &proggy.TinySZ8pt7b, 20, displayHeight-advOptY+advOptHeight*2, ss[0], colorWhite)
if len(ss) > 1 {
tinyfont.WriteLine(&display, &proggy.TinySZ8pt7b, 20, displayHeight-advOptY+advOptHeight*2+10, ss[1], colorWhite)
}
tinydraw.Circle(&display, 10, displayHeight-advOptY-4, 4, colorWhite)
tinydraw.Circle(&display, 10, displayHeight-advOptY+advOptHeight-4, 4, colorWhite)
tinydraw.Circle(&display, 10, displayHeight-advOptY+(advOptHeight)*2-4, 4, colorWhite)
display.Display() display.Display()
} }
func splitBefore(str string) []string { func splitBefore(str string, offset int) []string {
l := len(str) l := len(str)
a := 0 a := 0
s := make([]string, 1) s := make([]string, 0)
lineW := 28 - offset
if displayWidth <= 240 {
lineW = 40 - offset
}
for { for {
if l <= 28 { if l <= lineW {
s = append(s, str[a:a+l]) s = append(s, str[a:a+l])
break break
} else { } else {
for i := 28; i > 0; i-- { for i := lineW; i > 0; i-- {
if string(str[a+i]) == " " { if string(str[a+i]) == " " {
s = append(s, str[a:a+i]) s = append(s, str[a:a+i])
a = a + i + 1 a = a + i + 1

View file

@ -48,8 +48,11 @@ func Badge() {
break break
} }
case 1: case 1:
//logopurpleHardware() if hardwareName == "GOPHERBADGE" {
logopurpleHardware()
} else {
selectedScreen++ selectedScreen++
}
if quit { if quit {
break break
} }

View file

@ -7,9 +7,11 @@ package main
// This file is not compiled when using a specific target // This file is not compiled when using a specific target
const ( const (
hardware_name = "DEFAULT" hardwareName = "DEFAULT"
displayWidth = 320 displayWidth = 320
displayHeight = 240 displayHeight = 240
hasAccel = false
) )
const ( const (
@ -24,3 +26,9 @@ const (
menuItemSpace = 20 menuItemSpace = 20
menuCircleR = 6 menuCircleR = 6
) )
// snake
const (
snakeWidthBLOCKS = 32
snakeHeightBLOCKS = 24
)

View file

@ -13,9 +13,11 @@ import (
) )
const ( const (
hardware_name = "GOPHERBADGE" hardwareName = "GOPHERBADGE"
displayWidth = 320 displayWidth = 320
displayHeight = 240 displayHeight = 240
hasAccel = true
) )
// UI layout constants for gopherbadge (320x240) // UI layout constants for gopherbadge (320x240)
@ -38,6 +40,12 @@ const (
buttonBack = buttonB buttonBack = buttonB
) )
// snake
const (
snakeWidthBLOCKS = 32
snakeHeightBLOCKS = 24
)
var menuOptions = []int8{ var menuOptions = []int8{
modeBadge, modeBadge,
modeSchedule, modeSchedule,

View file

@ -13,9 +13,11 @@ import (
) )
const ( const (
hardware_name = "NICEBADGE" hardwareName = "NICEBADGE"
displayWidth = 240 displayWidth = 240
displayHeight = 135 displayHeight = 135
hasAccel = false
) )
// UI layout constants for nicebadge (240x135) // UI layout constants for nicebadge (240x135)
@ -25,7 +27,7 @@ const (
topBandHeight = 20 topBandHeight = 20
bottomBandHeight = 10 bottomBandHeight = 10
helloY = 20 helloY = 20
myNameIsY = 20 myNameIsY = 21
gophersY = 110 gophersY = 110
gophersX = 48 gophersX = 48
@ -38,6 +40,12 @@ const (
buttonBack = buttonB buttonBack = buttonB
) )
// snake
const (
snakeWidthBLOCKS = 24
snakeHeightBLOCKS = 13
)
var menuOptions = []int8{ var menuOptions = []int8{
modeBadge, modeBadge,
modeSchedule, modeSchedule,
@ -97,14 +105,11 @@ func initHardware() {
neo := machine.P1_11 neo := machine.P1_11
neo.Configure(machine.PinConfig{Mode: machine.PinOutput}) neo.Configure(machine.PinConfig{Mode: machine.PinOutput})
leds = ws2812.New(neo) leds = ws2812.NewWS2812(neo)
bzrPin = machine.P0_31 bzrPin = machine.P0_31
bzrPin.Configure(machine.PinConfig{Mode: machine.PinOutput}) bzrPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
//pwm := machine.PWM0
//speaker, _ := tone.New(pwm, bzrPin)
machine.InitADC() machine.InitADC()
ax = machine.ADC{Pin: machine.P0_02} ax = machine.ADC{Pin: machine.P0_02}
ay = machine.ADC{Pin: machine.P0_29} ay = machine.ADC{Pin: machine.P0_29}
@ -142,5 +147,3 @@ func getInput() {
buttonsState[buttonDown] = (ay.Get() < 12000) buttonsState[buttonDown] = (ay.Get() < 12000)
buttonsState[buttonUp] = (ay.Get() > 52000) buttonsState[buttonUp] = (ay.Get() > 52000)
} }
func Accel3D() {}

View file

@ -13,9 +13,11 @@ import (
) )
const ( const (
hardware_name = "GOBADGE" hardwareName = "GOBADGE"
displayWidth = 160 displayWidth = 160
displayHeight = 128 displayHeight = 128
hasAccel = true
) )
// UI layout constants for pybadge/gobadge (160x128) // UI layout constants for pybadge/gobadge (160x128)
@ -38,6 +40,12 @@ const (
buttonBack = buttonSelect buttonBack = buttonSelect
) )
// snake
const (
snakeWidthBLOCKS = 16
snakeHeightBLOCKS = 12
)
var menuOptions = []int8{ var menuOptions = []int8{
modeBadge, modeBadge,
modeSchedule, modeSchedule,

View file

@ -47,6 +47,9 @@ func ColorGame() {
display.FillRectangle(p1x-gameColorsSpeed, p1y-gameColorsSpeed, gameColorsCellSize, gameColorsCellSize, colorPurple) display.FillRectangle(p1x-gameColorsSpeed, p1y-gameColorsSpeed, gameColorsCellSize, gameColorsCellSize, colorPurple)
display.FillRectangle(p2x-gameColorsSpeed, p2y-gameColorsSpeed, gameColorsCellSize, gameColorsCellSize, colorOrange) display.FillRectangle(p2x-gameColorsSpeed, p2y-gameColorsSpeed, gameColorsCellSize, gameColorsCellSize, colorOrange)
gw := (gameColorsWidth * gameColorsCellSize) - gameColorsSpeed
gh := (gameColorsHeight * gameColorsCellSize) - gameColorsSpeed
for { for {
display.FillRectangle(p1x-gameColorsSpeed, p1y-gameColorsSpeed, gameColorsCellSize, gameColorsCellSize, colorOrange) display.FillRectangle(p1x-gameColorsSpeed, p1y-gameColorsSpeed, gameColorsCellSize, gameColorsCellSize, colorOrange)
display.FillRectangle(p2x-gameColorsSpeed, p2y-gameColorsSpeed, gameColorsCellSize, gameColorsCellSize, colorPurple) display.FillRectangle(p2x-gameColorsSpeed, p2y-gameColorsSpeed, gameColorsCellSize, gameColorsCellSize, colorPurple)
@ -56,16 +59,16 @@ func ColorGame() {
p2x += v2x p2x += v2x
p2y += v2y p2y += v2y
if (p1x < gameColorsSpeed && v1x < 0) || (p1x > (displayWidth-gameColorsSpeed) && v1x > 0) { if (p1x < gameColorsSpeed && v1x < 0) || (p1x > gw && v1x > 0) {
v1x = -v1x v1x = -v1x
} }
if (p2x < gameColorsSpeed && v2x < 0) || (p2x > (displayWidth-gameColorsSpeed) && v2x > 0) { if (p2x < gameColorsSpeed && v2x < 0) || (p2x > gw && v2x > 0) {
v2x = -v2x v2x = -v2x
} }
if (p1y < gameColorsSpeed && v1y < 0) || (p1y > (displayHeight-gameColorsSpeed) && v1y > 0) { if (p1y < gameColorsSpeed && v1y < 0) || (p1y > gh && v1y > 0) {
v1y = -v1y v1y = -v1y
} }
if (p2y < gameColorsSpeed && v2y < 0) || (p2y > (displayHeight-gameColorsSpeed) && v2y > 0) { if (p2y < gameColorsSpeed && v2y < 0) || (p2y > gh && v2y > 0) {
v2y = -v2y v2y = -v2y
} }

View file

@ -9,7 +9,7 @@ import (
const ( const (
population = 20 population = 20
cellSize int16 = 6 cellSize int16 = 5
gameWidth uint32 = uint32(displayWidth / cellSize) gameWidth uint32 = uint32(displayWidth / cellSize)
gameHeight uint32 = uint32(displayHeight / cellSize) gameHeight uint32 = uint32(displayHeight / cellSize)
) )
@ -20,24 +20,25 @@ var (
universe *game.Universe universe *game.Universe
cellBuf = []color.RGBA{ cellBuf = []color.RGBA{
colorWhite, colorWhite, colorWhite, colorWhite, colorWhite, colorWhite, colorWhite, colorWhite, colorBlack, colorWhite, colorWhite,
colorWhite, colorWhite, colorBlack, colorBlack, colorWhite, colorWhite, colorWhite, colorBlack, colorBlack, colorBlack, colorWhite,
colorWhite, colorBlack, colorBlack, colorBlack, colorBlack, colorWhite, colorBlack, colorBlack, colorBlack, colorBlack, colorBlack,
colorWhite, colorBlack, colorBlack, colorBlack, colorBlack, colorWhite, colorWhite, colorBlack, colorBlack, colorBlack, colorWhite,
colorWhite, colorWhite, colorBlack, colorBlack, colorWhite, colorWhite, colorWhite, colorWhite, colorBlack, colorWhite, colorWhite,
colorWhite, colorWhite, colorWhite, colorWhite, colorWhite, colorWhite,
} }
) )
func GameOfLife() { func GameOfLife() {
display.FillScreen(colorWhite) display.FillScreen(colorWhite)
gamebuffer = make([]byte, gameHeight*gameWidth) gamebuffer = make([]byte, gameHeight*gameWidth)
universe = game.NewUniverse(gameHeight, gameWidth) universe = game.NewUniverse(gameHeight, gameWidth)
universe.Randomize(population) universe.Randomize(population)
universe.Read(gamebuffer) universe.Read(gamebuffer)
x, y, z := accel.ReadRawAcceleration() x, y, z := int16(0), int16(0), int16(0)
if hasAccel {
x, y, z = accel.ReadRawAcceleration()
}
speed := 10 speed := 10
for { for {
@ -49,7 +50,9 @@ func GameOfLife() {
getInput() getInput()
if hasAccel {
x, y, z = accel.ReadRawAcceleration() x, y, z = accel.ReadRawAcceleration()
}
if x < (-31000) || x > 31000 || y < (-31000) || y > 31000 || z < (-31000) || z > 31000 || if x < (-31000) || x > 31000 || y < (-31000) || y > 31000 || z < (-31000) || z > 31000 ||
(!buttonsOldState[buttonA] && buttonsState[buttonA]) { (!buttonsOldState[buttonA] && buttonsState[buttonA]) {
universe.Reset() universe.Reset()
@ -78,7 +81,6 @@ func drawGrid() {
for rows = 0; rows < gameHeight; rows++ { for rows = 0; rows < gameHeight; rows++ {
for cols = 0; cols < gameWidth; cols++ { for cols = 0; cols < gameWidth; cols++ {
idx := universe.GetIndex(rows, cols) idx := universe.GetIndex(rows, cols)
switch { switch {
case universe.Cell(idx) == gamebuffer[idx]: case universe.Cell(idx) == gamebuffer[idx]:
// no change, so skip // no change, so skip

5
go.mod
View file

@ -10,9 +10,6 @@ require (
tinygo.org/x/tinyfont v0.6.0 tinygo.org/x/tinyfont v0.6.0
) )
require ( require github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/tinygo-org/pio v0.3.0 // indirect
)
replace tinygo.org/x/drivers => /home/conejo/go/src/tinygo.org/x/drivers replace tinygo.org/x/drivers => /home/conejo/go/src/tinygo.org/x/drivers

4
go.sum
View file

@ -4,8 +4,8 @@ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaU
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0= github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/tinygo-org/pio v0.3.0 h1:opEnOtw58KGB4RJD3/n/Rd0/djYGX3DeJiXLI6y/yDI= tinygo.org/x/drivers v0.34.0 h1:lw8ePJeUSn9oICKBvQXHC9TIE+J00OfXfkGTrpXM9Iw=
github.com/tinygo-org/pio v0.3.0/go.mod h1:wf6c6lKZp+pQOzKKcpzchmRuhiMc27ABRuo7KVnaMFU= tinygo.org/x/drivers v0.34.0/go.mod h1:ZdErNrApSABdVXjA1RejD67R8SNRI6RKVfYgQDZtKtk=
tinygo.org/x/tinydraw v0.4.0 h1:U9V0mHz8/jPShKjlh199vCfq1ARFyUOD1b+FfqIwV8c= tinygo.org/x/tinydraw v0.4.0 h1:U9V0mHz8/jPShKjlh199vCfq1ARFyUOD1b+FfqIwV8c=
tinygo.org/x/tinydraw v0.4.0/go.mod h1:WCV/EMljTv8w04iAxjv+fRD6/4ffx0afATYeJlN90Yo= tinygo.org/x/tinydraw v0.4.0/go.mod h1:WCV/EMljTv8w04iAxjv+fRD6/4ffx0afATYeJlN90Yo=
tinygo.org/x/tinyfont v0.6.0 h1:GibXDSFz6xrWnEDkDRo6vsbOyRw0MVj/eza3zNHMSHs= tinygo.org/x/tinyfont v0.6.0 h1:GibXDSFz6xrWnEDkDRo6vsbOyRw0MVj/eza3zNHMSHs=

View file

@ -62,7 +62,6 @@ func Info() {
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, (displayWidth-int16(w32))/2, qrSize+45, "for more information", colorWhite) tinyfont.WriteLine(&display, &freesans.Bold9pt7b, (displayWidth-int16(w32))/2, qrSize+45, "for more information", colorWhite)
} }
quit := false
for { for {
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
getInput() getInput()

View file

@ -21,12 +21,12 @@ func Leds() {
break break
} }
i += 2 i += 2
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)
} }
time.Sleep(50 * time.Millisecond)
for l := 0; l < numLEDs; l++ { for l := 0; l < numLEDs; l++ {
ledColors[l] = colorBlack ledColors[l] = colorBlackLED
} }
leds.WriteColors(ledColors) leds.WriteColors(ledColors)
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)

View file

@ -22,6 +22,7 @@ var (
colorPurple = color.RGBA{153, 51, 255, 255} colorPurple = color.RGBA{153, 51, 255, 255}
colorWhite = color.RGBA{255, 255, 255, 255} colorWhite = color.RGBA{255, 255, 255, 255}
colorBlack = color.RGBA{0, 0, 0, 255} colorBlack = color.RGBA{0, 0, 0, 255}
colorBlackLED = color.RGBA{0, 0, 0, 0}
colorText = color.RGBA{160, 160, 160, 255} colorText = color.RGBA{160, 160, 160, 255}
colorOrange = color.RGBA{255, 153, 51, 255} colorOrange = color.RGBA{255, 153, 51, 255}
) )
@ -86,7 +87,7 @@ func main() {
initHardware() initHardware()
display.FillScreen(colorBlack) display.FillScreen(colorBlack)
setCustomData() setCustomData()
adventure()
Info() Info()
for { for {

View file

@ -27,11 +27,6 @@ const (
SnakeRight SnakeRight
) )
const (
displayWidthBLOCKS = 32
displayHeightBLOCKS = 24
)
var ( var (
// Those variable are there for a more easy reading of the apple shape. // Those variable are there for a more easy reading of the apple shape.
re = colorRed // red re = colorRed // red
@ -54,7 +49,7 @@ var (
) )
type Snake struct { type Snake struct {
body [768][2]int16 body [snakeWidthBLOCKS * snakeHeightBLOCKS][2]int16
length int16 length int16
direction int16 direction int16
} }
@ -73,7 +68,7 @@ var scoreStr string
func NewSnakeGame() *SnakeGame { func NewSnakeGame() *SnakeGame {
return &SnakeGame{ return &SnakeGame{
snake: Snake{ snake: Snake{
body: [768][2]int16{ body: [snakeWidthBLOCKS * snakeHeightBLOCKS][2]int16{
{0, 3}, {0, 3},
{0, 2}, {0, 2},
{0, 1}, {0, 1},
@ -126,6 +121,21 @@ func (g *SnakeGame) Over() {
func (g *SnakeGame) splash() { func (g *SnakeGame) splash() {
display.FillScreen(bk) display.FillScreen(bk)
if displayWidth < 300 {
logoSmall := `
____ _ _ _ _ _____
/ ___|| \| | /_\ | |/ / __|
\___ \| \ |/ _ \| ' < | _|
|___/ |_|\_/_/ \_\_|\_\___|`
for i, line := range strings.Split(strings.TrimSuffix(logoSmall, "\n"), "\n") {
tinyfont.WriteLine(&display, &proggy.TinySZ8pt7b, 6, int16(14+i*11), line+"\n", gr)
}
tinyfont.WriteLine(&display, &freesans.Regular12pt7b, 10, 95, "Press A to start", colorRed)
if g.score > 0 {
scoreStr = strconv.Itoa(g.score)
tinyfont.WriteLine(&display, &freesans.Regular12pt7b, 20, 126, "SCORE: "+scoreStr, colorText)
}
} else {
logo := ` logo := `
___ ___ ___ ___ ___ ___
/ /\ / /\ / /\ / /\ / /\ / /\
@ -153,13 +163,12 @@ func (g *SnakeGame) splash() {
for i, line := range strings.Split(strings.TrimSuffix(logo, "\n"), "\n") { for i, line := range strings.Split(strings.TrimSuffix(logo, "\n"), "\n") {
tinyfont.WriteLine(&display, &proggy.TinySZ8pt7b, 0, int16(-6+i*11), line+"\n", gr) tinyfont.WriteLine(&display, &proggy.TinySZ8pt7b, 0, int16(-6+i*11), line+"\n", gr)
} }
tinyfont.WriteLine(&display, &freesans.Regular18pt7b, 30, 130, "Press A to start", colorRed) tinyfont.WriteLine(&display, &freesans.Regular18pt7b, 30, 130, "Press A to start", colorRed)
if g.score > 0 { if g.score > 0 {
scoreStr = strconv.Itoa(g.score) scoreStr = strconv.Itoa(g.score)
tinyfont.WriteLineRotated(&display, &freesans.Regular12pt7b, 300, 200, "SCORE: "+scoreStr, colorText, tinyfont.ROTATION_270) tinyfont.WriteLineRotated(&display, &freesans.Regular12pt7b, 300, 200, "SCORE: "+scoreStr, colorText, tinyfont.ROTATION_270)
} }
}
} }
func (g *SnakeGame) initSnake() { func (g *SnakeGame) initSnake() {
@ -184,11 +193,11 @@ func (g *SnakeGame) collisionWithSnake(x, y int16) bool {
} }
func (g *SnakeGame) createApple() { func (g *SnakeGame) createApple() {
g.appleX = int16(rand.Int31n(displayWidthBLOCKS)) g.appleX = int16(rand.Int31n(snakeWidthBLOCKS))
g.appleY = int16(rand.Int31n(displayHeightBLOCKS)) g.appleY = int16(rand.Int31n(snakeHeightBLOCKS))
for g.collisionWithSnake(g.appleX, g.appleY) { for g.collisionWithSnake(g.appleX, g.appleY) {
g.appleX = int16(rand.Int31n(displayWidthBLOCKS)) g.appleX = int16(rand.Int31n(snakeWidthBLOCKS))
g.appleY = int16(rand.Int31n(displayHeightBLOCKS)) g.appleY = int16(rand.Int31n(snakeHeightBLOCKS))
} }
g.drawApple(g.appleX, g.appleY) g.drawApple(g.appleX, g.appleY)
} }
@ -211,17 +220,17 @@ func (g *SnakeGame) moveSnake() {
x++ x++
break break
} }
if x >= displayWidthBLOCKS { if x >= snakeWidthBLOCKS {
x = 0 x = 0
} }
if x < 0 { if x < 0 {
x = displayWidthBLOCKS - 1 x = snakeWidthBLOCKS - 1
} }
if y >= displayHeightBLOCKS { if y >= snakeHeightBLOCKS {
y = 0 y = 0
} }
if y < 0 { if y < 0 {
y = displayHeightBLOCKS - 1 y = snakeHeightBLOCKS - 1
} }
if g.collisionWithSnake(x, y) { if g.collisionWithSnake(x, y) {