HOME ABOUT TUTORIALS EXAMPLES REFERENCE DONATE
info@jobase.org

Window
Mouse
Key
Circle
Line
Image
Math Functions
Collision Functions

{class} Window(width, height, caption)
This is the class for the main JoBase window. It is very unlikely that you will need to create a new instance of this class. Instead of using this class directly, use the {window} value that is built in to JoBase. Please look at the example below to see how the {window} value should be used.
{from} JoBase {import} *

window.caption = ¦"Window Example"}
window.green = 0.5
window.size = (300, 300)

{def} loop():
    window.red += 0.01

run()
quit()
Close the window.

This forces the window to close. Once it is closed, it can't be opened again.
maximize()
Maximize the window.

Depending on the computer setup, it will either maximize to a single window or fill the whole screen.
minimize()
Minimize the window.
make_active()
Activates the window.

On some operating systems, the window may not be activated.
collides_with(other) = {bool}
Checks if another object is on the screen.

You can check collision with any {JoBase} shape as well as the mouse. If {other} is off the edge of the screen, it will return false.
red = {float}
The red color of the window.

It should be in the range of {0} to {1}.
green = {float}
The green color of the window.

It should be in the range of {0} to {1}.
blue = {float}
The blue color of the window.

It should be in the range of {0} to {1}.
color = ({float}, {float}, {float})
The background color of the window.

Each value should be in the range of {0} to {1}.
x = {int}
The horizontal position of the window.

It is based on the {left} of the window and the {left} of the screen.
y = {int}
The vertical position of the window.

It is based on the {top} of the window and the {top} of the screen.
position = ({int}, {int})
The position of the window.

The position is based on the {top-left} of the window and the {top-left} of the screen.
width = {int}
The width of the window.
height = {int}
The height of the window.
size = ({int}, {int})
The size of the window.

The graphics will update slowly if you resize the window every frame.
caption = {str}
The window's caption.
fullscreen = {bool}
Toggles to or from fullscreen.

The following code is useful for many games.
{if} key.f11 {and} key.press: %# the fullscreen is toggled when you press F11}
    window.fullscreen = {not} window.fullscreen
visible = {bool}
The visibility of the window.

When it is false, the window is hidden including the taskbar icon.
maximum_width = {int}
The maximum width of the window.
maximum_height = {int}
The maximum height of the window.
maximum_size = ({int}, {int})
The maximum size of the window.
minimum_width = {int}
The minimum width of the window.
minimum_height = {int}
The minimum height of the window.
minimum_size = ({int}, {int})
The minimum size of the window.
key = {bool}
Enables or disables the keyboard.

When it is false, the user can't switch away from the window with keyboard shortcuts.
mouse = {bool}
Enables or disables the mouse.

When it is false, the mouse disappears and is prevented from leaving the window.
activate = {bool}
Becomes true when the user activates the window. {Read only}.
deactivate = {bool}
Becomes true when the user deactivates the window. {Read only}.
close = {bool}
Becomes true when the user closes the window. {Read only}.
hide = {bool}
Becomes true when the user hides (minimizes) the window. {Read only}.
move = {bool}
Becomes true when the user moves the window. {Read only}.
resize = {bool}
Becomes true when the user resizes the window. {Read only}.
show = {bool}
Becomes true when the user restores the window from being minimized. {Read only}.
text = {str}
This is the text the user is currently typing with their keyboard. {Read only}.

This value is very useful for games with text input.
{class} Mouse()
This is the class for the mouse. It is very unlikely that you will need to create a new instance of this class. Instead of using this class directly, use the {mouse} value that is built in to JoBase. Please look at the example below to see how the {mouse} value should be used.
{from} JoBase {import} *

mouse.cursor = HAND
timer = 5

{def} loop():
    {global} timer

    timer -= 1

    {if} timer < 0:
        mouse.visible = {not} mouse.visible
        timer = 5

run()
collides_with(other) = {bool}
Detects collision with another object.

You can check collision with any {JoBase} shape as well as the window.
x = {int}
The horizontal position of the mouse.
y = {int}
The vertical position of the mouse.
position = ({int}, {int})
The position of the mouse.
visible = {bool}
The visibility of the mouse.
cursor = {CURSOR}
The mouse appearance.
mouse.cursor = HAND %# changes the mouse icon}
The table below shows all the different mouse icons.
{Name} {Windows XP} {Mac OS X}
DEFAULT windows default mac default
CROSSHAIR windows crosshair mac crosshair
HAND windows hand mac hand
HELP windows help mac default
NO windows no mac no
SIZE windows size mac default
SIZE_DOWN windows vertical mac down
SIZE_DOWN_LEFT windows up mac default
SIZE_DOWN_RIGHT windows down mac default
SIZE_LEFT windows horizontal mac left
SIZE_LEFT_RIGHT windows horizontal mac horizontal
SIZE_RIGHT windows horizontal mac right
SIZE_UP windows vertical mac up
SIZE_UP_DOWN windows vertical mac vertical
SIZE_UP_LEFT windows down mac default
SIZE_UP_RIGHT windows up mac default
TEXT windows text mac text
WAIT windows wait mac wait
WAIT_ARROW windows wait arrow mac default
scroll = {bool}
Becomes true when the mouse wheel is being scrolled. {Read only}.
scroll_x = {float}
The horizontal scroll of the mouse. {Read only}.

