Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.24 KB | None | 0 0
  1. import pygame, random, sys
  2. from pygame.locals import *
  3. vec = pygame.math.Vector2
  4.  
  5. # game settings
  6. WIDTH = 480
  7. HEIGHT = 640
  8. FPS = 60
  9. TITLE = 'Flappy Bird Clone'
  10. FONT = pygame.font.match_font('arial')
  11.  
  12. # player properties
  13. PLAYER_HEIGHT = 40
  14. PLAYER_WIDTH = 57
  15.  
  16. # collumn properties
  17. COLLUMN_GAP = PLAYER_HEIGHT * 5
  18. COLLUMN_WIDTH = PLAYER_WIDTH * 2
  19.  
  20. # player gravity
  21. PLAYER_ACC = 0.5
  22. PLAYER_FRICTION = -0.12
  23. PLAYER_GRAV = 1
  24.  
  25. #           R   G   B
  26. BLACK   = (  0,  0,  0)
  27. WHITE   = (255,255,255)
  28. RED     = (255,  0,  0)
  29. GREEN   = (  0,255,  0)
  30. BLUE    = (  0,  0,255)
  31. YELLOW  = (255,255,  0)
  32. OLIVE   = (128,128,  0)
  33. LBLUE   = (  0,  0, 64)
  34.  
  35. # set up game
  36. pygame.init()
  37. pygame.mixer.init()
  38. window_surface = pygame.display.set_mode((WIDTH, HEIGHT))
  39. window_surface.fill(LBLUE)
  40. pygame.display.set_caption(TITLE)
  41. main_clock = pygame.time.Clock()
  42.  
  43. def terminate():
  44.     pygame.quit()
  45.     sys.exit()
  46.  
  47. def draw_text(surf, text, size, x, y):
  48.     font = pygame.font.Font(FONT, size)
  49.     text_surface = font.render(text, True, WHITE)
  50.     text_rect = text_surface.get_rect()
  51.     text_rect.midtop = (x, y)
  52.     surf.blit(text_surface, text_rect)
  53.  
  54. class Player(pygame.sprite.Sprite):
  55.     def __init__(self):
  56.         pygame.sprite.Sprite.__init__(self)
  57.         self.image = pygame.Surface((PLAYER_WIDTH, PLAYER_HEIGHT))
  58.         self.rect = self.image.get_rect()
  59.         self.image.fill(BLUE)
  60.        
  61.  
  62.     def update(self):
  63.         pass
  64.  
  65.     def jump(self):
  66.         pass
  67.  
  68. class Collumn(pygame.sprite.Sprite):
  69.     def __init__(self, x, y, w, h):
  70.         pygame.sprite.Sprite.__init__(self)
  71.         self.image = pygame.Surface((w, h))
  72.         self.rect = self.image.get_rect()
  73.         self.image.fill(GREEN)
  74.  
  75. all_sprites = pygame.sprite.Group()
  76. collumns = pygame.sprite.Group()
  77. player = Player()
  78. all_sprites.add(player)
  79. score = 0
  80. top_score = 0
  81.  
  82. # game loop
  83. running = True
  84. while running:
  85.     # keep speed at FPS
  86.     main_clock.tick(FPS)
  87.  
  88.     # events
  89.     for event in pygame.event.get():
  90.         if event.type == QUIT:
  91.             terminate()
  92.  
  93.     # update
  94.     all_sprites.update()
  95.  
  96.     # draw
  97.     window_surface.fill(LBLUE)
  98.     all_sprites.draw(window_surface)
  99.  
  100.     # flip the display
  101.     pygame.display.flip
  102.  
  103. terminate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement