game: add: scoreboard
This commit is contained in:
@ -174,7 +174,7 @@ def wall_collision(ball_angle: float, wall_angle: float) -> float:
|
||||
|
||||
return new_angle
|
||||
|
||||
def paddle_collision(ball: Ball, impact: Point, player: Player, inc_x: float, inc_y: float):
|
||||
async def paddle_collision(ball: Ball, impact: Point, player: Player, inc_x: float, inc_y: float):
|
||||
|
||||
diff_x: float = player.rail.stop.x - player.rail.start.x
|
||||
diff_y: float = player.rail.stop.y - player.rail.start.y
|
||||
@ -199,15 +199,14 @@ def paddle_collision(ball: Ball, impact: Point, player: Player, inc_x: float, in
|
||||
|
||||
hit_point: Point = Point(impact.x - inc_x, impact.y - inc_y)
|
||||
|
||||
print(hit_point, paddle)
|
||||
|
||||
if (not paddle.is_on(hit_point)):
|
||||
print(not paddle.is_on(hit_point))
|
||||
player.nb_goal += 1
|
||||
await SyncToAsync(player.game.broadcast)("goal", {"player": player.user_id, "nb_goal": player.nb_goal})
|
||||
return None
|
||||
|
||||
return ball.angle + math.pi
|
||||
|
||||
def collision(game: Game, impact_data: dict) -> bool:
|
||||
async def collision(game: Game, impact_data: dict) -> bool:
|
||||
|
||||
segment: Segment = impact_data.get("segment")
|
||||
|
||||
@ -218,7 +217,7 @@ def collision(game: Game, impact_data: dict) -> bool:
|
||||
if (player.rail is segment):
|
||||
player_hitted = player
|
||||
break
|
||||
|
||||
|
||||
surface_angle: float = math.atan2(segment.start.y - segment.stop.y, segment.start.x - segment.stop.y)
|
||||
|
||||
angle: float
|
||||
@ -227,7 +226,7 @@ def collision(game: Game, impact_data: dict) -> bool:
|
||||
angle = wall_collision(game.ball.angle, surface_angle)
|
||||
|
||||
else:
|
||||
angle = paddle_collision(game.ball, impact_data.get("impact"), player_hitted, impact_data.get("inc_x"), impact_data.get("inc_y"))
|
||||
angle = await paddle_collision(game.ball, impact_data.get("impact"), player_hitted, impact_data.get("inc_x"), impact_data.get("inc_y"))
|
||||
|
||||
if (angle is None):
|
||||
return False
|
||||
@ -243,11 +242,10 @@ async def update_ball(game: Game, impact_data: dict) -> None:
|
||||
|
||||
await asyncio.sleep(time_before_impact)
|
||||
|
||||
hit: bool = collision(game, impact_data)
|
||||
hit: bool = await collision(game, impact_data)
|
||||
|
||||
if (hit == False):
|
||||
await asyncio.sleep(0.1)
|
||||
print("Goal")
|
||||
game.ball.reset()
|
||||
else:
|
||||
game.ball.position = impact_data.get("impact")
|
||||
|
Reference in New Issue
Block a user