Skip to content

Commit

Permalink
game: Increasing ball speed at paddle hit
Browse files Browse the repository at this point in the history
  • Loading branch information
okbrandon committed Oct 11, 2024
1 parent 1e9e546 commit 4ceb61f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions backend/api/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,12 +718,16 @@ async def run_match_loop(self, match_id):
match_state['ball']['y'] - BALL_RADIUS <= match_state['playerA']['paddle_y'] + PADDLE_HEIGHT and # Ball's bottom is above paddle's bottom
match_state['ball']['y'] + BALL_RADIUS >= match_state['playerA']['paddle_y'] - PADDLE_HEIGHT): # Ball's top is below paddle's top
match_state['ball']['dx'] *= -1
match_state['ball']['dx'] *= 1.1
match_state['ball']['dy'] *= 1.1
await self.send_paddle_hit(match_state['playerA'], match_state['ball'])

elif (match_state['ball']['x'] + BALL_RADIUS >= TERRAIN_WIDTH - PADDLE_WIDTH and # Right side of ball hits Player B's paddle
match_state['ball']['y'] - BALL_RADIUS <= match_state['playerB']['paddle_y'] + PADDLE_HEIGHT and # Ball's bottom is above paddle's bottom
match_state['ball']['y'] + BALL_RADIUS >= match_state['playerB']['paddle_y'] - PADDLE_HEIGHT): # Ball's top is below paddle's top
match_state['ball']['dx'] *= -1
match_state['ball']['dx'] *= 1.1
match_state['ball']['dy'] *= 1.1
await self.send_paddle_hit(match_state['playerB'], match_state['ball'])

# Check for scoring
Expand Down

0 comments on commit 4ceb61f

Please sign in to comment.