def draw_ellipse(self,
                     color,
                     position,
                     size=None,
                     border_width=0,
                     anchor='topleft'):
        """
        Draws an ellipse on this image.

        :param color: a three-tuple of RGB values ranging from 0-255. Example:
                      (255, 128, 0) is orange.
        :type color: a three-tuple of ints.
        :param position: The starting position of the ellipse (top-left corner).
                         If position is a Rect, then size should be `None`.
        :type position: :class:`Vec2D <spyral.Vec2D>` or
                        :class:`Rect <spyral.Rect>`
        :param size: The size of the ellipse; should not be given if position is
                     a rect.
        :type size: :class:`Vec2D <spyral.Vec2D>`
        :param int border_width: The width of the ellipse. If it is 0, the
                          ellipse is filled with the color specified.
        :param str anchor: The anchor parameter is an
                           :ref:`anchor position <ref.anchors>`.
        :returns: This image.
        """
        if size is None:
            rect = spyral.Rect(position)
        else:
            rect = spyral.Rect(position, size)
        offset = self._calculate_offset(anchor, rect.size)
        pygame.draw.ellipse(self._surf, color, (rect.pos + offset, rect.size),
                            border_width)
        self._version += 1
        spyral.util.scale_surface.clear(self._surf)
        return self
Beispiel #2
0
    def __init__(self, scene):
        super(Scoreboard, self).__init__()
        self.scene = scene

        self.curr_score = 0
        self.curr_shots = 0

        self.curr_x_input = ""
        self.curr_y_input = ""

        self.score_posn = (1000, 100) # @TODO: magic

        self.inputs_text_posn = (1000, self.score_posn[1] + FONT_SIZE) # @TODO: magic

        self.x_input_posn = (self.inputs_text_posn[0] + 10, self.score_posn[1] + FONT_SIZE) # TODO: magic
        self.y_input_posn = (self.inputs_text_posn[0] + 68, self.score_posn[1] + FONT_SIZE) # TODO: magic

        self.submit_text_posn = (1000, self.y_input_posn[1] + FONT_SIZE) # @TODO: magic
        self.submit_input_posn = (1000 + 15, self.y_input_posn[1] + FONT_SIZE) # @TODO: magic

        self.input_rect_size = (45, 30) # @TODO: magic
        self.submit_rect_size = (95, 30) # @TODO: magic

        self.x_input_rect = spyral.Rect(self.x_input_posn, self.input_rect_size)
        self.y_input_rect = spyral.Rect(self.y_input_posn, self.input_rect_size)
        self.submit_input_rect = spyral.Rect(self.submit_input_posn, self.submit_rect_size)

        self.highlighted_coord = "x"

        self.redraw_all_pieces()
Beispiel #3
0
 def _set_collision_box(self):
     """
     Updates this View's collision box.
     """
     if self._mask is not None:
         pos = self._mask.topleft - self._offset
         area = spyral.Rect((0, 0), self._mask.size)
     else:
         pos = self._pos - self._offset
         area = spyral.Rect((0, 0), self.size)
     c = spyral.util._CollisionBox(pos, area)
     warped_box = self._parent()._warp_collision_box(c)
     self._scene()._set_collision_box(self, warped_box.rect)
Beispiel #4
0
    def _draw(self):
        """
        Internal method for generating this sprite's blit, unless it is
        invisible or currently static. If it has aged sufficiently or is being
        forced, it will become static; otherwise, it ages one step.
        """
        if not self.visible:
            return
        if self._image is None:
            raise spyral.NoImageError("A sprite must have an image"
                                      " set before it can be drawn.")
        if self._image_version != self._image._version:
            self._image_version = self._image._version
            self._recalculate_transforms()
            self._expire_static()
        if self._static:
            return

        area = spyral.Rect(self._transform_image.get_rect())
        b = spyral.util._Blit(self._transform_image, self._pos - self._offset,
                              area, self._computed_layer, self._blend_flags,
                              False)

        if self._make_static or self._age > 4:
            b.static = True
            self._make_static = False
            self._static = True
            self._parent()._static_blit(self, b)
            return
        self._parent()._blit(b)
        self._age += 1
Beispiel #5
0
    def __init__(self, scene):
        spyral.Sprite.__init__(self, scene)
        self.image = spyral.Image("images/mati2.png")
        self.layer = "fondo"

        self.scale = 2
        self.pos = (self.width, self.width)
        self.anchor = "midbottom"
        self.velocidad = 100.0 * self.scale.x

        self.pensamiento = None # Empezamos sin pensar

        self.animando = False
        self.moviendo = False
        self.cajita = spyral.Rect(self.width/2.0, self.height,
                             self.scene.width - self.width,
                             self.scene.height - self.height)

        self.estado = "despertando"

        # posicion del mouse inicial
        self.pos_mouse_anterior = self.scene.canvas.get_pointer()

        spyral.event.register("director.update", self.actualizar, scene=scene)
        spyral.event.register("Gato.image.animation.end", self.fin_animacion, scene=scene)
        spyral.event.register("Gato.pos.animation.end", self.fin_movimiento, scene=scene)
Beispiel #6
0
 def _get_rect(self):
     """
     A :class:`Rect <spyral.Rect>` representing the position and size of
     this View. Can be set through a ``Rect``, a 2-tuple of position and
     size, or a 4-tuple.
     """
     return spyral.Rect(self._pos, self.size)
Beispiel #7
0
 def check_pos(self, pos):
     r = spyral.Rect(self.pos.x + 20, self.pos.y + 20, self.pos.x + 100,
                     self.pos.y + 100)
     if r.collide_point(pos):
         event = spyral.event.Event(
             ubicacion=spyral.Vec2D(self.ROW, self.COL))
         spyral.event.queue("Tablero.movimiento", event)
Beispiel #8
0
    def clip(self, rect):
        """
        Applies any necessary cropping to this blit

        :param rect: The new maximal size of the blit.
        :type rect: :class:`Rect <spyral.Rect>`
        """
        self.area = self.area.clip(spyral.Rect(rect))
 def _recalculate_mask(self):
     """
     Forces a recomputation of the widget's mask, based on the position,
     internal boxes size, and the padding.
     """
     self.mask = spyral.Rect(self.x + self.padding, self.y + self.padding,
                             self.box_width + self.padding,
                             self._box_height + self.padding)
Beispiel #10
0
 def get_rect(self):
     """
     Returns a :ref:`rect <spyral_Rect>` representing where this
     sprite will be drawn.
     """
     return spyral.Rect(
         (self._pos[0] - self._offset[0], self._pos[1] - self._offset[1]),
         self.size)
Beispiel #11
0
 def _warp_collision_box(self, box):
     """
     Transforms the given collision box according to this view's scaling,
     cropping, and offset; then passes the box to this boxes parent.
     """
     box.position += self.pos
     box.apply_scale(self.scale)
     if self.crop:
         box.clip(spyral.Rect((0, 0), self.crop_size))
     return self._parent()._warp_collision_box(box)
    def __init__(self, scene, player):
        spyral.Sprite.__init__(self, scene)
        self.vel = 20
        self.anchor = "center"

        self.layer = "carros"

        self.girando = False
        self.moviendo = False
        self.frenando = False

        self.bonus = pygame.mixer.Sound('sounds/BonusCube_0.ogg')

        self.puntos = 4
        self.player = player
        if player == 1:
            self.x, self.y = spyral.Vec2D(scene.size) / 8.0
            spyral.event.register("input.keyboard.down.s", self.frena)
            spyral.event.register("input.keyboard.down.w", self.avanza)
            spyral.event.register("input.keyboard.down.a", self.izquierda)
            spyral.event.register("input.keyboard.down.d", self.derecha)
            # game keys
            spyral.event.register("input.keyboard.down.keypad_2", self.frena)
            spyral.event.register("input.keyboard.down.keypad_8", self.avanza)
            spyral.event.register("input.keyboard.down.keypad_4",
                                  self.izquierda)
            spyral.event.register("input.keyboard.down.keypad_6", self.derecha)
            self.image = spyral.Image("images/etoys-car.png")
            self.angle = 0
        elif player == 2:
            self.x, self.y = spyral.Vec2D(scene.size) * 0.875
            spyral.event.register("input.keyboard.down.down", self.frena)
            spyral.event.register("input.keyboard.down.up", self.avanza)
            spyral.event.register("input.keyboard.down.left", self.izquierda)
            spyral.event.register("input.keyboard.down.right", self.derecha)
            # game keys
            spyral.event.register("input.keyboard.down.keypad_3", self.frena)
            spyral.event.register("input.keyboard.down.keypad_9", self.avanza)
            spyral.event.register("input.keyboard.down.keypad_7",
                                  self.izquierda)
            spyral.event.register("input.keyboard.down.keypad_1", self.derecha)
            self.image = spyral.Image("images/etoys-car-green.png")
            self.angle = math.pi

        size = spyral.Vec2D(self.image.size)
        self.mask = spyral.Rect(size / 8, size * 0.875)

        spyral.event.register("director.update", self.corrige_dir)
        spyral.event.register("director.pre_render", self.chequea_choque)

        spyral.event.register("Carrito.angle.animation.end", self.fin_anim)
        spyral.event.register("Carrito.pos.animation.end", self.fin_mov)
        spyral.event.register("Carrito.vel.animation.end", self.fin_fren)
        spyral.event.register("Carrito.image.animation.end",
                              self.fin_explosion)
Beispiel #13
0
    def apply_scale(self, scale):
        """
        Applies the scaling factor to this blit.

        :param scale: The scaling factor
        :type scale: :class:`Vec2D <spyral.Vec2D>`
        """
        self.position = self.position * scale
        self.final_size = self.final_size * scale
        self.area = spyral.Rect(self.area.topleft * scale,
                                self.area.size * scale)
Beispiel #14
0
 def _static_blit(self, key, blit):
     """
     If this View is visible, applies offseting, scaling, and cropping
     before passing it up the transformation chain.
     """
     if self.visible:
         blit.position += self.pos
         blit.apply_scale(self.scale)
         if self.crop:
             blit.clip(spyral.Rect((0, 0), self.crop_size))
         self._parent()._static_blit(key, blit)
Beispiel #15
0
 def _set_state(self, state):
     old_value = self.value
     self._state = state
     if self.value != old_value:
         e = spyral.Event(name="changed", widget=self, form=self.form, value=self._get_value())
         self.scene._queue_event("form.%(form_name)s.%(widget)s.changed" %
                                     {"form_name": self.form.__class__.__name__,
                                      "widget": self.name},
                                 e)
     self.button.image = self._images[state]
     self.mask = spyral.Rect(self.pos, self.button.size)
     self._on_state_change()
Beispiel #16
0
 def _set_collision_box(self):
     """
     Updates this sprite's collision box.
     """
     if self.image is None:
         return
     if self._mask is None:
         area = spyral.Rect(self._transform_image.get_rect())
     else:
         area = self._mask
     c = spyral.util._CollisionBox(self._pos - self._offset, area)
     warped_box = self._parent()._warp_collision_box(c)
     self._scene()._set_collision_box(self, warped_box.rect)
