summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuild.sh13
-rw-r--r--go.mod14
-rw-r--r--index.html16
-rw-r--r--pengui.go30
4 files changed, 73 insertions, 0 deletions
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..ae7e042
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+name=pengui
+
+rm -rf build
+mkdir -p build
+
+cd build
+env GOOS=js GOARCH=wasm go build -o $name.wasm ..
+cp $(go env GOROOT)/misc/wasm/wasm_exec.js .
+cp ../index.html .
+
+[ "$1" = "serve" ] && gopherjs serve
+
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..d1057e7
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,14 @@
+module pengui
+
+go 1.18
+
+require (
+ github.com/ebitengine/purego v0.5.0 // indirect
+ github.com/hajimehoshi/ebiten/v2 v2.6.2 // indirect
+ github.com/jezek/xgb v1.1.0 // indirect
+ golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63 // indirect
+ golang.org/x/image v0.12.0 // indirect
+ golang.org/x/mobile v0.0.0-20230922142353-e2f452493d57 // indirect
+ golang.org/x/sync v0.3.0 // indirect
+ golang.org/x/sys v0.12.0 // indirect
+)
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..cdc36b5
--- /dev/null
+++ b/index.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<script src="wasm_exec.js"></script>
+<script>
+// Polyfill
+if (!WebAssembly.instantiateStreaming) {
+ WebAssembly.instantiateStreaming = async (resp, importObject) => {
+ const source = await (await resp).arrayBuffer();
+ return await WebAssembly.instantiate(source, importObject);
+ };
+}
+
+const go = new Go();
+WebAssembly.instantiateStreaming(fetch("pengui.wasm"), go.importObject).then(result => {
+ go.run(result.instance);
+});
+</script>
diff --git a/pengui.go b/pengui.go
new file mode 100644
index 0000000..60612a9
--- /dev/null
+++ b/pengui.go
@@ -0,0 +1,30 @@
+package main
+
+import (
+ "log"
+
+ "github.com/hajimehoshi/ebiten/v2"
+ "github.com/hajimehoshi/ebiten/v2/ebitenutil"
+)
+
+type Game struct{}
+
+func (g *Game) Update() error {
+ return nil
+}
+
+func (g *Game) Draw(screen *ebiten.Image) {
+ ebitenutil.DebugPrint(screen, "Hello, World!")
+}
+
+func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
+ return 320, 240
+}
+
+func main() {
+ ebiten.SetWindowSize(640, 480)
+ ebiten.SetWindowTitle("Hello, World!")
+ if err := ebiten.RunGame(&Game{}); err != nil {
+ log.Fatal(err)
+ }
+}