SHARE
TWEET

Untitled

a guest Mar 20th, 2017 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame
  2. import sys
  3. import time
  4. import random
  5. from pygame.locals import *
  6.  
  7. # Screen
  8. pygame.init()
  9. pygame.font.init()
  10. screen = pygame.display.set_mode((600, 600))
  11. screen_rect = screen.get_rect()
  12. pygame.display.set_caption("Egg Catch")
  13.  
  14. # Basket
  15. basket = pygame.image.load("/home/ken/art/basket.png")
  16. basket = pygame.transform.scale(basket, (80, 80))
  17. basket_rect = basket.get_rect()
  18. basket_rect.midbottom = screen_rect.midbottom
  19.  
  20. global moving_right
  21. global moving_left
  22. moving_right = False
  23. moving_left = True
  24.  
  25.  
  26. # Egg
  27. egg = pygame.image.load("/home/ken/art/egg.png")
  28. egg = pygame.transform.scale(egg, (40, 40))
  29. egg_rect = egg.get_rect()
  30.  
  31. gameRunning = True
  32. close = False
  33.  
  34. def check_keydown_events(event):
  35.     if event.key == pygame.K_RIGHT:
  36.         moving_right = True
  37.  
  38.     elif event.key == pygame.K_LEFT:
  39.         moving_left = True
  40.  
  41.     elif event.key == pygame.K_ESCAPE:
  42.         sys.exit()
  43.  
  44. def check_keyup_events(event):
  45.     if event.key == pygame.K_RIGHT:
  46.         moving_right = False
  47.  
  48.     elif event.key == pygame.K_LEFT:
  49.         moving_left = False
  50.  
  51. def check_events():
  52.     for event in pygame.event.get():
  53.         if event.type == pygame.QUIT:
  54.             sys.exit()
  55.         elif event.type == pygame.KEYUP:
  56.             check_keyup_events(event)
  57.         elif event.type == pygame.KEYDOWN:
  58.             check_keydown_events(event)
  59.         #elif event.type == pygame.KEYDOWN:
  60.         #   if event.key == K_LEFT:
  61.         #       basket_rect.left -= 1.5
  62.         #       basket_rect.bottom -= 0
  63.         #   elif event.key == K_RIGHT:
  64.         #       basket_rect.left += 1.5
  65.         #       basket_rect.bottom += 0
  66.  
  67. def blitme():
  68.     screen.blit(egg, egg_rect)
  69.     screen.blit(basket, basket_rect)
  70.    
  71.  
  72. def update():
  73.     screen.fill((255, 255, 255))
  74.  
  75.     check_events()
  76.    
  77.     if moving_right :
  78.         print moving_right, moving_left
  79.         basket_rect.left += 1.5
  80.  
  81.     if moving_left :
  82.         basket_rect.left -= 1.5
  83.  
  84.     blitme()
  85.     pygame.display.flip()
  86.  
  87.  
  88. while gameRunning:
  89.     update()
  90.     if close:
  91.         closeGame()
RAW Paste Data
Top