Advertisement
Guest User

pacman pygame

a guest
Jul 15th, 2018
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1.  
  2. # import pygame
  3. import pygame, sys
  4. from pygame import *
  5.  
  6. # initialize game engine
  7. pygame.init()
  8.  
  9. #screen size
  10. display_width = 500
  11. display_height = 500
  12.  
  13. # Open a window
  14. size = (display_width, display_height)
  15. screen = pygame.display.set_mode(size)
  16.  
  17. #music
  18. pygame.mixer.music.load('Pacmanmusic.wav')
  19. pygame.mixer.music.play(-1, 0.0)
  20.  
  21.  
  22.  
  23. # Set title to the window
  24. pygame.display.set_caption("Pacman")
  25.  
  26. fpsClock = pygame.time.Clock()
  27.  
  28. #sumtin
  29. dead=False
  30.  
  31. #background image
  32. background_image = pygame.image.load("Originalpacmaze.png")
  33. background_image = pygame.transform.scale(background_image,(500,500))
  34.  
  35. #pacman character
  36. pacman = pygame.image.load('pacman_left.png')
  37. pacmanx = 27
  38. pacmany = 23
  39. x_speed = 10
  40. y_speed = 10
  41. pacman = pygame.transform.scale(pacman,(pacmanx,pacmany))
  42.  
  43.  
  44. #quit function
  45. while not dead:
  46. for event in pygame.event.get():
  47. if event.type == pygame.QUIT:
  48. dead = True
  49.  
  50. ######## movement
  51. if event.type == KEYDOWN:
  52. if event.key == K_LEFT or event.key == ord('a'):
  53. pacman = pygame.image.load('pacman_left.png')
  54. elif event.key == K_RIGHT or event.key == ord('d'):
  55. pacman = pygame.image.load('pacman_right.png')
  56. elif event.key == K_UP or event.key == ord('w'):
  57. pacman = pygame.image.load('pacman_up.png')
  58. elif event.key == K_DOWN or event.key== ord ('s'):
  59. pacman = pygame.image.load('pacman_down.png')
  60.  
  61.  
  62. keys_pressed = key.get_pressed()
  63.  
  64. if keys_pressed[K_LEFT] or keys_pressed[ord('a')]:
  65. pacmanx -= 1.5
  66.  
  67. if keys_pressed[K_RIGHT] or keys_pressed[ord('d')]:
  68. pacmanx += 1.5
  69.  
  70. if keys_pressed[K_UP] or keys_pressed[ord('w')]:
  71. pacmany -= 1.5
  72.  
  73. if keys_pressed[K_DOWN] or keys_pressed[ord('s')]:
  74. pacmany += 1.5
  75.  
  76. ###############walls
  77.  
  78. pygame.sprite.spritecollideany
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. #################drawing
  88.  
  89.  
  90.  
  91. screen.blit(background_image, [0, 0])
  92. screen.blit(pacman,(pacmanx, pacmany))
  93.  
  94. pygame.display.flip()
  95. fpsClock.tick(60)
  96.  
  97. pygame.quit()
  98. quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement