game: add: speed increment
This commit is contained in:
parent
f2ce928fbb
commit
243227f743
@ -11,7 +11,7 @@ MAP_CENTER_Y = MAP_SIZE_Y / 2
|
||||
|
||||
WALL_RATIO = 1
|
||||
|
||||
BALL_SPEED_INC = 1
|
||||
BALL_SPEED_INC = 50
|
||||
BALL_SPEED_START = 170
|
||||
BALL_SIZE = 4
|
||||
BALL_SPAWN_POS_X = MAP_SIZE_X / 2
|
||||
|
@ -110,7 +110,7 @@ def get_interception(segment1: Segment, segment2: Segment):
|
||||
|
||||
return impact
|
||||
|
||||
def get_impact_point(segments: list[Segment], ball: Ball) -> dict:
|
||||
def get_impact_data(segments: list[Segment], ball: Ball) -> dict:
|
||||
|
||||
cos: float = round(math.cos(ball.angle), 6)
|
||||
sin: float = round(math.sin(ball.angle), 6)
|
||||
@ -224,14 +224,15 @@ async def collision(game: Game, impact_data: dict) -> bool:
|
||||
|
||||
if (player_hitted is None):
|
||||
angle = wall_collision(game.ball.angle, surface_angle)
|
||||
|
||||
else:
|
||||
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
|
||||
|
||||
game.ball.speed += config.BALL_SPEED_INC
|
||||
game.ball.angle = angle
|
||||
|
||||
return True
|
||||
|
||||
async def update_ball(game: Game, impact_data: dict) -> None:
|
||||
@ -245,7 +246,7 @@ async def update_ball(game: Game, impact_data: dict) -> None:
|
||||
hit: bool = await collision(game, impact_data)
|
||||
|
||||
if (hit == False):
|
||||
await asyncio.sleep(0.1)
|
||||
await asyncio.sleep(0.1) # delay to create frontend animation
|
||||
game.ball.reset()
|
||||
else:
|
||||
game.ball.position = impact_data.get("impact")
|
||||
@ -258,7 +259,7 @@ async def render(game: Game):
|
||||
|
||||
segments: list[Segment] = [player.rail for player in game.players] + [wall.rail for wall in game.walls]
|
||||
|
||||
impact_data: dict = get_impact_point(segments, game.ball)
|
||||
impact_data: dict = get_impact_data(segments, game.ball)
|
||||
|
||||
await update_ball(game, impact_data)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user