Example #1
0
    def display(self) -> None:
        """Permet d'afficher la créature"""

        if Creature.ALLOW_SKINS:
            Display.drawImg(img=self.img,
                            pos=self.pos,
                            radius=self.radius,
                            base_pos=Camera.pos)
        else:
            Display.drawCircle(pos=self.pos,
                               color=self.color,
                               radius=self.radius,
                               base_pos=Camera.pos)


        Display.drawText(text=self.name,
                         size=self.radius*0.75,
                         color=self.opposite_color,
                         pos=self.pos,
                         base_pos=Camera.pos)
Example #2
0
def buttonWin_Display(
    button: Button,
    mouse_pos: Vect2d,
) -> None:
    """Affichage du texte de fin"""

    min_size = max(button.size.x, button.size.y)

    font_size = min_size * 50 / 400

    Display.drawRect(Vect2d(0, 0), Display.size, (0, 0, 0, button.alpha))

    if button.alpha < 127:
        button.alpha += 1
    elif button.alpha < 255 and Map.game_finished:
        button.alpha += 1

    score = Map.player_infos.get("score", 0)
    tps = Map.player_infos.get("time", 0)

    Display.drawText(button.text,
                     button.pos + button.size / 2,
                     color=button.color,
                     size=font_size)

    Display.drawText("Score : " + str(score),
                     button.pos + button.size / 2 + Vect2d(0, button.size.y),
                     color=button.color,
                     size=font_size)

    Display.drawText("Temps : " + str(tps) + " secondes",
                     button.pos + button.size / 2 +
                     Vect2d(0, button.size.y * 2),
                     color=button.color,
                     size=font_size)
Example #3
0
def buttonEnd_Display(button: Button, mouse_pos: Vect2d) -> None:
    """Affichage du texte de fin"""

    min_size = max(button.size.x, button.size.y)

    font_size = min_size * 50 / 400
    # Taille de la police

    Display.drawRect(Vect2d(0, 0), Display.size, (0, 0, 0, button.alpha))
    # Fondu transparent

    if button.alpha < 127:
        # Si le jeu est en cours on a un fondu jusqu'à 50%
        button.alpha += 1
    elif button.alpha < 255 and Map.game_finished:
        # Sinon le fondu se fait jusqu'à 100%
        button.alpha += 1

    Display.drawText(button.text,
                     button.pos + button.size / 2,
                     color=button.color,
                     size=font_size)
Example #4
0
def buttonStart_Display(button: Button, mouse_pos: Vect2d) -> bool:
    """Affichage du bouton Start

    Args:
        button (Button): bouton start
        mouse_pos (Vect2d): position de la souris
    
    Returns:
        hand_cursor (bool): si la souris doit être affichée comme une main ou un curseur
    """

    if button.isMouseOver(mouse_pos):
        # Arc-en-ciel
        hand_cursor = True
        button.color_sat = (button.color_sat - 3 + 100) % 100
    else:
        # Flash épileptique
        hand_cursor = False
        button.color_sat = 100
        button.color_hue = (button.color_hue + 1) % 360

    button_color = Color.HSVToRGB(button.color_hue, button.color_sat, 100)

    min_size = max(button.size.x, button.size.y)
    # Taille minimale entre la largeur et la hauteur

    font_size = min_size * 50 / 400

    Display.drawRect(button.pos, button.size, color=button_color, fill=True)
    # Rectangle du bouton

    Display.drawText(button.text,
                     button.pos + button.size / 2,
                     color=Color.BLACK,
                     size=font_size)
    # Texte du bouton

    return hand_cursor
Example #5
0
def buttonEndChoice_Display(button: Button, mouse_pos: Vect2d) -> bool:
    """Affichage du bouton rejouer"""

    min_size = max(button.size.x, button.size.y)

    font_size = min_size * 50 / 400

    if button.isMouseOver(mouse_pos):
        hand_cursor = True
        c = Color.BLACK
        f = True
    else:
        hand_cursor = False
        c = button.color
        f = False

    Display.drawRect(button.pos, button.size, color=button.color, fill=f)

    Display.drawText(button.text,
                     button.pos + button.size / 2,
                     color=c,
                     size=font_size)

    return hand_cursor
Example #6
0
    def run(cls) -> None:
        """Méthode principale permettant de faire tourner le jeu"""

        cls.finished = False

        cls.keytime = {}

        cls.state = GameState.MENU

        while not cls.finished:
            cls.ESC_MAX_FRAMECOUNT = Display.real_framerate * 0.25
            # On veut quitter après 0.25 secondes

            cls.handleKeys()

            mx, my = pygame.mouse.get_pos()
            mouse_pos = Vect2d(mx, my)
            # Position de la souris

            mouse_pressed = pygame.mouse.get_pressed()[0]
            # Clic ou non

            Menu.state = GameState.MENU

            if cls.state == GameState.MENU:
                # Affichage du menu

                Menu.update(mouse_pos, mouse_pressed)

                if Menu.can_play:
                    # Si l'on veut rejouer
                    cls.state = GameState.GAME

                if Menu.can_quit:
                    # Si l'on veut quitter
                    cls.finished = True

                Menu.display()

                if Menu.can_play:
                    # Si l'on veut rejouer on remet le curseur normal
                    Display.setCursorArrow()

            elif cls.state == GameState.END:
                # Partie perdue

                Menu.update(mouse_pos, mouse_pressed)

                if not Map.game_finished:
                    # On update la map tant que la partie n'est pas terminée pour de bon
                    # afin de faire jouer les IA
                    Map.update()

                if Menu.can_play:
                    cls.state = GameState.GAME

                if Menu.can_quit:
                    cls.finished = True

                Map.display()
                Menu.display()
                # Affichage du menu et de l'effet de transparence au dessus de la map

                if Menu.can_play:
                    Display.setCursorArrow()
            elif cls.state == GameState.WIN:
                # Victoire

                Menu.update(mouse_pos, mouse_pressed)

                if Menu.can_play:
                    cls.state = GameState.GAME

                if Menu.can_quit:
                    cls.finished = True

                Menu.display()

                if Menu.can_play:
                    Display.setCursorArrow()
            elif cls.state == GameState.GAME:
                # Jeu en cours

                Map.setMousePos(mouse_pos / Display.zoom_factor)
                # On envoie la position de la souris à la map

                Map.update()
                Map.display()

                if Map.isPlayerAlive():
                    if Map.game_finished:
                        cls.state = GameState.WIN
                        Menu.applyState(GameState.WIN)
                else:
                    cls.state = GameState.END
                    Menu.applyState(GameState.END)
            else:
                raise ValueError("État inconnu")

            alpha = cls.keytime.get(pygame.K_ESCAPE,
                                    0) / cls.ESC_MAX_FRAMECOUNT * 255

            Display.drawText("Quitter...",
                             Vect2d(50, 25),
                             color=(255, 0, 0, alpha),
                             size=16,
                             base_pos=Vect2d(0, 0))

            # Affichage du "Quitter" rouge en haut à gauche proportionnellement au temps d'appui de la touche ESC

            Display.updateFrame()