diff options
| author | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-01-31 10:55:54 +0100 |
|---|---|---|
| committer | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-01-31 10:55:54 +0100 |
| commit | 4ce6fb5d2ceead254ee7ed32d2845234a1c195fe (patch) | |
| tree | 622c289a5e5cb846b4b113cbf1dd1ffbfa070ac5 /pong | |
| parent | ae2db9a668df875e5a3e76982a54e455ec080749 (diff) | |
| download | sylt-4ce6fb5d2ceead254ee7ed32d2845234a1c195fe.tar.gz | |
Add score!
Diffstat (limited to 'pong')
| -rw-r--r-- | pong/pong.tdy | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/pong/pong.tdy b/pong/pong.tdy index e1803d6..15998f3 100644 --- a/pong/pong.tdy +++ b/pong/pong.tdy @@ -19,7 +19,7 @@ blob Ball { blob Player { paddle: Paddle - score: int + score: float } blob State { @@ -137,7 +137,7 @@ update := fn state: State { state.ball.y = 10.0 state.ball.vx = -BALL_STARTV state.ball.vy = 0. - state.p1.score = state.p1.score + 1 + state.p1.score = state.p1.score + 1.0 } if state.ball.x > 20.0 { @@ -145,7 +145,7 @@ update := fn state: State { state.ball.y = 10.0 state.ball.vx = BALL_STARTV state.ball.vy = 0. - state.p2.score = state.p2.score + 1 + state.p2.score = state.p2.score + 1.0 } ball_and_paddle_check(state.p1.paddle, state.ball) @@ -158,6 +158,14 @@ draw := fn state: State { draw_rectangle(state.p1.paddle.x, state.p1.paddle.y, PADDLE_W, PADDLE_H) draw_rectangle(state.p2.paddle.x, state.p2.paddle.y, PADDLE_W, PADDLE_H) + for y := 0.0, y < state.p1.score, y = y + 1.0 { + draw_rectangle(15.0, y * 0.5, 0.5, 0.5) + } + + for y := 0.0, y < state.p2.score, y = y + 1.0 { + draw_rectangle(5.0, y * 0.5, 0.5, 0.5) + } + draw_rectangle(state.ball.x, state.ball.y, BALL_S, BALL_S) } @@ -170,13 +178,13 @@ init := fn { state.ball.vy = 0.0 state.p1 = Player() - state.p1.score = 0 + state.p1.score = 0.0 state.p1.paddle = Paddle() state.p1.paddle.x = 1. state.p1.paddle.y = 10. state.p2 = Player() - state.p2.score = 0 + state.p2.score = 0.0 state.p2.paddle = Paddle() state.p2.paddle.x = 19. state.p2.paddle.y = 10. |