Most mice don't have this feature.
scroll_y = {float}
The vertical scroll of the mouse. {Read only}.
move = {bool}
Becomes true when the mouse is being moved. {Read only}.
move_x = {int}
The horizontal distance the mouse was moved. {Read only}.
move_y = {int}
The vertical distance the mouse was moved. {Read only}.
press = {bool}
Becomes true when the mouse is pressed. {Read only}.
release = {bool}
Becomes true when the mouse is released. {Read only}.
left = {bool}
Becomes true when the left button is held. {Read only}.
middle = {bool}
Becomes true when the middle button is held. {Read only}.
right = {bool}
Becomes true when the right button is held. {Read only}.
enter = {bool}
Becomes true when the mouse is moved into the window. {Read only}.
leave = {bool}
Becomes true when the mouse is moved outside the window. {Read only}.
{class} Key()
This is the class for the keyboard events. It is very unlikely that you will need to create a new instance of this class. Instead of using this class directly, use the {key} value that is built in to JoBase. Please look at the example below to see how the {key} value should be used.
{from} JoBase {import} *

circle = Circle(200, 200)

{def} loop():
    circle.draw()

        {if} key.up:
    circle.y += 3

    {elif} key.down:
        circle.y -= 3

    {elif} key.left:
        circle.x -= 3

    {elif} key.right:
        circle.x += 3

    {if} key.press {or} key.release:
        circle.color = (random(), random(), random())

run()
press = {bool}
Becomes true when a key is pressed. {Read only}.
release = {bool}
Becomes true when a key is released. {Read only}.
name = {bool}
Becomes true when the key with a certain name is being held. {Read only}.

Here is a list of all the key names.
mod_shift mod_ctrl mod_alt mod_capslock mod_numlock mod_windows mod_command mod_option mod_scrolllock mod_function mod_accel mod_ctrl mod_cmd backspace tab linefeed clear return enter pause scrolllock sysreq escape space home left up right down pageup pagedown end begin delete select print execute insert undo redo menu find cancel help break modeswitch scriptswitch function motion_up motion_right motion_down motion_left motion_next_word motion_previous_word motion_beginning_of_line motion_end_of_line motion_next_page motion_previous_page motion_beginning_of_file motion_end_of_file motion_backspace motion_delete number pad numlock num_space num_tab num_enter num_f1 num_f2 num_f3 num_f4 num_home num_left num_up num_right num_down num_prior num_page_up num_next num_page_down num_end num_begin num_insert num_delete num_equal num_multiply num_add num_separator num_subtract num_decimal num_divide num_0 num_1 num_2 num_3 num_4 num_5 num_6 num_7 num_8 num_9 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 lshift rshift lctrl rctrl capslock lmeta rmeta lalt ralt lwindows rwindows lcommand rcommand loption roption space exclamation doublequote hash pound dollar percent ampersand apostrophe parenleft parenright asterisk plus comma minus period slash _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 colon semicolon less equal greater question at bracketleft backslash bracketright asciicircum underscore grave quoteleft 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 braceleft bar braceright asciitilde
{class} Circle(x = 0, y = 0, radius = 50, color = (1, 1, 1), opacity = 1)
This is the class for drawing a circle.
draw()
Draw the shape.
collides_with(other) = {bool}
Detects collision with another object.

You can check collision with any {JoBase} shape as well as the window and the mouse.
x = {int}
The horizontal position of the shape.
y = {int}
The vertical position of the shape.
position = ({int}, {int})
The position of the shape.
scale_x = {float}
The horizontal scale of the shape.
scale_y = {float}
The vertical scale of the shape.
scale = {float}
The overall scale of the shape.
anchor_x = {int}
The horizontal anchor position of the shape.
anchor_y = {int}
The vertical anchor position of the shape.
anchor = ({int}, {int})
The anchor position of the shape.
rotation = {float}
The rotation of the shape.
red = {float}
The red color of the shape.

It should be in the range of {0} to {1}.
green = {float}
The green color of the shape.

It should be in the range of {0} to {1}.
blue = {float}
The blue color of the shape.

It should be in the range of {0} to {1}.
color = ({float}, {float}, {float})
The color of the shape.

Each value should be in the range of {0} to {1}.
colors = [({float}, {float}, {float}), ...]
The individual colors of each vertex as a large list of tuples.

When you change the {color} value, all of these values change.
opacity = {float}
The opacity of the shape.

If the opacity is at {0.5}, the shape will blend into the background.
top = {int}
The top of the shape.
bottom = {int}
The bottom of the shape.
left = {int}
The left of the shape.
right = {int}
The right of the shape.
radius = {float}
The radius of the circle.
{class} Line(x1 = 0, y1 = 0, x2 = 100, y2 = 100, width = 1, color = (1, 1, 1), opacity = 1)
This is the class for drawing a line.
draw()
Draw the shape.
collides_with(other) = {bool}
Detects collision with another object.

