示例#1
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))
示例#2
0
class Game:
    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 = {}

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

    def add_score(self, score=10):
        self.score += score

    def game_over(self):
        # remettre le jeu à neuf
        # retirer le monstre
        self.all_monsters = pygame.sprite.Group()
        self.comet_event.all_comets = pygame.sprite.Group()
        self.player.health = self.player.max_health
        self.comet_event.reset_percent()
        self.is_playing = False
        self.score = 0
        # joueur le son
        self.sound_manager.play('game_over')

    def update(self, surface):
        # afficher le score sur l'ecran
        font = pygame.font.SysFont("monospace", 16, bold=True)
        score_text = font.render(
            f"Score : {self.score}",
            1,
            (0, 0, 0),
        )
        surface.blit(score_text, (20, 20))
        # appliquer l'image de mon joeur
        surface.blit(self.player.image, self.player.rect)
        # actualiser la barre de vie du joueur
        self.player.update_health_bar(surface)
        # actualiser la barre d'evenment du jeu
        self.comet_event.update_ber(surface)
        # actualiser l'animation du joueur
        self.player.update_animation()
        # recuperer les projectiles que le joueur lance
        for projectile in self.player.all_projectille:
            projectile.move()
        # recuperer les monstres de notre jeu
        for monster in self.all_monsters:
            monster.forward()
            monster.update_health_bar(surface)
            monster.update_animation()

        # recuperer le comet du jeu
        for comet in self.comet_event.all_comets:
            comet.fall()

        # appliquer l'ensemble des image du projectile
        self.player.all_projectille.draw(surface)

        # appliquer l'ensemble des images du groupe monster
        self.all_monsters.draw(surface)

        # appliquer l'ensemble des image du groupe comet
        self.comet_event.all_comets.draw(surface)

        # pour verifier si le joueur souhaite aller à gauche ou à droite
        if self.pressed.get(
                pygame.K_RIGHT
        ) and self.player.rect.x < surface.get_width() - 200:
            self.player.move_rigth()
        elif self.pressed.get(pygame.K_LEFT) and self.player.rect.x > 0:
            self.player.move_left()

    def spawn_monster(self, monster_name):
        self.all_monsters.add(monster_name.__call__(self))

    def check_collision(self, sprite, groupe):
        return pygame.sprite.spritecollide(sprite, groupe, False,
                                           pygame.sprite.collide_mask)
示例#3
0
class Game:
    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)

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

    def add_score(self, points=10):
        self.score += points

    def game_over(self):
        self.all_monsters = pygame.sprite.Group()
        self.comet_event.all_comets = pygame.sprite.Group()
        self.player.health = self.player.max_health
        self.comet_event.reset_percent()
        self.is_playing = False
        self.score = 0
        #jouerle son
        self.sound_manager.play('game_over')

    def update(self, screen):
        #afficher le score sur l ecran
        score_text = self.font.render(f"Score: {self.score}", 1, (0, 0, 0))
        screen.blit(score_text, (20, 20))
        screen.blit(self.player.image, self.player.rect)

        self.player.update_health_bar(screen)

        self.comet_event.update_bar(screen)

        self.player.update_animation()

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

        for monster in self.all_monsters:
            monster.forward()
            monster.update_health_bar(screen)
            monster.update_animation()

        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, sprite, group):
        return pygame.sprite.spritecollide(sprite, group, False,
                                           pygame.sprite.collide_mask)

    def spawn_monster(self, monster_class_name):
        monster = Mummy(self)
        self.all_monsters.add(monster_class_name.__call__(self))
示例#4
0
class Game:
    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 = {}


    def start(self):
        self.is_playing = True
        self.spawn_monster()
        self.spawn_monster()

    def game_over(self):
        # reiniciar el juego, eliminar monstruos, reiniciar el jugador a 100
        # puntos de salud, juego en espera
        self.all_monsters = pygame.sprite.Group()
        self.comet_event.all_comets = pygame.sprite.Group()
        self.player.health = self.player.max_health
        self.comet_event.reset_percent()
        self.is_playing = False


    def update(self, screen):

        # Aplicar mi imagen de jugador
        screen.blit(self.player.image, self.player.rect)

        # actualizar barra de vida del jugador
        self.player.update_health_bar(screen)

        # actualizar la barra de evento del juego
        self.comet_event.update_bar(screen)

        # recuperar proyectiles del jugador
        for projectile in self.player.all_projectiles:
            projectile.move()

        # recuperar los monstruos de nuestro jugador
        for monster in self.all_monsters:
            monster.forward()
            monster.update_health_bar(screen)

        # recuperar los cometas de nuestro jugador
        for comet in self.comet_event.all_comets:
            comet.fall()


        # aplicar todas las imágenes de mi grupo de proyectiles
        self.player.all_projectiles.draw(screen)

        # aplicar todas las imágenes de mi grupo de monstruos
        self.all_monsters.draw(screen)

        # aplicar todas las imagenes de grupo de cometas
        self.comet_event.all_comets.draw(screen)

        # Comprobar si el jugador quiere ir hacia la derecha y dentro del límite
        if self.pressed.get(pygame.K_RIGHT) and (self.player.rect.x +
            self.player.rect.width < screen.get_width()): self.player.move_right()
        # Comprobar si el jugador quiere ir hacia la izquierda y dentro del límite
        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 = Monster(self)
        self.all_monsters.add(monster)
示例#5
0
class Game():
    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 = {}

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

    def spawn_monster(self, monster_name):
        self.all_monster.add(monster_name.__call__(self))

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

    def add_score(self, points=10):
        # ajouter le nbr ptn au score
        self.score += points

    def game_over(self):
        # remettre le jeu a neuf et en attente
        self.all_monster = pygame.sprite.Group()
        self.comet_event.all_comet = pygame.sprite.Group()
        self.comet_event.reset_percent()
        self.player.health = self.player.max_health
        self.is_playing = False
        self.score = 0
        # jouer le son
        self.sound_manager.play("game_over")

    def update(self, screen):
        # afficher le score sur l'ecran
        score_text = self.font.render(f"Score : {self.score}", 1, (0, 0, 0))
        screen.blit(score_text, (20, 20))

        # Afficher l'image du joueur
        screen.blit(self.player.image, self.player.rect)

        # Acualiser la barre de vie du joueur
        self.player.update_health_bar(screen)

        # Actualiser l'animation du joueur
        self.player.update_animation()

        # Actualiser la barre d'event du jeu
        self.comet_event.update_bar(screen)

        # recuperer les projectile du joueur
        for projectile in self.player.all_projectile:
            projectile.move()

        # Recuperer les monstres du jeu
        for monster in self.all_monster:
            monster.forward()
            monster.update_health_bar(screen)
            monster.update_animation()

        # Recuperer les comets de notre jeu
        for comet in self.comet_event.all_comet:
            comet.fall()

        # appliquer les images du groupe projectile
        self.player.all_projectile.draw(screen)

        # appliquer les images du groupe monstre
        self.all_monster.draw(screen)

        # appliquer le groupe des comets
        self.comet_event.all_comet.draw(screen)

        # mouvement du joueur a droite ou gauche
        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()
示例#6
0
class Game:
    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()

    def start(self):
        self.is_playing = True
        self.spawn_monster()

    def game_over(self):
        self.all_monsters = pygame.sprite.Group()
        self.comet_event.all_comets = pygame.sprite.Group()
        self.player.health = self.player.max_health
        self.comet_event.reset_percent()
        self.is_playing = False

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

        #update hp bar of players
        self.player.update_health_bar(screen)

        #update event bar
        self.comet_event.update_bar(screen)

        for fireball in self.player.all_fireball:
            fireball.move()

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

        for comet in self.comet_event.all_comets:
            comet.fall()

        self.player.all_fireball.draw(screen)

        self.all_monsters.draw(screen)

        self.comet_event.all_comets.draw(screen)

        #verify if player wants to go left or right
        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_coll(self, sprite, group):
        return pygame.sprite.spritecollide(sprite, group, False,
                                           pygame.sprite.collide_mask)

    def spawn_monster(self):
        monster = Monster(self)
        self.all_monsters.add(monster)
