Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #coding:utf-8
- import pygame
- class Vaisseau():
- '''
- Vaisseaux: Joueur principale
- Poligône bleu 3vies
- '''
- def __init__(self,color, x, y, x1, y1, x2, y2):
- self.color = color
- self.x = x
- self.y = y
- self.x1 = x1
- self.y1 = y1
- self.x2 = x2
- self.y2 = y2
- def draw(self, window):
- #(0, 0, 255)
- pygame.draw.polygon(window,self.color , [(self.x, self.y), (self.x1, self.y1), (self.x2, self.y2)])
- pygame.display.flip()
- '''
- Vies du héros
- '''
- def life(vies):
- vies=3
- class Enemi():
- '''
- Ennemis: Bloc qui endommagent le vaisseau
- Ronds rouges -1vie
- '''
- def __init__(self, x1, y1):
- self.x1 = x1
- self.y1 = y1
- class Missiles():
- '''
- Class qui crée le missile lancé par le vaisseau
- le missile est vert et rectangulaire
- '''
- def __init__(self, color, Xmissile, Ymissile):
- self.color = color
- self.Xm = Xmissile
- self.Ym = Ymissile
- def draw(self, window):
- pygame.draw.rect(window,self.color , (self.Xm,self.Ym , 5, 10))
- pygame.display.update()
- def main():
- pygame.init()
- window = pygame.display.set_mode((750, 750))
- pygame.display.set_caption("Space Invader")
- x = 350
- y = 700
- x1 = 375
- y1 = 670
- x2 = 400
- y2 = 700
- vel = 25
- Ymis = y1
- vel_mis = 20
- game_launched = True
- while game_launched:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- game_launched = False
- vaisseau = Vaisseau((0, 0, 255), x, y, x1, y1 , x2, y2)
- vaisseau.draw(window)
- missile = Missiles((0,255,0), x1 , y1)
- missile.draw(window)
- keys = pygame.key.get_pressed()
- if keys[pygame.K_LEFT] and x > 0 and x2 > 0 and x1 > 0 :
- x -= vel
- x1 -= vel
- x2 -= vel
- window.fill((0, 0, 0))
- vaisseau = Vaisseau((0, 0, 255), x, y, x1, y1 , x2, y2)
- vaisseau.draw(window)
- pygame.display.update()
- if keys[pygame.K_RIGHT] and x < 750 and x2 <750 and x1 < 750:
- x += vel
- x1 += vel
- x2 += vel
- window.fill((0, 0, 0))
- vaisseau = Vaisseau((0, 0, 255), x, y, x1, y1 , x2, y2)
- vaisseau.draw(window)
- pygame.display.update()
- if keys[pygame.K_SPACE]:
- while Ymis > 0:
- Ymis -= vel_mis
- window.fill((0,0,0))
- missile = Missiles((0,255,0), x1 , Ymis)
- missile.draw(window)
- continue
- pygame.display.update()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement