Esempio n. 1
0
    compute_cursor(key_pressed)

    return ball, cursor, bricks, lifes


# Use it to determine the main program, RESPECT THE SYNTAX
if __name__ == '__main__':
    width_screen = 600
    height_screen = 600
    # Enable graphics engine
    engine = GameEngine(width_screen, height_screen)

    # Create ball
    ball = Ball(width_screen / 2, height_screen - 200)
    ball.dx = -6
    ball.dy = -3

    # Create cursor
    cursor = Cursor(width_screen / 2, height_screen - 30)
    # Create Bricks
    bricks = add_lines_brick(2, 3, width_screen)
    # Create lifes
    lifes = [
        Life(5, height_screen - 100),
        Life(50, height_screen - 100),
        Life(100, height_screen - 100)
    ]
    print(bricks)

    # Main loop for graphics
    while len(bricks) > 0 and len(lifes) > 0:
Esempio n. 2
0
    key = pygame.key.get_pressed()
    if key[pygame.K_w]:
        paddle1.rect.y += -paddle1.speed
    if key[pygame.K_s]:
        paddle1.rect.y += paddle1.speed
    if key[pygame.K_UP]:
        paddle2.rect.y += -paddle2.speed
    if key[pygame.K_DOWN]:
        paddle2.rect.y += paddle2.speed

    pong.rect.x += pong.speed * pong.dx
    pong.rect.y += pong.speed * pong.dy

    # -- Ball Collisions
    if pong.rect.y > 490:
        pong.dy = -1
    if pong.rect.x > 740:
        pong.rect.x, pong.rect.y = 375, 250
        pong.dx = -1
        paddle1.points += 1
    if pong.rect.y < 10:
        pong.dy = 1
    if pong.rect.x < 10:
        pong.rect.x, pong.rect.y = 375, 250
        pong.dx = 1
        paddle2.points += 1
    if paddle1.rect.colliderect(pong.rect):
        pong.dx = 1
    if paddle2.rect.colliderect(pong.rect):
        pong.dx = -1