Advertisement
Shcoder001

Pygame Game

Jan 26th, 2023
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. import pygame
  2.  
  3. pygame.init()
  4. screen = pygame.display.set_mode((900, 500))
  5. pygame.display.set_caption('My game')
  6. clock = pygame.time.Clock()
  7. player = pygame.rect.Rect(10, 200, 20, 100)
  8. bot = pygame.rect.Rect(885, 200, 20, 100)
  9. ball = pygame.rect.Rect(445, 245, 10, 10)
  10. running = True
  11. player_speed_y = 0
  12. while running:
  13.     for event in pygame.event.get():
  14.         if event.type == pygame.QUIT:
  15.             running = False
  16.         if event.type == pygame.KEYDOWN:
  17.             if event.key == pygame.K_UP:
  18.                 player_speed_y -= 1
  19.             if event.key == pygame.K_DOWN:
  20.                 player_speed_y += 1
  21.  
  22.         if event.type == pygame.KEYUP:
  23.             if event.key == pygame.K_UP:
  24.                 player_speed_y += 1
  25.             if event.key == pygame.K_DOWN:
  26.                 player_speed_y -= 1
  27.  
  28.     player.y += player_speed_y
  29.     screen.fill((0, 0, 0))
  30.     pygame.draw.rect(screen, (20, 200, 20), player)
  31.     pygame.draw.rect(screen, (200, 20, 20), bot)
  32.     pygame.draw.ellipse(screen, (255, 255, 255), ball)
  33.     pygame.display.flip()
  34.     clock.tick(60)
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement