From e2900f5ea428dce6dd4bb6cc31e191b255a9da06 Mon Sep 17 00:00:00 2001 From: davidovski Date: Fri, 20 Oct 2023 04:24:13 +0100 Subject: add airtime --- pengui.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'pengui.go') diff --git a/pengui.go b/pengui.go index 62353d7..1a38971 100644 --- a/pengui.go +++ b/pengui.go @@ -28,13 +28,13 @@ type Penguin struct { x, y float64 xv, yv float64 onGround bool - fx []float64 - fy []float64 + fx, fy []float64 + airTime float64 } func newPenguin() Penguin { penguin := Penguin{ - x: screen_w / 2, + x: -200, y: 0, xv: 0, yv: 0, @@ -68,7 +68,7 @@ func (p *Penguin) Cy() (float64) { func (penguin *Penguin) draw(screen *ebiten.Image, game Game) { op := &ebiten.DrawImageOptions{} - if penguin.onGround { + if penguin.airTime < 60 { angle := game.ground.angle(penguin.Cx(), 2) tx, ty := float64(penguin.Width()) / 2, float64(penguin.Height()) @@ -109,6 +109,7 @@ func (penguin *Penguin) update(game *Game) { penguin.fy = []float64{gy} if penguin.onGround{ + angle := game.ground.angle(penguin.Cx(), 1) dx, dy := Normalize(game.ground.normal(penguin.Cx(), 1)) @@ -148,8 +149,10 @@ func (penguin *Penguin) update(game *Game) { penguin.yv = 0 } penguin.onGround = true + penguin.airTime = 0 } else { penguin.onGround = false + penguin.airTime += 1 } } @@ -279,7 +282,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeigh func main() { ebiten.SetWindowSize(640, 480) ebiten.SetWindowTitle("penguin") - //ebiten.SetTPS(10) + ebiten.SetTPS(60) game := Game{} -- cgit v1.2.1