コード例 #1
0
    def credits(self):
        img_credits = pygame.transform.smoothscale(
            self.img_credits,
            util.scale(self.img_credits, height=self.unit * 13))
        img_credits_rect = img_credits.get_rect()
        img_credits_rect.centerx = self.screen.get_rect().centerx
        img_credits_rect.y = self.unit * 2

        back = False

        btn_back = MenuButton("BACK", self.unit,
                              (self.unit * 17, self.unit * 3))
        btn_back.rect.centerx = self.screen.get_rect().centerx
        btn_back.rect.y = self.unit * 45
        btn_back.set_status(1)

        self.draw_background()

        box = pygame.Surface((self.size[1], self.size[1]))
        box.fill((255, 255, 255))
        box.set_alpha(150)
        box_rect = box.get_rect()
        box_rect.centerx = self.screen.get_rect().centerx
        box_rect.y = 0
        self.screen.blit(box, box_rect)

        font = pygame.font.Font(data.filepath("font", "abel.ttf"),
                                int(self.unit * 1.5))
        color_text = (30, 30, 30)
        color_title = (122, 30, 30)

        credits = Constants.CREDITS.split("\n")
        spooler = []
        for line in credits:
            color = color_text
            if line and line[0] == "*":
                line = line[1:]
                color = color_title
            spooler.append(font.render(line, True, color))

        posy = 16 * self.unit
        advance = int(1.6 * self.unit)

        self.screen.blit(img_credits, img_credits_rect)
        btn_back.update()
        btn_back.draw(self.screen)

        for el in spooler:
            rect = el.get_rect()
            rect.centerx = self.screen.get_rect().centerx
            rect.y = posy
            self.screen.blit(el, rect)
            posy += advance

        while not back:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE or event.key == pygame.K_RETURN or event.key == pygame.K_SPACE:
                        return
                    elif event.key == pygame.K_1:
                        pygame.image.save(self.screen, "screenshot.jpg")
                elif event.type == pygame.QUIT:
                    self.running = False
                    return

            pygame.display.flip()
            self.clock.tick(30)
コード例 #2
0
    def credits(self):
        img_credits = pygame.transform.smoothscale(self.img_credits,util.scale(self.img_credits,height=self.unit*13))
        img_credits_rect = img_credits.get_rect()
        img_credits_rect.centerx = self.screen.get_rect().centerx
        img_credits_rect.y = self.unit*2

        back = False

        btn_back = MenuButton("BACK",self.unit,(self.unit*17, self.unit*3))
        btn_back.rect.centerx = self.screen.get_rect().centerx
        btn_back.rect.y = self.unit*45
        btn_back.set_status(1)

        self.draw_background()

        box = pygame.Surface((self.size[1],self.size[1]))
        box.fill((255,255,255))
        box.set_alpha(150)
        box_rect = box.get_rect()
        box_rect.centerx = self.screen.get_rect().centerx
        box_rect.y = 0
        self.screen.blit(box,box_rect)

        font = pygame.font.Font(data.filepath("font", "abel.ttf"), int(self.unit * 1.5))
        color_text = (30,30,30)
        color_title = (122,30,30)

        credits = Constants.CREDITS.split("\n")
        spooler = []
        for line in credits:
            color = color_text
            if line and line[0] == "*":
                line = line[1:]
                color = color_title
            spooler.append(font.render(line, True, color))

        posy = 16*self.unit
        advance = int(1.6*self.unit)

        self.screen.blit(img_credits, img_credits_rect)
        btn_back.update()
        btn_back.draw(self.screen)

        for el in spooler:
            rect = el.get_rect()
            rect.centerx = self.screen.get_rect().centerx
            rect.y = posy
            self.screen.blit(el, rect)
            posy += advance

        while not back:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE or event.key == pygame.K_RETURN or event.key == pygame.K_SPACE:
                        return
                    elif event.key == pygame.K_1:
                        pygame.image.save(self.screen, "screenshot.jpg")
                elif event.type == pygame.QUIT:
                    self.running = False
                    return


            pygame.display.flip()
            self.clock.tick(30)
