From 4aa801b6b17e1c34c05d94850b9450c05f6c60d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Sun, 31 Jan 2021 10:16:53 +0100 Subject: roof and floor --- pong/pong.tdy | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pong/pong.tdy b/pong/pong.tdy index 5d9b277..fc54e36 100644 --- a/pong/pong.tdy +++ b/pong/pong.tdy @@ -100,6 +100,14 @@ update := fn state: State { state.ball.x = state.ball.x + delta * state.ball.vx state.ball.y = state.ball.y + delta * state.ball.vy + if state.ball.y < 0. { + state.ball.vy = abs(state.ball.vy) + } + + if state.ball.y > 20. - 0.2 { + state.ball.vy = -abs(state.ball.vy) + } + ball_and_paddle_check(state.p1.paddle, state.ball) ball_and_paddle_check(state.p2.paddle, state.ball) @@ -121,8 +129,8 @@ init := fn { state.ball = Ball() state.ball.x = 10.0 state.ball.y = 10.0 - state.ball.vx = 3.0 - state.ball.vy = 0.0 + state.ball.vx = 1.0 + state.ball.vy = 2.0 state.p1 = Player() state.p1.paddle = Paddle() -- cgit v1.2.1