def test_bounce_ball_against_bottom_wall(self): hit_wall = pygame.mixer.Sound('../sounds/pong_wall.wav') hit_paddle = pygame.mixer.Sound('../sounds/pong_wall.wav') pong = Pong(hit_wall, hit_paddle) pong.ball = Ball(Config.ball_left_start_x, 500 - 20, 5, 5) pong.move_ball() self.assertEqual(pong.ball.vx, 5) self.assertEqual(pong.ball.vy, -5)
def test_bounce_ball_against_right_paddle(self): hit_wall = pygame.mixer.Sound('../sounds/pong_wall.wav') hit_paddle = pygame.mixer.Sound('../sounds/pong_wall.wav') pong = Pong(hit_wall, hit_paddle) pong.ball = Ball(960, 250, 5, 5) pong.move_ball() self.assertEqual(pong.ball.vx, -5) self.assertEqual(pong.ball.vy, 5)
def test_move_ball(self): hit_wall = pygame.mixer.Sound('../sounds/pong_wall.wav') hit_paddle = pygame.mixer.Sound('../sounds/pong_wall.wav') pong = Pong(hit_wall, hit_paddle) pong.move_ball() self.assertEqual(pong.ball.x, Config.ball_left_start_x + Config.ball_serve_left_vx) self.assertEqual(pong.ball.y, Config.ball_left_start_y + Config.ball_serve_left_vy)
def test_ball_missed_on_left(self): hit_wall = pygame.mixer.Sound('../sounds/pong_wall.wav') hit_paddle = pygame.mixer.Sound('../sounds/pong_wall.wav') pong = Pong(hit_wall, hit_paddle) pong.ball = Ball(-5, 250, -5, -5) pong.move_ball() self.assertEqual(pong.ball.x, Config.ball_left_start_x) self.assertEqual(pong.ball.y, Config.ball_left_start_y) self.assertEqual(pong.ball.vx, 0) self.assertEqual(pong.ball.vy, 0)
ball = Ball(Config.ball_left_start_x, Config.ball_left_start_y, Config.ball_size) score = Score() pong = Pong(leftPaddle, rightPaddle, ball, score, hit_wall, hit_paddle, Config.color) # Game Loop while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() keys = pygame.key.get_pressed() if keys[pygame.K_q]: pong.move_left_up() if keys[pygame.K_a]: pong.move_left_down() if keys[pygame.K_p]: pong.move_right_up() if keys[pygame.K_l]: pong.move_right_down() if keys[pygame.K_SPACE]: pong.serve() pong.move_ball() pong.draw(screen) pygame.time.delay(10)