Guest User

Untitled

a guest
Mar 18th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.80 KB | None | 0 0
  1. import pygame, sys, random, time
  2. from pygame.locals import *
  3.  
  4.  
  5. pygame.init()
  6.  
  7. MC = pygame.time.Clock()
  8. Score = 0
  9. WW = 400
  10. WH = 400
  11. T = True
  12. windowSurface = pygame.display.set_mode((WW, WH), 0,32)
  13. pygame.display.set_caption("Trump Chase")
  14. # colorvariables
  15. #font = pygame.font.SysFont('Comic Sans MS', 14)
  16. black = 0,0,0
  17. blue = 0,0,255
  18. gray = 128,128,128
  19. green = 0,128,0
  20. purple = 128,0,128
  21. red = 255,0,0
  22. white = 255,255,255
  23. yellow = 255,255,0
  24.  
  25. # Player and Food Structer
  26.  
  27. FC = 0 # Starting Number of food
  28. NF = 20 # Number or loops before more cubes
  29.  
  30. FS = 20 # Size of food
  31. trump = pygame.Rect(0,0,50,50)
  32. player = pygame.Rect(300,100,50,50)
  33. #image
  34. playerImage = pygame.image.load('Mexican.jpg')
  35. pSI = pygame.transform.scale(playerImage, (50,50))
  36. foodImage = pygame.image.load('Burrito.png')
  37. foodStretchedImage = pygame.transform.scale(foodImage, (FS, FS))
  38. trumpImage = pygame.image.load('Trump Picture.jpg')
  39. tSI = pygame.transform.scale(trumpImage, (50,50))
  40.  
  41. #sound
  42. SB = [pygame.mixer.Sound('fin.wav'), pygame.mixer.Sound('mexico_pays.wav')]
  43. pickUpSound = pygame.mixer.Sound('chime.wav')
  44. trumpHitSound = SB[random.randint(0,1)]
  45.  
  46. pygame.mixer.music.load('trumptrap.mp3')
  47. pygame.mixer.music.play(-1,0.0)
  48. MP = True
  49. # This code will keep track of the cubits
  50. foods = []
  51. for i in range(20):
  52. foods.append(pygame.Rect(random.randint(0, WW - FS), random.randint(0, WH - FS), FS , FS))
  53.  
  54. # Movement Variables
  55.  
  56.  
  57. ML = False
  58.  
  59. MR = False
  60.  
  61. MU = False
  62.  
  63. MD = False
  64.  
  65. MS = 6
  66.  
  67.  
  68.  
  69. # Game Loop
  70. print('Score:')
  71. while T :
  72. for event in pygame.event.get():
  73. if event.type == QUIT:
  74. pygame.quit()
  75. sys.exit()
  76. # Here are the keyboard variables
  77. if event.type == KEYDOWN:
  78. x = event.key
  79. if x == K_LEFT or x == K_a:
  80. MR = False
  81. ML = True
  82.  
  83. if x == K_RIGHT or x == K_d:
  84. ML = False
  85. MR = True
  86.  
  87. if x == K_UP or x == K_w:
  88. MD = False
  89. MU = True
  90.  
  91. if x == K_DOWN or x == K_s:
  92. MU = False
  93. MD = True
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101. if event.type == KEYUP:
  102.  
  103. if event.key == K_ESCAPE:
  104. pygame.quit()
  105. sys.exit()
  106.  
  107. x = event.key
  108.  
  109. if x == K_LEFT or x == K_a:
  110. ML = False
  111.  
  112. if x == K_RIGHT or x == K_d:
  113. MR = False
  114.  
  115. if x == K_UP or x == K_w:
  116. MU = False
  117.  
  118. if x == K_DOWN or x == K_s:
  119. MD = False
  120. # Teleportation Flow Controls
  121. if event.key == K_x:
  122. player.top = random.randint(0, WH - player.height)
  123. player.left = random.randint(0, WW - player.width)
  124.  
  125.  
  126. # Mouse Click Controls
  127. # if event.type == MOUSEBUTTONUP:
  128. # foods.append(pygame.Rect(event.pos[0], event.pos[1], FS, FS))
  129. # Food Counter
  130. FC += 1
  131. if FC >= NF:
  132. FC = 0
  133. foods.append(pygame.Rect(random.randint(0, WW - FS),random.randint(0, WH - FS), FS, FS))
  134. # kinda important to just be laying around
  135. windowSurface.fill(white)
  136.  
  137. # These are player movement controls
  138. if MD and player.bottom < WH:
  139. player.top += MS
  140.  
  141. if MU and player.top > 0:
  142. player.top -= MS
  143.  
  144. if ML and player.left > 0:
  145. player.left -= MS
  146.  
  147. if MR and player.right < WW:
  148. player.right += MS
  149.  
  150.  
  151.  
  152. #Check for eaten food squares, and remove them. Also the score code.
  153.  
  154. for food in foods[:]:
  155. if player.colliderect(food):
  156. Score += 1
  157. if MP:
  158. pickUpSound.play()
  159. foods.remove(food)
  160. print(Score)
  161. if Score == 420:
  162. print('You Win!')
  163. T = False
  164.  
  165.  
  166.  
  167. #------------------------------------------------------------------------------------------
  168.  
  169. if player.colliderect(trump):
  170. MD = False
  171. ML = False
  172. MU = False
  173. MR = False
  174. trumpHitSound.play()
  175. print("Game Over")
  176. pygame.quit()
  177. sys.exit()
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184. # Draw the food
  185.  
  186.  
  187. for food in foods:
  188. windowSurface.blit(foodStretchedImage, food)
  189. # Draws players
  190. MS = 6
  191. UL = (25,25)
  192. UR = (375, 25)
  193. DL = (25,375)
  194. DR = (375,375)
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201. #Trump AI
  202. #----------------------------------------------------------------------------------
  203.  
  204. if (trump.centerx ,trump.centery) == UL:
  205. trump.right += MS
  206. trump.bottom += MS
  207.  
  208. if (trump.centerx ,trump.centery) == UR:
  209. trump.left -= MS
  210. trump.bottom += MS
  211.  
  212. if (trump.centerx ,trump.centery) == DL:
  213. trump.up -= MS
  214. trump.right += MS
  215.  
  216. if(trump.centerx ,trump.centery) == DR:
  217. trump.up -= MS
  218. trump.right += MS
  219.  
  220. # Prevents Trump from going through wall
  221.  
  222. if trump.top < 0:
  223. if trump == UL:
  224. trump = DR
  225.  
  226. if trump == UR:
  227. trump = DL
  228.  
  229. if trump.left < 0:
  230. if trump == UL:
  231. trump = DR
  232.  
  233. if trump == DL:
  234. trump = UR
  235.  
  236. if trump.right > WW:
  237. if trump == UR:
  238. trump = DL
  239.  
  240. if trump == DR:
  241. trump = UL
  242.  
  243. if trump.bottom > WH:
  244. if trump == DR:
  245. trump = UR
  246.  
  247. if trump == DL:
  248. trump = UL
  249.  
  250.  
  251.  
  252.  
  253.  
  254. #----------------------------------------------------------
  255. windowSurface.blit( pSI, player)
  256.  
  257. windowSurface.blit( tSI, trump)
  258.  
  259.  
  260.  
  261. # Updates Display and Main Clock gives game constant speed no matter the device
  262.  
  263. pygame.display.update()
  264.  
  265. MC.tick(40)
Advertisement
Add Comment
Please, Sign In to add comment