SHARE
TWEET

Untitled

a guest Sep 20th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame
  2. import random
  3.  
  4. WIDTH=360
  5. HEIGHT=480
  6. FPS=30
  7.  
  8. BLACK=(0,0,0)
  9. WHITE=(255,255,255)
  10. RED=(255,0,0)
  11. GREEN=(0,255,0)
  12. BLUE=(0,0,255)
  13.  
  14.  
  15. class Player(pygame.sprite.Sprite):
  16.     def __init__(self):
  17.         pygame.sprite.Sprite.__init__(self)
  18.         self.image=pygame.Surface((50,50))
  19.         self.image.fill(GREEN)
  20.         self.rect=self.image.get_rect()
  21.         self.rect.center=(WIDTH / 2, HEIGHT / 2)
  22.  
  23.     def update(self):
  24.         self.rect.x+=5
  25.  
  26. pygame.init()
  27. screen=pygame.display.set_mode((WIDTH,HEIGHT))
  28. pygame.display.set_caption("My Game")
  29. clock=pygame.time.Clock()
  30. all_sprites=pygame.sprite.Group()
  31. player=Player()
  32. all_sprites.add(player)
  33.  
  34. running=True
  35. while running:
  36.     clock.tick(FPS)
  37.  
  38.     for event in pygame.event.get():
  39.         if event.type==pygame.QUIT:
  40.             running=False
  41.            
  42.     all_sprites.update()
  43.  
  44.            
  45.     screen.fill(BLACK)
  46.     all_sprites.draw(screen)
  47.     pygame.display.flip()
  48.  
  49. pygame.quit()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top