Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
smoketest: FORCE
mkdir -p out
tinygo build -o ./out/all.zero-kb02.uf2 --size short --target ./targets/zero-kb02.json ./games/all/
tinygo build -o ./out/flappygopher.zero-kb02.uf2 --size short --target ./targets/zero-kb02.json ./games/flappygopher/
tinygo build -o ./out/jumpingopher.zero-kb02.uf2 --size short --target ./targets/zero-kb02.json ./games/jumpingopher/
tinygo build -o ./out/blocks.zero-kb02.uf2 --size short --target ./targets/zero-kb02.json ./games/blocks/
tinygo build -o ./out/example_GeoM.zero-kb02.uf2 --size short --target ./targets/zero-kb02.json ./examples/GeoM/
tinygo build -o ./out/all.gopher-badge.uf2 --size short --target gopher-badge ./games/all/
tinygo build -o ./out/all.pybadge.uf2 --size short --target pybadge ./games/all/
tinygo build -o ./out/all.wioterminal.uf2 --size short --target wioterminal ./games/all/
tinygo build -o ./out/all.macropad-rp2040.uf2 --size short --target macropad-rp2040 ./games/all/
tinygo build -o ./out/all.gopher-board-i2c.uf2 --size short --target ./targets/gopher-board-i2c.json ./games/all/
tinygo build -o ./out/all.gopher-board-spi.uf2 --size short --target ./targets/gopher-board-spi.json ./games/all/
tinygo build -o ./out/all.wasm --size short --target wasm --no-debug --panic trap ./games/all/
tinygo build -o ./out/goradius.zero-kb02.uf2 --size short --target ./targets/zero-kb02.json ./games/goradius/
tinygo build -o ./out/all.zero-kb02.uf2 --size short --target ./targets/zero-kb02.json ./games/all/
tinygo build -o ./out/flappygopher.zero-kb02.uf2 --size short --target ./targets/zero-kb02.json ./games/flappygopher/
tinygo build -o ./out/jumpingopher.zero-kb02.uf2 --size short --target ./targets/zero-kb02.json ./games/jumpingopher/
tinygo build -o ./out/blocks.zero-kb02.uf2 --size short --target ./targets/zero-kb02.json ./games/blocks/
tinygo build -o ./out/example_GeoM.zero-kb02.uf2 --size short --target ./targets/zero-kb02.json ./examples/GeoM/
tinygo build -o ./out/example_drawing.zero-kb02.uf2 --size short --target ./targets/zero-kb02.json ./examples/drawing/
tinygo build -o ./out/all.gopher-badge.uf2 --size short --target gopher-badge ./games/all/
tinygo build -o ./out/all.pybadge.uf2 --size short --target pybadge ./games/all/
tinygo build -o ./out/all.wioterminal.uf2 --size short --target wioterminal ./games/all/
tinygo build -o ./out/all.macropad-rp2040.uf2 --size short --target macropad-rp2040 ./games/all/
tinygo build -o ./out/all.gopher-board-i2c.uf2 --size short --target ./targets/gopher-board-i2c.json ./games/all/
tinygo build -o ./out/all.gopher-board-spi.uf2 --size short --target ./targets/gopher-board-spi.json ./games/all/
tinygo build -o ./out/all.wasm --size short --target wasm --no-debug --panic trap ./games/all/
tinygo build -o ./out/goradius.zero-kb02.uf2 --size short --target ./targets/zero-kb02.json ./games/goradius/

FORCE:
97 changes: 97 additions & 0 deletions examples/drawing/drawing/drawing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package drawing

import (
"github.com/sago35/koebiten"
"tinygo.org/x/drivers/pixel"
)

var (
white = pixel.NewMonochrome(0xFF, 0xFF, 0xFF)
black = pixel.NewMonochrome(0x00, 0x00, 0x00)
)

type Pointer struct {
x, y int
}

type Game struct {
pointer Pointer
thick int
canvas *koebiten.Image
}

func NewGame() *Game {
return &Game{
pointer: Pointer{64, 32},
canvas: koebiten.NewImage(128, 64),
}
}

func (g *Game) Update() error {
if koebiten.IsKeyPressed(koebiten.KeyArrowLeft) {
g.pointer.x--
}
if koebiten.IsKeyPressed(koebiten.KeyArrowRight) {
g.pointer.x++
}
if koebiten.IsKeyPressed(koebiten.KeyArrowUp) {
g.pointer.y--
}
if koebiten.IsKeyPressed(koebiten.KeyArrowDown) {
g.pointer.y++
}

if koebiten.IsKeyPressed(koebiten.KeyRotaryLeft) {
g.thick--
if g.thick < 0 {
g.thick = 0
}
}
if koebiten.IsKeyPressed(koebiten.KeyRotaryRight) {
g.thick++
if g.thick > 10 {
g.thick = 10
}
}

if koebiten.IsKeyPressed(koebiten.Key0) {
g.draw(g.canvas, g.pointer.x, g.pointer.y, black)
}
if koebiten.IsKeyPressed(koebiten.Key1) || koebiten.IsKeyPressed(koebiten.Key2) ||
koebiten.IsKeyPressed(koebiten.Key3) || koebiten.IsKeyPressed(koebiten.Key4) ||
koebiten.IsKeyPressed(koebiten.Key5) || koebiten.IsKeyPressed(koebiten.Key6) ||
koebiten.IsKeyPressed(koebiten.Key7) || koebiten.IsKeyPressed(koebiten.Key8) ||
koebiten.IsKeyPressed(koebiten.Key9) || koebiten.IsKeyPressed(koebiten.Key10) ||
koebiten.IsKeyPressed(koebiten.Key11) {
g.draw(g.canvas, g.pointer.x, g.pointer.y, white)
}

return nil
}

func (g *Game) Draw(screen *koebiten.Image) {
g.canvas.DrawImage(screen, koebiten.DrawImageOptions{})
koebiten.DrawFilledCircle(screen, g.pointer.x, g.pointer.y, g.thick+1, white)
}

func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
return 128, 64
}

func (g *Game) draw(canvas *koebiten.Image, x, y int, color pixel.BaseColor) {
koebiten.DrawFilledCircle(g.canvas, x, y, g.thick, color)
}

func isAnyKeyPressed() bool {
keys := []koebiten.Key{
koebiten.Key0, koebiten.Key1, koebiten.Key2, koebiten.Key3,
koebiten.Key4, koebiten.Key5, koebiten.Key6, koebiten.Key7,
koebiten.Key8, koebiten.Key9, koebiten.Key10, koebiten.Key11,
}
for _, key := range keys {
if koebiten.IsKeyPressed(key) {
return true
}
}
return false
}
21 changes: 21 additions & 0 deletions examples/drawing/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"log"

"github.com/sago35/koebiten"
"github.com/sago35/koebiten/examples/drawing/drawing"
"github.com/sago35/koebiten/hardware"
)

func main() {
koebiten.SetHardware(hardware.Device)
koebiten.SetWindowSize(128, 64)
koebiten.SetWindowTitle("Drawing")

game := drawing.NewGame()

if err := koebiten.RunGame(game); err != nil {
log.Fatal(err)
}
}