Full API Documentation#

This is the top level init file for all of rubato.

Note

Every single class can be accessed through the top level or through the full module path.

game

The global game class that can be accessed anywhere. Initialized when rubato.init() is called.

Type:

Game

begin()[source]

Starts the main game loop.

Raises:

RuntimeError – Rubato has not been initialized before calling.

init(options={})[source]

Initializes rubato.

Parameters:

options (dict) – A game config. Defaults to the default config for Game.

Game#

The main game class. It controls everything in the game. The Display is where your game lives at a certain aspect ratio, The Screen is the actual size of the window which the user interacts with.

scenes#

The global scene manager.

Type:

SceneManager

radio#

The global radio system.

Type:

Radio

name#

The title of the game window.

Type:

str

fps#

The target fps of the game.

Type:

int

reset_display#

Controls whether or not the display should reset every frame.

Type:

bool

state#

The current state of the game.

Type:

STATE

class STATE[source]#

Bases: Enum

An enum to keep track of the state things

RUNNING: will run everything normally STOPPED: will quit the window PAUSED: will pause physics time calls. Please do not use this feature.

init(options={})[source]#

Initializes a game. Should only be called by rubato.init().

Parameters:

options (dict) – A game config. Defaults to the default config for Game.

constant_loop()[source]#

The constant game loop. Should only be called by rubato.begin().

update()[source]#

The update loop for the game. Called automatically every frame. Handles the game states. Will always process timed calls.

get_window_width()[source]#
Returns:

The height of the actual window (screen).

set_window_width(window_width)[source]#

Sets width of actual window (screen). :type window_width: int :param window_width: width clamped between the max display size initialized

rubato.init()

Return type:

None

get_window_height()[source]#
Returns:

The width of the actual window (screen).

set_window_height(window_height)[source]#

Sets height of actual window (screen). :type window_height: int :param window_height: height clamped between the max display size initialized

rubato.init()

Return type:

None

get_window_size()[source]#

The current size of the window

Returns:

A vector with x representing the width and y representing the height

Return type:

Vector

Input#

The Input module is the way you collect input from the user.

key#

The pygame key module.

Type:

pygame.key

mouse#

The pygame mouse module.

Type:

pygame.mouse

is_pressed(char)[source]#

Checks if a key is pressed.

Parameters:

char (str) – The name of the key to check.

Returns:

Whether or not the key is pressed.

Return type:

bool

mouse_over(center, dims=Vector(1, 1))[source]#

Checks if the mouse is inside a rectangle defined by its center and dimensions

Parameters:
  • center (Vector) – The center of the rectangle.

  • dims (Vector) – The dimensions of the rectangle. Defaults to Vector(1, 1).

Returns:

Whether or not the mouse is in the defined rectangle.

Return type:

bool

Radio#

The Radio module is a system used to communicate to all parts of the game. This is similar to event systems in other game engines.

To use this, first you need to listen for a specific key using the Radio.listen() function. Then from anywhere else in the code, you can broadcast that event key using the Radio.broadcast() function.

class Radio[source]#

Bases: object

Broadcast system manages all events and inter-class communication. Has a buffer system and a handler system.

events#

A list with all the event keys in the queue.

Type:

List[str]

listeners#

A dictionary with all of the active listeners.

Type:

dict[str, Callable]

__init__()[source]#

Initializes the Radio class

listen(event, func)[source]#

Creates an event listener and registers it.

Parameters:
  • event (str) – The event key to listen for.

  • func (Callable) – The function to run once the event is broadcast. It may take in a params dictionary argument.

register(listener)[source]#

Registers an event listener.

Parameters:

listener (Listener) – The listener object to be registered

broadcast(event, params)[source]#

Broadcast an event to be caught by listeners.

Parameters:
  • event (str) – The event key to broadcast.

  • params (dict) – A parameters dictionary

class Listener[source]#

Bases: object

The actual listener object itself.

event#

The event descriptor

Type:

str

callback#

The function called when the event occurs

Type:

Callable

registered#

Describes whether the listener is registered

Type:

bool

__init__(event, callback)[source]#
ping(params)[source]#

Calls the callback of this listener.

Parameters:

params (dict) – A parameters dictionary

remove()[source]#

Removes itself from the radio register.

Raises:

ValueError – Raises error when listener is not registered

Sound#

A fully functional, multi-channel sound system.

loaded_sounds()[source]#

A dictionary of all the loaded sounds. The keys are the filename.

Returns:

The returned dictionary.

Return type:

dict[str, pygame.mixer.Sound]

import_sound(rel_path, sound_name)[source]#

Imports a sound and saves it in the loaded_sounds dictionary with the key being the sound_name.

Parameters:
  • rel_path (str) – The relative path to the sound file you wish to import.

  • sound_name (str) – The name of the sound.

import_sound_folder(rel_path)[source]#

Imports a folder of sounds, saving each one in the loaded_sounds dictionary by filename.

Parameters:

rel_path (str) – The relative path to the folder you wish to import.

get_sound(sound_name)[source]#

Gets the sound based on the sound name.

Parameters:

sound_name (str) – The name of the sound.

Raises:

IdError – No sound is associated to the sound name.

Returns:

The sound.

Return type:

mixer.Sound

play_sound(sound_name, loops=0)[source]#

Plays a sound.

Parameters:
  • sound_name (str) – The name of the sound to play.

  • loops (int) – The number of times to loop a sound after the first play through. Use -1 to loop forever. Defaults to 0.

stop_sound(sound_name)[source]#

Stops a sound.

Parameters:

sound_name (str) – The name of the sound to stop.

Sprite#

The default Sprite class.

class Sprite[source]#

Bases: object

The base sprite class.

pos#

The current position of the sprite.

Type:

Vector

z_index#

The z_index of the sprite.

Type:

int

components#

All the components attached to this sprite.

Type:

List[Component]

__init__(options={})[source]#

Initializes a sprite.

Parameters:

options (dict) – A sprite config. Defaults to the default config for Sprite.

add(component)[source]#

Add a component to the sprite.

Parameters:

component (Component) – The component to add.

Raises:
Returns:

The current sprite

Return type:

Sprite

remove(comp_type)[source]#

Removes a component from the sprite.

Parameters:

comp_type (type) – The type of the component to remove.

Raises:

Warning – The component was not on the sprite and nothing was removed.

get(comp_type)[source]#

Gets a component from the sprite.

Parameters:

comp_type (type) – The type of the component to search for.

Returns:

The component if it was found or None if it wasn’t.

Return type:

Union[Component, None]

setup()[source]#

Run after initialization and before update loop begins

draw()[source]#

The draw loop

update()[source]#

The update loop

static center_to_tl(center, dims)[source]#

Converts center coordinates to top left coordinates

Parameters:
  • center (Vector) – The top left coordinate as a Vector

  • dims (Vector) – The width and the height of the item as a sprite as a Vector

Returns:

The new coordinates.

Return type:

Vector

Components#

The default Component class.

A component gives functionally to sprites.

class Component[source]#

Bases: object

A base component. Does nothing by itself.

sprite#

The sprite this component is attached to.

Type:

Sprite

required#

A list of components that are required by this component. (For example, a RigidBody needs a Hitbox).

Type:

List[type]

not_allowed#

A list of components that cannot be on the same Sprite. (For example, an Animation and an Image cannot be on the same Sprite)

Type:

List[type]

__init__()[source]#

Initializes a component

draw()[source]#

The draw loop

Return type:

None

update()[source]#

The main update loop for the component.

Return type:

None

setup()[source]#

Run after initialization and before update loop begins

Return type:

None

fixed_update()[source]#

The fixed update loop

Image#

The image component that renders an image from the filesystem.

class Image[source]#

Bases: Component

A component that handles Images.

image#

The pygame surface containing the image.

Type:

pygame.Surface

__init__(options={})[source]#

Initializes an Image

Parameters:

options (dict) – A Image config. Defaults to the default config for Image.

get_size()[source]#

Gets the current size of the frame.

Returns:

[description]

Return type:

[type]

scale(scale_factor)[source]#

Scales the image.

Parameters:

scale_factor (Vector) – The 2-d scale factor relative to it’s current size.

resize(new_size)[source]#

Resize the image to a given size in pixels.

Parameters:

new_size (Vector) – The new size of the image in pixels.

draw()[source]#

Draws the image if the z index is below the camera’s.

Parameters:

camera – The current Camera viewing the scene.

Animation#

Animations are a series of images that loop in a set loop

class Animation[source]#

Bases: Component

Made of a a dictionary holding the different states ie. running, idle, etc. each holding separate frames and their times.

rotation#

The rotation of the animation.

Type:

float

default_animation_length#

The default length of an animation in frames.

Type:

int

default_state#

The key of the default state. Defaults to None.

Type:

Union[str, None]

current_state#

The key of the current state. Defaults to “”.

Type:

str

animation_frames_left#

The number of animation frames left.

Type:

int

current_frame#

The current frame of the animation.

Type:

int

loop#

Whether the animation should loop. Defaults to False.

Type:

bool

__init__(options={})[source]#

Initializes an Animation.

Parameters:

options (dict) – A Animation config. Defaults to the default config for Animation.

property image: pygame.Surface#

The current image.

Returns:

The pygame surface holding the current image.

Return type:

Surface

property anim_frame: Image#

The current frame.

Returns:

The image representing the current frame.

Return type:

Image

scale(scale_factor)[source]#

Scales the Images to the given scale factor.

Parameters:

scale_factor (Vector) – The 2-d scale factor relative to it’s current size.

resize(new_size)[source]#

Resize the image to a given size in pixels.

Parameters:

new_size (Vector) – The new size of the image in pixels.

set_current_state(new_state, loop=False)[source]#

Set the current animation state.

Parameters:
  • new_state (str) – The key of the new current state.

  • loop (bool) – Whether to loop the state. Defaults to False.

Raises:

KeyError – The new_state key is not in the initialized states.

add_state(state_name, image_and_times)[source]#

Initializes a state to this animation component.

Parameters:
  • state_name (str) – The key used to reference this state.

  • image_and_times (Union[List[tuple], list]) – The list of images and times. Should be the output of the import_animation_folder function or a list containing tuples following the format: (Image, frame_number)

Raises:

Error – The animation frame tuple is invalid.

setup()[source]#

Run after initialization and before update loop begins

Return type:

None

draw()[source]#

The draw loop

static import_animation_folder(rel_path)[source]#

Imports a folder of images, creating rubato.Image for each one and placing it in a list by order in directory. Directory must be solely comprised of images.

Parameters:

rel_path (str) – The relative path to the folder you wish to import

Returns:

a list of rubato.Image s. Filled with all images in given directory.

Return type:

list

Rectangle#

Hitbox#

Various hitbox components that enable collisions

class Hitbox[source]#

Bases: Component

The basic hitbox

__init__()[source]#

Initializes a component

update()[source]#

The main update loop for the component.

draw()[source]#

The draw loop

bounding_box_dimensions()[source]#

Returns the dimensions of the bounding box surrounding the polygon.

Returns:

A vector with the x variable holding the width and the y variable holding the height.

Return type:

Vector

collide(other, callback=lambda c: ...)[source]#

A simple collision engine for most use cases.

Parameters:
  • other (Hitbox) – The other rigidbody to collide with.

  • callback (Callable) – The function to run when a collision is detected. Defaults to None.

Returns:

Returns a collision info object if a collision is detected or nothing if no collision is detected.

Return type:

Union[CollisionInfo, None]

class Polygon[source]#

Bases: Hitbox

A custom polygon class with an arbitrary number of vertices

verts#

A list of the vertices in the Polygon, in either clockwise or anticlockwise direction.

Type:

List[Vector]

scale#

The scale of the polygon.

Type:

Union[float, int]

__init__(options={})[source]#

Initializes a Polygon

Parameters:
  • verts – A list of the vertices in the Polygon.

  • pos – The position of the center of the Polygon as a function. Defaults to lambda: Vector(0, 0).

  • scale – The scale of the polygon. Defaults to 1.

  • rotation – The rotation angle of the polygon in degrees as a function. Defaults to lambda: 0.

static generate_rect(w=32, h=32)[source]#

Creates a rectangle from its dimensions.

Parameters:
  • w (int) – The width of the hitbox.

  • h (int) – The height of the hitbox.

Returns:

The vertices of the rectangle.

Return type:

List[Vector]

static generate_polygon(num_sides, radius=1)[source]#

Creates a normal polygon with a specified number of sides and an optional radius.

Parameters:
  • num_sides (int) – The number of sides of the polygon.

  • radius (Union[float, int]) – The radius of the polygon. Defaults to 1.

Raises:

SideError – Raised when the number of sides is less than 3.

Returns:

The vertices of the polygon.

Return type:

List[Vector]

property pos: Vector#

The getter method for the position of the Polygon’s center

Return type:

Vector

clone()[source]#

Creates a copy of the Polygon at the current position

Return type:

Polygon

transformed_verts()[source]#

Maps each vertex with the Polygon’s scale and rotation

Return type:

List[Vector]

real_verts()[source]#

Returns the a list of vertices in absolute coordinates

Return type:

List[Vector]

bounding_box_dimensions()[source]#

Returns the dimensions of the bounding box surrounding the polygon.

Returns:

A vector with the x variable holding the width and the y variable holding the height.

Return type:

Vector

draw()[source]#

The draw loop

class Rectangle[source]#

Bases: Polygon

_summary_

Parameters:

Polygon (_type_) – _description_

__init__(options)[source]#

Initializes a Polygon

Parameters:
  • verts – A list of the vertices in the Polygon.

  • pos – The position of the center of the Polygon as a function. Defaults to lambda: Vector(0, 0).

  • scale – The scale of the polygon. Defaults to 1.

  • rotation – The rotation angle of the polygon in degrees as a function. Defaults to lambda: 0.

class Circle[source]#

Bases: Hitbox

A custom circle class defined by a position, radius, and scale

radius#

The radius of the circle.

Type:

int

scale#

The scale of the circle.

Type:

int

__init__(options={})[source]#

Initializes a Circle

Parameters:
  • pos – The position of the circle as a function. Defaults to lambda: Vector(0, 0).

  • radius – The radius of the circle. Defaults to 1.

  • scale – The scale of the circle. Defaults to 1.

property pos: Vector#

The getter method for the position of the circle’s center

Return type:

Vector

clone()[source]#

Creates a copy of the circle at the current position

Return type:

Circle

transformed_radius()[source]#

Gets the true radius of the circle

Return type:

int

draw()[source]#

The draw loop

class CollisionInfo[source]#

Bases: object

A class that represents information returned in a successful collision

shape_a#

A reference to the first shape.

Type:

Union[Circle, Polygon, None]

shape_b#

A reference to the second shape.

Type:

Union[Circle, Polygon, None]

seperation#

The vector that would separate the two colliders.

Type:

Vector

__init__()[source]#

Initializes a Collision Info

class SAT[source]#

Bases: object

A general class that does the collision detection math between circles and polygons

static overlap(shape_a, shape_b)[source]#

Checks for overlap between any two shapes (Polygon or Circle)

Parameters:
  • shape_a (Hitbox) – The first shape.

  • shape_b (Hitbox) – The second shape.

Returns:

If a collision occurs, a CollisionInfo is returned. Otherwise None is returned.

Return type:

Union[CollisionInfo, None]

static circle_circle_test(shape_a, shape_b)[source]#

Checks for overlap between two circles

static polygon_polygon_test(shape_a, shape_b, flip=False)[source]#

Checks for overlap between two polygons

Return type:

Optional[CollisionInfo]

static perpendicular_axis(verts, index)[source]#

Finds a vector perpendicular to a side

Return type:

Vector

static project_verts(verts, axis)[source]#

Projects the vertices onto a given axis. Returns as a vector x is min, y is max

Return type:

Vector

RigidBody#

The Rigidbody component contains an implementation of rigidbody physics. They have hitboxes and can collide and interact with other rigidbodies.

class RigidBody[source]#

Bases: Component

A RigidBody implementation with built in physics and collisions. Rigidbodies require hitboxes.

