Advertisement
thenewboston

[source code] Pygame (Python Game Development) Tutorial 81

Nov 15th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 19.87 KB | None | 0 0
  1. import pygame
  2. import time
  3. import random
  4.  
  5. pygame.init()
  6.  
  7. display_width = 800
  8. display_height = 600
  9.  
  10. gameDisplay = pygame.display.set_mode((display_width,display_height))
  11.  
  12.  
  13. pygame.display.set_caption('Tanks')
  14.  
  15. #icon = pygame.image.load("apple.png")      
  16. #pygame.display.set_icon(icon)
  17.  
  18. white = (255,255,255)
  19. black = (0,0,0)
  20.  
  21.  
  22. red = (200,0,0)
  23. light_red = (255,0,0)
  24.  
  25. yellow = (200,200,0)
  26. light_yellow = (255,255,0)
  27.  
  28. green = (34,177,76)
  29. light_green = (0,255,0)
  30.  
  31. clock = pygame.time.Clock()
  32.  
  33.  
  34.  
  35.  
  36. tankWidth = 40
  37. tankHeight = 20
  38.  
  39. turretWidth = 5
  40. wheelWidth = 5
  41.  
  42. ground_height = 35
  43.  
  44.  
  45.  
  46.  
  47.  
  48. smallfont = pygame.font.SysFont("comicsansms", 25)
  49. medfont = pygame.font.SysFont("comicsansms", 50)
  50. largefont = pygame.font.SysFont("comicsansms", 85)
  51.  
  52. #img = pygame.image.load('snakehead.png')
  53. #appleimg = pygame.image.load('apple.png')
  54.  
  55. def score(score):
  56.  
  57.     text = smallfont.render("Score: "+str(score), True, black)
  58.     gameDisplay.blit(text, [0,0])
  59.    
  60.  
  61. def text_objects(text, color,size = "small"):
  62.  
  63.     if size == "small":
  64.         textSurface = smallfont.render(text, True, color)
  65.     if size == "medium":
  66.         textSurface = medfont.render(text, True, color)
  67.     if size == "large":
  68.         textSurface = largefont.render(text, True, color)
  69.  
  70.     return textSurface, textSurface.get_rect()
  71.  
  72. def text_to_button(msg, color, buttonx, buttony, buttonwidth, buttonheight, size = "small"):
  73.     textSurf, textRect = text_objects(msg,color,size)
  74.     textRect.center = ((buttonx+(buttonwidth/2)), buttony+(buttonheight/2))
  75.     gameDisplay.blit(textSurf, textRect)
  76.    
  77. def message_to_screen(msg,color, y_displace = 0, size = "small"):
  78.     textSurf, textRect = text_objects(msg,color,size)
  79.     textRect.center = (int(display_width / 2), int(display_height / 2)+y_displace)
  80.     gameDisplay.blit(textSurf, textRect)
  81.  
  82. def tank(x,y,turPos):
  83.     x = int(x)
  84.     y = int(y)
  85.  
  86.  
  87.     possibleTurrets = [(x-27, y-2),
  88.                        (x-26, y-5),
  89.                        (x-25, y-8),
  90.                        (x-23, y-12),
  91.                        (x-20, y-14),
  92.                        (x-18, y-15),
  93.                        (x-15, y-17),
  94.                        (x-13, y-19),
  95.                        (x-11, y-21)
  96.                        ]
  97.  
  98.     pygame.draw.circle(gameDisplay, black, (x,y), int(tankHeight/2))
  99.     pygame.draw.rect(gameDisplay, black, (x-tankHeight, y, tankWidth, tankHeight))
  100.  
  101.     pygame.draw.line(gameDisplay, black, (x,y), possibleTurrets[turPos], turretWidth)
  102.  
  103.     pygame.draw.circle(gameDisplay, black, (x-15, y+20), wheelWidth)
  104.     pygame.draw.circle(gameDisplay, black, (x-10, y+20), wheelWidth)
  105.        
  106.  
  107.     pygame.draw.circle(gameDisplay, black, (x-15, y+20), wheelWidth)
  108.     pygame.draw.circle(gameDisplay, black, (x-10, y+20), wheelWidth)
  109.     pygame.draw.circle(gameDisplay, black, (x-5, y+20), wheelWidth)
  110.     pygame.draw.circle(gameDisplay, black, (x, y+20), wheelWidth)
  111.     pygame.draw.circle(gameDisplay, black, (x+5, y+20), wheelWidth)
  112.     pygame.draw.circle(gameDisplay, black, (x+10, y+20), wheelWidth)
  113.     pygame.draw.circle(gameDisplay, black, (x+15, y+20), wheelWidth)
  114.  
  115.     return possibleTurrets[turPos]
  116.  
  117.  
  118. def enemy_tank(x,y,turPos):
  119.     x = int(x)
  120.     y = int(y)
  121.  
  122.  
  123.     possibleTurrets = [(x+27, y-2),
  124.                        (x+26, y-5),
  125.                        (x+25, y-8),
  126.                        (x+23, y-12),
  127.                        (x+20, y-14),
  128.                        (x+18, y-15),
  129.                        (x+15, y-17),
  130.                        (x+13, y-19),
  131.                        (x+11, y-21)
  132.                        ]
  133.  
  134.     pygame.draw.circle(gameDisplay, black, (x,y), int(tankHeight/2))
  135.     pygame.draw.rect(gameDisplay, black, (x-tankHeight, y, tankWidth, tankHeight))
  136.  
  137.     pygame.draw.line(gameDisplay, black, (x,y), possibleTurrets[turPos], turretWidth)
  138.  
  139.     pygame.draw.circle(gameDisplay, black, (x-15, y+20), wheelWidth)
  140.     pygame.draw.circle(gameDisplay, black, (x-10, y+20), wheelWidth)
  141.        
  142.  
  143.     pygame.draw.circle(gameDisplay, black, (x-15, y+20), wheelWidth)
  144.     pygame.draw.circle(gameDisplay, black, (x-10, y+20), wheelWidth)
  145.     pygame.draw.circle(gameDisplay, black, (x-5, y+20), wheelWidth)
  146.     pygame.draw.circle(gameDisplay, black, (x, y+20), wheelWidth)
  147.     pygame.draw.circle(gameDisplay, black, (x+5, y+20), wheelWidth)
  148.     pygame.draw.circle(gameDisplay, black, (x+10, y+20), wheelWidth)
  149.     pygame.draw.circle(gameDisplay, black, (x+15, y+20), wheelWidth)
  150.  
  151.     return possibleTurrets[turPos]
  152.  
  153.  
  154. def game_controls():
  155.  
  156.  
  157.     gcont = True
  158.  
  159.     while gcont:
  160.         for event in pygame.event.get():
  161.                 #print(event)
  162.                 if event.type == pygame.QUIT:
  163.                     pygame.quit()
  164.                     quit()
  165.  
  166.  
  167.         gameDisplay.fill(white)
  168.         message_to_screen("Controls",green,-100,size="large")
  169.         message_to_screen("Fire: Spacebar",black,-30)
  170.         message_to_screen("Move Turret: Up and Down arrows",black,10)
  171.         message_to_screen("Move Tank: Left and Right arrows",black,50)
  172.         message_to_screen("Pause: P",black,90)
  173.  
  174.  
  175.         button("play", 150,500,100,50, green, light_green, action="play")
  176.         button("Main", 350,500,100,50, yellow, light_yellow, action="main")
  177.         button("quit", 550,500,100,50, red, light_red, action ="quit")
  178.  
  179.  
  180.  
  181.         pygame.display.update()
  182.  
  183.         clock.tick(15)
  184.  
  185.  
  186. def button(text, x, y, width, height, inactive_color, active_color, action = None):
  187.     cur = pygame.mouse.get_pos()
  188.     click = pygame.mouse.get_pressed()
  189.     #print(click)
  190.     if x + width > cur[0] > x and y + height > cur[1] > y:
  191.         pygame.draw.rect(gameDisplay, active_color, (x,y,width,height))
  192.         if click[0] == 1 and action != None:
  193.             if action == "quit":
  194.                 pygame.quit()
  195.                 quit()
  196.  
  197.             if action == "controls":
  198.                 game_controls()
  199.  
  200.             if action == "play":
  201.                 gameLoop()
  202.  
  203.             if action == "main":
  204.                 game_intro()
  205.            
  206.     else:
  207.         pygame.draw.rect(gameDisplay, inactive_color, (x,y,width,height))
  208.  
  209.     text_to_button(text,black,x,y,width,height)
  210.        
  211.  
  212.  
  213. def pause():
  214.  
  215.     paused = True
  216.     message_to_screen("Paused",black,-100,size="large")
  217.     message_to_screen("Press C to continue playing or Q to quit",black,25)
  218.     pygame.display.update()
  219.     while paused:
  220.         for event in pygame.event.get():
  221.                
  222.                 if event.type == pygame.QUIT:
  223.                     pygame.quit()
  224.                     quit()
  225.                 if event.type == pygame.KEYDOWN:
  226.                     if event.key == pygame.K_c:
  227.                         paused = False
  228.                     elif event.key == pygame.K_q:
  229.                         pygame.quit()
  230.                         quit()
  231.  
  232.        
  233.  
  234.         clock.tick(5)
  235.  
  236.  
  237.  
  238. def barrier(xlocation,randomHeight, barrier_width):
  239.    
  240.     pygame.draw.rect(gameDisplay, black, [xlocation, display_height-randomHeight, barrier_width,randomHeight])
  241.    
  242. def explosion(x, y, size=50):
  243.  
  244.     explode = True
  245.  
  246.     while explode:
  247.         for event in pygame.event.get():
  248.             if event.type == pygame.QUIT:
  249.                 pygame.quit()
  250.                 quit()
  251.  
  252.         startPoint = x,y
  253.  
  254.         colorChoices = [red, light_red, yellow, light_yellow]
  255.  
  256.         magnitude = 1
  257.  
  258.         while magnitude < size:
  259.  
  260.             exploding_bit_x = x +random.randrange(-1*magnitude,magnitude)
  261.             exploding_bit_y = y +random.randrange(-1*magnitude,magnitude)
  262.  
  263.             pygame.draw.circle(gameDisplay, colorChoices[random.randrange(0,4)], (exploding_bit_x,exploding_bit_y),random.randrange(1,5))
  264.             magnitude += 1
  265.  
  266.             pygame.display.update()
  267.             clock.tick(100)
  268.  
  269.         explode = False
  270.        
  271.        
  272.  
  273.  
  274. def fireShell(xy,tankx,tanky,turPos,gun_power,xlocation,barrier_width,randomHeight,enemyTankX, enemyTankY):
  275.     fire = True
  276.     damage = 0
  277.  
  278.     startingShell = list(xy)
  279.  
  280.     print("FIRE!",xy)
  281.  
  282.     while fire:
  283.         for event in pygame.event.get():
  284.             if event.type == pygame.QUIT:
  285.                 pygame.quit()
  286.                 quit()
  287.  
  288.         #print(startingShell[0],startingShell[1])
  289.         pygame.draw.circle(gameDisplay, red, (startingShell[0],startingShell[1]),5)
  290.  
  291.  
  292.         startingShell[0] -= (12 - turPos)*2
  293.  
  294.         # y = x**2
  295.         startingShell[1] += int((((startingShell[0]-xy[0])*0.015/(gun_power/50))**2) - (turPos+turPos/(12-turPos)))
  296.  
  297.         if startingShell[1] > display_height-ground_height:
  298.             print("Last shell:",startingShell[0], startingShell[1])
  299.             hit_x = int((startingShell[0]*display_height-ground_height)/startingShell[1])
  300.             hit_y = int(display_height-ground_height)
  301.             print("Impact:", hit_x,hit_y)
  302.            
  303.             if enemyTankX + 15 > hit_x > enemyTankX - 15:
  304.                 print("HIT TARGET!")
  305.                 damage = 25
  306.            
  307.            
  308.             explosion(hit_x,hit_y)
  309.             fire = False
  310.  
  311.         check_x_1 = startingShell[0] <= xlocation + barrier_width
  312.         check_x_2 = startingShell[0] >= xlocation
  313.  
  314.         check_y_1 = startingShell[1] <= display_height
  315.         check_y_2 = startingShell[1] >= display_height - randomHeight
  316.  
  317.         if check_x_1 and check_x_2 and check_y_1 and check_y_2:
  318.             print("Last shell:",startingShell[0], startingShell[1])
  319.             hit_x = int((startingShell[0]))
  320.             hit_y = int(startingShell[1])
  321.             print("Impact:", hit_x,hit_y)
  322.             explosion(hit_x,hit_y)
  323.             fire = False
  324.            
  325.  
  326.         pygame.display.update()
  327.         clock.tick(60)
  328.     return damage
  329.  
  330.        
  331. def e_fireShell(xy,tankx,tanky,turPos,gun_power,xlocation,barrier_width,randomHeight,ptankx,ptanky):
  332.  
  333.     damage = 0
  334.     currentPower = 1
  335.     power_found = False
  336.  
  337.     while not power_found:
  338.         currentPower += 1
  339.         if currentPower > 100:
  340.             power_found = True
  341.         #print(currentPower)
  342.  
  343.         fire = True
  344.         startingShell = list(xy)
  345.  
  346.  
  347.         while fire:
  348.             for event in pygame.event.get():
  349.                 if event.type == pygame.QUIT:
  350.                     pygame.quit()
  351.                     quit()
  352.  
  353.             #pygame.draw.circle(gameDisplay, red, (startingShell[0],startingShell[1]),5)
  354.  
  355.             startingShell[0] += (12 - turPos)*2
  356.             startingShell[1] += int((((startingShell[0]-xy[0])*0.015/(currentPower/50))**2) - (turPos+turPos/(12-turPos)))
  357.  
  358.             if startingShell[1] > display_height-ground_height:
  359.                 hit_x = int((startingShell[0]*display_height-ground_height)/startingShell[1])
  360.                 hit_y = int(display_height-ground_height)
  361.                 #explosion(hit_x,hit_y)
  362.                 if ptankx+15 > hit_x > ptankx - 15:
  363.                     print("target acquired!")
  364.                     power_found = True
  365.                 fire = False
  366.  
  367.             check_x_1 = startingShell[0] <= xlocation + barrier_width
  368.             check_x_2 = startingShell[0] >= xlocation
  369.  
  370.             check_y_1 = startingShell[1] <= display_height
  371.             check_y_2 = startingShell[1] >= display_height - randomHeight
  372.  
  373.             if check_x_1 and check_x_2 and check_y_1 and check_y_2:
  374.                 hit_x = int((startingShell[0]))
  375.                 hit_y = int(startingShell[1])
  376.                 #explosion(hit_x,hit_y)
  377.                 fire = False
  378.    
  379.  
  380.    
  381.     fire = True
  382.     startingShell = list(xy)
  383.     print("FIRE!",xy)
  384.  
  385.     while fire:
  386.         for event in pygame.event.get():
  387.             if event.type == pygame.QUIT:
  388.                 pygame.quit()
  389.                 quit()
  390.  
  391.         #print(startingShell[0],startingShell[1])
  392.         pygame.draw.circle(gameDisplay, red, (startingShell[0],startingShell[1]),5)
  393.  
  394.  
  395.         startingShell[0] += (12 - turPos)*2
  396.  
  397.  
  398.  
  399.         # y = x**2
  400.  
  401.         gun_power = random.randrange(int(currentPower*0.90), int(currentPower*1.10))
  402.        
  403.         startingShell[1] += int((((startingShell[0]-xy[0])*0.015/(gun_power/50))**2) - (turPos+turPos/(12-turPos)))
  404.  
  405.         if startingShell[1] > display_height-ground_height:
  406.             print("last shell:",startingShell[0],startingShell[1])
  407.             hit_x = int((startingShell[0]*display_height-ground_height)/startingShell[1])
  408.             hit_y = int(display_height-ground_height)
  409.             print("Impact:",hit_x,hit_y)
  410.             if ptankx + 15 > hit_x > ptankx - 15:
  411.                 print("HIT TARGET!")
  412.                 damage = 25
  413.             explosion(hit_x,hit_y)
  414.             fire = False
  415.  
  416.         check_x_1 = startingShell[0] <= xlocation + barrier_width
  417.         check_x_2 = startingShell[0] >= xlocation
  418.  
  419.         check_y_1 = startingShell[1] <= display_height
  420.         check_y_2 = startingShell[1] >= display_height - randomHeight
  421.  
  422.         if check_x_1 and check_x_2 and check_y_1 and check_y_2:
  423.             print("Last shell:",startingShell[0], startingShell[1])
  424.             hit_x = int((startingShell[0]))
  425.             hit_y = int(startingShell[1])
  426.             print("Impact:", hit_x,hit_y)
  427.             explosion(hit_x,hit_y)
  428.             fire = False
  429.  
  430.        
  431.        
  432.  
  433.         pygame.display.update()
  434.         clock.tick(60)
  435.     return damage
  436.  
  437. def power(level):
  438.     text = smallfont.render("Power: "+str(level)+"%",True, black)
  439.     gameDisplay.blit(text, [display_width/2,0])
  440.  
  441.  
  442.  
  443. def game_intro():
  444.  
  445.     intro = True
  446.  
  447.     while intro:
  448.         for event in pygame.event.get():
  449.                 #print(event)
  450.                 if event.type == pygame.QUIT:
  451.                     pygame.quit()
  452.                     quit()
  453.  
  454.                 if event.type == pygame.KEYDOWN:
  455.                     if event.key == pygame.K_c:
  456.                         intro = False
  457.                     elif event.key == pygame.K_q:
  458.                        
  459.                         pygame.quit()
  460.                         quit()
  461.  
  462.         gameDisplay.fill(white)
  463.         message_to_screen("Welcome to Tanks!",green,-100,size="large")
  464.         message_to_screen("The objective is to shoot and destroy",black,-30)
  465.         message_to_screen("the enemy tank before they destroy you.",black,10)
  466.         message_to_screen("The more enemies you destroy, the harder they get.",black,50)
  467.         #message_to_screen("Press C to play, P to pause or Q to quit",black,180)
  468.  
  469.  
  470.         button("play", 150,500,100,50, green, light_green, action="play")
  471.         button("controls", 350,500,100,50, yellow, light_yellow, action="controls")
  472.         button("quit", 550,500,100,50, red, light_red, action ="quit")
  473.  
  474.  
  475.  
  476.         pygame.display.update()
  477.  
  478.         clock.tick(15)
  479.  
  480. def game_over():
  481.  
  482.     game_over = True
  483.  
  484.     while game_over:
  485.         for event in pygame.event.get():
  486.                 #print(event)
  487.                 if event.type == pygame.QUIT:
  488.                     pygame.quit()
  489.                     quit()
  490.  
  491.         gameDisplay.fill(white)
  492.         message_to_screen("Game Over",green,-100,size="large")
  493.         message_to_screen("You died.",black,-30)
  494.  
  495.  
  496.  
  497.         button("play Again", 150,500,150,50, green, light_green, action="play")
  498.         button("controls", 350,500,100,50, yellow, light_yellow, action="controls")
  499.         button("quit", 550,500,100,50, red, light_red, action ="quit")
  500.  
  501.  
  502.         pygame.display.update()
  503.  
  504.         clock.tick(15)
  505.  
  506. def you_win():
  507.  
  508.     win = True
  509.  
  510.     while win:
  511.         for event in pygame.event.get():
  512.                 #print(event)
  513.                 if event.type == pygame.QUIT:
  514.                     pygame.quit()
  515.                     quit()
  516.  
  517.         gameDisplay.fill(white)
  518.         message_to_screen("You won!",green,-100,size="large")
  519.         message_to_screen("Congratulations!",black,-30)
  520.  
  521.  
  522.  
  523.         button("play Again", 150,500,150,50, green, light_green, action="play")
  524.         button("controls", 350,500,100,50, yellow, light_yellow, action="controls")
  525.         button("quit", 550,500,100,50, red, light_red, action ="quit")
  526.  
  527.  
  528.         pygame.display.update()
  529.  
  530.         clock.tick(15)
  531.  
  532.  
  533. def health_bars(player_health, enemy_health):
  534.  
  535.     if player_health > 75:
  536.         player_health_color = green
  537.     elif player_health > 50:
  538.         player_health_color = yellow
  539.     else:
  540.         player_health_color = red
  541.  
  542.     if enemy_health > 75:
  543.         enemy_health_color = green
  544.     elif enemy_health > 50:
  545.         enemy_health_color = yellow
  546.     else:
  547.         enemy_health_color = red
  548.  
  549.     pygame.draw.rect(gameDisplay, player_health_color, (680, 25, player_health, 25))
  550.     pygame.draw.rect(gameDisplay, enemy_health_color, (20, 25, enemy_health, 25))
  551.  
  552.  
  553.  
  554.  
  555. def gameLoop():
  556.     gameExit = False
  557.     gameOver = False
  558.     FPS = 15
  559.  
  560.     player_health = 100
  561.     enemy_health = 100
  562.  
  563.     barrier_width = 50
  564.  
  565.     mainTankX = display_width * 0.9
  566.     mainTankY = display_height * 0.9
  567.     tankMove = 0
  568.     currentTurPos = 0
  569.     changeTur = 0
  570.  
  571.     enemyTankX = display_width * 0.1
  572.     enemyTankY = display_height * 0.9
  573.  
  574.  
  575.    
  576.  
  577.     fire_power = 50
  578.     power_change = 0
  579.  
  580.     xlocation = (display_width/2) + random.randint(-0.2*display_width, 0.2*display_width)
  581.     randomHeight = random.randrange(display_height*0.1,display_height*0.6)
  582.  
  583.    
  584.     while not gameExit:
  585.        
  586.        
  587.         if gameOver == True:
  588.             #gameDisplay.fill(white)
  589.             message_to_screen("Game Over",red,-50,size="large")
  590.             message_to_screen("Press C to play again or Q to exit",black,50)
  591.             pygame.display.update()
  592.             while gameOver == True:
  593.                 for event in pygame.event.get():
  594.                     if event.type == pygame.QUIT:
  595.                         gameExit = True
  596.                         gameOver = False
  597.  
  598.                     if event.type == pygame.KEYDOWN:
  599.                         if event.key == pygame.K_c:
  600.                             gameLoop()
  601.                         elif event.key == pygame.K_q:
  602.                            
  603.                             gameExit = True
  604.                             gameOver = False
  605.          
  606.  
  607.  
  608.         for event in pygame.event.get():
  609.  
  610.             if event.type == pygame.QUIT:
  611.                 gameExit = True
  612.  
  613.             if event.type == pygame.KEYDOWN:
  614.                 if event.key == pygame.K_LEFT:
  615.                     tankMove = -5
  616.                    
  617.                 elif event.key == pygame.K_RIGHT:
  618.                     tankMove = 5
  619.                    
  620.                 elif event.key == pygame.K_UP:
  621.                     changeTur = 1
  622.                    
  623.                 elif event.key == pygame.K_DOWN:
  624.                     changeTur = -1
  625.  
  626.                 elif event.key == pygame.K_p:
  627.                     pause()
  628.  
  629.                 elif event.key == pygame.K_SPACE:
  630.                     damage = fireShell(gun,mainTankX,mainTankY,currentTurPos,fire_power,xlocation,barrier_width,randomHeight,enemyTankX,enemyTankY)
  631.                     enemy_health -= damage
  632.                     damage = e_fireShell(enemy_gun,enemyTankX,enemyTankY,8,50,xlocation,barrier_width,randomHeight,mainTankX,mainTankY)
  633.                     player_health -= damage
  634.                    
  635.                 elif event.key == pygame.K_a:
  636.                     power_change = -1
  637.                 elif event.key == pygame.K_d:
  638.                     power_change = 1
  639.  
  640.             elif event.type == pygame.KEYUP:
  641.                 if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
  642.                     tankMove = 0
  643.  
  644.                 if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
  645.                     changeTur = 0
  646.                    
  647.                 if event.key == pygame.K_a or event.key == pygame.K_d:
  648.                     power_change = 0
  649.                
  650.  
  651.  
  652.                    
  653.        
  654.         mainTankX += tankMove
  655.  
  656.         currentTurPos += changeTur
  657.  
  658.         if currentTurPos > 8:
  659.             currentTurPos = 8
  660.         elif currentTurPos < 0:
  661.             currentTurPos = 0
  662.  
  663.  
  664.         if mainTankX - (tankWidth/2) < xlocation+barrier_width:
  665.             mainTankX += 5
  666.            
  667.  
  668.         gameDisplay.fill(white)
  669.         health_bars(player_health,enemy_health)
  670.         gun = tank(mainTankX,mainTankY,currentTurPos)
  671.         enemy_gun = enemy_tank(enemyTankX, enemyTankY, 8)
  672.         fire_power += power_change
  673.  
  674.         power(fire_power)
  675.  
  676.         barrier(xlocation,randomHeight,barrier_width)
  677.         gameDisplay.fill(green, rect=[0, display_height-ground_height, display_width, ground_height])
  678.         pygame.display.update()
  679.  
  680.         if player_health < 1:
  681.             game_over()
  682.         elif enemy_health < 1:
  683.             you_win()
  684.         clock.tick(FPS)
  685.  
  686.     pygame.quit()
  687.     quit()
  688.  
  689. game_intro()
  690. gameLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement