def on_spawn(self, tileset: TilesetAsset, text: str = '', scale: int = 1, layer: int = 0, line_height: int = 4): """ Creates text (using a sprite sheet) to be rendered. """ # the spacing between each sprite self.charSpacing: int = 0 # the spacing between each line self.lineHeight: int = line_height # the scaling of the text (as int to keep pixel perfect) self.scale: int = scale # location marker representing current line and column self.loc: Vector = Vector(0, 0) # the sprite sheet currently in use self.sheet: TilesetAsset = tileset # the layer to draw this text self.layer: int = layer self.sprites: t.List[Sprite] = [] self._text = text if self._text != '': self.load_text(self._text)
def position(self, position: Union[tuple, Vector]): """ Set the world position of this object. Args: pos (Union[tuple, Vector]): [description] """ self._pos = Vector(position) self.on_position_change()
def __init__(self, *args, pos: tuple, **kwargs): """ Initializes a Component. Args: pos (tuple, optional): the initial world position of the object """ super(GameObject, self).__init__(*args, **kwargs) self._pos: Vector = Vector(pos)
def local_position(self) -> Vector: """ Get or set the position of this component with respect to the parent. If this component is the top-most in hierarchy (the parent), the position retrieved will be with respect to world-space. Otherwise, it will be with respect to the parent of this component (local). """ if self.parent is None: return self.position else: a = self.position b = self.root.position return Vector(a.x - b.x, a.y - b.y)
def position(self, position: tuple): """ Overrides `GameObject.position` setter method Args: position (tuple): the new position of this component """ a: Vector = self.position b: Vector = Vector(position) diff = b - a GameObject.position.fset(self, b) # type: ignore for child in self.children: child.position += diff
class AnimationFrame: """ A class describing a frame of an animation. Args: image (ImageAsset): the image to display duration (float): the amount of time to display this image for (in seconds) flip_x (bool): if true, flip this image horizontally flip_y (bool): if true, flip this image vertically """ image: ImageAsset duration: float flip_x: bool = False flip_y: bool = False offset: Vector = Vector(0, 0)
def on_spawn(self, image: ImageAsset, scale: float = 1, layer: int = 0): """ A sprite object. These are loaded from an image. Args: img ([type]): the image to use batch ([type], optional): the pyglet batch to render this sprite. Defaults to None. """ self._image = image self._group = SpriteGroup(image) self.vertex_list = self.scene.batch.pyglet_batch.add_indexed( 4, pyglet.gl.GL_TRIANGLES, self._group, [0, 1, 2, 0, 2, 3], 'position3f', # FIXME: 'color3B' (255, 255, 255) higher than (1.0, 1.0, 1.0)? ('color3f', (1.0, 1.0, 1.0) * 4), 'uv2f') self._scale = scale # offset of position due to inverse scaling self._offset = Vector(0, 0) self.is_flipped_x = False self.is_flipped_y = False self._scale_x, self._scale_y = 1, 1 self._width, self._height = self.orig_width, self.orig_height # texture coordinates self._s, self._t = (0, 1), (0, 1) self.update_vertex_data()
def offset(self) -> Vector: x, y = tuple(self._offset) if self.is_flipped_x: x *= -1 if self.is_flipped_y: y *= -1 return Vector(x, y)
def test_comparisons(): assert vec == (0, 0) assert vec == Vector(0, 0)
def test_operations(): assert vec + (1, 1) == (1, 1) assert vec + Vector(1, 1) == (1, 1) assert Vector(1, 1) * 2 == (2, 2)
from konkyo.structs.vector import Vector vec = Vector(0, 0) def test_comparisons(): assert vec == (0, 0) assert vec == Vector(0, 0) def test_operations(): assert vec + (1, 1) == (1, 1) assert vec + Vector(1, 1) == (1, 1) assert Vector(1, 1) * 2 == (2, 2)