static#

Whether or not the rigidbody is static (as in, it does not move).

Type:

bool

gravity#

The acceleration of the gravity that should be applied.

Type:

Vector

friction#

The friction coefficient of the Rigidbody (usually a a value between 0 and 1).

Type:

float

max_speed#

The maximum speed of the Rigidbody.

Type:

Vector

min_speed#

The minimum speed of the Rigidbody.

Type:

Vector

velocity#

The current velocity of the Rigidbody.

Type:

Vector

inv_mass#

The inverse of the mass of the Rigidbody (0 if the mass is infinite).

Type:

float

bounciness#

How bouncy the rigidbody is (usually a value between 0 and 1).

Type:

float

__init__(options={})[source]#

Initializes a Rigidbody.

Parameters:

options (dict) – A rigidbody config. Defaults to the default config for RigidBody

property mass: float#

The mass of the Rigidbody (readonly)

Return type:

float

physics()[source]#

The physics calculation

add_force(force)[source]#

Add a force to the Rigidbody.

Parameters:

force (Vector) – The force to add.

add_cont_force(impulse, time)[source]#

Add a continuous force to the Rigidbody. A continuous force is a force that is continuously applied over a time period. (the force is added every frame for a specific duration).

Parameters:
  • impulse (Vector) – The force to add.

  • time (int) – The time in seconds that the force should be added.

static handle_collision(col)[source]#

Handle the collision between two rigidbodies.

Parameters:

col (CollisionInfo) – The collision information.

fixed_update()[source]#

The update loop

Group#

Groups contain sprites and allow specific sprites to be seperated.

class Group[source]#

Bases: object

A group of sprites

__init__()[source]#
add(item)[source]#

Adds an item to the group.

Parameters:

item (Union[Sprite, Group, List[Union[Sprite, Group]]]) – The item or list of items to add to the group.

Raises:

Error – The item being added is the group itself. A group cannot be added to itself.

remove(item)[source]#

Removes an item from the group.

Parameters:

item (Union[Sprite, Group]) – The item to remove from the group.

Raises:

ValueError – The item is not in the group and cannot be deleted.

Scene#

THe Scene class which is a collection of groups. It also houses the current scene camera. Scenes come with a default group that everything is added to if no other groups are specified.

class Scene[source]#

Bases: object

A scene is a collection of groups.

root#

The base group of sprites in the scene.

Type:

Group

camera#

The camera of this scene.

Type:

Camera

id#

The id of this scene.

Type:

str

__init__()[source]#

Initializes a scene with an empty collection of sprites, a new camera, and a blank id.

add(item)[source]#

Adds an item to the root group.

Parameters:

item (Union[Sprite, Group, List[Union[Sprite, Group]]]) – The item or list of items to add.

remove(item)[source]#

Removes an item from the root group.

Parameters:

item (Union[Sprite, Group]) – The item to remove.

setup()[source]#

The start loop for this scene. It is run before the first frame.

update()[source]#

The update loop for this scene. Is empty by default an can be overridden.

fixed_update()[source]#

The fixed update loop for this scene. Is empty by default an can be overridden.

SceneManager#

The Scene Manager houses a collection of scenes and allows switching between different scenes. Each Game object has a scene manager. It also handles drawing and updating the current scene.

class SceneManager[source]#

Bases: object

The Scene Manager contains and handle multiple scenes.

scenes#

The collection of scenes in the manager. Accessed by scene id.

Type:

Dict[str, Scene]

current#

The id of the current scene.

Type:

str

__init__()[source]#

Initializes the scene manager with no scenes and current set to 0.

property is_empty: bool#

Checks if the scene manager contains no scene.

Returns:

True if the scene is empty. False otherwise.

Return type:

bool

property current_scene: Scene#

Gets the current scene.

Returns:

The current scene.

Return type:

Scene

add(scene, scene_id)[source]#

Add a scene to the current scene manager.

Parameters:
  • scene (Scene) – The scene to add to the manager.

  • scene_id (str) – The id of the scene.

Raises:

IdError – The given scene id is already used.

set(scene_id)[source]#

Changes the current scene.

