예제 #1
0
 def __init__(self):  #Créer le constructeur de la classe
     self.is_playing = False  #Dire que le jeu n'as pas commencé
     self.end_game = False  #Signaler que le jeu n'est pas terminé
     self.all_players = pygame.sprite.Group()  #Créer le groupe du joueur
     self.player = Player(self)  #Ajouter le joueur au jeu
     self.all_players.add(self.player)  #Ajouter le joueur au groupe
     self.all_monsters = pygame.sprite.Group(
     )  #Créer le groupe des monstres
     self.pressed = {
     }  #Définir le dictionnaire pour savoir si des touches sont pressées
     self.comet_event = CometFallEvent(self)  #Stocker la classe des comètes
     self.score = 0  #Définir la score initial
     self.font = pygame.font.Font("assets/Righteous-Regular.ttf",
                                  25)  # Créer la police du texte du score
     self.sound_manager = SoundManager()  #Stocker la classe des sons
     self.all_boss = pygame.sprite.Group()  # Créer le groupe du monstre
     self.boss = Boss(self)  # Stocker la classe du boss
     self.projectile = True
     self.event = 1
     self.paused = False
     self.end_text = self.font.render(
         "Congratulations ! You have completed the game !!!", 1,
         (0, 0, 0))  # Créer le texte des vies globales
     self.general_data = {}
     self.infinite = False
     self.recovback()
예제 #2
0
 def __init__(self):
     self.is_playing = True
     self.all_players = pygame.sprite.Group()
     self.player = Player(self)
     self.all_players.add(self.player)
     self.comet_event = CometFallEvent()
     self.all_monsters = pygame.sprite.Group()
     self.pressed = {}
예제 #3
0
class Game:
    def __init__(self):
        self.is_playing = False
        self.all_players = pygame.sprite.Group()
        self.son = pygame.mixer.Sound("assets/sounds/game_over.ogg")
        self.player = player(self)
        self.all_players.add(self.player)
        self.commet_event = CometFallEvent(self)
        self.all_monstres = pygame.sprite.Group()
        self.pressed = {}

    def start(self):
        self.is_playing = True
        self.spawn_monstre(Mummy)
        self.spawn_monstre(Mummy)
        self.spawn_monstre(Alien)

    def game_over(self):
        self.all_monstres = pygame.sprite.Group()
        self.commet_event.all_comet = pygame.sprite.Group()
        self.player.vie = self.player.max_vie
        self.commet_event.reset_percent()
        self.son.play()
        self.is_playing = False

    def update(self, screen):
        screen.blit(self.player.image, self.player.rect)
        self.player.char_bar_vie(screen)
        self.commet_event.update_bar(screen)
        self.player.update_animation()

        for projectile in self.player.all_projectiles:
            projectile.move()
        for monstre in self.all_monstres:
            monstre.forward()
            monstre.char_bar_vie(screen)
            monstre.update_animation()

            self.player.all_projectiles.draw(screen)  # charger le joueur

        for comet in self.commet_event.all_comet:
            comet.fall()

        self.all_monstres.draw(screen)
        self.commet_event.all_comet.draw(screen)
        # VERIVIER LE DEPLACEMENT
        if self.pressed.get(pygame.K_RIGHT) and self.player.rect.x < 1200:
            self.player.deplacement_droite()
        if self.pressed.get(pygame.K_LEFT) and self.player.rect.x > 0:
            self.player.deplacement_gauche()

    def check_collision(self, sprite, group):
        return pygame.sprite.spritecollide(sprite, group, False,
                                           pygame.sprite.collide_mask)

    def spawn_monstre(self, monster_class_name):

        self.all_monstres.add(monster_class_name.__call__(self))
예제 #4
0
class Game:

	def __init__(self):
		self.all_players = pygame.sprite.Group()
		self.all_monsters = pygame.sprite.Group()
		self.player = Player(self)		
		self.all_players.add(self.player)
		self.comet_event = CometFallEvent(self)
		self.pressed = {}
		self.is_playing = False
				
	def game_over(self):
		
		mixer.Sound(os.path.join('assets', 'sounds', 'game_over.ogg')).play()

		self.all_monsters = pygame.sprite.Group()
		self.comet_event.all_comets = pygame.sprite.Group()

		self.player.health = self.player.max_health
		self.is_playing = False

	def update(self, screen):
		screen.blit(self.player.image, self.player.rect)

		self.player.update_health_bar(screen)

		#atualiza a barra de eventos
		self.comet_event.update_bar(screen)

		for projectile in self.player.all_projectiles:
			projectile.move()

		for monter in self.all_monsters:
			monter.forward()
			monter.update_health_bar(screen)

		for comet in self.comet_event.all_comets:
			comet.fall()
					
		self.player.all_projectiles.draw(screen)
		self.all_monsters.draw(screen)
		self.comet_event.all_comets.draw(screen)

		if self.pressed.get(pygame.K_RIGHT) and self.player.rect.x + self.player.rect.width < screen.get_width():
			self.player.move_right()
		
		elif self.pressed.get(pygame.K_LEFT) and self.player.rect.x > 0:
			self.player.move_left()


	def check_collision(self, sprit, group):
		# 3o param checks if the entity dies with the collision 
		return pygame.sprite.spritecollide(sprit, group, False, pygame.sprite.collide_mask)

	def generate_monster(self, x=5):

		for i in range(x):
			self.all_monsters.add(Monster(self))
예제 #5
0
 def __init__(self):
     self.is_playing = False
     self.all_players = pygame.sprite.Group()
     self.son = pygame.mixer.Sound("assets/sounds/game_over.ogg")
     self.player = player(self)
     self.all_players.add(self.player)
     self.commet_event = CometFallEvent(self)
     self.all_monstres = pygame.sprite.Group()
     self.pressed = {}
예제 #6
0
 def __init__(self):
     self.is_playing = False
     self.all_players = pygame.sprite.Group()
     self.player = Player(self)
     self.all_players.add(self.player)
     self.comet_event = CometFallEvent(self)
     self.all_monsters = pygame.sprite.Group()
     self.font_text = pygame.font.Font("assets/DancingScript-Bold.ttf", 80)
     self.score = 0
     self.sound_manager = SoundManager()
     self.pressed = {}
예제 #7
0
 def __init__(self):
     self.is_playing = False
     self.all_players = pygame.sprite.Group()
     self.player = Player(self)
     self.all_players.add(self.player)
     #comet initialization
     self.comet_event = CometFallEvent(self)
     #monster groups
     self.all_monsters = pygame.sprite.Group()
     self.pressed = {}
     self.spawn_monster()
예제 #8
0
 def __init__(self):
     #definir si notre jeu a commené ou non
     self.is_playing = 0 #0 = menu accueil / 1 = jeu / 2 = ecran game over
     #generer joueur
     self.player = Player(self)
     self.all_players = pygame.sprite.Group()
     self.all_players.add(self.player)
     #generer event
     self.comet_event = CometFallEvent(self)
     self.all_monsters = pygame.sprite.Group()
     self.pressed = {}
예제 #9
0
 def __init__(self):
     # Définir si le jeu à commencer ou non
     self.is_playing = False
     # Charger un joueur
     self.all_players = pygame.sprite.Group()
     self.player = Player(self)
     self.all_players.add(self.player)
     # générer l'evenement de la pluie de comètes
     self.comet_event = CometFallEvent(self)
     # Groupe de monstres
     self.all_monsters = pygame.sprite.Group()
     self.pressed = {}
예제 #10
0
 def __init__(self):
     #definir si notre jeu a commencer ou pas
     self.is_playing = False
     #generer notre joueur
     self.all_players = pygame.sprite.Group()
     self.player = Player(self)
     self.all_players.add(self.player)
     #groupe de monstre
     self.all_monsters = pygame.sprite.Group()
     self.pressed = {}
     #geenerer l'evenement
     self.comet_event = CometFallEvent(self)
예제 #11
0
파일: game.py 프로젝트: iness18/pythonGame
 def __init__(self):
     # definir si le jeu a commence ou non
     self.is_playing = False
     self.player = Player(self)  # Generer joueur
     self.all_player = pygame.sprite.Group()
     self.all_player.add(self.player)
     self.all_monster = pygame.sprite.Group()  # groupe de monstre
     self.sound_manager = SoundManager()
     self.comet_event = CometFallEvent(self)
     self.font = pygame.font.Font("./assets/PottaOne.ttf", 20)
     self.score = 0
     self.pressed = {}
예제 #12
0
 def __init__(self):
     # Definir si el jugador a comenzado o no
     self.is_playing = False
     # Generar nuestro juego y crear una instancia de jugador
     self.all_players = pygame.sprite.Group()
     self.player = Player(self)
     self.all_players.add(self.player)
     # generar eventos
     self.comet_event = CometFallEvent(self)
     # Grupo de monstruos
     self.all_monsters = pygame.sprite.Group()
     self.pressed = {}
예제 #13
0
    def __init__(self):
        # define when the game starts
        self.is_playing = False
        #add a player in the game
        self.all_players = pygame.sprite.Group()
        self.player = Player(self)
        self.all_players.add(self.player)
        # generate the event
        self.comet_event = CometFallEvent()

        # create a group of monster
        self.all_monsters = pygame.sprite.Group()
        self.pressed = {}
예제 #14
0
 def __init__(self):
     self.is_playing = False
     self.all_players = pygame.sprite.Group()
     self.player = Player(self)
     self.all_players.add(self.player)
     self.all_monsters = pygame.sprite.Group()
     #gerer le son
     self.sound_manager = SoundManager()
     #mettre le score a 0
     self.font = pygame.font.Font("assets/my_custom_font.ttf", 25)
     self.score = 0
     self.pressed = {}
     self.comet_event = CometFallEvent(self)
예제 #15
0
 def __init__(self):
     # check if game has started
     self.is_playing = False
     # check if game_over banner must be loaded
     self.restart = False
     # generate Player
     self.all_players = pygame.sprite.Group()
     self.player = Player(self)
     self.all_players.add(self.player)
     # generer comete
     self.comet_event = CometFallEvent(self)
     # create monster group
     self.all_monsters = pygame.sprite.Group()
     self.pressed = {}
예제 #16
0
    def __init__(self):
        #check if the game is started or not
        self.is_playing = False
        #generer notre joueur
        self.player = Player(self)
        self.all_players = pygame.sprite.Group()

        self.comet_event = CometFallEvent()
        # on gere notre groupe de monstres
        self.all_players.add(self.player)
        #groupe de monstre
        self.all_monsters = pygame.sprite.Group
        self.all_monsters = pygame.sprite.Group()
        self.pressed = {}
예제 #17
0
파일: games.py 프로젝트: sebvtl728/jeux
    def __init__(self):
        # définir si le jeu a commancé
        self.is_playing = False

        # generer le joueur
        self.all_players = pygame.sprite.Group()
        self.player = Player(self)
        self.all_players.add(self.player)

        #generer l'attaque des comets
        self.comet_event = CometFallEvent(self)

        #groupe de monstre
        self.all_monsters = pygame.sprite.Group()
        self.pressed = {}
예제 #18
0
 def __init__(self):
     # definir si le jeu a commencer ou non
     self.is_playing = False
     self.all_players = pygame.sprite.Group()
     # generer notre joueur
     self.player = Player(self)
     self.all_players.add(self.player)
     # generer l'evenement
     self.comet_event = CometFallEvent(self)
     # definir un groupe de monsters
     self.all_monsters = pygame.sprite.Group()
     # gerer le son
     self.sound_manager = SoundManager()
     # mettre le score à zero
     self.score = 0
     self.pressed = {}
예제 #19
0
 def __init__(self):
     # Generer joueur
     self.all_players = pygame.sprite.Group()
     self.player = Player(self)
     self.all_players.add(self.player)
     # Groupe de Monstres
     self.all_monsters = pygame.sprite.Group()
     # Jeu a commencé ou non ?
     self.isPlaying = False
     # Comet
     self.comet_event = CometFallEvent(self)
     # Gérer le son
     self.soundManager = SoundManager()
     # Mettre score à 0
     self.score = 0
     self.pressed = {}
     self.font = pygame.font.Font("assets/PottaOne-Regular.ttf", 25)