Beispiel #17
0
    def crop(self, position, size=None):
        """
        Removes the edges of an image, keeping the internal rectangle specified
        by position and size.

        :param position: The upperleft corner of the internal rectangle that
                         will be preserved.
        :type position: a :class:`Vec2D <spyral.Vec2D>` or a
                        :class:`Rect <spyral.Rect>`.
        :param size: The size of the internal rectangle to preserve. If a Rect
                     was passed in for position, this should be None.
        :type size: :class:`Vec2D <spyral.Vec2D>` or None.
        :returns: This image.
        """
        if size is None:
            rect = spyral.Rect(position)
        else:
            rect = spyral.Rect(position, size)
        new = _new_spyral_surface(size)
        new.blit(self._surf, (0, 0), (rect.pos, rect.size))
        self._surf = new
        self._version += 1
        return self
Beispiel #18
0
 def _get_rect(self):
     """
     Returns a :class:`Rect <spyral.Rect>` representing the position and size
     of this Sprite's image. Note that if you change a property of this rect
     that it will not actually update this sprite's properties:
     
     >>> my_sprite.rect.top = 10
     
     Does not adjust the y coordinate of `my_sprite`. Changing the rect will
     adjust the sprite however
     
     >>> my_sprite.rect = spyral.Rect(10, 10, 64, 64)
     """
     return spyral.Rect(self._pos, self.size)
Beispiel #19
0
 def _render_images(self):
     """
     Recreates the cached images of this widget (based on the
     **self._image_locations** internal variabel) and sets the widget's image
     based on its current state.
     """
     for state in self._states:
         if self._nine_slice:
             size = self._padding + self._content_size
             nine_slice_image = spyral.Image(self._image_locations[state])
             self._images[state] = spyral.image.render_nine_slice(nine_slice_image, size)
         else:
             self._images[state] = spyral.Image(self._image_locations[state])
     self.button.image = self._images[self._state]
     self.mask = spyral.Rect(self.pos, self.button.size)
     self._on_state_change()
Beispiel #20
0
    def __init__(self, scene):
        spyral.Sprite.__init__(self, scene)
        self.image = spyral.Image(filename="images/comodo.png")
        self.layer = "frente"
        self.pos = (0, scene.height - self.height)

        self.estado = "normal"
        self.cajita = spyral.Rect(0, 60, scene.width - self.width,
                                  scene.height - self.height)
        self.vida = 100

        spyral.event.register("input.keyboard.down.space", self.salto)
        spyral.event.register("input.keyboard.down.up", self.salto)
        spyral.event.register("Comodo.y.animation.end", self.fin_salto)
        spyral.event.register("Comodo.muere", self.muere)

        spyral.event.register("director.update", self.chequea)
        pygame.mixer.init()
        pygame.mixer.music.load("sounds/Harp.ogg")
        pygame.mixer.music.play(-1)
        self.flap = pygame.mixer.Sound('sounds/bird_flap.ogg')
Beispiel #21
0
 def finalize(self):
     self.rect = spyral.Rect(self.position, self.area.size)
 def _recalculate_mask(self):
     """
     Recalculate this widget's mask based on its size, position, and padding.
     """
     self.mask = spyral.Rect(self.pos, self.size + self.padding)
 def __init__(self, form, name):
     self.__style__ = form.__class__.__name__ + '.' + name
     self.name = name
     self.form = form
     spyral.View.__init__(self, form)
     self.mask = spyral.Rect(self.pos, self.size)
Beispiel #24
0
 def _get_rect(self):
     """
     Returns a :class:`Rect <spyral.Rect>` representing the position (0, 0)
     and size of this Scene.
     """
     return spyral.Rect((0, 0), self.size)
Beispiel #25
0
 def apply_scale(self, scale):
     self.position = self.position * scale
     self.area = spyral.Rect(self.area.topleft * scale,
                             self.area.size * scale)
Beispiel #26
0
 def real_rect(self):
     return spyral.Rect(self.rect.left - self.width/2.0,
                        self.rect.top - self.height,
                        self.width, self.height)
Beispiel #27
0
 def clip(self, rect):
     self.area = self.area.clip(spyral.Rect(rect))