Parameters:

scene_id (str) – The id of the new scene.

draw()[source]#

Calls the draw function of the current scene.

update()[source]#

Calls the update function of the current scene.

fixed_update()[source]#

Calls the fixed update function of the current scene.

Camera#

The Camera is what handles where things are drawn. A camera can zoom, pan around, and also travel along the z-index. Items only render if their z-index is less than that of the camera’s.

class Camera[source]#

Bases: object

The camera class.

pos#

The current position of the camera.

Type:

Vector

zoom#

The current zoom of the camera.

Type:

int

z_index#

The current z_index of the camera.

Type:

int

__init__(pos=Vector(), zoom=1, z_index=0)[source]#

Initializes a camera.

Parameters:
  • pos (Vector) – The starting position of the camera. Defaults to Vector().

  • zoom (int) – The starting zoom of the camera. Defaults to 1.

  • z_index (int) – The starting z_index of the camera. Defaults to 0.

transform(point)[source]#

Converts world space coordinates into screen space coordinates according to the camera.

Parameters:

point (Vector) – The point in world space coordinates.

Returns:

The translated coordinates,

where the first item is the x-coordinate and the second item is the y-coordinate. The coordinates are returned with the same type that is given.

Return type:

tuple

Utilities#

Math#

A more complete math class.

INFINITY#

The max value of a float.

Type:

float

clamp(a, lower, upper)[source]#

Clamps a value.

Parameters:
  • a (Union[float, int]) – The value to clamp.

  • lower (Union[float, int]) – The lower bound of the clamp.

  • upper (Union[float, int]) – The upper bound of the clamp.

Returns:

The clamped result.

Return type:

float

sign(n)[source]#

Checks the sign of n.

Parameters:

n (Union[float, int]) – A number to check.

Returns:

The sign of the number. (1 for positive, -1 for negative)

Return type:

int

lerp(a, b, t)[source]#

Linearly interpolates between lower and upper bounds by t

Parameters:
  • a (Union[float, int]) – The lower bound.

  • a – The upper bound.

  • t (float) – Distance between upper and lower (1 gives b, 0 gives a).

Returns:

The lerped value.

Return type:

float

Display#

Global display class that allows any file to access the displayed screen.

set_display(new_surface)[source]#

Set the global display.

Parameters:

new_surface (Surface) – The new surface to set.

update(surface, pos)[source]#

Update the current display.

Parameters:
  • surface (Surface) – The surface to draw on the display.

  • pos (tuple) – The position to draw the surface on.

set_window_position(x, y)[source]#

Set the position of the Pygame window.

Parameters:
  • x (int) – The x position.

  • y (int) – The y position.

set_window_name(name)[source]#

Set the title of the PyGame window.

Parameters:

name (str) – The name of the PyGame window.

Vector#

A vector implementation.

class Vector[source]#

Bases: object

A Vector object that defines a 2D point in space

x#

The x coordinate.

Type:

Union[float, int]

y#

The y coordinate.

Type:

Union[float, int]

__init__(x=0, y=0)[source]#

Initializes a vector.

Parameters:
  • x (Union[float, int]) – The x coordinate. Defaults to 0.

  • y (Union[float, int]) – The y coordinate. Defaults to 0.

translate(x, y)[source]#

Translates the vector’s x y and z coordinates by some constants.

Parameters:
  • x (Union[float, int]) – The change in x.

  • y (Union[float, int]) – The change in y.

offset(other)[source]#

Offsets the x and y coordinates of a vector by those of another vector.

Parameters:

other (Vector) – Another vector.

Returns:

A new vector with the translated x and y coordinates.

Return type:

Vector

to_tuple()[source]#

Returns the x and y coordinates of the vector as a tuple.

Return type:

tuple

static from_tuple(coords)[source]#

Returns a Vector from a coordinate tuple :type coords: tuple :param coords: tuple with an x and y coordinate [float | int].

Returns: Vector with specified coordinates.

Return type:

Vector

dot(other)[source]#

Takes the dot product of vectors.

Parameters:

other (Vector) – The other vector.

Returns:

The resulting dot product.

Return type:

Union[float, int]

cross(other)[source]#

Takes the cross product of vectors.

Parameters:

other (Vector) – The other vector.

Returns:

The resulting cross product.

Return type:

Union[float, int]

crossp()[source]#

Does Vector(self.y, -self.x).

Returns:

The resulting vector.

Return type:

Vector

pow(num)[source]#

Takes the power of the elements in the vector to the num.

Parameters:

num (Union[float, int]) – The exponent to use.

Returns:

The new vector.

Return type:

Vector

clamp(lower, upper, absolute=False)[source]#

Clamps x and y between the two values given.

Parameters:
  • lower (Union[Vector, int, float]) – The lower bound.

  • upper (Union[Vector, int, float]) – The upper bound.

  • absolute (bool) – Whether to clamp the absolute value of the vector instead of the actual value.

property mag: float#

Returns the squared magnitude of the vector.

Return type:

float

property magnitude: float#

Returns the magnitude of the vector.

Return type:

float

normalize()[source]#

Normalize the vector.

unit()[source]#

Returns the unit vector of this vector.

Return type:

Vector

static from_radial(angle, magnitude)[source]#

Gives you a Vector from the given direction and distance.

Parameters:
  • angle (float) – Direction of vector in radians.

  • magnitude (float) – Length of vector.

Returns:

Vector from the given direction and distance

Return type:

Vector

property angle: float#

Returns the angle of the vector

Return type:

float

invert(axis)[source]#

Inverts the vector in the axis given

Parameters:

axis (str) – The axis to invert the vector in (x or y).

Raises:

ValueError – The value for axis is not “x” or “y”

to_int()[source]#

Returns a new vector with values that are ints.

Return type:

Vector

clone()[source]#

Returns a copy of the vector.

Return type:

Vector

lerp(target, t)[source]#

Changes its values x and y to fit the target vector by amount t.

Parameters:
  • target (Vector) – the target velocity.

  • t (float) – the amount you lerp between 0 and 1.

Returns:

The resulting vector.

Return type:

Vector

round(decimal_places)[source]#

Rounds x and y to decimal_places

Parameters:

decimal_places (int) – the amount of decimal places rounded to.

ceil()[source]#

Returns the cieled vector.

Return type:

Vector

direction_to(vector)[source]#

Treating vectors as points the direction to the other vector from the current vector.

Parameters:

vector (Vector) – The other vector.

Returns:

The direction to the new vector in radians.

Return type:

float

distance_to(vector)[source]#

Treating vectors as points the distance to the other vector from the current vector.

Parameters:

vector (Vector) – The other vector.

Returns:

Distance to new vector.

Return type:

float

absolute()[source]#

Returns a vector representing the absolute values of the current vector

Return type:

Vector

Time#

A time class to monitor time and to call functions in the future.

frames#

The total number of elapsed frames since the start of the game.

Type:

int

fixed_delta_time(form='milli')[source]#

Gets the time since the fixed update frame.

Parameters:

form (str) – The format the output should be (sec, milli). Defaults to milli.

Raises:

ValueError – The form is not “sec” or “milli”.

Returns:

Time since the fixed update frame, in the given form.

Return type:

float

delta_time(form='milli')[source]#

Gets the time since the last frame.

Parameters:

form (str) – The format the output should be (sec, milli). Defaults to milli.

Raises:

ValueError – The form is not “sec” or “milli”.

Returns:

Time since the last frame, in the given form.

Return type:

float

now()[source]#

Gets the time since the start of the game, in milliseconds.

Returns:

Time since the start of the game, in milliseconds.

Return type:

int

delayed_call(time_delta, func)[source]#

Calls the function func at a later

Parameters:
  • time_delta (int) – The time from now (in milliseconds) to run the function at.

  • func (Callable) – The function to call.

delayed_frames(frames_delta, func)[source]#

Calls the function func at a later frame.

Parameters:
  • frames_delta (int) – The number of frames to wait.

  • func (Callable) – The function to call

milli_to_sec(milli)[source]#

Converts milliseconds to seconds.

Parameters:

milli (int) – A number in milliseconds.

Returns:

The converted number in seconds.

Return type:

float

set_clock(new_clock)[source]#

Allows you to set the clock object property to a Pygame Clock object.

Parameters:

clock – A pygame Clock object.

process_calls()[source]#

Processes the calls needed

Color#

A Color implementation.

class Color[source]#

Bases: object

A Color implentation.

r#

The red value.

Type:

float

g#

The green value.

Type:

float

b#

The blue value.

Type:

float

__init__(r=0.0, g=0.0, b=0.0)[source]#

Initializes an Color class.

Parameters:
  • r (float) – The red value. Defaults to 0.0.

  • g (float) – The green value. Defaults to 0.0.

  • b (float) – The blue value. Defaults to 0.0.

to_tuple()[source]#

Converts the Color to a tuple.

Returns:

The tuple representing the color.

Return type:

tuple(int, int, int)

check_values()[source]#

Makes the Color values legit. In other words, clamps them between 0 and 255.

lerp(other, t)[source]#

Lerps between this color and another.

Parameters:
  • other (Color) – The other Color to lerp with.

  • t (float) – The amount to lerp.

Returns:

The lerped Color. This Color remains unchanged.

Return type:

Color

to_hex()[source]#

Converts the Color to hexadecimal.

Returns:

The hexadecimal output in lowercase. (i.e. ffffff)

Return type:

str

static from_hex(h)[source]#

Creates an Color from a hex string.

Parameters:

h (str) – The hexadecimal value in lowercase.

Returns:

The Color value.

Return type:

Color

static from_hsv(h, s, v)[source]#

Creates an Color from an HSV.

Parameters:
  • h (int) – The hue amount.

  • s (int) – The saturation amount.

  • v (int) – The value amount.

Returns:

The Color value.

Return type:

Color

class property random[source]#

A Color class with a random color.

Returns:

A random color.

Return type:

Color

class property black[source]#

A Color class of the color black.

Returns:

(0, 0, 0)

Return type:

Color

class property white[source]#

A Color class of the color white.

Returns:

(255, 255, 255)

Return type:

Color

class property red[source]#

A Color class of the color red.

Returns:

(255, 0, 0)

Return type:

Color

class property lime[source]#

A Color class of the color lime.

Returns:

(0, 255, 0)

Return type:

Color

class property blue[source]#

A Color class of the color blue.

Returns:

(0, 0, 255)

Return type:

Color

class property yellow[source]#

A Color class of the color yellow.

Returns:

(255, 255, 0)

Return type:

Color

class property cyan[source]#

A Color class of the color cyan.

Returns:

(0, 255, 255)

Return type:

Color

class property magenta[source]#

A Color class of the color magenta.

Returns:

(255, 0, 255)

Return type:

Color

class property silver[source]#

A Color class of the color silver.

Returns:

(192, 192, 192)

Return type:

Color

class property gray[source]#

A Color class of the color gray.

Returns:

(128, 128, 128)

Return type:

Color

class property maroon[source]#

A Color class of the color maroon.

Returns:

(128, 0, 0)

Return type:

Color

class property olive[source]#

A Color class of the color olive.

Returns:

(128, 128, 0)

Return type:

Color

class property green[source]#

A Color class of the color green.

Returns:

(0, 128, 0)

Return type:

Color

class property purple[source]#

A Color class of the color purple.

Returns:

(128, 0, 128)

Return type:

Color

class property teal[source]#

A Color class of the color teal.

Returns:

(0, 128, 128)

Return type:

Color

class property navy[source]#

A Color class of the color navy.

Returns:

(0, 0, 128)

Return type:

Color

Errors#

Some custom errors

exception Error[source]#

Bases: Exception

A basic rubato Error.

exception IdError[source]#

Bases: Exception

An error that is raised when an invalid ID is used.

exception SideError[source]#

Bases: Exception

An error that is raised when the number of sides is invalid

exception DuplicateComponentError[source]#

Bases: Exception

An error that is raised when you try to add a component to a sprite that already has a component of the same type

exception ComponentNotAllowed[source]#

Bases: Exception

An error that is raised when you try to add a component on a sprite that is not allowed by another component on that sprite.