Documentation


PixelPAD Reference

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.
val
The 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
snd
The sound to play.
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')
  

Multiplayer Functions

Multiplayer is now in beta. Expect there to be bugs. Please report any bugs to hello@pixelpad.io, or use our Reddit
Description
mp_multiplayer = True must be set in the game script (start). This ensures games are synced to all players. If this is off or not stated, then the game state from the adminn players won't be sent to the other players and games won't be synced.

mp_client_connect() is a list of ID's all the players that joined during this frame.

mp_client_disconnect() is a list ID'S of all the players that disconnected during this frame.

If an object has an mp_id set, this will be considered a multiplayer object, and can only be controlled by players logged in with that mp_id

mp_client_data_sync(mp_obj) syncs the data given by the client to this object. used if you want the client's objects to be persistent room to room.

mp_get_clients() get list all clients currently connected to the room.

mp_my_mpid_get() get the current player's mpid.

mp_reload_all() completely reload the game for all players.

Below is a quickstart example to get you started on multiplayer games.
Example
  
  #ROOM START
  #local player list
  playerList = []
  
  #ROOM LOOP 
  for client in mp_client_connect():
    p = object_new("obj_player")
    p.mp_id = client
    playerList.append(p)
    mp_client_data_sync(p) #sync data room to room.
    
  for clientID in mp_client_disconnect():
    for user in playerList:
      if user.mp_id == clientID:
        playerList.remove(user)
        destroy(user)
    
  

General Information

Try to avoid key_is_down as this will send a large amount of data to all players and increases the likelihood of games desyncing.

The state of the game script is not synced between players, but the state of the room is synced. This means objects created after the game has started will be created for the second player that joins if its created within the room.

randint() will not be synced and will cause issues if you expect both players to have the same random integers.

Being inactive for a period of time will destroy your connection to the server.

The first person to join the ROOM is the admin. If the admin minimizes the browser, or goes to a different room, the second person in the room will be admin. If the admin is lagging, so will the other players in the room.

mouse_x() and mouse_y() only changes for other users when there is a mousedown, or mouseup event. This means, you must bundle mouse_x() and mouse_y() events within an "if a mouse_is_down()" event, otherwise unexpected things may happen.



PixelPAD Blockly Reference



Getting Started

PixelPAD Blockly is a drag-and-drop way to create any games! Before you get started with this, you might want to try out our BrambleBerry Tales puzzles in the Tutorials section!

To create a new project, navigate to the My Apps section and select Create New App. You can provide a name and image, and under App Engine select blockly-playground.

To get started with PixelPAD Blockly, you should make sure you have a Game Start Block! Everything in PixelPAD Blockly works through objects. Every object you see in the game, has to be created. Take a look at these examples and try to recreate them!


Example 1

Example 1


Example 2

Example 2




Blocks 

Most of PixelPAD blockly blocks are described over here. Some specific blocks, like logic, loops, text and more can be found on the Blockly wiki page.

Game 


Game Start

You can put other blocks inside the Game Start Block, either in the start space or the update space. Any block that you put in start will run one time when you first press Play. Any block that you put in update will run after you press Play and will run again really fast, 30 times per second!


Reload Game

You can reload your game with this block. This can be useful to restart a game after a player either wins or looses. All Global variables will stay the same when you reload.


Show Text

You can show text anywhere in the game screen. Make sure to put this block inside an update section, or else you will not see the text!


Collision Check

You can use this block to detect if this object is colliding with another object of a certain type. You can also use it to access that object, and for example destroy it. Take a look at the example below. If this object collides with an Asteroid, it removes the Asteroid from the game.

Collision Example


Objects


Object

You can put other blocks inside the Object Block, either in the start space or the update space. Any block that you put in start will run one time when this object is created. Any block that you put in update will keep running while the object exists, 30 times per second!

When you create an object, you should change 'default' to the type of that object. For example 'Ship' or 'Obstacle'.


Create_Object
This creates an object of a certain type. Make sure the change 'default' to the type of that object. For example 'Ship' or 'Obstacle'. You can create many objects of the same type, and they will all have the same behaviour.
 
Destroy
This is used to remove an object from the game. Remember that when you destroy an object, it will be gone forever!

Myself
This block links to an object itself. You can use it together with the Destroy block to destroy the object itself.

Input


Key Pressed

You can use this together with an if-block from the Logic category. Then you can make something happen, if a key is pressed. You can select which key you want to check for and then from these three options:

was pressed: Was the key just pressed?

is pressed: Is the key currently held down?

was released: Was the key just released?


Mouse Pressed

Very similar to the key press, this will detect if your mouse button was pressed. The left mouse button is the same as touch on a tablet or mobile device!


Mouse Pos

You can get the position of the mouse in your screen. For this we use (left and right) and (up and down).


Mouse Over

You can use this together with an if-block from the Logic category. That way, you can detect if the mouse is currently over this object. 


Variables

Variables are used to store information. Think of them like a box, with a name on it. The information you store is inside that box. I can then look at that information, and change it. For example, if I would like to store the score of a player, I would create a variable called 'score'. First I set the score to 0, but every time a player gets a point, I add one point to the score. You can store anything you want in a variable, like numbers, text and more.


Create Var

You can create a new variable with this button. Simply type the name of the variable, and it will allow you to use it to store information.


Set Var

You can set a variable, which means you change it to the value you want.


Change Var

You can also simply change the variable, which means we take the original value, and add the new value to it. For example if we change the score of 16 by 1, it will become 17. This can only be used for numbers!


The Var

Besides setting the variable name, we can select a variable type of three options. The first option, the, means that this variable exists in only once in the entire game. That makes sense when storing score, since there is only one score in your game.


My Var

The second option, my, means that the variable is part of that object. This makes sense if you have multiple characters in your game, and they all have their own health. Of course if one character loses health, the other character should not be affected.


Local Var

The last option, _ , is a very specific one. It is only used in loops, like the one in the example below. Here, the variable 'i' is not part of the object, but only part of the loop. 

Local Var Example


Movement


Move Forward

This makes your object move forward by a number of steps. If your object is rotated, it will automatically move in the right direction. If you want to move backward, you can just put a negative number here.


Set Pos

You can set the position of the object in your screen. For this we use (left and right) and (up and down).


Set Angle

You can rotate the object to an angle, between 0 and 360 degrees.


Set Scale

You can set the scale of the object. By default this is 1.


 

Sprites


Set Sprite

You can change the sprite of your object with these simple blocks. You can select a sprite from the different categories, but you can not upload your own sprites.