Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- pygame.init()
- screen = pygame.display.set_mode((900, 500))
- pygame.display.set_caption('My game')
- clock = pygame.time.Clock()
- player = pygame.rect.Rect(10, 200, 20, 100)
- bot = pygame.rect.Rect(885, 200, 20, 100)
- ball = pygame.rect.Rect(445, 245, 10, 10)
- running = True
- player_speed_y = 0
- while running:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_UP:
- player_speed_y -= 1
- if event.key == pygame.K_DOWN:
- player_speed_y += 1
- if event.type == pygame.KEYUP:
- if event.key == pygame.K_UP:
- player_speed_y += 1
- if event.key == pygame.K_DOWN:
- player_speed_y -= 1
- player.y += player_speed_y
- screen.fill((0, 0, 0))
- pygame.draw.rect(screen, (20, 200, 20), player)
- pygame.draw.rect(screen, (200, 20, 20), bot)
- pygame.draw.ellipse(screen, (255, 255, 255), ball)
- pygame.display.flip()
- clock.tick(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement