Advertisement
Guest User

Space invaders

a guest
May 19th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.91 KB | None | 0 0
  1. #coding:utf-8
  2. import pygame
  3.  
  4. class Vaisseau():
  5.     '''
  6.    Vaisseaux: Joueur principale
  7.    Poligône bleu 3vies
  8.    '''
  9.     def __init__(self,color, x, y, x1, y1, x2, y2):
  10.         self.color = color
  11.         self.x = x
  12.         self.y = y
  13.         self.x1 = x1
  14.         self.y1 = y1
  15.         self.x2 = x2
  16.         self.y2 = y2
  17.     def draw(self, window):
  18.         #(0, 0, 255)
  19.        pygame.draw.polygon(window,self.color , [(self.x, self.y), (self.x1, self.y1), (self.x2, self.y2)])
  20.         pygame.display.flip()
  21.  
  22.         '''
  23.        Vies du héros
  24.        '''
  25.         def life(vies):
  26.             vies=3  
  27.  
  28. class Enemi():
  29.     '''
  30.    Ennemis: Bloc qui endommagent le vaisseau
  31.    Ronds rouges -1vie
  32.    '''
  33.     def __init__(self, x1, y1):
  34.         self.x1 = x1
  35.         self.y1 = y1
  36.  
  37.  
  38. class Missiles():
  39.     '''
  40.    Class qui crée le missile lancé par le vaisseau
  41.    le missile est vert et rectangulaire
  42.    '''
  43.     def __init__(self, color, Xmissile, Ymissile):
  44.         self.color = color
  45.         self.Xm = Xmissile
  46.         self.Ym = Ymissile
  47.     def draw(self, window):
  48.  
  49.         pygame.draw.rect(window,self.color , (self.Xm,self.Ym , 5, 10))
  50.         pygame.display.update()
  51.  
  52.  
  53. def main():
  54.    
  55.     pygame.init()
  56.  
  57.     window = pygame.display.set_mode((750, 750))
  58.     pygame.display.set_caption("Space Invader")
  59.      
  60.     x = 350
  61.     y = 700
  62.     x1 = 375
  63.     y1 = 670
  64.     x2 = 400
  65.     y2 = 700
  66.     vel = 25
  67.     Ymis = y1
  68.     vel_mis = 20
  69.  
  70.  
  71.  
  72.     game_launched = True
  73.  
  74.     while game_launched:
  75.    
  76.         for event in pygame.event.get():
  77.             if event.type == pygame.QUIT:
  78.                 game_launched = False  
  79.  
  80.  
  81.         vaisseau = Vaisseau((0, 0, 255), x, y, x1, y1 , x2, y2)
  82.         vaisseau.draw(window)
  83.        
  84.         missile = Missiles((0,255,0), x1 , y1)
  85.         missile.draw(window)
  86.        
  87.         keys = pygame.key.get_pressed()
  88.         if keys[pygame.K_LEFT] and x > 0 and x2 > 0 and x1 > 0 :
  89.             x -= vel
  90.             x1 -= vel
  91.             x2 -= vel
  92.             window.fill((0, 0, 0))
  93.  
  94.             vaisseau = Vaisseau((0, 0, 255), x, y, x1, y1 , x2, y2)
  95.             vaisseau.draw(window)
  96.  
  97.             pygame.display.update()
  98.  
  99.         if keys[pygame.K_RIGHT] and x < 750 and x2 <750 and x1 < 750:
  100.             x += vel
  101.             x1 += vel
  102.             x2 += vel
  103.             window.fill((0, 0, 0))
  104.  
  105.             vaisseau = Vaisseau((0, 0, 255), x, y, x1, y1 , x2, y2)
  106.             vaisseau.draw(window)
  107.  
  108.             pygame.display.update()
  109.        
  110.         if keys[pygame.K_SPACE]:  
  111.             while Ymis > 0:
  112.                
  113.                 Ymis -= vel_mis
  114.                
  115.                 window.fill((0,0,0))
  116.              
  117.                 missile = Missiles((0,255,0), x1 , Ymis)
  118.                 missile.draw(window)
  119.                
  120.                 continue
  121.                 pygame.display.update()
  122.                
  123.  
  124. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement