summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/penguin.pngbin0 -> 7252 bytes
-rwxr-xr-xbuild.sh1
-rw-r--r--pengui.go39
3 files changed, 37 insertions, 3 deletions
diff --git a/assets/penguin.png b/assets/penguin.png
new file mode 100644
index 0000000..435ecfe
--- /dev/null
+++ b/assets/penguin.png
Binary files differ
diff --git a/build.sh b/build.sh
index ae7e042..d057c90 100755
--- a/build.sh
+++ b/build.sh
@@ -8,6 +8,7 @@ cd build
env GOOS=js GOARCH=wasm go build -o $name.wasm ..
cp $(go env GOROOT)/misc/wasm/wasm_exec.js .
cp ../index.html .
+cp -r ../assets .
[ "$1" = "serve" ] && gopherjs serve
diff --git a/pengui.go b/pengui.go
index 60612a9..842584b 100644
--- a/pengui.go
+++ b/pengui.go
@@ -1,29 +1,62 @@
package main
import (
+ _ "image/png"
+ "image/color"
"log"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
)
+var img *ebiten.Image
+
+var x float64 = 0
+var y float64 = 0
+
+func init() {
+ var err error
+ img, _, err = ebitenutil.NewImageFromFile("assets/penguin.png")
+ if err != nil {
+ log.Fatal(err)
+ }
+}
+
type Game struct{}
func (g *Game) Update() error {
+ if ebiten.IsKeyPressed(ebiten.KeyArrowRight) {
+ x = x + 1
+ }
+ if ebiten.IsKeyPressed(ebiten.KeyArrowLeft) {
+ x = x - 1
+ }
+ if ebiten.IsKeyPressed(ebiten.KeyArrowUp) {
+ y = y - 1
+ }
+ if ebiten.IsKeyPressed(ebiten.KeyArrowDown) {
+ y = y + 1
+ }
+ log.Printf("%f %f\n", x, y)
+
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {
- ebitenutil.DebugPrint(screen, "Hello, World!")
+ screen.Fill(color.RGBA{0xfe, 0xfe, 0xfe, 0xff})
+
+ op := &ebiten.DrawImageOptions{}
+ op.GeoM.Translate(x, y)
+ screen.DrawImage(img, op)
}
func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
- return 320, 240
+ return 640, 480
}
func main() {
ebiten.SetWindowSize(640, 480)
- ebiten.SetWindowTitle("Hello, World!")
+ ebiten.SetWindowTitle("penguin")
if err := ebiten.RunGame(&Game{}); err != nil {
log.Fatal(err)
}