You can check collision with any {JoBase} shape as well as the window and the mouse.
x = {int}
The horizontal position of the shape.
y = {int}
The vertical position of the shape.
position = ({int}, {int})
The position of the shape.
scale_x = {float}
The horizontal scale of the shape.
scale_y = {float}
The vertical scale of the shape.
scale = {float}
The overall scale of the shape.
anchor_x = {int}
The horizontal anchor position of the shape.
anchor_y = {int}
The vertical anchor position of the shape.
anchor = ({int}, {int})
The anchor position of the shape.
rotation = {float}
The rotation of the shape.
red = {float}
The red color of the shape.

It should be in the range of {0} to {1}.
green = {float}
The green color of the shape.

It should be in the range of {0} to {1}.
blue = {float}
The blue color of the shape.

It should be in the range of {0} to {1}.
color = ({float}, {float}, {float})
The color of the shape.

Each value should be in the range of {0} to {1}.
colors = [({float}, {float}, {float}), ...]
The individual colors of each vertex as a large list of tuples.

When you change the {color} value, all of these values change.
opacity = {float}
The opacity of the shape.

If the opacity is at {0.5}, the shape will blend into the background.
top = {int}
The top of the shape.
bottom = {int}
The bottom of the shape.
left = {int}
The left of the shape.
right = {int}
The right of the shape.
width = {float}
The width of the line.
x1 = {int}
The first horizontal position of the line.
y1 = {int}
The first vertical position of the line.
position1 = ({int}, {int})
The first position of the line.
x2 = {int}
The second horizontal position of the line.
y2 = {int}
The second vertical position of the line.
position2 = ({int}, {int})
The second position of the line.
{class} Image(image = MAN, x = 0, y = 0, rotation = 0)
This is the class for drawing an image. For the {name} you can put the filename of your own image. It can be in {PNG}, {GIF}, {JPG}, {BMP} or {DDS} format. Depending on your computer setup, you may be able to load other files as well.

The example below shows you how to load your own image.
ball = Image(¦"images/ball.png"})
Alternatively, you can use a {JoBase} image.
rocket = Image(ROCKET)
Here is a list of all the {JoBase} image names, more are coming.
MAN BAD ROCKET ENEMY ASTRONAUT
draw()
Draw the shape.
collides_with(other) = {bool}
Detects collision with another object.

You can check collision with any {JoBase} shape as well as the window and the mouse.
x = {int}
The horizontal position of the shape.
y = {int}
The vertical position of the shape.
position = ({int}, {int})
The position of the shape.
scale_x = {float}
The horizontal scale of the shape.
scale_y = {float}
The vertical scale of the shape.
scale = {float}
The overall scale of the shape.
anchor_x = {int}
The horizontal anchor position of the shape.
anchor_y = {int}
The vertical anchor position of the shape.
anchor = ({int}, {int})
The anchor position of the shape.
rotation = {float}
The rotation of the shape.
red = {float}
The red color of the shape.

It should be in the range of {0} to {1}.
green = {float}
The green color of the shape.

It should be in the range of {0} to {1}.
blue = {float}
The blue color of the shape.

It should be in the range of {0} to {1}.
color = ({float}, {float}, {float})
The color of the shape.

Each value should be in the range of {0} to {1}.
colors = [({float}, {float}, {float}), ...]
The individual colors of each vertex as a large list of tuples.

When you change the {color} value, all of these values change.
opacity = {float}
The opacity of the shape.

If the opacity is at {0.5}, the shape will blend into the background.
top = {int}
The top of the shape.
bottom = {int}
The bottom of the shape.
left = {int}
The left of the shape.
right = {int}
The right of the shape.
width = {int}
The width of the image.
height = {int}
The height of the image.
image = {str}
The image filename.

If you change this value during the game, it will load the new image.
{def} distance(x1, y1, x2, y2) = {float}
Find the distance between two points.
{def} angle(x1, y1, x2, y2) = {float}
Find the angle of the two points in degrees.

Returns a number between {0} and {360}.
{def} direction(length, angle) = ({float}, {float})
Find the horizontal and vertical length of a line based on the length and angle.

This function is useful for making an object travel in a specific direction.
{def} random_number(number1, number2) = {int}
Returns a random whole number between {number1} and {number2}.
{def} random_decimal(number1, number2) = {float}
Returns a random decimal between {number1} and {number2}.
{def} rotate_point(x, y, center_x, center_y, rotation) = ({float}, {float})
Rotates a point around a central position.
{def} rotate_toward_goal(current, goal, increment = 1) = {float}
Changes the {current} angle to match the {goal} angle.

This function was made with space ships in mind. It is useful for making an object rotate slowly to point to another object.
{def} point_collides_with_shape(x, y, shape) = {bool}
Check if a point collides with a shape.

The shape needs to be a list of points.
{def} shape_collides_with_shape(shape1, shape2) = {bool}
Check if the shapes collide with each other.

The shapes need to be a list of points.
{def} point_collides_with_point(x1, y1, x2, y2) = {bool}
Check if the points collide with each other.

This function is slightly pointless, we added it for consistency.