blooming8

bobo

Aug 22nd, 2014 (edited)
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | None | 0 0
  1. import pygame
  2. from pygame.locals import *
  3.  
  4. pygame.init()
  5.  
  6. # some parameters
  7. screen_size = width, height = (480, 360)
  8. shift = 60
  9. origins = (0, 0)
  10. ghost_start_pos = (470, 0)
  11.  
  12. # screen
  13. screen = pygame.display.set_mode(screen_size)
  14. pygame.display.set_caption('just trying')
  15.  
  16. # images
  17. mario = pygame.image.load('NewRaccoonMario.png').convert_alpha()
  18. ghost = pygame.image.load('ghost.gif').convert()
  19. mario_rect = mario.get_rect()
  20. ghost_rect = ghost.get_rect()
  21. background = pygame.image.load('mario_scenario.jpg').convert()
  22.  
  23. while 1:
  24.     for event in pygame.event.get():
  25.         if event.type == QUIT:
  26.             exit()
  27.         elif event.type == KEYDOWN:
  28.             key = pygame.key.get_pressed()
  29.             if key[K_ESCAPE]:
  30.                 exit()
  31.             elif key[K_UP]:
  32.                 mario_rect.move_ip(0, -shift)
  33.             elif key[K_DOWN]:
  34.                 mario_rect.move_ip(0, shift)
  35.             elif key[K_RIGHT]:
  36.                 mario_rect.move_ip(shift, 0)
  37.             elif key[K_LEFT]:
  38.                 mario_rect.move_ip(-shift, 0)
  39.  
  40.     ghost_rect.move_ip(-50, 0)
  41.     if ghost_rect.left < 0:
  42.         ghost_rect.move_ip(ghost_start_pos)
  43.     if mario_rect.left < 0:
  44.         mario_rect.move_ip(1, 0)
  45.     elif mario_rect.right > width:
  46.         mario_rect.move_ip(470, 0)
  47.     elif mario_rect.top > height:
  48.         mario_rect.move_ip(359, 0)
  49.     elif mario_rect.bottom < 0:
  50.         mario_rect.move_ip(0, 0)
  51.     if mario_rect.colliderect(ghost_rect):
  52.         pass
  53.  
  54.     screen.blit(background, origins)
  55.     screen.blit(mario, mario_rect)
  56.     screen.blit(ghost, ghost_rect)
  57.     pygame.time.delay(50)
  58.     pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment