JoBase Lessons Demos Games Reference Download

Classes

Functions

Window Camera Cursor Key Base Rectangle Image Text Circle Line Shape Physics Body Group Joint Pin Spring Groove
run random randint sin cos tan asin acos atan sqrt cbrt ceil floor

Welcome to the reference manual. Once you are familiar with JoBase, use this page to discover all the JoBase features.

Below is a list of built in colors.

class Window(title = "JoBase", width = 640, height = 480, color = WHITE)
This class is for managing the main window. Don't try to instance this class directly, use the inbuilt window variable instead.
import JoBase

window.color = BLUE
window.size = 300, 300

def loop():
    window.red += 0.01

run()
                
title: str
The title of the window.
red, color.r: float
The red color of the window.
green, color.g: float
The green color of the window.
blue, color.b: float
The blue color of the window.
color: (float, float, float)
The color of the window.
width, size.x: float
The width of the window in pixels.
height, size.y: float
The height of the window in pixels.
size: (float, float)
The dimensions of the window in pixels.
resize: bool
Check if the window has been resized.
close()
Close the window and terminate the program.
maximize()
Maximize the window. You can restore the maximized window with the restore method.
minimize()
Minimize the window. You can restore the minimized window with the restore method.
restore()
Restore the window from maximized or minimized. The window returns to its normal state.
focus()
Give the window input focus. It can be very disruptive to the user when the window is forced to the top - use this method sensibly.
class Camera(x = 0, y = 0)
This class is for managing the game camera. By moving it around, you can change your view of things on the screen. Don't try to instance this class directly, use the inbuilt camera variable instead.
x, pos.x, position.x: float
The x position of the camera.
y, pos.y, position.y: float
The y position of the camera.
pos, position: (float, float)
The position of the camera.
top: float
The top of the viewport.
bottom: float
The bottom of the viewport.
left: float
The left of the viewport.
right: float
The right of the viewport.
class Cursor()
This class represents the cursor. Don't try to instance this class directly, use the inbuilt cursor variable instead.
import JoBase

def loop():
    window.color = GOLD if cursor.hold else LIGHT_BLUE

run()
                
x, pos.x, position.x: float
The x position of the cursor.
y, pos.y, position.y: float
The y position of the cursor.
pos, position: (float, float)
The position of the cursor.
move: bool
The cursor has moved.
enter: bool
The cursor has entered the window.
leave: bool
The cursor has left the window.
press: bool
A cursor button is pressed.
release: bool
A cursor button is released.
hold: bool
A cursor button is held down.
[name]: bool
Access the state of a specific mouse button. Below is a list of all the mouse button names. Some buttons are not present on all devices.
left right middle _4 _5 _6 _7 _8
[name].press: bool
A cursor button is pressed.
[name].release: bool
A cursor button is released.
[name].hold: bool
A cursor button is held down.
collide, collides_with(object) -> bool
Check if the cursor collides with the another object.
class Key()
This class is for detecting keyboard input. Don't try to instance this class directly, use the inbuilt key variable instead.
press: bool
A key is pressed down.
release: bool
A key is released.
repeat: bool
When the user holds a key down, a series of events are fired.
hold: bool
A key is held down.
[name]: bool
Access the state of a specific key. Below is a list of all the key names.
space apostrophe comma minus period slash _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 semicolon equal a b c d e f g h i j k l m n o p q r s t u v w x y z left_bracket backslash right_bracket backquote escape enter tab backspace insert delete right left down up page_up page_down home end caps_lock scroll_lock num_lock print_screen pause f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 f22 f23 f24 f25 pad_0 pad_1 pad_2 pad_3 pad_4 pad_5 pad_6 pad_7 pad_8 pad_9 pad_decimal pad_divide pad_multiply pad_subtract pad_add pad_enter pad_equal left_shift left_ctrl left_alt left_super right_shift right_ctrl right_alt right_super menu
[name].press: bool
The key is pressed.
[name].release: bool
The key is released.
[name].repeat: bool
When the key is held down, a series of events are fired.
[name].hold: bool
The key is held down.
class Base()
This is the base class for all drawing primitives. The attributes of this class are shared with other objects. Some of the attributes are only useful when the object is added to the physics engine. Do not try to instance this class directly.
x, pos.x, position.x: float
The x position of the object.
y, pos.y, position.y: float
The y position of the object.
pos, position: (float, float)
The position of the object.
left: float
The left position of the object.
top: float
The top position of the object.
right: float
The right position of the object.
bottom: float
The bottom position of the object.
scale.x: float
The horizontal scale of the object.
scale.y: float
The vertical scale of the object.
scale: (float, float)
The scale of the object.
anchor.x: float
The horizontal origin of the object.
anchor.y: float
The vertical origin of the object.
anchor: (float, float)
The rotational origin of the object.
angle: float
The angle of the object.
red, color.r: float
The red color of the object.
green, color.g: float
The green color of the object.
blue, color.b: float
The blue color of the object.
alpha, color.a: float
The transparency of the object.
color: (float, float, float, float)
The color of the object.
body: Body
The body that the object is attached to. This attribute is used to give your object physics properties. See the Body documentation to learn more about this feature.
mass, weight: float
The weight of the object in a physics environment - high means heavy.
elasticity: float
The bounciness of the object in a physics environment. It is best to keep this value between 0 (not bouncy) and 1 (perfectly bouncy).
friction: float
The roughness of the object in a physics environment. It is best to keep this value between 0 (slippery) and 1 (rough).
collide, collides_with(object) -> bool
Check if the object collides with the another object.
draw()
Draw the object on the screen.
class Rectangle(x = 0, y = 0, width = 50, height = 50, angle = 0, color = BLACK)
This class is for drawing rectangles. Because it extends the Base class, it contains the same attributes.
width, size.x: float
The width of the rectangle in pixels.
height, size.y: float
The height of the rectangle in pixels.
size: (float, float)
The dimensions of the rectangle in pixels.
class Image(name = MAN, x = 0, y = 0, angle = 0, width = 0, height = 0, color = WHITE)
This class is for drawing images. Because it extends the Rectangle class, it contains the same attributes. The name is a string of the filepath to the image. JoBase contains the following built in images.
MAN
COIN
ENEMY
The example below loads an image and renders it to the screen.
import JoBase

enemy = Image(ENEMY)

def loop():
    enemy.draw()

run()
                
class Text(content = "Text", x = 0, y = 0, font_size = 50, angle = 0, color = BLACK, font = DEFAULT)
This class is for drawing text. Because it extends the Rectangle class, it contains the same attributes.
content: str
The string content of the text.
font: str
The filepath to the font family of the text. JoBase contains the following built in fonts.
CODE
Code
DEFAULT
Default
HANDWRITING
Handwriting
JOINED
Joined
PENCIL
Pencil
SERIF
Serif
TYPEWRITER
Typewriter
The example below loads the pencil font and draws the text.
import JoBase

text = Text("Pencil Font", font = PENCIL)
text.font_size = 80

def loop():
    text.draw()

run()
                    
font_size: float
The size of the font.
class Circle(x = 0, y = 0, diameter = 50, color = BLACK)
This class is for drawing circles. Because it extends the Base class, it contains the same attributes.
diameter: float
The diameter of the circle.
radius: float
The radius of the circle (half of the diameter).
class Shape(points = ((0, 25), (25, -25), (-25, -25)), x = 0, y = 0, angle = 0, color = BLACK)
This class is for drawing polygons. Because it extends the Base class, it contains the same attributes.
points: ((float, float), ...)
The coordinates that define the shape. Setting this attribute can be computationally expensive, beware of using this feature on large batches of shapes.
class Line(points = ((-25, -25), (25, 25)), width = 2, x = 0, y = 0, angle = 0, color = BLACK)
This class is for drawing lines. Because it extends the Shape class, it contains the same attributes.
width: float
The thickness of the line.
class Physics(gravity_x: 0, gravity_y: -500)
This class is a physics engine environment. Add objects to give them realistic physics. You can run a basic demo by typing the following command into the terminal.
python -m JoBase.examples.physics
The example below creates a box that bounces on the ground.
import JoBase

engine = Physics()

box = Rectangle(y = 300, angle = 10)
box.body = engine.body()

floor = Rectangle(width = window.width, height = 20)
floor.body = engine.body(STATIC)
floor.bottom = camera.bottom

def loop():
    engine.update()

    floor.draw()
    box.draw()

run()
                
gravity.x: float
The horizontal gravity.
gravity.y: float
The vertical gravity. A negative number makes the objects fall to the bottom.
gravity: (float, float)
The gravity in the physics environment.
group() -> object
Create a group for the physics environment. Check the Group documentation to learn how to use this feature.
body(int = DYNAMIC) -> object
Create a body for the physics environment. The body type can be DYNAMIC (default) or STATIC. Check the Body documentation to learn how to use this feature.
update()
Calculate the next step for the physics engine. It's good practice to call this in the game loop.
class Body()

This object represents a body in a physics environment. A body can have multiple shapes attached. Don't try to instance this class directly, call the Physics.body() method instead.

                    # TODO
                
type: int
The body type in a physics environment. When it is DYNAMIC, the body can move about. If you set the type to STATIC, the body acts as a solid wall that can't move.
speed, velocity: (float, float)
The speed of the body in a physics environment.
torque: float
The rotational force applied to the body in a physics environment.
class Group()

This object represents a group in a physics environment. Shapes with the same group don't have collisions with each other. Don't try to instance this class directly, call the Physics.group() method instead.

                    # TODO
                
class Joint()

This is the base class for all joint objects. A joint is a constraint between two bodies.

red, color.r: float
The red color of the joint.
green, color.g: float
The green color of the joint.
blue, color.b: float
The blue color of the joint.
alpha, color.a: float
The transparency of the joint.
color: (float, float, float, float)
The color of the joint.
width: float
The thickness of the joint when rendered.
draw()
Draw the joint on the screen.
class Pin(a: object, b: object, length = 0, width = 2, color = BLACK)

This class constrains two bodies at a fixed distance from each other. It is an extension of the Joint class. Parameters a and b must be instances of Base. If length is 0, the distance will be calculated automatically.

start: (float, float)
The anchor of the joint on the first body.
end: (float, float)
The anchor of the joint on the second body.
length: float
The distance to set between the two bodies.
class Spring(a: object, b: object, length = 0, stiffness = 10, damping = .5, width = 2, color = BLACK)

This class constrains two bodies with a spring joint. It is an extension of the Joint class. Parameters a and b must be instances of Base. If length is 0, the distance will be calculated automatically.

start: (float, float)
The anchor of the joint on the first body.
end: (float, float)
The anchor of the joint on the second body.
length: float
The resting length of the spring.
stiffness: float
The strength of the spring.
damping: float
This reduces the bounciness of the spring. It is best to keep this attribute between 0 (bouncy) and 1 (smooth).
class Groove(a: object, b: object, start = (50, 0), end = (100, 0), width = 2, color = BLACK)

This class links a body to a groove on another body. It is an extension of the Joint class. Parameters a and b must be instances of Base. The groove is attached to body a.

import JoBase

engine = Physics()

floor = Rectangle(width = window.width, height = 20)
floor.elasticity = 0.9
floor.bottom = camera.bottom
floor.body = engine.body(STATIC)

a = Rectangle(50, 100, color = GRAY)
a.elasticity = 0.9
a.body = engine.body()

b = Rectangle(0, 300, color = LIGHT_BLUE)
b.elasticity = 0.9
b.body = engine.body()

groove = Groove(a, b, width = 10)

def loop():
    engine.update()

    a.draw()
    b.draw()
    floor.draw()
    groove.draw()

run()
                
start: (float, float)
The anchor of the joint on the first body.
end: (float, float)
The anchor of the joint on the second body.
groove: (float, float)
The ending position of the groove in relation to the first body.
def run()
Run the game and display the window. Always call this method at the bottom of your code.
def random(float, float) -> float
Find a random decimal between two numbers.
def randint(int, int) -> int
Find a random integer between two whole numbers inclusively.
def sin(float) -> float
Find the sine of a number.
def cos(float) -> float
Find the cosine of a number.
def tan(float) -> float
Find the tangent of a number.
def asin(float) -> float
Find the inverse sine of a number.
def acos(float) -> float
Find the inverse cosine of a number.
def atan(float) -> float
Find the inverse tangent of a number.
def sqrt(float) -> float
Find the square root of a number.
def cbrt(float) -> float
Find the cube root of a number.
def ceil(float) -> float
Round up to the nearest whole number
def floor(float) -> float
Round down to the nearest whole number