diff options
author | davidovski <david@davidovski.xyz> | 2024-04-21 21:23:21 +0100 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2024-04-21 21:23:21 +0100 |
commit | 2d6d9f97093544e0d2faccc94f3b8bf369c03819 (patch) | |
tree | cab6b58d90a066b743764dfa91fcabfc87e9ba0e /player.go | |
parent | 64757d18c4b2669c46f2dc88293cf2f0ea1887db (diff) |
add placing objects
Diffstat (limited to 'player.go')
-rw-r--r-- | player.go | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/player.go b/player.go deleted file mode 100644 index 4fe7aa8..0000000 --- a/player.go +++ /dev/null @@ -1,52 +0,0 @@ -package main - -import ( - "github.com/hajimehoshi/ebiten/v2" -) - -const ( - gravity = 0.01 - friction = 0.6 -) - -type GameObject struct { - x, y float32 - vx, vy float32 - image *ebiten.Image - onGround bool -} - - -type Player struct { - GameObject -} - -func (o * GameObject) Update(tilemap Tilemap) { - o.vy += gravity - - o.x += o.vx - if tilemap.CollideObject(o) { - o.x -= o.vx - o.vx = 0 - } - - o.y += o.vy - if (tilemap.CollideObject(o)) { - - o.onGround = true; - o.vx *= friction - - o.y -= o.vy - o.vy = 0 - } else { - o.onGround = false; - } -} - -func (o * GameObject) Draw(screen *ebiten.Image, tilemap Tilemap) { - op := &ebiten.DrawImageOptions{} - op.GeoM.Translate(float64(o.x * float32(tilemap.tileSize)), float64(o.y * float32(tilemap.tileSize))) - screen.DrawImage(o.image, op) -} - - |