예제 #1
0
class Score(object):
    def __init__(self, asset):
        self.score = 0
        self.old_score = self.score

        self.collect = asset["effects"]["collects-effects"]
        self.font = Font(asset["fonts"]["CursedTimerUlil-Aznm"], 20)

    @property
    def getScore(self):
        return self.score

    def check(self):
        if self.score < 0:
            return True

    def add_score(self):
        self.score += 1
        new_score = self.old_score + 10
        if self.score == new_score:
            self.collect.play()
            self.old_score = self.score

    def rescore(self):
        self.score -= 1

    def draw(self, screen):
        text, rect = self.font.render("Skor: " + str(self.score),
                                      (133, 230, 159))
        screen.blit(text, rect)
예제 #2
0
def main():
    parser = argparse.ArgumentParser(description='test font')
    parser.add_argument('-f', '--font_dir', type=str, required=True)
    parser.add_argument('-o', '--output_dir', type=str, required=True)
    args = parser.parse_args()

    files = filter((lambda x: x.lower().endswith('.ttf')),
                   os.listdir(args.font_dir))

    pygame.init()

    for file in files:
        try:
            font = Font(os.path.join(args.font_dir, file), size=24)
            font.strong = True
            font.oblique = True
            font.antialiased = True
            font.origin = True
            font.strength = 0.01
            surface, _ = font.render(RENDER_TEXT,
                                     fgcolor=Color(255, 255, 255, 255),
                                     bgcolor=Color(0, 0, 0, 0))
            img = pygame.surfarray.array3d(surface)
            img = np.transpose(img, [1, 0, 2])
            # print(img.shape)
            # cv2.imshow('test', img)
            # cv2.waitKey()
            cv2.imwrite(os.path.join(args.output_dir, file + ".png"), img)
            # print(file, img.shape)
        except Exception:
            print(file, "Exception")
예제 #3
0
class Score(object):
    def __init__(self, font_path):
        self.collect = Sound(COLLECT_BACKSOUND)
        self.font = Font(font_path, 24)
        self.score = 0
        self.old_score = self.score

    def add_score(self):
        self.score += 1
        new_score = self.old_score + 10
        if self.score == new_score:
            self.collect.play()
            self.old_score = self.score

    def rescore(self):
        self.score -= 1

    def check(self):
        if self.score < 0:
            return True
        else:
            return False

    def draw(self, screen):
        text_surface, rect = self.font.render("Score: " + str(self.score),
                                              (133, 230, 159))
        screen.blit(text_surface, (10, 10))
예제 #4
0
class StartGame(object):
    def __init__(self, screen, rect, background):
        init()
        self.screen = screen
        self.rect = rect
        self.background = background
        self.font = Font(TITLE_FONT, 40)
        self.font_start = Font(PRESS_START_FONT, 15)
        self.font_author = Font(PRESS_START_FONT, 12)
        self.font_information = Font(INFORMATION_FONT, 8)
        self.gamelan_music = music.load(GAMELAN_BACKSOUND)
        self.click_sound = Sound(CLICK_BACKSOUND)

    def load_image(self, path, convert_alpha=False, convert=True):
        try:
            resource = PyGameImageLoad(path)
        except PyGameErrorException:
            print("duarrr")
            exit(0)
        if convert:
            return resource.convert()
        elif convert_alpha:
            return resource.convert_alpha()
        else:
            return resource

    def run(self):
        clock = Clock()
        music.play()
        text_surface, rect = self.font.render("Pocong Runner", (150, 51, 51))
        author_surface, author_rect = self.font_author.render(
            "@billalxcode", (255, 255, 255))
        author_rect.center = self.rect.center
        author_rect.bottom += 165

        start_text_surface, start_rect = self.font_start.render(
            "Tekan enter untuk memulai...", (255, 255, 255))
        info_surface, info_rect = self.font_information.render(
            "* Jika anda mengklaim pemilik dari font/gambar silahkan chat pembuat. Terima kasih telah mendukung saya.",
            (255, 255, 255))
        info_rect.bottom += self.rect.height - 20
        blink_rect = start_rect
        blink_rect.center = self.rect.center
        blink_rect.bottom += 150

        while True:
            for event in get():
                if event.type == QUIT:
                    return True
                elif event.type == KEYDOWN:
                    self.click_sound.play()
                    if event.key == K_SPACE or event.key == 13:
                        return False
            self.screen.blit(self.background, (0, 0))
            self.screen.blit(author_surface, author_rect)
            self.screen.blit(text_surface.convert_alpha(),
                             (self.rect.width / 2, 100))
            self.screen.blit(start_text_surface, blink_rect)
            self.screen.blit(info_surface, info_rect)
            clock.tick(60)

            update()
