예제 #1
0
def draw_board(surf):
    surf.blit(BORDER, (0, 0))
    for tile in range(len(STRUCTURE)):
        center = get_center(tile)
        draw_hex(surf, *center)
        text.text_to_screen(surf, "{}".format(tile),
                            center[0] - 6 * len(str(tile)),
                            center[1] + RADIUS / 2)
예제 #2
0
    def show_text(self):
        # score
        score = "%d - %d" % (self.score[0], self.score[1])
        text_to_screen(screen, score, screen_width / 2 - 45, 16, 32,
                       (230, 230, 230))

        # start text
        if self.start_text:
            text_to_screen(screen, "PRESS SPACE TO START",
                           screen_width / 2 - 94, 64, 16, (180, 180, 180))
예제 #3
0
def draw_board(surf):
    for tile in range(len(STRUCTURE)):
        center = get_center(tile)
        draw_hex(surf, *center)
        text.text_to_screen(
            surf, "B: {}, W: {}".format(globals()["pbc"],
                                        globals()["pwc"]), SCREENX - 100, 10)
        text.text_to_screen(surf, "{}".format(tile),
                            center[0] - 6 * len(str(tile)),
                            center[1] + RADIUS / 2)
예제 #4
0
def start_screen():

    run = True
    while run:

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        keys = pygame.key.get_pressed()

        if keys[pygame.K_c]:
            run = False
        screen_start.fill(black)
        text_to_screen(screen_start, "Welcome to Brick Breaker",
                       screen_width / 2 - 200, screen_height / 2 - 200)
        text_to_screen(screen_start, "Press c to start",
                       screen_width / 2 - 150, screen_height / 2 - 50)
        pygame.display.update()
        clock.tick(60)
예제 #5
0
def gameover_screen():

    run = True
    while run:

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        keys = pygame.key.get_pressed()

        if keys[pygame.K_c]:
            run = False
        # if keys[pygame.K_r]:
        #     game_init()

        screen_gameover.fill(black)
        text_to_screen(screen_gameover, "Game Over", screen_width / 2 - 100,
                       screen_height / 2 - 100)
        text_to_screen(screen_gameover, "Press c to restart",
                       screen_width / 2 - 150, screen_height / 2)
        pygame.display.update()
        clock.tick(60)
예제 #6
0
car1_x = width - 150

car2_y = 650
car2_x = width - 150

lines = Lines()
text = lines.next

while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

        if event.type == pygame.KEYDOWN:
            if len(text) < 20:
                text += ' .. ' + lines.next
            if text[0] == event.unicode:
                text = text[1:]
                car2_x -= 12

    screen.blit(background, (0, 0))
    screen.blit(car1, (car1_x, car1_y))
    screen.blit(car2, (car2_x, car2_y))
    screen.blit(foreground, (0, 0))

    pygame.draw.rect(screen, GREY, [text_posx, text_posy, width, 30], 0)

    text_to_screen(screen, text, text_posx, text_posy)
    pygame.display.flip()
    car1_x -= random.choice((0, 0, 0, 1, 1, 0, 0, 2, 3, 0, 1, 0))
예제 #7
0
                            wc -= 1
                        else:
                            bc -= 1
                        turn += 1
                    if turn == 18:
                        print b.greedy_swap()
            elif not done:
                if len(raw_command.split()) == 4:
                    t1, t2, t3, t4 = map(int, raw_command.split())
                    b.swap(t1, t2)
                    b.swap(t3, t4)
                    path, vic, _ = b.eval()
                    done = True
                    screen.fill((255, 255, 255))
                else:
                    print("Invalid swap")
        except Exception, e:
            print(e)

    screen.blit(textinput.get_surface(), (10, 10))

    # draw the game board
    draw_board(screen)
    draw_state(screen, b.state)
    draw_path(screen, path)
    text.text_to_screen(screen, vic, 10, SCREENY - 50)

    # update the screen
    pygame.display.update()
    clock.tick(30)
예제 #8
0
 def show(self):
     rounded_rect(screen, self.col, (self.x, self.y, self.w, self.h), 0.2)
     text_to_screen(screen, self.name, self.x + self.w / 2 - 40,
                    self.y + 10, 16, (30, 30, 30))
예제 #9
0
def game_init():
    black = (0, 0, 0)

    pygame.init()
    run = True
    screen_width = 1500
    screen_height = 700
    screen = pygame.display.set_mode((screen_width, screen_height))

    all_sprites_list = pygame.sprite.Group()

    bricks_list = pygame.sprite.Group()
    for i in range(0, 12):
        for j in range(0, 5):
            bricks = Brick(100, 25)

            bricks.rect.x = (screen_width - 1300) + (i * 100)
            bricks.rect.y = (screen_height - 600) + (j * 50)

            bricks_list.add(bricks)
            all_sprites_list.add(bricks)

    paddle_list = pygame.sprite.Group()
    paddle = Paddle()
    paddle.rect.x = screen_width / 2
    paddle.rect.y = screen_height - 20
    paddle_list.add(paddle)
    all_sprites_list.add(paddle)

    ball = Ball(paddle.rect.x + paddle.paddle_width / 2, paddle.rect.y - (paddle.paddle_height + 10))
    ball.count = 4
    all_sprites_list.add(ball)

    clock = pygame.time.Clock()
    while run:
        screen.fill(black)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        keys = pygame.key.get_pressed()

        if keys[pygame.K_LEFT]:

            paddle.moveLeft(5)

            if paddle.rect.x <= 0:
                paddle.rect.x = 0

        if keys[pygame.K_RIGHT]:

            paddle.moveRight(5)

            if paddle.rect.x >= screen_width - paddle.paddle_width:
                paddle.rect.x = screen_width - paddle.paddle_width

        # ball.update(paddle.rect.x, paddle.rect.y)

        if pygame.sprite.spritecollide(ball, bricks_list, True):

            if ball.speed > 0:
                ball.wall_bounce()

            if ball.speed < 0:
                ball.wall_bounce()

        if pygame.sprite.spritecollide(ball, paddle_list, False):

            if ball.speed > 0:
                if ball.rect.x + ball.ball_width / 2 < paddle.rect.x + paddle.paddle_width / 2:
                    ball.left_bounce()
                if ball.rect.x + ball.ball_width / 2 == paddle.rect.x + paddle.paddle_width / 2:
                    ball.wall_bounce()
                if ball.rect.x + ball.ball_width / 2 > paddle.rect.x + paddle.paddle_width / 2:
                    ball.wall_bounce()
            if ball.speed < 0:
                if ball.rect.x + ball.ball_width / 2 < paddle.rect.x + paddle.paddle_width / 2:
                    ball.wall_bounce()
                if ball.rect.x + ball.ball_width / 2 == paddle.rect.x + paddle.paddle_width / 2:
                    ball.wall_bounce()
                if ball.rect.x + ball.ball_width / 2 > paddle.rect.x + paddle.paddle_width / 2:
                    ball.right_bounce()
        if ball.count == 0:
            run = False
            gameover_screen()

        if not bricks_list:
            run = False
            gameover_screen()


        all_sprites_list.update(paddle.rect.x + paddle.paddle_width / 2, paddle.rect.y - (paddle.paddle_height + 10))
        all_sprites_list.draw(screen)
        text_to_screen(screen, "Balls left: " + str(ball.count-1), 10, 10)
        pygame.display.flip()
        clock.tick(120)