From ae2db9a668df875e5a3e76982a54e455ec080749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Sun, 31 Jan 2021 10:48:30 +0100 Subject: SOME BLANCE --- pong/pong.tdy | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pong/pong.tdy b/pong/pong.tdy index ab1459b..e1803d6 100644 --- a/pong/pong.tdy +++ b/pong/pong.tdy @@ -7,6 +7,7 @@ blob Paddle { } BALL_S := 0.4 +BALL_STARTV := 5.0 blob Ball { x: float @@ -71,14 +72,16 @@ rect_overlap := fn ax: float, ay: float, aw: float, ah: float, bx: float, by: fl } ball_and_paddle_check := fn pad: Paddle, ball: Ball { + if rect_overlap(ball.x, ball.y, BALL_S, BALL_S, pad.x, pad.y, PADDLE_W, PADDLE_H) { + SPEEDUP := 0.5 ballcy := ball.y + BALL_S / 2. padcy := pad.y + PADDLE_H / 2. if ball.x < pad.x { - ball.vx = -abs(ball.vx) + ball.vx = -abs(ball.vx) - SPEEDUP ball.vy = ball.vy + (ballcy - padcy) * 3. } else { - ball.vx = abs(ball.vx) + ball.vx = abs(ball.vx) + SPEEDUP ball.vy = ball.vy + (ballcy - padcy) * 3. } } @@ -88,8 +91,6 @@ update := fn state: State { delta := get_delta() speed := delta * SPEED - paddle_height := 1.0 - if key_down("w") { state.p1.paddle.y = state.p1.paddle.y - speed } @@ -101,8 +102,8 @@ update := fn state: State { state.p1.paddle.y = 0.0 } - if state.p1.paddle.y > 20.0 - paddle_height { - state.p1.paddle.y = 20.0 - paddle_height + if state.p1.paddle.y > 20.0 - PADDLE_H { + state.p1.paddle.y = 20.0 - PADDLE_H } if key_down("i") { @@ -116,11 +117,10 @@ update := fn state: State { state.p2.paddle.y = 0.0 } - if state.p2.paddle.y > 20.0 - paddle_height { - state.p2.paddle.y = 20.0 - paddle_height + if state.p2.paddle.y > 20.0 - PADDLE_H { + state.p2.paddle.y = 20.0 - PADDLE_H } - state.ball.x = state.ball.x + delta * state.ball.vx state.ball.y = state.ball.y + delta * state.ball.vy @@ -135,7 +135,7 @@ update := fn state: State { if state.ball.x < 0.0 { state.ball.x = 10.0 state.ball.y = 10.0 - state.ball.vx = -10. + state.ball.vx = -BALL_STARTV state.ball.vy = 0. state.p1.score = state.p1.score + 1 } @@ -143,7 +143,7 @@ update := fn state: State { if state.ball.x > 20.0 { state.ball.x = 10.0 state.ball.y = 10.0 - state.ball.vx = 10. + state.ball.vx = BALL_STARTV state.ball.vy = 0. state.p2.score = state.p2.score + 1 } @@ -166,7 +166,7 @@ init := fn { state.ball = Ball() state.ball.x = 10.0 state.ball.y = 10.0 - state.ball.vx = 3.0 + state.ball.vx = BALL_STARTV state.ball.vy = 0.0 state.p1 = Player() -- cgit v1.2.1