Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.12 KB | None | 0 0
  1. import pygame, time, random, sys
  2. from pygame.locals import *
  3. pygame.init()
  4.  
  5. ##################################### SETTING UP THE BASIC INFOMATION FOR THE GAME WINDOW ########################################
  6. WINDOWWIDTH = 700
  7. WINDOWHEIGHT = 500
  8. TEXTCOLOR = (100, 255, 100)
  9. BACKGROUND = (0, 0, 0)
  10. ##################################################################################################################################
  11. Red = (255, 0, 0)
  12.  
  13. clock = pygame.time.Clock()
  14. minutes = 0
  15. seconds = 0
  16. milliseconds = 0
  17.  
  18. FPS = 60
  19. fpsClock = pygame.time.Clock()
  20.  
  21.  
  22.  
  23. ############################################### SETTING UP THE TEXT WELCOME SCREEN ###############################################
  24.  
  25.  
  26. pygame.init()
  27. mainClock = pygame.time.Clock()
  28. windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
  29. pygame.display.set_caption("Zombie Defense")
  30. pygame.mouse.set_visible(False)
  31.  
  32. pygame.font.init()
  33. font = pygame.font.SysFont(None, 48)
  34. text = font.render("Zombie Defence", 1, (0,0,0))
  35. ##################################################################################################################################
  36.  
  37.  
  38.  
  39.  
  40. ###################################################################### ASSIGNING THE IMAGES NAMES ################################
  41.  
  42. fd = pygame.image.load("fd.png")
  43. bg = pygame.image.load("b.jpg")
  44. Bad = pygame.image.load("Untitled-1.jpg")
  45. player = pygame.image.load("player.png")
  46. zed = pygame.image.load("Zombie.png")
  47. bullet = pygame.image.load("Bullet.png")
  48. info = pygame.image.load("INFO.png")
  49. player2 = pygame.image.load("player2.png")
  50. player3 = pygame.image.load("player3.png")
  51.  
  52. ##################################################################################################################################
  53.  
  54. font_S = pygame.font.Font(None, 44)
  55.  
  56. BLACK = (0,0,0)
  57. WHITE = (255,255,255)
  58.  
  59. playerx = 10
  60. playery = 10
  61.  
  62. dead = False
  63.  
  64. zedx = 100
  65. zedy = 10
  66.  
  67. bulletx = playerx
  68. bullety = 400
  69.  
  70.  
  71. pygame.key.set_repeat(10, 10)
  72. main_Menu = True
  73.  
  74. def terminate():
  75. pygame.quit()
  76. sys.exit()
  77.  
  78.  
  79. ################################################# SCORE ##########################################################################
  80. def text_Screen1(msg, colour, Pos_X, Pos_y):
  81. screen_text = font_S.render(msg, True, colour)
  82. windowSurface.blit(screen_text, [WINDOWWIDTH/ 3, WINDOWHEIGHT/ 10])
  83. ##################################################################################################################################
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92. ######################### ALLOWS PLAYER TO EXIT BY PRESSING ESC ##################################################################
  93. def waitForPlayerToPressKey():
  94. while True:
  95. for event in pygame.event.get():
  96. if event.type == QUIT:
  97. terminate()
  98. if event.type == KEYDOWN:
  99. if event.key == K_ESCAPE:
  100. terminate()
  101. return
  102. ##################################################################################################################################
  103.  
  104.  
  105. ##################### SETTING VALUES FOR PLAYER MOVEMENT #########################################################################
  106. def Start():
  107. b_Change = 0
  108. zed_Change = 0
  109. x_Change = 0
  110. playerx = 50
  111. playery = 400
  112. zedy = 10
  113. bullety = 450
  114. ##################################################################################################################################
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. ######################################################### MAIN GAME LOOP #########################################################
  122.  
  123. while True:
  124. pygame.display.update()
  125. playerx += x_Change
  126. zedy += zed_Change
  127. bullety += b_Change
  128.  
  129. global dead
  130.  
  131. if not dead:
  132. print("Test")
  133. windowSurface.blit(bg, (0, 0))
  134. windowSurface.blit(player, (playerx, playery))
  135. windowSurface.blit(zed, (zedx, zedy))
  136. # windowSurface.blit(info, (0, 0))
  137. windowSurface.blit(bullet, (playerx, bullety))
  138.  
  139.  
  140. elif dead:
  141. windowSurface.blit(fd, (0, 0))########################### GAME OVER #####################################################
  142. print("Nice people")
  143.  
  144. pygame.display.update()
  145. fpsClock.tick(FPS)
  146.  
  147.  
  148. for event in pygame.event.get():
  149. if event.type == QUIT:
  150. terminate()
  151. if event.type == KEYDOWN:
  152. if event.key == K_ESCAPE:
  153. terminate()
  154. return
  155. if event.type == KEYDOWN:
  156. if dead:
  157. if event.key == K_RETURN:
  158. dead = False
  159. if event.key == K_p:
  160. windowSurface.blit(bg, (0,0))######################### APPLYING BACKGROUND ########################################
  161. if event.key == K_d:
  162. #playerx += 5
  163. x_Change = 3
  164. zed_Change = 2
  165. if event.key == K_a:
  166. #playerx -= 5
  167. x_Change = -3
  168. zed_Change = 2
  169. if event.key == K_i:
  170. windowSurface.blit(info, (0, 0))######################### INFOMATION SCREEN ##########################################
  171. if event.key == K_SPACE:
  172. b_Change = -7
  173. if event.type == KEYUP:
  174. if event.key == K_d:
  175. x_Change = 0
  176. zed_Change = 0
  177. if event.key == K_i:
  178. windowSurface.blit(info,(0, 0))
  179. if event.key == K_a:
  180. x_Change = 0
  181. zed_Change = 0
  182. if zedy > 550:
  183. zedy = 10
  184. dead = True
  185. print ("done!")
  186. if event.key == K_SPACE:
  187. b_Change = -7
  188. windowSurface.blit(bullet, (playerx, bullety))
  189. if bullety < -50:
  190. bullety = playery
  191. b_Change = 0
  192.  
  193.  
  194. text_Screen1("Score: " , Red, 1.25, 35)
  195.  
  196. ##################################################################################################################################
  197.  
  198.  
  199.  
  200. def drawText(text, font, surface, x, y):
  201. textobj = font.render(text, 1, TEXTCOLOR)
  202. textrect = textobj.get_rect()
  203. textrect.topleft = (x, y)
  204. surface.blit(textobj, textrect)
  205.  
  206.  
  207.  
  208. ################################################################################ PUTTING THE TEXT ONTO THE WINDOW ################
  209.  
  210. drawText('Zombie Defence', font, windowSurface, (WINDOWWIDTH / 3), (WINDOWHEIGHT / 3))
  211. drawText('Press a key to start.', font, windowSurface, (WINDOWWIDTH / 3) - 30, (WINDOWHEIGHT / 3) + 50)
  212.  
  213. ##################################################################################################################################
  214.  
  215.  
  216. ############################################# CALLIGN THE DEFs ###################################################################
  217.  
  218. pygame.display.update()
  219. time.sleep(3)
  220. Start()
  221. waitForPlayerToPressKey()
  222. text_Screen1()
  223.  
  224.  
  225. ##################################################################################################################################
  226.  
  227.  
  228.  
  229. player = pygame.Rect(300, 500, 40, 40)
  230. pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement