コード例 #1
0
def draw_text_wrapped(target,
                      text,
                      pos,
                      font,
                      color=c.white,
                      word_wrap_width=None):
    if len(text) == 0:
        line_count = 0

    line_spacing = font.get_linesize()
    lines = util.split_text(text, font, word_wrap_width=word_wrap_width)
    line_count = len(lines)
    text_surface = Surface(Vec(word_wrap_width, line_spacing * line_count))
    text_surface.set_colorkey(c.black)
    text_surface.fill(c.black)

    for line_number, line in enumerate(lines):

        draw_surface(target=text_surface,
                     surface=Surface.from_pgsurface(
                         font.render(line, True, color)),
                     pos=Vec(0, line_number * line_spacing))

    draw_surface(target=target, surface=text_surface, pos=pos)

    return line_count
コード例 #2
0
 def __init__(self,
              start_pos=Vec(0, 0),
              end_pos=Vec(0, 0),
              jerk=1.0,
              duration=1):
     self.start_pos = start_pos
     self.end_pos = end_pos
     self.jerk = jerk
     self.duration = duration
コード例 #3
0
def draw_text(target, color, pos, text, font, x_center=True, y_center=True):
    text_pg_surface = font.render(text, True, color)
    text_surface = Surface.from_pgsurface(text_pg_surface)

    width, height = text_surface.size
    if x_center is True:
        x = pos.x - width / 2
    else:
        x = pos.x
    if y_center is True:
        y = pos.y - height / 2
    else:
        y = pos.y

    draw_surface(target=target, surface=text_surface, pos=Vec(x, y))

    return Rect(Vec(x, y), text_surface.size)
コード例 #4
0
def draw_surface(target, surface, pos, x_align=AlignX.Left, y_align=AlignY.Up):
    aligned_pos = Vec(pos.x, pos.y)

    aligned_pos -= surface.anchor

    if x_align == AlignX.Center:
        aligned_pos.x -= surface.width / 2
    elif x_align == AlignX.Right:
        aligned_pos.x -= surface.width

    if y_align == AlignY.Center:
        aligned_pos.y -= surface.height / 2
    if y_align == AlignY.Down:
        aligned_pos.y -= surface.height

    target._pg_surface.blit(surface._pg_surface, aligned_pos.tuple)

    # Return extent of drawn surface
    size = Vec(surface.width, surface.height)
    return Rect(aligned_pos, size)
コード例 #5
0
    def pos(self, t):

        x = (1 - pow(t, self.jerk)) * self.start_pos.x + (pow(
            t, self.jerk)) * self.end_pos.x
        y = (1 - pow(t, self.jerk)) * self.start_pos.y + (pow(
            t, self.jerk)) * self.end_pos.y
        #if t > 0:
        # if(self.start_pos.x != self.end_pos.x):
        # 	x = math.floor((1-pow(t,self.jerk))*self.start_pos.x + pow(t,self.jerk)*self.end_pos.x)
        # if(self.start_pos.y != self.end_pos.y):
        # 	y = math.floor((1-pow(t,self.jerk))*self.start_pos.y + pow(t,self.jerk)*self.end_pos.y)

        return Vec(x, y)
コード例 #6
0
    def rect(self):
        sprite = self._sprites[self.cur_sprite_index]
        size = Vec(sprite.get_width(), sprite.get_height())
        return Rect(pos=self.cur_pos, size=size)

    # def __deepcopy__(self, memo):
    # 	other = Animation(	duration=self.duration,
    # 						tweens=self._tweens,
    # 						anchor_points=self.anchor_points,
    # 						loop=self.loop)

    # 	other._sprites = deepcopy(self._sprites)
    # 	other._frames = copy(self._frames)
    # 	other._tween_start_frames = copy(self._tween_start_frames)

    # 	return othe
コード例 #7
0
    def from_string(cls, s):
        name_of_owner = "<NO OWNER NAME>"
        name_of_action = "<NO ACTION NAME>"
        duration = 1
        _sprites = []
        sprite_lengths = []
        _tweens = []
        anchor_points = []
        loop = False

        #Warrior's Rest
        # 	duration is 60
        # 	has tween
        # 		duration is 60
        # 		starts at (0,0)
        # 		ends at (0,0)
        # 		jerk is 1.0
        # 	has sub-animation
        # 		duration is 60
        # 		sprite is "WarriorIdle.png"
        # 		anchor is bottom left

        cur_tween = None
        in_sub_animation = False
        cur_sub_index = 0

        for line in s.splitlines():

            # Match possessive unit name with action name
            # ex: Warrior's Strike
            match = re.search('^([a-zA-Z]*)\'s (.*)', line.rstrip())
            if match:
                name_of_owner = match.group(1)
                name_of_action = match.group(2)
                continue

            # Match duration of animation
            line_match = re.search('^\tduration is (-*[0-9]+)', line.rstrip())
            if line_match:
                duration = int(line_match.group(1))
                continue
            # Match beginning of tween data
            line_match = re.search('^\thas tween', line.rstrip())
            if line_match:
                cur_tween = Tween()
                if in_sub_animation == True:
                    cur_sub_index += 1
                    in_sub_animation = False
                continue
            # Match beginning of sub-animation data
            line_match = re.search('^\thas sub-animation', line.rstrip())
            if line_match:
                in_sub_animation = True
                if cur_tween != None:
                    _tweens.append(cur_tween)
                    cur_tween = None
                continue
            if cur_tween != None:
                # Match duration length of current tween
                line_match = re.search('^\t\tduration is (-*[0-9]+)',
                                       line.rstrip())
                if line_match:
                    cur_tween.duration = int(line_match[1])
                    continue
                # Match start_pos of current tween
                line_match = re.search(
                    '^\t\tstarts? (?:at )?\((-*[0-9]+),(-*[0-9]+)\)',
                    line.rstrip())
                if line_match:
                    cur_tween.start_pos = Vec(int(line_match[1]),
                                              int(line_match[2]))
                    continue
                # Match end_pos of current tween
                line_match = re.search(
                    '^\t\tends? (?:at )?\((-*[0-9]+),(-*[0-9]+)\)',
                    line.rstrip())
                if line_match:
                    cur_tween.end_pos = Vec(int(line_match[1]),
                                            int(line_match[2]))
                    continue
                # Match jerk of current tween
                line_match = re.search('^\t\tjerk is (-*[0-9]+\.[0-9]+)',
                                       line.rstrip())
                if line_match:
                    cur_tween.jerk = float(line_match[1])
                    continue
            elif in_sub_animation == True:
                # TODO: This is vulnerable to incorrectly formatted animation files,
                # 		because it doesn't check that each sub-animation only has 1
                #		duration, sprite path, anchor

                # Match duration of current sub-animation
                line_match = re.search('^\t\tduration is ([0-9]+)',
                                       line.rstrip())
                if line_match:
                    sprite_lengths.append(int(line_match[1]))
                    continue
                # Match sprite (filepath) of current sub-animation
                line_match = re.search('^\t\tsprite is \"(.*)\"',
                                       line.rstrip())
                if line_match:
                    _sprites.append(Surface.from_file(filepath=line_match[1]))
                    continue
                # Match sprite (filepath) of current sub-animation
                line_match = re.search('^\t\tanchor is (.*)', line.rstrip())
                if line_match:
                    if line_match[1] == "bottom left":
                        anchor_points.append(
                            Vec(0, _sprites[cur_sub_index].height))
                        continue

        new = Animation(duration=duration,
                        sprites=_sprites,
                        sprite_lengths=sprite_lengths,
                        tweens=_tweens,
                        anchor_points=anchor_points,
                        loop=loop)

        return new
コード例 #8
0
 def __init__(self, size):
     self._pg_surface = pg.Surface(size.tuple)
     self.filepath = None
     self.anchor = Vec(0, 0)
コード例 #9
0
 def size(self):
     return Vec(self.width, self.height)
コード例 #10
0
 def from_pgsurface(cls, pg_surface):
     new = Surface(size=Vec(0, 0))
     new._pg_surface = pg_surface
     return new
コード例 #11
0
ファイル: constants.py プロジェクト: boulware/trait-game
dark_grey = (50, 50, 50)
dkgrey = (30, 30, 30)
ltgrey = (150, 150, 150)
very_dark_blue = (0, 0, 40)
purple = (128, 0, 128)
gold = (255, 215, 0)
pink = (255, 200, 200)
blue_green = (0, 150, 150)

# Game parameters
skill_slots = 4

# Editor layout parameters

general_ui_layout = {
    'tabs_origin': Vec(0, 0),
    'tab_size': Vec(100, 50),
}


class EditableType(Enum):
    Unit = 0
    Skill = 1
    Battle = 2


editable_type_strings = ["Unit", "Skill", "Battle"]

# We could probably do full layout information here.
# a dict that maps property names to a rect, which positions
# the element.