diff options
author | davidovski <david@davidovski.xyz> | 2023-10-17 03:47:26 +0100 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2023-10-17 03:47:26 +0100 |
commit | 7f912ab41b97bbc6e6167781e863460484bd4a1d (patch) | |
tree | f75fa6be762dad64af97a659a3aac5855db194c4 /pengui.go | |
parent | 59a76335613b836312f03a539e61c00a09b0962d (diff) |
make penguin move
Diffstat (limited to 'pengui.go')
-rw-r--r-- | pengui.go | 39 |
1 files changed, 36 insertions, 3 deletions
@@ -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) } |