from pygame import image, Color

from esp_hadouken.GameChild import *
from esp_hadouken.Font import *

class Score(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.pos = self.get_configuration()["ending-plate-position"]
        self.set_plate()

    def set_plate(self):
        path = self.get_resource("ending-plate-path")
        self.plate = image.load(path).convert_alpha()

    def render_score(self):
        config = self.get_configuration()
        color = Color(config["ending-score-color"])
        size = config["ending-score-size"]
        score = Font(self, size).render(self.build_text(), True, color)
        rect = score.get_rect()
        rect.center = self.plate.get_rect().center
        self.plate.blit(score, rect)

    def build_text(self):
        return "%i:%02i" % divmod(int(self.get_timer().total()), 60)

    def update(self):
        if self.active:
            self.set_plate()
            self.render_score()
            self.draw()

    def draw(self):
        self.parent.blit(self.plate, self.pos)

    def activate(self):
        self.active = True

    def deactivate(self):
        self.active = False
from pygame import Surface, Color
from pygame.locals import *

from esp_hadouken.GameChild import *
from Cell import *

class NamePrompt(GameChild, Surface):

    cell_count = 3
    transparent_color = Color("brown")

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.init_surface()
        self.subscribe_to_events()
        self.add_cells()
        self.deactivate()

    def init_surface(self):
        size = self.get_configuration()["scoreboard-prompt-dimensions"]
        Surface.__init__(self, size)
        self.set_transparent()
        rect = self.get_rect()
        rect.center = self.parent.get_rect().center
        self.rect = rect

    def set_transparent(self):
        color = self.transparent_color
        self.set_colorkey(color)
        self.fill(color)

    def subscribe_to_events(self):
        self.subscribe_to(KEYDOWN, self.respond_to_key)

    def respond_to_key(self, event):
        if self.active:
            key = event.key
            if key >= K_a and key <= K_z:
                self.get_active_cell().set_char(key)
                self.change_active_cell(1)
                self.parent.update()
            elif key == K_BACKSPACE:
                if self.get_active_cell().is_blank():
                    self.change_active_cell(-1)
                self.get_active_cell().reset()
                self.parent.update()

    def get_active_cell(self):
        return self.cells[self.active_cell_index]

    def change_active_cell(self, increment):
        limit = len(self.cells) - 1
        index = self.active_cell_index + increment
        if index > limit:
            index = limit
        elif index < 0:
            index = 0
        self.active_cell_index = index

    def add_cells(self):
        cells = []
        for ii in range(self.cell_count):
            cells.append(Cell(self, ii))
        self.cells = cells
        self.active_cell_index = 0

    def activate(self):
        self.active = True

    def deactivate(self):
        self.active = False

    def update(self):
        if self.active:
            self.draw()

    def draw(self):
        self.parent.blit(self, self.rect)

    def get_initials(self):
        return "".join(map(str, self.cells))
from pygame import Surface, Color
from pygame.locals import *

from esp_hadouken.GameChild import *
from esp_hadouken.Font import *

class Cell(GameChild, Surface):

    def __init__(self, parent, index):
        GameChild.__init__(self, parent)
        self.index = index
        self.init_surface()
        self.reset()

    def __str__(self):
        return chr(self.char).upper()

    def init_surface(self):
        size = self.get_configuration()["scoreboard-prompt-dimensions"]
        margin = self.get_margin()
        width = size[0] / self.parent.cell_count - margin
        Surface.__init__(self, (width, size[1]))
        rect = self.get_rect()
        rect.left = (self.get_width() + margin) * self.index + margin / 2
        self.rect = rect

    def get_margin(self):
        return self.get_configuration()["scoreboard-prompt-margin"]

    def reset(self):
        self.set_char(self.get_blank_char())

    def get_blank_char(self):
        return ord(self.get_configuration()["scoreboard-prompt-blank-char"])

    def set_char(self, char):
        self.char = char
        self.set_color()
        self.draw()

    def set_color(self):
        char = self.char
        if char == self.get_blank_char():
            color = Color(
                self.get_configuration()["scoreboard-prompt-blank-color"])
        else:
            color = self.get_glyph_palette()[char - K_a]
        self.color = color

    def activate(self):
        self.active = True

    def deactivate(self):
        self.active = False

    def draw(self):
        self.fill(self.color)
        self.render_char()
        self.parent.blit(self, self.rect)

    def render_char(self):
        config = self.get_configuration()
        size = config["scoreboard-prompt-text-size"]
        color = Color(config["scoreboard-prompt-text-color"])
        text = Font(self, size).render(str(self), True, color)
        rect = text.get_rect()
        rect.center = self.get_rect().center
        self.blit(text, rect)

    def is_blank(self):
        return self.char == self.get_blank_char()
54.81.71.219
54.81.71.219
54.81.71.219
 
June 7, 2018


↠ RSS Feed ↞