Beispiel #1
0
def r_update_iris_in(self, complete):
    transition_sprite = self.rd["t_sprite"]
    w = transition_sprite.width
    h = transition_sprite.height

    if self.rd["t_arg"]:
        x, y = self.rd["t_arg"]
    else:
        x = w / 2
        y = h / 2

    r = int(math.hypot(max(x, sge.game.width - x),
                       max(y, sge.game.height - y)) * (1 - complete))
    eraser = sge.Sprite(width=w, height=h)
    eraser_eraser = sge.Sprite(width=w, height=h)
    eraser_eraser.draw_circle(x, y, r, fill=sge.Color((0, 0, 0, 255)))

    eraser.draw_lock()
    eraser.draw_rectangle(0, 0, w, h, fill=sge.Color((0, 0, 0, 255)))
    eraser.draw_sprite(eraser_eraser, 0, 0, 0,
                       blend_mode=sge.BLEND_RGBA_SUBTRACT)
    eraser.draw_unlock()

    transition_sprite.draw_sprite(eraser, 0, 0, 0,
                                  blend_mode=sge.BLEND_RGBA_SUBTRACT)
Beispiel #2
0
    def project_text(self,
                     font,
                     text,
                     x,
                     y,
                     z,
                     width=None,
                     height=None,
                     color=sge.Color("black"),
                     halign="left",
                     valign="top",
                     anti_alias=True):
        """
        Project text onto the room.

        Arguments:

        - ``x`` -- The horizontal location relative to the room to
          project the text.
        - ``y`` -- The vertical location relative to the room to project
          the text.
        - ``z`` -- The Z-axis position of the projection in the room.

        See the documentation for :meth:`sge.Sprite.draw_text` for more
        information.
        """
        if not isinstance(color, sge.Color):
            e = "`{}` is not a sge.Color object.".format(repr(color))
            raise TypeError(e)

        sprite = sge.Sprite.from_text(font, text, width, height, color, halign,
                                      valign, anti_alias)
        self.project_sprite(sprite, 0, x, y, z)
Beispiel #3
0
def r_update_fade(self, complete):
    transition_sprite = self.rd["t_sprite"]
    w = transition_sprite.width
    h = transition_sprite.height
    if complete < 0.5:
        diff = (complete - self.rd["t_complete_last"]) * 2
        c = sge.Color([int(round(diff * 255))] * 3)
        darkener = sge.Sprite(width=w, height=h)
        darkener.draw_rectangle(0, 0, w, h, c)
        transition_sprite.draw_sprite(darkener, 0, 0, 0,
                                      blend_mode=sge.BLEND_RGB_SUBTRACT)
    else:
        complete = (complete - 0.5) * 2
        c = sge.Color((0, 0, 0, int(round(255 - complete * 255))))
        transition_sprite.draw_clear()
        transition_sprite.draw_rectangle(0, 0, w, h, fill=c)
Beispiel #4
0
def r_update_dissolve(self, complete):
    transition_sprite = self.rd["t_sprite"]
    w = transition_sprite.width
    h = transition_sprite.height
    diff = complete - self.rd["t_complete_last"]
    c = sge.Color((0, 0, 0, int(round(diff * 255))))
    eraser = sge.Sprite(width=w, height=h)
    eraser.draw_rectangle(0, 0, w, h, c)
    transition_sprite.draw_sprite(eraser, 0, 0, 0,
                                  blend_mode=sge.BLEND_RGBA_SUBTRACT)
Beispiel #5
0
def r_update_wipe_downright(self, complete):
    transition_sprite = self.rd["t_sprite"]
    w = transition_sprite.width
    h = transition_sprite.height
    x = w * complete * 2
    y = w * complete * 2
    eraser = sge.Sprite(width=w, height=h)
    eraser.draw_polygon([(0, 0), (x, 0), (0, y)],
                        fill=sge.Color((0, 0, 0, 255)), anti_alias=True)
    transition_sprite.draw_sprite(eraser, 0, 0, 0,
                                  blend_mode=sge.BLEND_RGBA_SUBTRACT)
Beispiel #6
0
    def render(self, text, antialias, color, background=None):
        w = (self.width + self.hsep) * len(text)
        h = self.height + self.vsep
        xscale = (self.width /
                  self.sprite.width if self.sprite.width > 0 else 1)
        yscale = (self.height /
                  self.sprite.height if self.sprite.height > 0 else 1)
        surf = pygame.Surface((w, h), pygame.SRCALPHA)
        surf.fill(pygame.Color(0, 0, 0, 0))
        if not isinstance(color, pygame.Color):
            color = pygame.Color(color)
        sge_color = sge.Color((color.r, color.g, color.b, color.a))

        for i in six.moves.range(len(text)):
            if text[i] in self.chars:
                cimg = s_get_image(self.sprite,
                                   self.chars[text[i]],
                                   xscale=xscale,
                                   yscale=yscale,
                                   blend=sge_color)
                surf.blit(cimg, (i * (self.width + self.hsep), 0))
            elif text[i].swapcase() in self.chars:
                cimg = s_get_image(self.sprite,
                                   self.chars[text[i].swapcase()],
                                   xscale=xscale,
                                   yscale=yscale,
                                   blend=sge_color)
                surf.blit(cimg, (i * (self.width + self.hsep), 0))

        if background is None:
            return surf
        else:
            rsurf = pygame.Surface((w, h), pygame.SRCALPHA)
            rsurf.fill(background)
            rsurf.blit(surf, (0, 0))
            return rsurf
Beispiel #7
0
def r_update_pixelate(self, complete):
    transition_sprite = self.rd["t_sprite"]
    w = transition_sprite.width
    h = transition_sprite.height
    smooth = sge.game.scale_smooth
    sge.game.scale_smooth = False

    if complete < 0.8:
        complete *= 1.25
        swidth = max(1, w * (1 - complete))
        sheight = max(1, h * (1 - complete))
        transition_sprite.width = swidth
        transition_sprite.height = sheight
        transition_sprite.width = w
        transition_sprite.height = h
    else:
        diff = (complete - self.rd["t_complete_last"]) * 5
        c = sge.Color((0, 0, 0, int(round(diff * 255))))
        eraser = sge.Sprite(width=w, height=h)
        eraser.draw_rectangle(0, 0, w, h, c)
        transition_sprite.draw_sprite(eraser, 0, 0, 0,
                                      blend_mode=sge.BLEND_RGBA_SUBTRACT)

    sge.game.scale_smooth = smooth
Beispiel #8
0
    def __init__(self,
                 objects=(),
                 width=None,
                 height=None,
                 views=None,
                 background=None,
                 background_x=0,
                 background_y=0,
                 object_area_width=None,
                 object_area_height=None):
        """
        Arguments:

        - ``views`` -- A list containing all :class:`sge.View` objects
          in the room.  If set to :const:`None`, a new view will be
          created with ``x=0``, ``y=0``, and all other arguments
          unspecified, which will become the first view of the room.
        - ``background`` -- The :class:`sge.Background` object used.  If
          set to :const:`None`, a new background will be created with no
          layers and the color set to black.

        All other arguments set the respective initial attributes of the
        room.  See the documentation for :class:`sge.Room` for more
        information.
        """
        self.rd = {}
        self.width = width if width is not None else sge.game.width
        self.height = height if height is not None else sge.game.height
        self.rd["swidth"] = self.width
        self.rd["sheight"] = self.height

        if object_area_width is None:
            object_area_width = sge.game.width
        if object_area_height is None:
            object_area_height = sge.game.height

        self.__object_area_width = object_area_width
        self.__object_area_height = object_area_height
        self.background_x = background_x
        self.background_y = background_y
        self.alarms = {}
        self.rd["new_objects"] = []
        self.rd["projections"] = []

        if views is not None:
            self.views = list(views)
        else:
            self.views = [sge.View(0, 0)]

        if background is not None:
            self.background = background
        else:
            self.background = sge.Background((), sge.Color("black"))

        self.rd["started"] = False

        self.objects = []
        r_set_object_areas(self)

        self.add(sge.game.mouse)
        for obj in objects:
            self.add(obj)