示例#7
0
文件: games.py 项目: sebvtl728/jeux
class Game:
    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 = {}

    def start(self):
        self.is_playing = True
        self.spawn_monster(Mechant)
        self.spawn_monster(Mechant)
        self.spawn_monster(SuperMechant)

    def game_over(self):
        # reinitialisation du jeu pour une nouvelle partie
        self.all_monsters = pygame.sprite.Group()
        self.comet_event.all_comets = pygame.sprite.Group()
        self.player.health = self.player.max_health
        self.comet_event.reset_percent()
        self.is_playing = False

    def update(self, screen):
        #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'attaque des comets
        self.comet_event.update_bar(screen)

        #actualisation de l'animation du joueur
        self.player.update_animation()

        #recuperation des projectiles du joueur
        for projectile in self.player.all_projectiles:
            projectile.move()

        # recuperation des monstres
        for monster in self.all_monsters:
            monster.forward()
            monster.update_health_bar(screen)
            monster.update_animation()

        #recuperation des commettes
        for comet in self.comet_event.all_comets:
            comet.fall()

        #chargement des projectiles
        self.player.all_projectiles.draw(screen)

        #chargement des monstres
        self.all_monsters.draw(screen)

        #chargement des comettes
        self.comet_event.all_comets.draw(screen)

        # verifier si le joueur souhaite aller de gauche à droite
        # print(game.pressed)
        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()

        #print(self.player.rect.x)

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

    def spawn_monster(self, mechant_class_name):
        self.all_monsters.add(mechant_class_name.__call__(self))
示例#8
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
示例#9
0
class Game:

    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 = {}

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

    def add_score(self, points=10):
        self.score += points

    def game_over(self):
        # remettre le jeu à neuf, retirer les monstres, remettre le joueur a 100 de vie, et mettre le jeu en attente
        self.all_monsters = pygame.sprite.Group()
        self.comet_event.all_comets = pygame.sprite.Group()
        self.player.health = self.player.max_health
        self.comet_event.reset_percent()
        self.is_playing = False
        self.score = 0
        # jouer le son
        self.sound_manager.play('game_over')

    def update(self, screen):
        # afficher le score sur l'écran
        score_text = self.font.render(f"Score : {self.score}", 1, (0, 0, 0))
        screen.blit(score_text, (20, 20))

        # appliquer l'image de mon 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'évenement du jeu
        self.comet_event.update_bar(screen)

        # actualiser l'animation du joueur
        self.player.update_animation()

        # recuperer les projectiles du joueur
        for projectile in self.player.all_projectiles:
            projectile.move()

        # recuperer les monstres de notre jeu
        for monster in self.all_monsters:
            monster.forward()
            monster.update_health_bar(screen)
            monster.update_animation()

        # recuperer les cometes de notre jeu
        for comet in self.comet_event.all_comets:
            comet.fall()

        # appliquer l'ensemble des images de mon groupe de projectiles
        self.player.all_projectiles.draw(screen)

        # appliquer l'ensemble des images de mon groupe de monstres
        self.all_monsters.draw(screen)

        # appliquer l'ensemble des images de mon groupe de cometes
        self.comet_event.all_comets.draw(screen)

        # verifier si le joueur souhaite aller à 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):
        self.all_monsters.add(monster_class_name.__call__(self))
示例#10
0
class Game:

    player: object

    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)


    def start(self):
        self.is_playing = True
        self.spawn_monster()
        self.spawn_monster()


    def game_over(self):
        #remettre le jeu a neuf, retirer les monstre, remettre le joeur a 100 pdv
        self.all_monsters = pygame.sprite.Group()
        self.comet_event.all_comets = pygame.sprite.Group()
        self.player.health = self.player.max_health
        self.comet_event.reset_percent()
        self.is_playing = False




    def update(self, screen):
        # appliquer l'image de mon joueur
        screen.blit(self.player.image, self.player.rect)

        # actualiser la barre de vie du joueur
        self.player.update_health_bar(screen)



        # recuperer les projectiles du joueur
        for projectile in self.player.all_projectiles:
            projectile.move()

        # récupérer les monstres de notre jeu
        for monster in self.all_monsters:
            monster.forward()
            monster.update_health_bar(screen)

        #récupere les comets de notre jeu
        for comet in self.comet_event.all_comets:
            comet.fall()


        #actualiser la barre d'evenement du jeu
        self.comet_event.update_bar(screen)


        # apppliquer l'ensemble des images de mon groupe de projectiles
        self.player.all_projectiles.draw(screen)

        # appliquer l'ensemble des images de mon groupe de monstre
        self.all_monsters.draw(screen)

        #appliquer l'ensemble des images de mon groupe de comete
        self.comet_event.all_comets.draw(screen)

        # verifier si le joueur souhaite aller a gauche ou a 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 = Monster(self)
        self.all_monsters.add(monster)
示例#11
0
class Game:
    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()

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

    def add_score(self, points=10):
        # Ajouter le nombre de point au score
        self.score += 20

    def game_over(self):
        # Remettre le jeu a zéro.
        self.all_monster = pygame.sprite.Group()
        self.comet_event.all_comets = pygame.sprite.Group()
        self.player.health = self.player.max_health
        self.comet_event.reset_percent()
        self.is_playing = False
        self.score = 0
        # jouer le son
        self.sound_manager.play("game_over")

    def update(self, screen):
        # Afficher le score sur l'ecran
        score_text = self.font.render(f"Score: {self.score}", 1, (0, 0, 0))
        screen.blit(score_text, (20, 20))

        # Appliquer l'image du joueur
        screen.blit(self.player.image, self.player.rect)
        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()

        # Recupereer les projectile du joueur
        for projectile in self.player.all_projectiles:
            projectile.move()

        # Recuperer les projectile du joueur
        for monster in self.all_monster:
            monster.forward()
            monster.update_health_bar(screen)
            monster.update_animation()

        # Recuperer les cometes du joueur
        for comet in self.comet_event.all_comets:
            comet.fall()

        # Applique l'image du projectile
        self.player.all_projectiles.draw(screen)

        # Appliquer l'ensemble des images de monstre
        self.all_monster.draw(screen)

        # Appliquer l'ensemble des image du goupe comete
        self.comet_event.all_comets.draw(screen)

        # Verifier si le joueur souhaite aller a gauche ou a 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, sprinte, group):
        return pygame.sprite.spritecollide(sprinte, group, False,
                                           pygame.sprite.collide_mask)

    def spawn_monster(self, monster_class_name):
        monster = Mummy(self)
        self.all_monster.add(monster_class_name.__call__(self))
示例#12
0
class Game:
    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 = {}

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

    def add_score(self, points=20):
        self.score += points

    def game_over(self):
        self.all_monsters = pygame.sprite.Group()
        self.comet_event.all_comets = pygame.sprite.Group()
        self.player.health = self.player.max_health
        self.comet_event.reset_percent()
        self.is_playing = False
        self.score = 0
        self.sound_manager.play("game_over")

    def update(self, screen):

        # font_number = pygame.font.Font("assets/Archivo-Italic.ttf", 80)
        score_text = self.font_text.render(f"Score : {self.score}", 1,
                                           (0, 0, 255))
        # score_number = font_number.render(f"{self.score}", 1, (0, 0, 255))
        screen.blit(score_text, (20, 20))
        # screen.blit(score_number, (230, 20))

        screen.blit(self.player.image, self.player.rect)

        self.player.update_health_bar(screen)

        self.comet_event.update_bar(screen)

        self.player.update_animation()

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

        for monster in self.all_monsters:
            monster.forward()
            monster.update_health_bar(screen)
            monster.update_animation()

        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 spawn_monster(self, monster_class_name):
        self.all_monsters.add(monster_class_name.__call__(self))

    @staticmethod
    def check_collision(sprite, sprite_group):
        return pygame.sprite.spritecollide(sprite, sprite_group, False,
                                           pygame.sprite.collide_mask)
示例#13
0
class 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 = {}

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

    def add_score(self, points):
        self.score += points

    def game_over(self):
        #remettre le jeu a neuf, enlever le monstre, remettre le joueur a 100 de vie, jeu en attente
        self.all_monsters = pygame.sprite.Group()
        self.comet_event.all_comets = pygame.sprite.Group()
        self.player.health = self.player.max_health
        self.comet_event.reset_percent()
        self.is_playing = False
        self.score = 0
        #jouer le son
        self.sound_manager.play('game_over')

    def update(self, screen):
        #afficher le score
        score_text = self.font.render(f"Score : {self.score}", 1, (0, 0, 0))
        screen.blit(score_text, (20, 20))

        # screen image
        screen.blit(self.player.image, self.player.rect)

        # actulisation barre vie joueur
        self.player.update_health_bar(screen)

        #actualiser la barre d'evenement du jeu
        self.comet_event.update_bar(screen)

        #actualiser l'animation du jouer
        self.player.update_anumation()

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

        # recuperer monstres
        for monster in self.all_monsters:
            monster.forward()
            monster.update_health_bar(screen)
            monster.update_animation()

        #recuperer les comettes
        for comet in self.comet_event.all_comets:
            comet.fall()

        # appliquer groupe projectile
        self.player.all_projectiles.draw(screen)

        # appiquer images groupe monstres
        self.all_monsters.draw(screen)

        #appliquer l'ensemble des images de groupe comette
        self.comet_event.all_comets.draw(screen)

        # verifier direction
        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):
        self.all_monsters.add(monster_class_name.__call__(self))
示例#14
0
class Game:
    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()

    def start(self):
        self.is_playing = True
        #self.spawn_monster(BadWorm)
        #self.spawn_monster(BadWorm)
        #self.spawn_monster(Boss)

    def game_over(self):
        #remettre le jeu à neuf, retirer les monstres, remettre le joeueur à 100 vie, jeu en attente
        self.all_monsters = pygame.sprite.Group()
        self.comet_event.all_comets = pygame.sprite.Group()
        self.player.health = self.player.max_health
        self.comet_event.reset_percent()
        self.is_playing = False
        self.score = 0
        self.sound_manager.play('game_over')

    def add_score(self, points=10):
        self.score += points

    def update(self, screen):
        #afficher le score sur l'ecran
        score_text = self.font.render(f"Score: {self.score}", 1, (0, 0, 0))
        screen.blit(score_text, (20, 20))

        #AFFICHAGE MESSAGERIE
        self.message.init_messagerie(screen)

        #appliquer 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'event
        self.comet_event.update_bar(screen)

        #actualiser l'animation du joueur
        self.player.update_animation()

        #recup les projectiles du joueur
        for projectile in self.player.all_projectiles:
            projectile.move()

        #recup les monstres du jeu
        for monster in self.all_monsters:
            monster.forward()
            monster.update_health_bar(screen)
            monster.update_animation()

        #recup les comets
        for comet in self.comet_event.all_comets:
            comet.fall()

        #appliquer les projectiles
        self.player.all_projectiles.draw(screen)

        #appliquer l'ensemble des images de mon groupe de monstre
        self.all_monsters.draw(screen)

        #appliquer l'ensemble des images de mon groupe de comettes
        self.comet_event.all_comets.draw(screen)

        #verfier si le joueur souhaite aller à gauche ou à droite ou sauter
        if self.pressed.get(
                pygame.K_RIGHT
        ) and self.player.rect.x + self.player.rect.width < screen.get_width():
            self.player.move_right()
        if self.pressed.get(pygame.K_LEFT) and self.player.rect.x > 0:
            self.player.move_left()

        #CODE JUMP
        if self.pressed.get(pygame.K_UP):
            self.player.jump()

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

    def spawn_monster(self, monster_class_name):
        self.all_monsters.add(monster_class_name.__call__(self))
示例#15
0
class Game:

    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 = {}

    def update(self, screen):
        # 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'évenement du jeu
        self.comet_event.update_bar(screen)

        # récupérer les projectiles du joueur
        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)

        # récupérer les cometes
        for comete in self.comet_event.all_cometes:
            comete.fall()

        # appliquer l'ensemble des images du groupe de projectiles
        self.player.all_projectiles.draw(screen)

        # appliquer l'ensemble des images du groupe de monstres
        self.all_monsters.draw(screen)

        # appliquer l'ensemble des images du groupe de comètes
        self.comet_event.all_cometes.draw(screen)

        # vérifier si le joueur souhaite aller à 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 = Monster(self)
        self.all_monsters.add(monster)

    def game_over(self):
        # remettre le jeu à neuf, retirer les monstres, remettre le joueur à 100 de vie et mettre le jeu en attente
        self.all_monsters = pygame.sprite.Group()
        self.comet_event.all_cometes = pygame.sprite.Group()
        self.player.health = self.player.max_health
        self.comet_event.reset_percent()
        self.is_playing = False

    def start(self):
        self.is_playing = True
        self.spawn_monster()
        self.spawn_monster()
示例#16
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))
示例#17
0
class Game:
    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()

    def start(self):
        """lance le jeu et les monstres"""
        self.is_playing = True
        self.spawn_monster(Mummy)
        self.spawn_monster(Mummy)
        self.spawn_monster(Alien)

        #le joueur dans un groupe
        self.all_players = pygame.sprite.Group()
        #generer notre joueur
        self.player = Player(self)
        #ajoute le joueur au groupe
        self.all_players.add(self.player)

    def add_score(self, points=10):
        """ajout de points """
        self.score += points

    def game_over(self):
        """ arret du jeu """
        #groupe de monstre vide
        self.all_monsters = pygame.sprite.Group()
        #groupe de comètes vide
        self.comet_event.all_comets = pygame.sprite.Group()
        #vie du joueur
        self.player.health = self.player.max_health
        #jauge d'événement à 0
        self.comet_event.reset_percent()
        self.is_playing = False
        #remise à 0 du score
        self.score = 0
        #son game over
        self.sound_manager.play('game_over')

    def update(self, screen):
        """mise à jour des evevenements """

        score_text = self.font.render(f"Score : {self.score}", 1, (0, 0, 0))
        screen.blit(score_text, (20, 20))

        #appliquer l'image de mon joueur
        screen.blit(self.player.image, self.player.rect)
        #actualise la barre de vie du joueur
        self.player.update_health_bar(screen)

        #actualise la barre d'évènement du jeu
        self.comet_event.update_bar(screen)

        #actualiser l'animation du joeur
        self.player.update_animation()

        #boucle sur les projectiles
        for projectile in self.player.all_projectiles:
            #lance projectile
            projectile.move(screen.get_width())

        #boucle sur les monstres
        for monster in self.all_monsters:
            #fait avancer les monstres
            monster.forward()
            #affiche bar de vie
            monster.update_health_bar(screen)
            #anime le monstre
            monster.update_animation()

        #appliquer le projectile sur l'ecran
        self.player.all_projectiles.draw(screen)

        #boucle sur les cometes
        for comet in self.comet_event.all_comets:
            comet.fall()

        #appliquer les monstres
        self.all_monsters.draw(screen)

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

        #verifie le sens de deplacement du joueur
        #print(self.pressed)
        #si touche droite activée
        if self.pressed.get(
                pygame.K_RIGHT
        ) and self.player.rect.x + self.player.rect.width < screen.get_width():
            #déplacement à droite
            self.player.move_right()
            #si touche gauche activée
        elif self.pressed.get(pygame.K_LEFT) and self.player.rect.x > 0:
            #déplacement à gauche
            self.player.move_left()

    def check_collision(self, sprite, group):
        """methode qui gere les collisions"""
        return pygame.sprite.spritecollide(sprite, group, False,
                                           pygame.sprite.collide_mask)

    def spawn_monster(self, monster_class_name):
        """methode d'apparition du monstre"""
        #création d'une liste de monstres
        self.all_monsters.add(monster_class_name.__call__(self))
示例#18
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()
示例#19
0
class Game:
    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()

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

    def game_over(self):
        self.all_monsters = pygame.sprite.Group()
        self.comet_event.all_comets = pygame.sprite.Group()
        self.player.health = self.player.max_health
        self.comet_event.reset_percent()
        self.is_playing = False
        self.score = 0
        self.sound_manager.play('game_over')

    def add_score(self, score=1):
        self.score += score

    def update(self, screen):
        # afficher le score:
        score_text = self.font.render(f'Score: {self.score}', 1, (0, 0, 0))
        screen.blit(score_text, (20, 20))

        # Add player image
        screen.blit(self.player.image, self.player.rect)

        # actualiser la barre de vie du joueur
        self.player.update_health_bar(screen)

        # actualiser l'animation du joueur
        self.player.update_animation()

        # actualiser la barre d'evenement du jeu
        self.comet_event.update_bar(screen)

        # recuperer les pojectiles du joueur
        for projectile in self.player.all_projectiles:
            projectile.move()

        # recuperer les monstres
        for monster in self.all_monsters:
            monster.forward()
            monster.update_health_bar(screen)
            monster.update_animation()

        # recuperer les commettes du jeu
        for comet in self.comet_event.all_comets:
            comet.fall()

        # appliquer l'ensemble des images du groupe projectile
        self.player.all_projectiles.draw(screen)

        # appliquer l'ensemble des images du groupe monstre
        self.all_monsters.draw(screen)

        # appliquer l'ensemble des images du groupe comet
        self.comet_event.all_comets.draw(screen)

        # Verifier si le joueur souhaite aller à 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):
        self.all_monsters.add(monster_class_name.__call__(self))