Untitled

mail@pastecode.io avatar
unknown
python
a year ago
1.2 kB
2
Indexable
import pygame
from random import randrange
pygame.init()

screen = pygame.display.set_mode((400,400))
basket = pygame.Surface((100, 20))
ball1 = pygame.Surface((20, 20))

basket.fill((255, 255, 255))
ball1.fill((0,0,255))

base = basket.get_rect()
ball = ball1.get_rect()

base.x = 200
base.y = 380

ball.x = randrange(0, 381)
ball.y = -20

c = 0

my_text = f"{c}"
font = pygame.font.SysFont("calibri", 30)
text = font.render(my_text, True, (255, 255, 255))
screen.blit(text, (50, 30))

clock = pygame.time.Clock()
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    
    ball.y += 10
    if ball.y > 400:
        ball.x = randrange(0, 381)
        ball.y = -20
        
    keys = pygame.key.get_pressed()
    if keys[pygame.K_a]:
        base.x -= 5
    elif keys[pygame.K_d]:
        base.x += 5

    if ball.colliderect(base):
        c += 1
        text = font.render(f'{c//3}', True, (255, 255, 255))

    screen.fill((0, 0, 0))
    screen.blit(ball1, ball)
    screen.blit(basket, base)
    screen.blit(text, (50, 30))

    pygame.display.flip()
    clock.tick(60)

pygame.quit()
Leave a Comment