From 06b4a8680b472832051a070e525be1b78458b15f Mon Sep 17 00:00:00 2001 From: WildTrack Date: Thu, 9 May 2019 12:45:07 +0200 Subject: [PATCH] Fix hitbox --- game/pong.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/game/pong.py b/game/pong.py index e6ff358..af8ed1f 100644 --- a/game/pong.py +++ b/game/pong.py @@ -54,6 +54,7 @@ def loop(deltatime: float, difficulty: float, end): deplacementtrait(difficulty) _, _, x2, _ = canvas.coords(balle) + if x2 >= 396: end() return @@ -68,18 +69,24 @@ def collision(): xt1, yt1 = canvas.coords(trait) xt1, yt1, xt2, yt2 = xt1 - 5, yt1 - 45, xt1 + 5, yt1 + 45 x1, y1, x2, y2 = canvas.coords(balle) + if x1 <= 5: cos = -cos if y1 <= 5 or y2 >= 295: sin = -sin if x2 + 5 >= xt1 and x1 - 5 <= xt2 and y1 - 5 <= yt2 and y2 + 5 >= yt1: - cos = -abs(cos) + if x1 + B_RADIUS >= xt1 + 5: + sin = -sin + else: + cos = -abs(cos) + canvas.itemconfigure(balle, outline = ACCENT_COLOR, fill = ACCENT_COLOR) canvas.after(200, lambda: canvas.itemconfigure(balle, outline=SECONDARY_COLOR, fill=SECONDARY_COLOR)) def deplacementtrait(difficulty: float): _, y1 = canvas.coords(trait) y1, y2 = y1 - 45, y1 + 45 + if haut and y1 >= 10: canvas.move(trait, 0, -PAST_Y * difficulty) if bas and y2 <= 290: