def test_moving_ball():
    ball = Ball(surface)
    for i in range(0, 10):
        oldDirection = ball.get_current_position()
        ball.update_ball()
        pygame.display.flip()
        assert ball.get_current_position() != oldDirection
    def __init__(self):
        self.middle_rects = self.create_middle_rects(5, 15)

        # Initialize entities
        self.player = Player(20, 20, 100, PLAYER_COLOR)
        self.enemy = Enemy(SCREEN_WIDTH - 20 - 20, 20, 100, ENEMY_COLOR)
        self.ball = Ball(12, 600)

        # Initialize fonts
        self.score_font = pygame.font.Font("8bit.ttf", SCORE_SIZE)
        self.player_score_label = self.score_font.render(
            str(self.player.score), True, SCORE_COLOR)
        self.enemy_score_label = self.score_font.render(
            str(self.enemy.score), True, SCORE_COLOR)
Exemple #3
0
    def __init__(self, screen, resource_loader):
        super().__init__()
        self.screen = screen
        self.screen_rect = self.screen.get_rect()

        self.player = Paddle(config.BRICK_SIZE, 3 * config.BRICK_SIZE,
                             2 * config.BRICK_SIZE, self.screen_rect.centery,
                             config.PLAYER_SPEED, self.screen,
                             InputController())
        self.ball = Ball(
            config.BRICK_SIZE,
            self.screen_rect.centerx,
            self.screen_rect.centery,
            2,
            self.screen,
            bounce_sound=resource_loader.get_sound('ball_bounce_2'),
            hit_sound=resource_loader.get_sound('ball_hit'))
        self.enemy = Paddle(config.BRICK_SIZE, 3 * config.BRICK_SIZE,
                            config.SCREEN_WIDTH - 2 * config.BRICK_SIZE,
                            self.screen_rect.centery, config.ENEMY_SPEED,
                            self.screen, AIController(self))
        self.entities = [self.ball, self.player, self.enemy]
        self.paddles = [self.player, self.enemy]

        self.player_score = 0
        self.enemy_score = 0
        self.player_score_textbox = SimpleTextBox(self.screen_rect.centerx -
                                                  40,
                                                  36,
                                                  self.screen,
                                                  text=str(self.player_score))
        self.enemy_score_textbox = SimpleTextBox(self.screen_rect.centerx + 40,
                                                 36,
                                                 self.screen,
                                                 text=str(self.enemy_score))
        self.widgets = [self.player_score_textbox, self.enemy_score_textbox]
        self.score_point_sound = resource_loader.get_sound('score_point')

        self._init_static_elements()
Exemple #4
0
    def __init__(self, surface, username, numberOfPlayers, soundsOn):
        # Initialize variables
        self.__clock = pygame.time.Clock()
        self.__surface = surface
        self.__isRunning = True
        self.__username = username
        self.__numberOfPlayers = numberOfPlayers
        self.__soundsOn = soundsOn

        # Initialize the game entities
        self.__ball = Ball(self.__surface)
        self.__score = self.__ball.get_score()
        self.__playfield = Playfield(self.__surface, self.__username,
                                     self.__score)
        self.__surface = self.__playfield.get_surface()
        self.__snake = Snake(self.__surface, self.__isRunning)
        self.__food = Food(self.__surface)

        # Check if multiplayer or not
        if self.__numberOfPlayers == 0:
            self.__paddle = Paddle(self.__surface)
        else:
            self.__paddle = Paddle(self.__surface, True)
def test_ball_creation():
    ball = Ball(surface)
    assert ball.get_current_position() == (400, 400)
    assert ball.get_score() == 0