From 13d2bbb024ebc52b42045b7002c396bc90ee9193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Sun, 31 Jan 2021 10:27:07 +0100 Subject: add score and stuff --- pong/pong.tdy | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pong/pong.tdy b/pong/pong.tdy index d79175d..3d7f3f4 100644 --- a/pong/pong.tdy +++ b/pong/pong.tdy @@ -13,6 +13,7 @@ blob Ball { blob Player { paddle: Paddle + score: int } blob State { @@ -108,6 +109,22 @@ update := fn state: State { state.ball.vy = -abs(state.ball.vy) } + if state.ball.x < 0.0 { + state.ball.x = 10.0 + state.ball.y = 10.0 + state.ball.vx = -10. + state.ball.vy = 0. + state.p1.score = state.p1.score + 1 + } + + if state.ball.x > 20.0 { + state.ball.x = 10.0 + state.ball.y = 10.0 + state.ball.vx = 10. + state.ball.vy = 0. + state.p2.score = state.p2.score + 1 + } + ball_and_paddle_check(state.p1.paddle, state.ball) ball_and_paddle_check(state.p2.paddle, state.ball) } @@ -130,11 +147,13 @@ init := fn { state.ball.vy = 2.0 state.p1 = Player() + state.p1.score = 0 state.p1.paddle = Paddle() state.p1.paddle.x = 1. state.p1.paddle.y = 10. state.p2 = Player() + state.p2.score = 0 state.p2.paddle = Paddle() state.p2.paddle.x = 19. state.p2.paddle.y = 10. -- cgit v1.2.1