コード例 #3
0
    def highscores(self, scored=False):
        #scored = {'elapse':str,'score':int,'index':int,'scored':bool}

        back = False

        btn_back = MenuButton("BACK", self.unit,
                              (self.unit * 17, self.unit * 3))
        btn_back.rect.centerx = self.screen.get_rect().centerx
        btn_back.rect.y = self.unit * 45
        btn_back.set_status(1)

        self.draw_background()

        highscores = Highscores()
        if scored and not scored['scored']:
            highscores.insert("Your name", str(scored["score"]),
                              scored["elapse"])

        box = pygame.Surface((self.size[1], self.size[1]))
        box.fill((255, 255, 255))
        box.set_alpha(150)
        box_rect = box.get_rect()
        box_rect.centerx = self.screen.get_rect().centerx
        box_rect.y = 0
        self.screen.blit(box, box_rect)

        font_text = pygame.font.Font(data.filepath("font", "abel.ttf"),
                                     int(self.unit * 1.6))
        font_title = pygame.font.Font(data.filepath("font", "abel.ttf"),
                                      int(self.unit * 5))
        color_text = (30, 30, 30)
        color_title = (122, 30, 30)

        posy = 8 * self.unit
        advance = int(2.2 * self.unit)

        btn_back.update()
        self.screen.blit(btn_back.image, btn_back.rect)

        title = font_title.render("HIGH SCORES", True, color_title)
        rect = title.get_rect()
        rect.centerx = self.screen.get_rect().centerx
        rect.y = 1 * self.unit

        self.screen.blit(title, rect)
        line = pygame.Surface((self.size[1], int(self.unit * 2.2)))
        line.fill((255, 255, 255))
        line.set_alpha(50)
        line_rect = line.get_rect()
        line_rect.centerx = self.screen.get_rect().centerx
        line_me = pygame.Surface((self.size[1], int(self.unit * 2.2)))
        line_me.fill((30, 200, 30))
        line_me.set_alpha(50)
        ii = 0
        for el in highscores.scores:
            index = font_text.render(str(ii + 1), True, color_title)
            name = font_text.render(el["name"], True, color_text)
            elapse = font_text.render(el["elapse"], True, color_text)
            score = font_text.render(el["score"], True, color_text)
            line_rect.y = posy
            if not ii % 2:
                self.screen.blit(line, line_rect)
            if scored and scored["scored"] and ii == scored[
                    "index"] or ii == Constants.MAXSCORE:
                self.screen.blit(line_me, line_rect)
            rect = index.get_rect()
            rect.y = posy

            rect.x = self.screen.get_rect().centerx - self.unit * 13
            if ii < Constants.MAXSCORE: self.screen.blit(index, rect)
            rect.x += self.unit * 3
            self.screen.blit(name, rect)
            rect.x += self.unit * 16
            self.screen.blit(elapse, rect)
            rect.x += self.unit * 5
            self.screen.blit(score, rect)
            posy += advance
            ii += 1

        while not back:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE or event.key == pygame.K_RETURN or event.key == pygame.K_SPACE:
                        return
                    elif event.key == pygame.K_1:
                        pygame.image.save(self.screen, "screenshot.jpg")
                elif event.type == pygame.QUIT:
                    self.running = False
                    return

            btn_back.update()
            btn_back.draw(self.screen)
            pygame.display.flip()
            self.clock.tick(30)
コード例 #4
0
    def highscores(self,scored=False):
        #scored = {'elapse':str,'score':int,'index':int,'scored':bool}

        back = False

        btn_back = MenuButton("BACK",self.unit,(self.unit*17, self.unit*3))
        btn_back.rect.centerx = self.screen.get_rect().centerx
        btn_back.rect.y = self.unit*45
        btn_back.set_status(1)

        self.draw_background()

        highscores = Highscores()
        if scored and not scored['scored']:
            highscores.insert("Your name",str(scored["score"]),scored["elapse"])

        box = pygame.Surface((self.size[1],self.size[1]))
        box.fill((255,255,255))
        box.set_alpha(150)
        box_rect = box.get_rect()
        box_rect.centerx = self.screen.get_rect().centerx
        box_rect.y = 0
        self.screen.blit(box,box_rect)

        font_text = pygame.font.Font(data.filepath("font", "abel.ttf"), int(self.unit * 1.6))
        font_title = pygame.font.Font(data.filepath("font", "abel.ttf"), int(self.unit * 5))
        color_text = (30,30,30)
        color_title = (122,30,30)

        posy = 8*self.unit
        advance = int(2.2*self.unit)

        btn_back.update()
        self.screen.blit(btn_back.image, btn_back.rect)

        title = font_title.render("HIGH SCORES",True,color_title)
        rect = title.get_rect()
        rect.centerx = self.screen.get_rect().centerx
        rect.y = 1*self.unit

        self.screen.blit(title,rect)
        line = pygame.Surface((self.size[1],int(self.unit*2.2)))
        line.fill((255,255,255))
        line.set_alpha(50)
        line_rect = line.get_rect()
        line_rect.centerx = self.screen.get_rect().centerx
        line_me = pygame.Surface((self.size[1],int(self.unit*2.2)))
        line_me.fill((30,200,30))
        line_me.set_alpha(50)
        ii=0
        for el in highscores.scores:
            index = font_text.render(str(ii+1),True,color_title)
            name = font_text.render(el["name"],True,color_text)
            elapse = font_text.render(el["elapse"],True,color_text)
            score = font_text.render(el["score"],True,color_text)
            line_rect.y = posy
            if not ii % 2:
                self.screen.blit(line,line_rect)
            if scored and scored["scored"] and ii==scored["index"] or ii==Constants.MAXSCORE:
                self.screen.blit(line_me,line_rect)
            rect = index.get_rect()
            rect.y = posy

            rect.x = self.screen.get_rect().centerx-self.unit*13
            if ii < Constants.MAXSCORE: self.screen.blit(index, rect)
            rect.x+= self.unit*3
            self.screen.blit(name, rect)
            rect.x+= self.unit*16
            self.screen.blit(elapse, rect)
            rect.x+= self.unit*5
            self.screen.blit(score, rect)
            posy += advance
            ii+=1

        while not back:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE or event.key == pygame.K_RETURN or event.key == pygame.K_SPACE:
                        return
                    elif event.key == pygame.K_1:
                        pygame.image.save(self.screen, "screenshot.jpg")
                elif event.type == pygame.QUIT:
                    self.running = False
                    return

            btn_back.update()
            btn_back.draw(self.screen)
            pygame.display.flip()
            self.clock.tick(30)