diff options
Diffstat (limited to 'pongo.go')
| -rw-r--r-- | pongo.go | 14 |
1 files changed, 5 insertions, 9 deletions
@@ -192,10 +192,9 @@ func pong() error { } } - oldPos := ball.pos ball.pos = ball.pos.add(ball.velocity) switch { - case ball.bounds().HasIntersection(paddle1.bounds()): + case ball.bounds().HasIntersection(paddle1.bounds()) && ball.velocity.x <= 0: ping.Play(-1, 0) d := ball.pos.y - paddle1.pos if d < 0 { @@ -207,8 +206,7 @@ func pong() error { } speed := ballSpeed * (1 + 4*d/(float64(paddle1.bounds().H)/2+float64(ball.bounds().H))) ball.velocity = vector2{speed * math.Cos(angle), speed * math.Sin(angle)} - ball.pos = oldPos - case ball.bounds().HasIntersection(paddle2.bounds()): + case ball.bounds().HasIntersection(paddle2.bounds()) && ball.velocity.x >= 0: ping.Play(-1, 0) d := ball.pos.y - paddle2.pos if d < 0 { @@ -221,16 +219,14 @@ func pong() error { angle += math.Pi speed := ballSpeed * (1 + 4*d/(float64(paddle2.bounds().H)/2+float64(ball.bounds().H))) ball.velocity = vector2{speed * math.Cos(angle), speed * math.Sin(angle)} - ball.pos = oldPos case rectRight(ball.bounds()) <= 0: aiScore++ ball.reset(right) case ball.bounds().X >= screenWidth: playerScore++ ball.reset(left) - case ball.bounds().Y <= 0 || rectBottom(ball.bounds()) >= screenHeight: + case ball.bounds().Y <= 0 && ball.velocity.y < 0 || rectBottom(ball.bounds()) >= screenHeight && ball.velocity.y > 0: ping.Play(-1, 0) - ball.pos = oldPos ball.velocity.y = -ball.velocity.y } } @@ -261,10 +257,10 @@ func pong() error { fmt.Fprintln(os.Stderr, err) } - if err := numbers.Draw(renderer, playerScore, paddle1.bounds().X+20, 30); err != nil { + if err := numbers.Draw(renderer, playerScore, 150, 30); err != nil { fmt.Fprintln(os.Stderr, err) } - if err := numbers.Draw(renderer, aiScore, paddle2.bounds().X-500, 30); err != nil { + if err := numbers.Draw(renderer, aiScore, 1300, 30); err != nil { fmt.Fprintln(os.Stderr, err) } |
