aboutsummaryrefslogtreecommitdiffstats
path: root/pong
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-01-31 10:38:05 +0100
committerGustav Sörnäs <gustav@sornas.net>2021-01-31 10:38:05 +0100
commit32158bc19333fbfc7affefc5ef6ff5e34c0109f1 (patch)
tree9e81c33e4ffc96ad9606c0bb2a017768d4c1559e /pong
parent13d2bbb024ebc52b42045b7002c396bc90ee9193 (diff)
downloadsylt-32158bc19333fbfc7affefc5ef6ff5e34c0109f1.tar.gz
variable ball and paddle size. also add dv instead of set on paddle collision
Diffstat (limited to 'pong')
-rw-r--r--pong/pong.tdy26
1 files changed, 15 insertions, 11 deletions
diff --git a/pong/pong.tdy b/pong/pong.tdy
index 3d7f3f4..8727d50 100644
--- a/pong/pong.tdy
+++ b/pong/pong.tdy
@@ -1,8 +1,13 @@
+PADDLE_W := 0.5
+PADDLE_H := 3.0
+
blob Paddle {
x: float
y: float
}
+BALL_S := 0.4
+
blob Ball {
x: float
y: float
@@ -66,17 +71,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, 0.2, 0.2, pad.x, pad.y, 0.2, 1.) {
- ballcy := ball.y + 0.1
- padcy := pad.y + 0.5
+ if rect_overlap(ball.x, ball.y, BALL_S, BALL_S, pad.x, pad.y, PADDLE_W, PADDLE_H) {
+ ballcy := ball.y + BALL_S / 2.
+ padcy := pad.y + PADDLE_H / 2.
if ball.x < pad.x {
ball.vx = -abs(ball.vx)
- ball.vy = (ballcy - padcy) * 3.
+ ball.vy = ball.vy + (ballcy - padcy) * 3.
} else {
ball.vx = abs(ball.vx)
- ball.vy = (ballcy - padcy) * 3.
+ ball.vy = ball.vy + (ballcy - padcy) * 3.
}
- log(ball.vx, ball.vy)
}
}
@@ -132,10 +136,10 @@ update := fn state: State {
draw := fn state: State {
clear()
- draw_rectangle(state.p1.paddle.x, state.p1.paddle.y, 0.2, 1.)
- draw_rectangle(state.p2.paddle.x, state.p2.paddle.y, 0.2, 1.)
+ 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)
- draw_rectangle(state.ball.x, state.ball.y, 0.2, 0.2)
+ draw_rectangle(state.ball.x, state.ball.y, BALL_S, BALL_S)
}
init := fn {
@@ -143,8 +147,8 @@ init := fn {
state.ball = Ball()
state.ball.x = 10.0
state.ball.y = 10.0
- state.ball.vx = 1.0
- state.ball.vy = 2.0
+ state.ball.vx = 3.0
+ state.ball.vy = 0.0
state.p1 = Player()
state.p1.score = 0