PixelPAD 2D - legacy
Objects
Objects are the main part of any PixelPAD game. Each object represents one active "thing" in your game.
Like rooms, each object is defined by an object script, which says what the object looks like, how it should react to other objects, and other things like that.
A room can have as many active objects as you want, but when you change rooms, they're all destroyed. To create a new object, use the object_new function.
Rooms
In PixelPAD, rooms are where your game takes place.
A room is defined by a room script, which is a Python program whose main purpose is to create and connect objects. You can think of a room as a "scene": a collection of game objects working together to present a specific scenario to the player.
There can only be one room active at a time. To change which room is active, use the room_set function.
Sprites
Sprites are pictures. In PixelPAD, every object has a sprite assigned to it that says how the object looks in the game.
A sprite is ultimately just an image file uploaded from your computer. You can add one by using the green plus sign (+) on the ASSETS sidebar.
To load a sprite from within a script, use the sprite_new function.
Functions
PixelPAD has a number of Python functions, or commands, which affect your game. This is a full list of all functions currently in PixelPAD.
animation_new(sprite: sprite, fps: int, start: int, end: int) -> animation
Description
Create a new animation object from the provided sprite sheet.
Parameters
sprite
The sprite sheet to create the animation from.
fps
The frame rate of the animation.
start
The frame number of the sprite sheet to start the animation from. 0 is the top left corner, with numbers increasing to the right and downwards.
end
The frame number of the sprite sheet to end the animation on. 0 is the top left corner, with numbers increasing to the right and downwards.
Returns
A new animation object that plays frames from start to end at a rate of fps.
Example
walk_right_sheet = sprite_new('spr_walk_right_sheet', 1, 4)
walk_right_anim = animation_new(walk_right_sheet, 4, 0, 3)
animation_set(obj: gameobject, anim: animation) -> None
Description
Set the current animation of the game object obj to the animation anim. Does nothing if the animation is already set on the object.
Parameters
obj
The game object instance to set the animation for.
anim
The animation object to set.
Returns
No return value.
animation_set(player, walk_right_anim)
camera_move(dx: int, dy: int) -> None
Description
Move the camera by the specified distances.
Parameters
dx
The distance along the X axis to move the camera.
dy
The distance along the Y axis to move the camera.
Returns
No return value.
Example
if player.x < -200:
camera_move(-200, 0)
camera_set(x: int, y: int) -> None
Description
Move the camera directly to the specified coordinates.
Parameters
x
The X coordinate to move the camera to.
y
The Y coordinate to move the camera to.
Returns
No return value.
Example
camera_set(player.x, player.y)
collision_check(obj: gameobject, filter: str or gameobject) -> gameobject or bool
Description
Checks whether the game object obj is colliding with any of the objects matched by filter.
Parameters
obj
The game object to check collisions for.
filter
Objects to check for collision with. If a single game object is passed, checks only that game object. If the name of a game object asset is passed, checks against all objects which are instances of that asset.
Returns
The first game object that obj is colliding with if there is a collision, False otherwise.
Example
enemy = collision_check(player, 'obj_enemy')
if enemy:
player.health = player.health - 1
collision_check_all(obj: gameobject, filter: str or gameobject) -> list or bool
Description
Checks whether the game object obj is colliding with any of the objects matched by filter.
Parameters
obj
The game object to check collisions for.
filter
Objects to check for collision with. If a single game object is passed, checks only that game object. If the name of a game object asset is passed, checks against all objects which are instances of that asset.
Returns
A list of all game objects that are colliding with obj if there are any collisions, False otherwise.
Example
enemies = collision_check_all(player, 'obj_enemy')
for enemy in enemies:
player.health = player.health - 1
data_clear() -> None
Description
Clears all save data for the current player.
Parameters
No parameters.
Returns
No return value.
Example
data_clear()
data_load(key: str, default: str or int or bool) -> str or int or bool
Description
Loads a piece of data from the player's persistent save file. Data can be a string, a number, or a boolean.
Parameters
key
A unique name for the piece of data to load. Can be any string.
default
The data to return if there is no data saved under the provided key.
Returns
The data stored under key, or default if there is no data stored under key.
Example
current_room = data_load('current_room', 'rm_start')
room_set(current_room)
data_save(key: str, val: str or int or bool) -> None
Description
Saves a piece of data into the player's persistent save file. Data can be a string, a number, or a boolean.
Parameters
key
A unique name for the piece of data to save.
Returns
No return value.
Example
data_save('current_lives', player.lives)
editor_open(name: str, section: str, line: int) -> None
Description
Opens the named script asset in the code editor. Automatically opens the specified section and scrolls to the specified line number.
Parameters
name
The name of the script asset to open in the code editor.
section
The section of the script to open. Can be either start or loop.
line
The line number of the script to scroll to once the script is open.
Returns
No return value.
Example
editor_open('obj_player', 'loop', 7)
key_is_pressed(key: str) -> bool
Description
Determines whether a keyboard key is currently pressed down.
Parameters
key
The name of a keyboard key to check, as a string. Possible values are A through Z, 0 through 9, left/right/up/down, space, enter, backspace, escape, shift, and ctrl.
Returns
True if the key is currently pressed down, False otherwise.
Example
if key_is_pressed('up'):
player.y = player.y + 1
key_was_pressed(key: str) -> bool
Description
Determines whether a keyboard key was pressed down on the current frame.
Parameters
key
The name of a keyboard key to check, as a string. Possible values are A through Z, 0 through 9, left/right/up/down, space, enter, backspace, escape, shift, and ctrl.
Returns
True if the key was pressed down on the current frame, False otherwise.
Example
if key_was_pressed('space'):
onground = False
mouse_is_pressed(button: str) -> bool
Description
Determines whether a mouse button is currently pressed down.
Parameters
button
The name of a mouse button to check, as a string. Possible values are left, right, and middle.
Returns
True if the button is currently pressed down, False otherwise.
Example
if mouse_is_pressed('left'):
object_new('obj_projectile')
mouse_was_pressed(button: str) -> bool
Description
Determines whether a mouse button was pressed down on the current frame.
Parameters
button
The name of a mouse button to check, as a string. Possible values are left, right, and middle.
Returns
True if the button was pressed down on the current frame, False otherwise.
Example
if mouse_was_pressed('right'):
print('right mouse button was clicked!')
mouse_x() -> int
Description
Returns the current X coordinate of the mouse pointer.
Parameters
No parameters.
Returns
The current X coordinate of the mouse pointer. 0 is the middle of the screen, positive numbers are to the right, and negative numbers are to the left.
Example
player.x = mouse_x()
mouse_y() -> int
Description
Returns the current Y coordinate of the mouse pointer.
Parameters
No parameters.
Returns
The current Y coordinate of the mouse pointer. 0 is the middle of the screen, positive numbers are towards the top, and negative numbers are towards the bottom.
Example
player.y = mouse_y()
object_new(name: str) -> gameobject
Description
Creates a new instance of the named game object in the current room.
Parameters
name
The name of a game object asset to instantiate, as a string.
Returns
A new instance of the named game object asset.
Example
player = object_new('obj_player')
object_destroy(obj: gameobject) -> None
Description
Destroys a game object instance.
Parameters
obj
The game object instance to destroy.
Returns
No return value.
Example
if player.is_dead:
object_destroy(player)
room_get() -> str
Description
Returns the name of the active room.
Parameters
No parameters.
Returns
The name of the active room, as a string.
Example
if room_get() == 'rm_gameover':
print('You lost!')
room_set(name: str) -> None
Description
Changes the active room to name.
Parameters
name
The name of a room asset to set as the active room, as a string.
Returns
No return value.
Example
room_set('rm_gameover')
sound_new(name: str) -> sound
Description
Loads a sound asset.
Parameters
name
The name of the sound asset to load.
Returns
A sound which can be played.
Example
jump_sfx = sound_new('snd_jump')
sound_play(snd: sound) -> None
Description
Plays a sound.
Parameters
Returns
No return value.
sound_play(footstep_sfx)
sound_loop(snd: sound) -> None
Description
Toggle whether a sound will loop when it finishes playing.
Parameters
snd
The sound to toggle looping for.
Returns
No return value.
Example
sound_loop(background_music)
sound_stop(snd: sound) -> None
Description
Stops a currently playing sound. If the sound is started again, it will replay from the beginning.
Parameters
snd
The sound to stop playing.
Returns
No return value.
Example
if not player.moving:
sound_stop(footsteps_sfx)
sound_volume(volume: int) -> None
Description
Change the volume of the sound mixer.
Parameters
volume
The volume to set the mixer to. Muted is 0, maximum is 100.
Returns
No return value.
Example
sound_volume(50)
sprite_new(name: str[, rows: int, cols: int]) -> sprite
Description
Loads a sprite asset.
Parameters
name
The name of a sprite to load, as a string.
rows (
optional)
If the sprite asset is a sprite sheet, the number of rows in the sprite sheet.
cols (
optional)
If the sprite asset is a sprite sheet, the number of columns in the sprite sheet.
Returns
A sprite which can be assigned to an object.
Example
player.sprite = sprite_new('spr_player')