예제 #20
0
 def __init__(self):
     # definir si le jeu est lancé ou non
     self.is_playing = False
     # generer le joueur lors de la creation du'une nouvelle partie
     self.all_players = pygame.sprite.Group()
     self.player = Player(self)
     self.all_players.add(self.player)
     # generer l'evenement
     self.CometFallEvent = CometFallEvent(self)
     # groupe de monster
     self.all_monsters = pygame.sprite.Group()
     self.font = pygame.font.Font("assets/mycustomfont.ttf", 25)
     # gerer le son
     self.sound_manager = SoundManager()
     # mettre le score à 0
     self.score = 0
     self.pressed = {}
예제 #21
0
 def __init__(self):
     # Definir si notre jeu à commencé ou non
     self.is_playing = False
     # Generer notre joueur
     self.all_players = pygame.sprite.Group()
     self.player = Player(self)
     self.all_players.add(self.player)
     # Générer l'évenement
     self.comet_event = CometFallEvent(self)
     # Creez un groupe de monstre
     self.all_monsters = pygame.sprite.Group()
     # gerer le son
     self.sound_manager = SoundManager()
     self.font = pygame.font.Font("assets/my_custom_font.ttf", 25)
     #mettre le score à 0
     self.score = 0
     self.pressed = {}
예제 #22
0
파일: game.py 프로젝트: jjpro201/JJPRO_GAME
 def __init__(self):
     #definir le commencement du jeu
     self.is_playing = False
     #generate player
     self.all_players = pygame.sprite.Group()
     self.player = Player(self)
     self.all_players.add(self.player)
     #generer l'evenement
     self.comet_event = CometFallEvent(self)
     #groupe monstres
     self.all_monsters = pygame.sprite.Group()
     #gestion du son
     self.sound_manager = SoundManager()
     #METTRE score a zero
     self.font = pygame.font.Font("assets/font.ttf", 25)
     self.score = 0
     self.pressed = {}
예제 #23
0
 def __init__(self):
     self.is_playing = False
     # Génération de notre joueur
     self.all_player = pygame.sprite.Group()
     self.player = Player(self)
     self.all_player.add(self.player)
     # Générer l'évènement
     self.comet_event = CometFallEvent(self)
     # groupe de monstres
     self.all_monster = pygame.sprite.Group()
     self.pressed = {}
     # Mettre le score a 0
     self.score = 0
     self.font = pygame.font.SysFont("monospace", 16, True)
     # fself.ont = pygame.font.Font("assets/my_custom_font.ttf", 25)
     # Gestion des effets sonores
     self.sound_manager = SoundManager()
예제 #24
0
 def __init__(self):
     # definir si notre jeu a commencé ou non
     self.is_playing = False
     # generer notre joueur
     self.all_players = pygame.sprite.Group()
     self.player = Player(self)
     self.all_players.add(self.player)
     # generer l'evenement
     self.comet_event = CometFallEvent(self)
     # groupe de monstres
     self.all_monsters = pygame.sprite.Group()
     # gerer le son
     self.sound_manager = SoundManager()
     # mettre le score à 0
     self.font = pygame.font.Font("assets/HanaleiFill-Regular.ttf", 25)
     self.score = 0
     self.pressed = {}
예제 #25
0
    def __init__(self):
        #definir si le jeu a commencé
        self.is_playing = False
        #générer le joueur
        self.all_players = pygame.sprite.Group()
        self.player = Player(self)
        self.all_players.add(self.player)

        #APPEL MESSAGERIE
        self.message = Message(self)

        #gérer l'event
        self.comet_event = CometFallEvent(self)
        #groupe de monstre
        self.all_monsters = pygame.sprite.Group()
        self.score = 0
        self.pressed = {}
        self.font = pygame.font.Font("assets/font.ttf", 25)
        self.sound_manager = SoundManager()
예제 #26
0
    def __init__(self, screen_width, screen_height):
        #le jeu a commencé T/F
        self.is_playing = False
        #taille de l'ecran de jeu
        self.screen_width = screen_width
        self.screen_height = screen_height
        #groupe de monstre
        self.all_monsters = pygame.sprite.Group()
        #générer l'evenement
        self.comet_event = CometFallEvent(self)
        #touche pressee
        self.pressed = {}
        #score à 0
        self.score = 0

        #afficher le score sur l'écran
        self.font = pygame.font.Font("assets/myfont.ttf", 30)

        #gerer le son
        self.sound_manager = SoundManager()
예제 #27
0
    def __init__(self):
        # Generer le jouer
        self.all_players = pygame.sprite.Group()
        self.player = Player(self)
        self.all_players.add(self.player)

        # Definir si le jeu a commence
        self.is_playing = False

        # groupe de monstre
        self.all_monsters = pygame.sprite.Group()
        self.pressed = {}

        # generer l'evenement comet
        self.comet_event = CometFallEvent(self)

        # mettre le score a zero
        self.font = pygame.font.SysFont('monospace', 25, True)
        self.score = 0

        # gerer le son
        self.sound_manager = SoundManager()
예제 #28
0
class Game:
    def __init__(self):
        #definir si notre jeu a commené ou non
        self.is_playing = 0 #0 = menu accueil / 1 = jeu / 2 = ecran game over
        #generer joueur
        self.player = Player(self)
        self.all_players = pygame.sprite.Group()
        self.all_players.add(self.player)
        #generer event
        self.comet_event = CometFallEvent(self)
        self.all_monsters = pygame.sprite.Group()
        self.pressed = {}

    def start(self):
        self.is_playing = 1
        self.start_spawn()

    def start_spawn(self):
        self.spawn_monster(Mummy)
        self.spawn_monster(Mummy)
        self.spawn_monster(Alien)

    def update(self, screen):
        #joueur
        screen.blit(self.player.image, self.player.rect)
        #animation joueur
        self.player.animate()
        #actualiser la barre de vie du joueur
        self.player.update_health_bar(screen)
        #actualiser  barre event
        self.comet_event.update_bar(screen)

        #recuperer projectiles joueur
        for projectile in self.player.all_projectiles:
            projectile.move()
        #recuperer monstres
        for monster in self.all_monsters:
            monster.forward()
            monster.update_health_bar(screen)
            #animation monstre
            monster.animate(loop=True)
        #recuperer comettes
        for comet in self.comet_event.all_comets:
            comet.fall()

        #projectile
        self.player.all_projectiles.draw(screen)
        #monstres
        self.all_monsters.draw(screen)
        #comettes
        self.comet_event.all_comets.draw(screen)

        #verifier si le joueur Gauche ou Droite
        if self.pressed.get(pygame.K_RIGHT) and self.player.rect.x + self.player.rect.width < screen.get_width():
            self.player.move_right()
        elif self.pressed.get(pygame.K_LEFT) and self.player.rect.x > 0:
            self.player.move_left()

    def check_collision(self, sprite, group):
        return pygame.sprite.spritecollide(sprite, group, False, pygame.sprite.collide_mask)

    def spawn_monster(self, monster_class_name):
        #ajouter un monstre
        self.all_monsters.add(monster_class_name.__call__(self))
    
    def game_over(self):
        #remetre le jeu a neuf, monters delete, joueur 100 vie, jeu en attente
        self.all_monsters = pygame.sprite.Group()
        self.player.health = self.player.max_health
        self.is_playing = 2
        self.comet_event.all_comets = pygame.sprite.Group()
        self.comet_event.reset_percent()
예제 #29
0
class Game:  #Créer la classe du jeu
    """Définir les attributs du jeu"""
    def __init__(self):  #Créer le constructeur de la classe
        self.is_playing = False  #Dire que le jeu n'as pas commencé
        self.end_game = False  #Signaler que le jeu n'est pas terminé
        self.all_players = pygame.sprite.Group()  #Créer le groupe du joueur
        self.player = Player(self)  #Ajouter le joueur au jeu
        self.all_players.add(self.player)  #Ajouter le joueur au groupe
        self.all_monsters = pygame.sprite.Group(
        )  #Créer le groupe des monstres
        self.pressed = {
        }  #Définir le dictionnaire pour savoir si des touches sont pressées
        self.comet_event = CometFallEvent(self)  #Stocker la classe des comètes
        self.score = 0  #Définir la score initial
        self.font = pygame.font.Font("assets/Righteous-Regular.ttf",
                                     25)  # Créer la police du texte du score
        self.sound_manager = SoundManager()  #Stocker la classe des sons
        self.all_boss = pygame.sprite.Group()  # Créer le groupe du monstre
        self.boss = Boss(self)  # Stocker la classe du boss
        self.projectile = True
        self.event = 1
        self.paused = False
        self.end_text = self.font.render(
            "Congratulations ! You have completed the game !!!", 1,
            (0, 0, 0))  # Créer le texte des vies globales
        self.general_data = {}
        self.infinite = False
        self.recovback()

    def register(self):
        if self.infinite is False:
            self.general_data["level"] = self.level
            self.general_data["lives"] = self.life
            with open("data.json", "w") as database:
                json.dump(self.general_data, database)

    def pause(self):
        if self.paused is False:
            self.paused = True

        else:
            self.paused = False

    def recovback(self):
        if self.infinite is False:
            database = open("data.json").read()
            data = json.loads(database)
            self.level = data["level"]
            self.life = data["lives"]

    def spawn_boss(self):
        self.all_boss.add(self.boss)  # Ajouter un boss au groupe de boss

    def spawn_monster(
            self,
            monster_name):  #Définir la méthode pour faire spawner les monstres
        """Faire spawner les monstres"""
        self.all_monsters.add(
            monster_name.__call__(self))  #Ajouter des monstres au groupe

    def start(self):  #Méthode pour lancer le jeu
        if self.infinite is False:
            self.is_playing = True  #Lancer le jeu
            """Faire spawner les monstres en fonction du niveau"""
            if self.level == 1:  # Action s'exécutant si on est au niveau 1
                self.spawn_monster(Mummy)

            elif self.level == 2:  # Action s'exécutant si on est au niveau 2
                self.spawn_monster(Mummy)  # Faire apparaître une momie
                self.spawn_monster(Mummy)  # Faire apparaître un momie

            elif self.level == 3:  # Action s'exécutant si on est au niveau 3
                self.spawn_monster(Alien)  # Faire apparaître un alien

            elif self.level == 10:
                self.all_monsters = pygame.sprite.Group()
                self.spawn_boss()

            else:
                self.spawn_monster(Mummy)  # Faire apparaître un momie
                self.spawn_monster(Mummy)  # Faire apparaître un momie
                self.spawn_monster(Alien)  # Faire apparaître un alien

        else:
            self.is_playing = True
            self.spawn_monster(Mummy)  # Faire apparaître un momie
            self.spawn_monster(Mummy)  # Faire apparaître un momie
            self.spawn_monster(Alien)  # Faire apparaître un alien

    def game_over(self):  # Méthode pour réinitialiser le jeu
        if self.life <= 0:
            self.all_monsters = pygame.sprite.Group(
            )  # Supprimer tous les monstres
            self.player.health = self.player.max_health  # Réinitialiser les vies du joueur
            self.is_playing = False  # Afficher le menu du jeu
            self.comet_event.all_comets = pygame.sprite.Group(
            )  # Supprimer les comètes
            self.comet_event.reset_percent()  # Réinitialiser le pourcentage
            self.score = 0  # Réinitialiser le score
            self.sound_manager.play_sound(
                "game_over")  # Jouer le son du Game Over
            self.life = 3
            self.level = 1

    def block_projectile(self):
        print(self.comet_event.fall_mode)
        if self.boss.rect.x == 800:
            self.projectile = False

        elif self.boss.rect.x == 600:
            self.projectile = True

    def end(self):
        self.end_game = True  # Signaler que le jeu est terminé
        self.all_monsters = pygame.sprite.Group(
        )  # Supprimer tous les monstres
        self.player.health = self.player.max_health  # Réinitialiser les vies du joueur
        self.comet_event.all_comets = pygame.sprite.Group(
        )  # Supprimer les comètes
        self.comet_event.reset_percent()  # Réinitialiser le pourcentage

    def remove_life(self):
        self.life -= 1
        self.player.health = self.player.max_health  # Réinitialiser les vies du joueur
        self.comet_event.all_comets = pygame.sprite.Group(
        )  # Supprimer les comètes
        self.comet_event.reset_percent()  # Réinitialiser le pourcentage
        self.all_monsters = pygame.sprite.Group(
        )  # Supprimer tous les monstres
        self.comet_event.game.start()  # Faire apparaître les monstres
        self.player.rect.x = 400  # Définir l'abcisse du joueur

    def check_collision(self, sprite, group):
        """Vérifier les collisions"""
        return pygame.sprite.spritecollide(
            sprite, group, False,
            pygame.sprite.collide_mask)  #Vérifier les collisions

    def game_over(self):  #Méthode pour réinitialiser le jeu
        self.all_monsters = pygame.sprite.Group()  #Supprimer tous les monstres
        self.player.health = self.player.max_health  #Réinitialiser les vies du joueur
        self.is_playing = False  #Afficher le menu du jeu
        self.comet_event.all_comets = pygame.sprite.Group(
        )  #Supprimer les comètes
        self.comet_event.reset_percent()  #Réinitialiser le pourcentage
        self.score = 0  #Réinitialiser le score
        self.sound_manager.play_sound("game_over")  #Jouer le son du Game Over
        self.level = 1
        self.life = 3

    def add_level(self):
        self.level += 1

    def add_score(
        self, points
    ):  #Définir une méthode pour définir le nombre de points à ajouter au score
        self.score += points  #Ajouter des points au score

    def update(self, screen):  #Mettre à jour le jeu quand il est lancé
        """Afficher le score sur l'écran"""
        self.score_text = self.font.render(
            f"Score: {self.score}", 1, (0, 0, 0))  # Créer le texte du score
        self.level_text = self.font.render(
            f"Level: {self.level}", 1, (0, 0, 0))  # Créer le texte du niveau
        self.life_text = self.font.render(
            f"Lifes: {self.life}", 1,
            (0, 0, 0))  # Créer le texte des vies globales
        """Dessiner les éléments"""
        screen.blit(self.player.image,
                    self.player.rect)  # Afficher le joueur sur la fenêtre
        self.player.all_projectiles.draw(
            screen)  # Dessiner les projectiles sur la fenêtre
        self.all_monsters.draw(screen)  # Afficher les monstres sur la fenêtre
        self.comet_event.all_comets.draw(
            screen)  #Dessiner sur la fenêtre les comètes
        if self.end_game is False:
            screen.blit(self.score_text,
                        (20, 20))  # Dessiner le texte du score
            if self.infinite:
                screen.blit(self.life_text,
                            (20, 60))  # Dessiner le texte des vies globales

            elif self.infinite is False:
                screen.blit(self.level_text,
                            (20, 60))  # Dessiner le texte du niveau
                screen.blit(self.life_text,
                            (20, 100))  # Dessiner le texte des vies globales

        if self.level == 10:
            screen.blit(self.boss.image,
                        self.boss.rect)  # Afficher le joueur sur la fenêtre
        """Actualiser les barres"""
        self.player.updade_health_bar(
            screen)  # Actualiser la barre de vies du joueur
        self.comet_event.update_bar(screen)  #Actualiser la barre des comètes
        self.player.update_animation()  #Mettre à jour l'animation du joueur
        if self.level == 10:
            self.boss.update_health_bar(
                screen)  # Actualiser la barre de vies du joueur
        """Déplacer les éléments"""
        """Déplacer le projectile"""
        for projectile in self.player.all_projectiles:  # Dans Projectile
            projectile.move()  # Faire déplacer les projectile

        for comet in self.comet_event.all_comets:  #Dans les comètes
            comet.fall()  #Faire tomber la pluie de comètes
        """Appeler les évènements d'action du boss"""
        if self.level == 10:
            self.boss.go_and_back()
            self.boss.fly()
            self.block_projectile()
            if self.boss.rect.x == 800:
                self.event += 1
                if (self.event %
                        2) == 0 and self.comet_event.fall_mode is False:
                    self.spawn_monster(Mummy)
        """Récupérer les monstres dans le main"""
        for monster in self.all_monsters:  # Dans Projectile
            monster.forward()  # Faire déplacer les projectile
            monster.updade_health_bar(
                screen)  # Dessiner la barre de vie sur la fenêtre
            monster.update_animation(
            )  #Mettre à jour les animations du monstre
        """Vérifier la direction du joueur"""
        if self.pressed.get(
                pygame.K_RIGHT
        ) and self.player.rect.x + self.player.rect.width < screen.get_width(
        ) and self.paused is False:  # Vérifier
            # que la touche gauche est pressée et que le joueur ne dépasse pas la bordure
            # droite et que le jeu n'est pas en pause
            self.player.move_right(
            )  # Si c'est le cas déplacer le joueur à droite

        elif self.pressed.get(
                pygame.K_LEFT
        ) and self.player.rect.x > 0 and self.paused is False:  # Vérifier que la touche gauche est pressée, que
            #et que le joueur ne dépasse pas la bordure gauche
            self.player.move_left(
            )  # Si c'est le cas déplacer le joueur à gauche

        elif self.pressed.get(pygame.K_m):
            if self.sound_manager.sound:
                self.sound_manager.sound = False

            else:
                self.sound_manager.sound = True
예제 #30
0
class Game:
    def __init__(self):
        # Generer joueur
        self.all_players = pygame.sprite.Group()
        self.player = Player(self)
        self.all_players.add(self.player)
        # Groupe de Monstres
        self.all_monsters = pygame.sprite.Group()
        # Jeu a commencé ou non ?
        self.isPlaying = False
        # Comet
        self.comet_event = CometFallEvent(self)
        # Gérer le son
        self.soundManager = SoundManager()
        # Mettre score à 0
        self.score = 0
        self.pressed = {}
        self.font = pygame.font.Font("assets/PottaOne-Regular.ttf", 25)

    def start(self):
        self.isPlaying = True
        self.spawn_monster(Mummy)
        self.spawn_monster(Mummy)
        self.spawn_monster(Alien)

    def game_over(self):
        # Reinit le jeu
        self.all_monsters = pygame.sprite.Group()
        self.player.health = self.player.max_health
        self.isPlaying = False
        self.comet_event.all_comets = pygame.sprite.Group()
        self.comet_event.reset_percent()
        self.score = 0
        self.soundManager.play('gameOver')

    def update(self, screen):
        # Afficher le score
        #font = pygame.font.SysFont("monospace", 16)
        scoreText = self.font.render(f"Score: {self.score}", 1, (0, 0, 0))
        screen.blit(scoreText, (20, 20))
        # Appliquer l'image du joueur
        screen.blit(self.player.image, self.player.rect)
        # Actualiser la barre de vie du joueur
        self.player.update_health_bar(screen)
        # Actualiser la barre d'événement du jeu
        self.comet_event.update_bar(screen)
        # Actualiser l'animation du joueur
        self.player.update_animation()

        # Recuperer projectile
        for projectile in self.player.all_projectiles:
            projectile.move()

        # Récupérer les Monstres
        for monster in self.all_monsters:
            monster.forward()
            monster.update_health_bar(screen)
            monster.update_animation()

        # Récupérer les comètes
        for comet in self.comet_event.all_comets:
            comet.fall()

        # Dessiner Image projectiles
        self.player.all_projectiles.draw(screen)

        # Dessiner Groupe de monstre
        self.all_monsters.draw(screen)

        # Appliquer les comètes
        self.comet_event.all_comets.draw(screen)

        # Vérifier si à gauche ou à droite
        if self.pressed.get(
                pygame.K_RIGHT
        ) and self.player.rect.x + self.player.rect.width < screen.get_width():
            self.player.move_right()
        elif self.pressed.get(pygame.K_LEFT) and self.player.rect.x > 0:
            self.player.move_left()

    def check_collision(self, sprite, group):
        return pygame.sprite.spritecollide(sprite, group, False,
                                           pygame.sprite.collide_mask)

    def spawn_monster(self, monsterClassName):
        #monster = Mummy(self)
        self.all_monsters.add(monsterClassName.__call__(self))