Advertisement
trodland

Pygame Template With Player Classs

Apr 4th, 2020
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. import pygame, math, random
  2. pygame.init()
  3. clock = pygame.time.Clock()
  4. WIDTH = 800
  5. HEIGHT = 600
  6. screen = pygame.display.set_mode((WIDTH, HEIGHT))
  7. run = True
  8.  
  9. playergroup = pygame.sprite.Group()
  10.  
  11. ###################### CLASS PLAYER ######################
  12. class Player(pygame.sprite.Sprite):
  13.     def __init__(self,x,y):
  14.         pygame.sprite.Sprite.__init__(self)
  15.         self.image = pygame.image.load('dot16.png').convert_alpha()
  16.         self.rect = self.image.get_rect()
  17.         self.rect.x = x
  18.         self.rect.y = y
  19.        
  20.     def update(self):
  21.         pass
  22.    
  23. ###################### OBJECT CREATION ######################    
  24.  
  25. player = Player(WIDTH/2,HEIGHT/2)
  26. playergroup.add(player)
  27.  
  28. ###################### MAIN LOOP ######################
  29. while run:
  30.    
  31.     playergroup.update()
  32.        
  33.     screen.fill((255,255,255))
  34.    
  35.     playergroup.draw(screen)
  36.    
  37.     clock.tick(30)
  38.     pygame.display.update()
  39.     for event in pygame.event.get():
  40.         if event.type == pygame.QUIT:
  41.             run = False
  42. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement