aboutsummaryrefslogtreecommitdiffstats
path: root/pong/pong.tdy
diff options
context:
space:
mode:
authorEdvard Thörnros <edvard.thornros@gmail.com>2021-01-31 10:27:07 +0100
committerEdvard Thörnros <edvard.thornros@gmail.com>2021-01-31 10:28:21 +0100
commit13d2bbb024ebc52b42045b7002c396bc90ee9193 (patch)
tree3cb9e2260dc350b7725d51926f22dd2b41562756 /pong/pong.tdy
parent62ed092e7cdb70cb97d36736605428457f948fae (diff)
downloadsylt-13d2bbb024ebc52b42045b7002c396bc90ee9193.tar.gz
add score and stuff
Diffstat (limited to 'pong/pong.tdy')
-rw-r--r--pong/pong.tdy19
1 files changed, 19 insertions, 0 deletions
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.