Advertisement
thenewboston

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

Nov 15th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 20.58 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 + 10 > hit_x > enemyTankX - 10:
  304.                 print("Critical Hit!")
  305.                 damage = 25
  306.             elif enemyTankX + 15 > hit_x > enemyTankX - 15:
  307.                 print("Hard Hit!")
  308.                 damage = 18
  309.             elif enemyTankX + 25 > hit_x > enemyTankX - 25:
  310.                 print("Medium Hit")
  311.                 damage = 10
  312.             elif enemyTankX + 35 > hit_x > enemyTankX - 35:
  313.                 print("Light Hit")
  314.                 damage = 5
  315.            
  316.            
  317.             explosion(hit_x,hit_y)
  318.             fire = False
  319.  
  320.         check_x_1 = startingShell[0] <= xlocation + barrier_width
  321.         check_x_2 = startingShell[0] >= xlocation
  322.  
  323.         check_y_1 = startingShell[1] <= display_height
  324.         check_y_2 = startingShell[1] >= display_height - randomHeight
  325.  
  326.         if check_x_1 and check_x_2 and check_y_1 and check_y_2:
  327.             print("Last shell:",startingShell[0], startingShell[1])
  328.             hit_x = int((startingShell[0]))
  329.             hit_y = int(startingShell[1])
  330.             print("Impact:", hit_x,hit_y)
  331.             explosion(hit_x,hit_y)
  332.             fire = False
  333.            
  334.  
  335.         pygame.display.update()
  336.         clock.tick(60)
  337.     return damage
  338.  
  339.        
  340. def e_fireShell(xy,tankx,tanky,turPos,gun_power,xlocation,barrier_width,randomHeight,ptankx,ptanky):
  341.  
  342.     damage = 0
  343.     currentPower = 1
  344.     power_found = False
  345.  
  346.     while not power_found:
  347.         currentPower += 1
  348.         if currentPower > 100:
  349.             power_found = True
  350.         #print(currentPower)
  351.  
  352.         fire = True
  353.         startingShell = list(xy)
  354.  
  355.  
  356.         while fire:
  357.             for event in pygame.event.get():
  358.                 if event.type == pygame.QUIT:
  359.                     pygame.quit()
  360.                     quit()
  361.  
  362.             #pygame.draw.circle(gameDisplay, red, (startingShell[0],startingShell[1]),5)
  363.  
  364.             startingShell[0] += (12 - turPos)*2
  365.             startingShell[1] += int((((startingShell[0]-xy[0])*0.015/(currentPower/50))**2) - (turPos+turPos/(12-turPos)))
  366.  
  367.             if startingShell[1] > display_height-ground_height:
  368.                 hit_x = int((startingShell[0]*display_height-ground_height)/startingShell[1])
  369.                 hit_y = int(display_height-ground_height)
  370.                 #explosion(hit_x,hit_y)
  371.                 if ptankx+15 > hit_x > ptankx - 15:
  372.                     print("target acquired!")
  373.                     power_found = True
  374.                 fire = False
  375.  
  376.             check_x_1 = startingShell[0] <= xlocation + barrier_width
  377.             check_x_2 = startingShell[0] >= xlocation
  378.  
  379.             check_y_1 = startingShell[1] <= display_height
  380.             check_y_2 = startingShell[1] >= display_height - randomHeight
  381.  
  382.             if check_x_1 and check_x_2 and check_y_1 and check_y_2:
  383.                 hit_x = int((startingShell[0]))
  384.                 hit_y = int(startingShell[1])
  385.                 #explosion(hit_x,hit_y)
  386.                 fire = False
  387.    
  388.  
  389.    
  390.     fire = True
  391.     startingShell = list(xy)
  392.     print("FIRE!",xy)
  393.  
  394.     while fire:
  395.         for event in pygame.event.get():
  396.             if event.type == pygame.QUIT:
  397.                 pygame.quit()
  398.                 quit()
  399.  
  400.         #print(startingShell[0],startingShell[1])
  401.         pygame.draw.circle(gameDisplay, red, (startingShell[0],startingShell[1]),5)
  402.  
  403.  
  404.         startingShell[0] += (12 - turPos)*2
  405.  
  406.  
  407.  
  408.         # y = x**2
  409.  
  410.         gun_power = random.randrange(int(currentPower*0.90), int(currentPower*1.10))
  411.        
  412.         startingShell[1] += int((((startingShell[0]-xy[0])*0.015/(gun_power/50))**2) - (turPos+turPos/(12-turPos)))
  413.  
  414.         if startingShell[1] > display_height-ground_height:
  415.             print("last shell:",startingShell[0],startingShell[1])
  416.             hit_x = int((startingShell[0]*display_height-ground_height)/startingShell[1])
  417.             hit_y = int(display_height-ground_height)
  418.             print("Impact:",hit_x,hit_y)
  419.  
  420.  
  421.             if ptankx + 10 > hit_x > ptankx - 10:
  422.                 print("Critical Hit!")
  423.                 damage = 25
  424.             elif ptankx + 15 > hit_x > ptankx - 15:
  425.                 print("Hard Hit!")
  426.                 damage = 18
  427.             elif ptankx + 25 > hit_x > ptankx - 25:
  428.                 print("Medium Hit")
  429.                 damage = 10
  430.             elif ptankx + 35 > hit_x > ptankx - 35:
  431.                 print("Light Hit")
  432.                 damage = 5
  433.  
  434.  
  435.            
  436.             explosion(hit_x,hit_y)
  437.             fire = False
  438.  
  439.         check_x_1 = startingShell[0] <= xlocation + barrier_width
  440.         check_x_2 = startingShell[0] >= xlocation
  441.  
  442.         check_y_1 = startingShell[1] <= display_height
  443.         check_y_2 = startingShell[1] >= display_height - randomHeight
  444.  
  445.         if check_x_1 and check_x_2 and check_y_1 and check_y_2:
  446.             print("Last shell:",startingShell[0], startingShell[1])
  447.             hit_x = int((startingShell[0]))
  448.             hit_y = int(startingShell[1])
  449.             print("Impact:", hit_x,hit_y)
  450.             explosion(hit_x,hit_y)
  451.             fire = False
  452.  
  453.        
  454.        
  455.  
  456.         pygame.display.update()
  457.         clock.tick(60)
  458.     return damage
  459.  
  460. def power(level):
  461.     text = smallfont.render("Power: "+str(level)+"%",True, black)
  462.     gameDisplay.blit(text, [display_width/2,0])
  463.  
  464.  
  465.  
  466. def game_intro():
  467.  
  468.     intro = True
  469.  
  470.     while intro:
  471.         for event in pygame.event.get():
  472.                 #print(event)
  473.                 if event.type == pygame.QUIT:
  474.                     pygame.quit()
  475.                     quit()
  476.  
  477.                 if event.type == pygame.KEYDOWN:
  478.                     if event.key == pygame.K_c:
  479.                         intro = False
  480.                     elif event.key == pygame.K_q:
  481.                        
  482.                         pygame.quit()
  483.                         quit()
  484.  
  485.         gameDisplay.fill(white)
  486.         message_to_screen("Welcome to Tanks!",green,-100,size="large")
  487.         message_to_screen("The objective is to shoot and destroy",black,-30)
  488.         message_to_screen("the enemy tank before they destroy you.",black,10)
  489.         message_to_screen("The more enemies you destroy, the harder they get.",black,50)
  490.         #message_to_screen("Press C to play, P to pause or Q to quit",black,180)
  491.  
  492.  
  493.         button("play", 150,500,100,50, green, light_green, action="play")
  494.         button("controls", 350,500,100,50, yellow, light_yellow, action="controls")
  495.         button("quit", 550,500,100,50, red, light_red, action ="quit")
  496.  
  497.  
  498.  
  499.         pygame.display.update()
  500.  
  501.         clock.tick(15)
  502.  
  503. def game_over():
  504.  
  505.     game_over = True
  506.  
  507.     while game_over:
  508.         for event in pygame.event.get():
  509.                 #print(event)
  510.                 if event.type == pygame.QUIT:
  511.                     pygame.quit()
  512.                     quit()
  513.  
  514.         gameDisplay.fill(white)
  515.         message_to_screen("Game Over",green,-100,size="large")
  516.         message_to_screen("You died.",black,-30)
  517.  
  518.  
  519.  
  520.         button("play Again", 150,500,150,50, green, light_green, action="play")
  521.         button("controls", 350,500,100,50, yellow, light_yellow, action="controls")
  522.         button("quit", 550,500,100,50, red, light_red, action ="quit")
  523.  
  524.  
  525.         pygame.display.update()
  526.  
  527.         clock.tick(15)
  528.  
  529. def you_win():
  530.  
  531.     win = True
  532.  
  533.     while win:
  534.         for event in pygame.event.get():
  535.                 #print(event)
  536.                 if event.type == pygame.QUIT:
  537.                     pygame.quit()
  538.                     quit()
  539.  
  540.         gameDisplay.fill(white)
  541.         message_to_screen("You won!",green,-100,size="large")
  542.         message_to_screen("Congratulations!",black,-30)
  543.  
  544.  
  545.  
  546.         button("play Again", 150,500,150,50, green, light_green, action="play")
  547.         button("controls", 350,500,100,50, yellow, light_yellow, action="controls")
  548.         button("quit", 550,500,100,50, red, light_red, action ="quit")
  549.  
  550.  
  551.         pygame.display.update()
  552.  
  553.         clock.tick(15)
  554.  
  555.  
  556. def health_bars(player_health, enemy_health):
  557.  
  558.     if player_health > 75:
  559.         player_health_color = green
  560.     elif player_health > 50:
  561.         player_health_color = yellow
  562.     else:
  563.         player_health_color = red
  564.  
  565.     if enemy_health > 75:
  566.         enemy_health_color = green
  567.     elif enemy_health > 50:
  568.         enemy_health_color = yellow
  569.     else:
  570.         enemy_health_color = red
  571.  
  572.     pygame.draw.rect(gameDisplay, player_health_color, (680, 25, player_health, 25))
  573.     pygame.draw.rect(gameDisplay, enemy_health_color, (20, 25, enemy_health, 25))
  574.  
  575.  
  576.  
  577.  
  578. def gameLoop():
  579.     gameExit = False
  580.     gameOver = False
  581.     FPS = 15
  582.  
  583.     player_health = 100
  584.     enemy_health = 100
  585.  
  586.     barrier_width = 50
  587.  
  588.     mainTankX = display_width * 0.9
  589.     mainTankY = display_height * 0.9
  590.     tankMove = 0
  591.     currentTurPos = 0
  592.     changeTur = 0
  593.  
  594.     enemyTankX = display_width * 0.1
  595.     enemyTankY = display_height * 0.9
  596.  
  597.  
  598.    
  599.  
  600.     fire_power = 50
  601.     power_change = 0
  602.  
  603.     xlocation = (display_width/2) + random.randint(-0.2*display_width, 0.2*display_width)
  604.     randomHeight = random.randrange(display_height*0.1,display_height*0.6)
  605.  
  606.    
  607.     while not gameExit:
  608.        
  609.        
  610.         if gameOver == True:
  611.             #gameDisplay.fill(white)
  612.             message_to_screen("Game Over",red,-50,size="large")
  613.             message_to_screen("Press C to play again or Q to exit",black,50)
  614.             pygame.display.update()
  615.             while gameOver == True:
  616.                 for event in pygame.event.get():
  617.                     if event.type == pygame.QUIT:
  618.                         gameExit = True
  619.                         gameOver = False
  620.  
  621.                     if event.type == pygame.KEYDOWN:
  622.                         if event.key == pygame.K_c:
  623.                             gameLoop()
  624.                         elif event.key == pygame.K_q:
  625.                            
  626.                             gameExit = True
  627.                             gameOver = False
  628.          
  629.  
  630.  
  631.         for event in pygame.event.get():
  632.  
  633.             if event.type == pygame.QUIT:
  634.                 gameExit = True
  635.  
  636.             if event.type == pygame.KEYDOWN:
  637.                 if event.key == pygame.K_LEFT:
  638.                     tankMove = -5
  639.                    
  640.                 elif event.key == pygame.K_RIGHT:
  641.                     tankMove = 5
  642.                    
  643.                 elif event.key == pygame.K_UP:
  644.                     changeTur = 1
  645.                    
  646.                 elif event.key == pygame.K_DOWN:
  647.                     changeTur = -1
  648.  
  649.                 elif event.key == pygame.K_p:
  650.                     pause()
  651.  
  652.                 elif event.key == pygame.K_SPACE:
  653.                     damage = fireShell(gun,mainTankX,mainTankY,currentTurPos,fire_power,xlocation,barrier_width,randomHeight,enemyTankX,enemyTankY)
  654.                     enemy_health -= damage
  655.                     damage = e_fireShell(enemy_gun,enemyTankX,enemyTankY,8,50,xlocation,barrier_width,randomHeight,mainTankX,mainTankY)
  656.                     player_health -= damage
  657.                    
  658.                 elif event.key == pygame.K_a:
  659.                     power_change = -1
  660.                 elif event.key == pygame.K_d:
  661.                     power_change = 1
  662.  
  663.             elif event.type == pygame.KEYUP:
  664.                 if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
  665.                     tankMove = 0
  666.  
  667.                 if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
  668.                     changeTur = 0
  669.                    
  670.                 if event.key == pygame.K_a or event.key == pygame.K_d:
  671.                     power_change = 0
  672.                
  673.  
  674.  
  675.                    
  676.        
  677.         mainTankX += tankMove
  678.  
  679.         currentTurPos += changeTur
  680.  
  681.         if currentTurPos > 8:
  682.             currentTurPos = 8
  683.         elif currentTurPos < 0:
  684.             currentTurPos = 0
  685.  
  686.  
  687.         if mainTankX - (tankWidth/2) < xlocation+barrier_width:
  688.             mainTankX += 5
  689.            
  690.  
  691.         gameDisplay.fill(white)
  692.         health_bars(player_health,enemy_health)
  693.         gun = tank(mainTankX,mainTankY,currentTurPos)
  694.         enemy_gun = enemy_tank(enemyTankX, enemyTankY, 8)
  695.         fire_power += power_change
  696.  
  697.         power(fire_power)
  698.  
  699.         barrier(xlocation,randomHeight,barrier_width)
  700.         gameDisplay.fill(green, rect=[0, display_height-ground_height, display_width, ground_height])
  701.         pygame.display.update()
  702.  
  703.         if player_health < 1:
  704.             game_over()
  705.         elif enemy_health < 1:
  706.             you_win()
  707.         clock.tick(FPS)
  708.  
  709.     pygame.quit()
  710.     quit()
  711.  
  712. game_intro()
  713. gameLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement