Exemple #1
0
    def __init__(self) -> None:
        self.text_color = (200, 200, 200)
        self.next_text = Text("next", self.text_color, 20, Position(290, 20))
        self.lines_cleared_block = UIBlock(Position(290, 120))
        self.lines_cleared_block.add(
            Text("cleared", self.text_color, 20, Position(0, 0)))
        self.lines_cleared_block.add(
            Text("0", self.text_color, 20, Position(0, 0)))
        self.score_block = UIBlock(Position(290, 180))
        self.score_block.add(Text("score", self.text_color, 20, Position(0,
                                                                         0)))
        self.score_block.add(Text("0", self.text_color, 20, Position(0, 0)))
        self.level_block = UIBlock(Position(290, 240))
        self.level_block.add(Text("level", self.text_color, 20, Position(0,
                                                                         0)))
        self.level_block.add(Text("0", self.text_color, 20, Position(0, 0)))

        self.pause = Text("PAUSE", (255, 255, 255), 20,
                          Position(s.GAME_W // 2, s.GAME_H // 2))
        self.game_over = Text("GAME OVER", (255, 255, 255), 20,
                              Position(s.GAME_W // 2, s.GAME_H // 2))

        self.score_plate = NameInput()

        self.fps = Text("fps: 60", self.text_color, 20, Position(290, 400))
Exemple #2
0
    def __init__(self) -> None:
        self.move_timer = 0
        self.text = Text("select player", (200, 200, 200), 30,
                         Position(s.WIN_W / 2, 50))
        self.text2 = Text(
            "Start to change current player name",
            (200, 200, 200),
            15,
            Position(s.WIN_W / 2, 75),
        )
        self.text3 = Text("A to play", (200, 200, 200), 15,
                          Position(s.WIN_W / 2, 95))

        self.name_input = NameInput()
        self.name_input_enabled = False

        self.player_button = SwitcherButton(
            save.score_list.players,
            0,
            (200, 200, 200),
            20,
            Position(s.WIN_W / 4 + 20, s.WIN_H / 2),
            horizontal=True,
        )
        self.level_button = SwitcherButton(
            list(map(str, range(31))),
            0,
            (200, 200, 200),
            20,
            Position(s.WIN_W * 3 / 4, s.WIN_H / 2),
            horizontal=False,
        )
Exemple #3
0
    def initialize(self):
        """Luo sprite ryhmän, jossa pelilaatat on asetettu järjestykseen.
        """
        board = self.game.get_board()
        size = self.game.get_size()

        score = self.game.get_score()
        text = "Score: " + str(score)
        margin = 15
        W = self.cell_size * self.game.get_size() - margin * 2
        score_x = self.m_x + margin
        score_y = self.m_y - (self.cell_size - margin)
        self.texts.add(
            Text(text, score_x, score_y, 30, (255, 255, 255), W, 50,
                 (0, 0, 180)))

        highscore = self.game.get_score()
        text = "Best score: " + str(highscore)
        margin = 15
        score_x = self.m_x + self.cell_size * self.game.get_size() + margin
        score_y = self.m_y - (self.cell_size - margin)
        self.texts.add(
            Text(text, score_x, score_y, 30, (255, 255, 255),
                 self.screen_size[0] - score_x - margin, 50, (0, 0, 180)))

        for y in range(size):
            for x in range(size):
                value = board[y][x]
                normalized_x = x * self.cell_size + self.m_x
                normalized_y = y * self.cell_size + self.m_y

                self.tiles.add(
                    Tile(0,
                         normalized_x,
                         normalized_y,
                         self.cell_size,
                         color=None,
                         image=self.files.get_tile0_img_str(),
                         files=self.files))  # tausta
                if value == 0:
                    continue
                self.tiles.add(
                    Tile(value,
                         normalized_x,
                         normalized_y,
                         self.cell_size,
                         color=None,
                         image=self.files.get_tile_img_str(),
                         files=self.files))  # tile

        self.update_buttons()

        self.all_sprites.add(self.tiles, self.texts)
Exemple #4
0
 def update_score(self) -> None:
     self.score_screen = []
     self.score_screen.append(
         Text("High scores:", (200, 200, 200), 30,
              Position(s.WIN_W / 2, 50)))
     for i, score in enumerate(high_score.score_list.score_list):
         self.score_screen.append(
             Text(
                 (score[0] + ": " +
                  str(score[1])) if score[1] != 0 else "...vacant...",
                 (200, 200, 200),
                 20,
                 Position(s.WIN_W / 2, 100 + (i + 1) * 30),
             ))
Exemple #5
0
 def drawAdditionalContent(self):
     textSprite = Text(text="Pause",
                       fontSize=50,
                       location=(self.pageSize[POS_X] / 2,
                                 self.pageSize[POS_Y] / 2),
                       alignment=CENTER_MIDDLE)
     textSprite.update()
     self.popUpPage.blit(textSprite.image, textSprite.rect)
Exemple #6
0
 def draw_bloc(self, x, y, width, height, text, size):
     """ Draw all twwet bloc. """
     bloc = pygame.Surface((width, height), pygame.SRCALPHA)
     pygame.draw.rect(bloc, self.colors['blue_light_t'],
                      (0, 0, width, height), 0)
     pygame.draw.rect(bloc, self.colors['white'], (0, 0, width, height), 1)
     Text(bloc, text, 0, 0, width, height, size)
     self.screen.blit(bloc, (x, y))
Exemple #7
0
    def __init__(self) -> None:
        self.name = "enter your name"
        self.letter = "A"
        self.buttons = []
        self.move_timer = 0
        self.plate = pygame.Surface((300 * s.scale, 300 * s.scale))

        self.game_over = Text("Name change", (255, 255, 255), 30,
                              Position(s.WIN_W // 2, s.WIN_H // 4))
        self.name_text = Text(self.name, (255, 255, 255), 30,
                              Position(s.WIN_W // 2, s.WIN_H * 2 // 4))
        self.press_a_btn = Text(
            "A to select letter",
            (255, 255, 255),
            15,
            Position(s.WIN_W // 2, s.WIN_H * 3 // 4),
        )
        self.press_start_btn = Text(
            "Start to confirm",
            (255, 255, 255),
            15,
            Position(s.WIN_W // 2, s.WIN_H * 3 // 4 + 15),
        )
        self.press_b_btn = Text(
            "B to clear letter",
            (255, 255, 255),
            15,
            Position(s.WIN_W // 2, s.WIN_H * 3 // 4 + 30),
        )
        x0 = 0
        y0 = 0
        for letter in LETTERS:
            x = x0 * 15 * s.scale + 90 * s.scale
            y = y0 * 20 * s.scale + 75 * s.scale
            self.buttons.append(
                Button(letter, letter, 14, Position(x, y), self.plate))
            x0 += 1
            if x0 == 9:
                x0 = 0
                y0 += 1
Exemple #8
0
    def __init__(
        self,
        options: list,
        current_index: int,
        color: tuple,
        size: int,
        position: Position,
        horizontal: bool = True,
    ) -> None:
        self._options = options
        self._current_index = current_index
        self.color = color
        self.size = size
        self.position = position
        self.horizontal = horizontal

        self._text = Text(options[current_index], color, size, position)

        if horizontal:
            self.width = int(size * (len(options[current_index])) / 3.3 + 5)
            self.ar1 = Arrow(
                Position(self._text.position.x - self.width,
                         self._text.position.y),
                size,
                horizontal=True,
                flip=False,
                tag="Left",
            )
            self.ar2 = Arrow(
                Position(self._text.position.x + self.width,
                         self._text.position.y),
                size,
                horizontal=True,
                flip=True,
                tag="Right",
            )
        else:
            self.ar1 = Arrow(
                Position(self._text.position.x, self._text.position.y - size),
                size,
                horizontal=False,
                flip=False,
                tag="Up",
            )
            self.ar2 = Arrow(
                Position(self._text.position.x, self._text.position.y + size),
                size,
                horizontal=False,
                flip=True,
                tag="Down",
            )
Exemple #9
0
 def drawAdditionalContent(self, data, appendButtons=[]):
     self.allSprites = []
     text = Text(text="Player %s Win!" % (data + 1),
                 fontSize=50,
                 alignment=CENTER_MIDDLE,
                 location=(self.pageSize[POS_X]/2, self.pageSize[POS_Y]/4),
                 basePoint=self.popUpPageBasePoint)
     self.allSprites.append(text)
     for appendButton in appendButtons:
         buttonSprite = Button(appendButton["func"],
                               buttonSize=(150, 40),
                               text=appendButton["name"],
                               fontSize=30,
                               location=(self.pageSize[POS_X] if appendButton["location"][POS_X] == PARENT_SIZE_WIDTH  else appendButton["location"][POS_X],
                                         self.pageSize[POS_Y] if appendButton["location"][POS_Y] == PARENT_SIZE_HEIGHT  else appendButton["location"][POS_Y]),
                               alignment=appendButton["alignment"],
                               basePoint=self.popUpPageBasePoint)
         buttonSprite.listen(appendButton["listener"])
         self.allSprites.append(buttonSprite)
Exemple #10
0
    def __init__(self,
                 func,
                 fontType=DEFAULT_FONT_TYPE,
                 fontSize=DEFAULT_FONT_SIZE,
                 textColor=WHITE,
                 text="",
                 buttonLifeTimer=CONTINUANCE,
                 textIndex=0,
                 location=(0, 0),
                 alignment=TOP_LEFT,
                 backgroundColor=GREEN,
                 buttonSize=(150, 40),
                 hoverColor=DARK_GREEN,
                 basePoint=(0, 0)):
        super().__init__()
        self.buttonSize = buttonSize
        self.backgroundColor = backgroundColor
        self.hoverColor = hoverColor
        self.buttonLifeTimer = buttonLifeTimer

        self.basePoint = basePoint
        self.textLocation = (self.buttonSize[POS_X] / 2,
                             self.buttonSize[POS_Y] / 2)
        self.buttonBasePoint = location

        self.effect = func
        self.alignment = alignment

        self.textSprite = Text(fontType,
                               fontSize,
                               textColor,
                               text,
                               textIndex=textIndex,
                               location=self.textLocation,
                               alignment=CENTER_MIDDLE,
                               basePoint=self.basePoint)
        self.buildImage(self.backgroundColor)
Exemple #11
0
    def update_pop_ups(self, tag: str, b_press=set()):
        """Renderöi pop-up ikkunat näkyville tagin perusteella. Myös sen napit.

        Args:
            tag (str): mikä pop-up ikkuna halutaan näkyville.
            b_press (set(str), valinnainen): Renderöi kaikki setissä olevat napit painetuiksi.
        """
        size = (350, 250)
        x = (self.screen_size[0] - size[0]) // 2
        y = (self.screen_size[1] - size[1]) // 2
        restart_pop = Tile(0, x, y, color=(100, 100, 100))
        restart_pop.color = (230, 200, 200)
        restart_pop.image = pg.transform.scale(restart_pop.img, size)
        self.pop_ups.add(restart_pop)

        # Buttons:

        margin = 15
        b_size = (90, 35)
        if "b_yes" in b_press:
            b_color = (0, 100, 0)
        else:
            b_color = (0, 200, 0)
        b_yes = Button(tag="b_yes",
                       text="Yes",
                       text_color=(240, 240, 240),
                       img_file_str=self.files.get_button_img_str(),
                       b_color=b_color,
                       position=(x + size[0] // 2 - b_size[0] * 1.5 + 20,
                                 y + size[1] // 1.5),
                       size=b_size,
                       rotate=0)

        if "b_no" in b_press:
            b_color = (100, 0, 0)
        else:
            b_color = (200, 0, 0)
        b_no = Button(tag="b_no",
                      text="No",
                      text_color=(240, 240, 240),
                      img_file_str=self.files.get_button_img_str(),
                      b_color=b_color,
                      position=(x + size[0] // 2 + b_size[0] * .5 - 20,
                                y + size[1] // 1.5),
                      size=b_size,
                      rotate=0)

        self.pop_up_buttons.add(b_yes)
        self.pop_up_buttons.add(b_no)

        # Text:
        x = x + margin
        y = y + margin
        s = ""
        if tag == "restart":
            s = "Are you sure you want restart?"
        elif tag == "menu":
            s = "Return to the main menu?"
        text = Text(s, x, y, 25, (255, 255, 255), size[0] - margin * 2, 40,
                    (100, 100, 100))

        self.pop_ups.add(text)
Exemple #12
0
 def draw(self):
     self.scoreSprite = Text(text=self.getText(self.scores[0].score, self.scores[1].score))
     return self.scoreSprite
Exemple #13
0
 def draw(self):
     self.scoreSprite = Text(text=self.getText(self.scoreC.score))
     return self.scoreSprite
Exemple #14
0
    def process(self):
        # Load Image
        slitherPosterImg = utility.loadImage("2017_slither_poster")
        slitherPosterImg = utility.resizeImage(slitherPosterImg, (800, 600))
        slitherPosterRect = slitherPosterImg.get_rect()
        slitherPosterRect.center = SCREEN_MID

        # Load Sound
        introBMG = utility.loadSound("BGM")
        introBMG.set_volume(0.3)

        # event
        mEventDistributor = pygameEventDistributor(GAME_INTRO_LISTENING_EVENT)
        mEventDistributor.listen(
            Request("GameIntro_quit", self._quit, addtionalTarget=pygame.QUIT))
        mTickEventHandler = tickEventHandler.TickEventHandler(
            mEventDistributor)

        # button settings
        buttonSize = (150, 40)
        fontSize = 30
        padding_x = 150
        padding_y = 150

        # make button
        player1Btn = Button(self.returnP1HS,
                            text="1 player",
                            alignment=BOTTOM_LEFT,
                            location=(0 + padding_x,
                                      SCREEN_HEIGHT - padding_y),
                            buttonSize=buttonSize,
                            fontSize=fontSize)
        player1Btn.listen(mTickEventHandler)
        player2Btn = Button(self.returnP2C,
                            text="2 players",
                            alignment=BOTTOM_RIGHT,
                            location=(SCREEN_WIDTH - padding_x,
                                      SCREEN_HEIGHT - padding_y),
                            buttonSize=buttonSize,
                            fontSize=fontSize)
        player2Btn.listen(mTickEventHandler)
        quitBtn = Button(self._quit,
                         text="quit",
                         alignment=BOTTOM_MIDDLE,
                         location=(SCREEN_WIDTH / 2, SCREEN_HEIGHT),
                         buttonSize=buttonSize,
                         fontSize=fontSize,
                         backgroundColor=RED)
        quitBtn.listen(mTickEventHandler)

        # make text
        title = Text(color=BLUE,
                     text="Slither Game by Enjoeyland",
                     fontSize=40,
                     location=(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4),
                     alignment=TOP_MIDDLE)

        # merge(make intro page)
        groupIntro = pygame.sprite.Group()
        groupIntro.add(player1Btn)
        groupIntro.add(player2Btn)
        groupIntro.add(quitBtn)
        groupIntro.add(title)

        utility.playSound(introBMG, loops=PLAY_INFINITELY)

        while self.__changedGameState == None:

            mEventDistributor.distribute()

            self.screen.fill(SCREEN_BACKGROUND)

            self.screen.blit(slitherPosterImg, (0, 0))

            groupIntro.update()
            groupIntro.draw(self.screen)

            pygame.display.update()
            pygame.time.Clock().tick(10)

        introBMG.fadeout(2)
        return self.__changedGameState