예제 #5
0
class Slider():
    """
    Slider code lifted from
    https://www.dreamincode.net/forums/topic/401541-buttons-and-sliders-in-pygame/
    """
    def __init__(self, name, val, min_max, pos, window, dim=[150, 30]):
        self.name = name
        self.val = val
        self.min_v, self.max_v = min_max
        self.xpos, self.ypos = pos
        self.window = window
        self.width, self.height = dim
        self.hit = False

        #Slider background
        self.surf = pygame.surface.Surface((self.width, self.height))
        self.surf.set_alpha(200)
        self.surf.fill((100, 100, 100))

        pygame.draw.rect(self.surf, (255, 255, 255),
                         [1, 1, self.width - 2, self.height - 2], 1)
        pygame.draw.rect(self.surf, (0, 0, 0),
                         [5, self.height - 9, self.width - 10, 2], 0)
        pygame.draw.rect(self.surf, (255, 255, 255),
                         [5, self.height - 10, self.width - 10, 4], 1)

        #Slider text
        self.FONT = Font('NotoSansMono-Regular.ttf', 10)
        self.txt_surf, self.txt_rect = self.FONT.render(
            self.name + f'{self.val:.4}', (255, 255, 255))

        #Slider button
        self.button_surf = pygame.surface.Surface((20, 20))
        self.button_rect = self.button_surf.get_rect()
        self.button_surf.fill((1, 1, 1))
        self.button_surf.set_colorkey((1, 1, 1))
        pygame.draw.circle(self.button_surf, (255, 255, 255), (10, 10), 3)
        pygame.draw.circle(self.button_surf, (0, 0, 0), (10, 10), 2)

    def draw(self):
        """
        Draws the slider.
        """
        surf = self.surf.copy()
        x = 5 + int((self.val - self.min_v) / (self.max_v - self.min_v) *
                    (self.width - 10))
        y = self.height - 8
        self.button_rect = self.button_surf.get_rect(center=(x, y))
        surf.blit(self.button_surf, self.button_rect)
        self.button_rect.move_ip(self.xpos, self.ypos)

        x, y = self.surf.get_rect().center
        self.txt_rect = self.txt_surf.get_rect(center=(x, y - 4))

        surf.blit(self.txt_surf, self.txt_rect)
        self.window.blit(surf, (self.xpos, self.ypos))

    def move(self):
        """
        Moves the slider handle and updates text.
        """
        self.txt_surf, _ = self.FONT.render(self.name + f'{self.val:.4}',
                                            (255, 255, 255))
        self.val = ((pygame.mouse.get_pos()[0] - self.xpos - 5) /
                    (self.width - 10) * (self.max_v - self.min_v)) + self.min_v
        self.val = np.clip(self.val, self.min_v, self.max_v)
예제 #6
0
def introGame(screen, asset, data):
    #=== Background image ===#
    logs.info("Mengatur latar belakang...")
    bg = scale(asset["backgrounds"]["intro"], (config.getRect.size))

    #=== Button play image ===#
    logs.info("Mengatur button...")
    btn_play = asset["other"]["btn-play2"]
    btn_play = scale(
        btn_play, (int(btn_play.get_width() / 2), btn_play.get_height() - 100))
    btn_play_center = btn_play.get_rect()
    btn_play_center.center = config.getRect.center

    #=== button keluar  image ===#
    btn_keluar = asset["other"]["btn-keluar2"]
    btn_keluar = scale(
        btn_keluar,
        (int(btn_keluar.get_width() / 2), btn_keluar.get_height() - 100))
    btn_keluar_center = btn_keluar.get_rect()
    btn_keluar_center.center = config.getRect.center
    btn_keluar_center.bottom += 100

    #=== Button settings image ===#
    btn_settings = asset["other"]["btn-settings2"]
    btn_settings = scale(
        btn_settings,
        (int(btn_settings.get_width() / 2), btn_settings.get_height() - 100))
    btn_settings_center = btn_settings.get_rect()
    btn_settings_center.center = config.getRect.center
    btn_settings_center.bottom += 50

    #=== Button credits image ===#
    btn_credits = asset["other"]["btn-credits"]
    btn_credits = scale(btn_credits, (100, 100))
    btn_credits_center = btn_credits.get_rect()
    btn_credits_center.center = config.getRect.center
    btn_credits_center.bottom = config.getRect.height
    btn_credits_center.right = config.getRect.width

    btn_close = asset["other"]["btn-close"]
    btn_close = scale(btn_close, (100, 100))
    btn_close_center = btn_close.get_rect()
    btn_close_center.center = config.getRect.center
    btn_close_center.bottom = config.getRect.height
    btn_close_center.right = config.getRect.width

    #=== Settings coint image ===#
    coint_image = asset["other"]["coint"]
    coint_image = scale(coint_image, (40, 40))
    coint_image.set_colorkey("black")
    coint_rect = coint_image.get_rect()

    #=== Window credit image ===#
    win_credits = asset["other"]["credits2"]
    win_credits = scale(win_credits, (500, 500))
    win_credits.set_colorkey("black")
    win_credits_center = win_credits.get_rect()
    win_credits_center.center = config.getRect.center

    #=== Font warning ===#
    logs.info("Mengatur teks peringatan")
    info = Font(asset["fonts"]["AboveDemoRegular-lJMd"], 10)
    info_text, info_rect = info.render(
        "*Jika anda mengklaim pemilik dari asset game ini, silahkan hubungi pembuat.",
        (255, 255, 255))
    info_rect.bottom = config.getRect.height

    #=== Font coint ===#
    logs.info("Mengatur teks coint")
    id, coint, name = data
    font_coint = Font(asset["fonts"]["PressStart2P"], 20)
    coint_text, coint_text_rect = font_coint.render(str(coint),
                                                    (255, 255, 255))
    coint_text_rect.bottom = 28
    coint_text_rect.right += 45

    credit_window = False

    running = True
    while running:
        events = core.events()
        if events["type"]["quit"]:
            return False
        elif events["type"]["mousedown"]:
            if events["keys"]["button"] == 1:
                if not credit_window:
                    if btn_play_center.collidepoint(get_pos()):
                        asset["effects"]["click-effects"].play()
                        return True
                    elif btn_settings_center.collidepoint(get_pos()):
                        asset["effects"]["click-effects"].play()
                        credit_window = True
                    elif btn_keluar_center.collidepoint(get_pos()):
                        asset["effects"]["click-effects"].play()
                        return False
                    elif btn_credits_center.collidepoint(get_pos()):
                        asset["effects"]["click-effects"].play()
                        credit_window = True
                else:
                    if btn_close_center.collidepoint(get_pos()):
                        asset["effects"]["click-effects"].play()
                        credit_window = False

        screen.blit(bg, (0, 0))
        if credit_window:
            screen.blit(win_credits, win_credits_center)
            screen.blit(btn_close, btn_close_center)
        else:
            screen.blit(btn_play, btn_play_center)
            screen.blit(btn_keluar, btn_keluar_center)
            screen.blit(btn_settings, btn_settings_center)
            screen.blit(btn_credits, btn_credits_center)
            screen.blit(coint_image, coint_rect)
            screen.blit(coint_text, coint_text_rect)
        screen.blit(info_text, info_rect)
        update()