Skip to main content

pewpew library

The pewpew library contains all the functions for configuring levels and managing entities.

Enums

EntityType

  • ASTEROID
  • BAF
  • INERTIAC
  • MOTHERSHIP
  • MOTHERSHIP_BULLET
  • ROLLING_CUBE
  • ROLLING_SPHERE
  • UFO
  • WARY
  • CROWDER
  • CUSTOMIZABLE_ENTITY
  • SHIP
  • BOMB
  • BAF_BLUE
  • BAF_RED
  • WARY_MISSILE
  • UFO_BULLET
  • SPINY
  • SUPER_MOTHERSHIP
  • PLAYER_BULLET
  • BOMB_EXPLOSION
  • PLAYER_EXPLOSION
  • BONUS
  • FLOATING_MESSAGE
  • POINTONIUM
  • KAMIKAZE
  • BONUS_IMPLOSION
  • MACE
  • PLASMA_FIELD

MothershipType

  • THREE_CORNERS
  • FOUR_CORNERS
  • FIVE_CORNERS
  • SIX_CORNERS
  • SEVEN_CORNERS

CannonType

  • SINGLE
  • TIC_TOC
  • DOUBLE
  • TRIPLE
  • FOUR_DIRECTIONS
  • DOUBLE_SWIPE
  • HEMISPHERE
  • SHOTGUN
  • LASER

CannonFrequency

  • FREQ_30
  • FREQ_15
  • FREQ_10
  • FREQ_7_5
  • FREQ_6
  • FREQ_5
  • FREQ_3
  • FREQ_2
  • FREQ_1

BombType

  • FREEZE
  • REPULSIVE
  • ATOMIZE
  • SMALL_ATOMIZE
  • SMALL_FREEZE

MaceType

  • DAMAGE_PLAYERS
  • DAMAGE_ENTITIES

BonusType

  • REINSTANTIATION
  • SHIELD
  • SPEED
  • WEAPON
  • MACE

WeaponType

  • BULLET
  • FREEZE_EXPLOSION
  • REPULSIVE_EXPLOSION
  • ATOMIZE_EXPLOSION
  • PLASMA_FIELD
  • WALL_TRAIL_LASSO
  • MACE

AsteroidSize

  • SMALL
  • MEDIUM
  • LARGE
  • VERY_LARGE

Functions

print()

pewpew.print(str: string)

Prints str in the console for debugging.

Example:

local some_number = 42
pewpew.print("the value of some_number is: " .. some_number)

pewpew.print_debug_info()

Prints debug info: the number of entities created and the amount of memory used by the script.

Example:

pewpew.print_debug_info()

set_level_size()

pewpew.set_level_size(
width: FixedPoint,
height: FixedPoint
)

Sets the level's size. Implicetely adds walls to make sure that entities can not go outside of the level's boundaries. width and height are clamped to the range ]0fx, 6000fx]. If this function is not called, the level size is (10fx, 10fx), which is uselessly small for most cases.

Example:

local width = 300fx
local height = 200fx
pewpew.set_level_size(width, height)

add_wall()

pewpew.add_wall(
start_x: FixedPoint,
start_y: FixedPoint,
end_x: FixedPoint,
end_y: FixedPoint
): int

Adds a wall to the level from (start_x,start_y) to (end_x,end_y), and returns its wall ID. A maximum of 200 walls can be added to a level.

Example:

pewpew.add_wall(100fx, 100fx, 200fx, 200fx)

remove_wall()

pewpew.remove_wall(wall_id: int)

Remove the wall with the given wall_id.

Example:

local wall_id = pewpew.add_wall(100fx, 100fx, 200fx, 200fx)
-- Later, when the wall needs to be removed:
pewpew.remove_wall(wall_id)

add_update_callback()

pewpew.add_update_callback(update_callback: function)

Adds a callback that will be updated at each game tick.

Example:

local tick_count = 0
pewpew.add_update_callback(function()
pewpew.print("this is tick " .. tick_count)
tick_count = tick_count + 1
end)

get_number_of_players()

pewpew.get_number_of_players(): int

Returns the number of players in the game.


increase_score_of_player()

pewpew.increase_score_of_player(
player_index: int,
delta: int
)

Increases the score of the player at the specified player_index by an amount of delta. player_index must in the range [0, get_number_of_players() - 1]. Note that delta can be negative.


increase_score_streak_of_player()

pewpew.increase_score_streak_of_player(
player_index: int,
delta: int
)

Increases the score streak counter of the player at the specified player_index by an amount of delta. This counter is used to determine at which level of score streak the player is at. In turn, the score streak level is used to determine how much pointonium is given. Typically the score streak counter should be increased when an enemy is destroyed with the same score that the enemy provide. player_index must in the range [0, get_number_of_players() - 1]. Note that delta can be negative.


get_score_streak_level()

pewpew.get_score_streak_level(player_index: int): int

Returns a number between 0 and 3. 0 is the lowest score streak (no pointonium is given), while 3 is the highest (3 pointoniums is usually given)


stop_game()

pewpew.stop_game()

Ends the current game.


get_player_inputs()

pewpew.get_player_inputs(player_index: int): FixedPoint, FixedPoint, FixedPoint, FixedPoint

Returns the inputs of the player at the specified index. The return values are in order: the movement joystick's angle (between 0 and 2pi), the movement joystick's distance (between 0 and 1), the shoot joystick's angle (between 0 and 2pi), and the shoot joystick's distance (between 0 and 1).

Example:

local move_angle, move_distance, shoot_angle, shoot_distance = pewpew.get_player_inputs(0)

get_score_of_player()

pewpew.get_score_of_player(player_index: int): int

Returns the score of the player at the specified player_index. player_index must in the range [0, get_number_of_players() - 1].


configure_player()

pewpew.configure_player(
player_index: int,
configuration: table {
has_lost: bool,
shield: int,
camera_x_override: FixedPoint,
camera_y_override: FixedPoint,
camera_distance: FixedPoint,
camera_rotation_x_axis: FixedPoint,
move_joystick_color: int,
shoot_joystick_color: int
}
)

Configures the player at the specified player_index. player_index must in the range [0, get_number_of_players() - 1]. A camera_distance less than 0fx makes the camera move away from the ship. camera_rotation_x_axis is in radian and rotates along the X axis. To temporarily override the XY position of the camera, set both camera_x_override and camera_y_override; this will make the camera be interpolated from wherever it was, to that new position.

Example:

pewpew.configure_player(0, {shield = 3, camera_distance = 50fx, move_joystick_color = 0xffff00ff})

configure_player_hud()

pewpew.configure_player_hud(
player_index: int,
configuration: table {
top_left_line: string
}
)

Configures the player's HUD.player_index must in the range [0, get_number_of_players() - 1].

Example:

pewpew.configure_player_hud(0, {top_left_line = "Hello World"})

get_player_configuration()

pewpew.get_player_configuration(player_index: int): table {
shield: int,
has_lost: bool
}

Returns a map containing the configuration of the player at the specified player_index.

Example:

local shield = pewpew.get_player_configuration(0).shield

configure_player_ship_weapon()

pewpew.configure_player_ship_weapon(
ship_id: EntityId,
configuration: table {
frequency: int,
cannon: int,
duration: int
}
)

Configures the weapon of the ship identified with ship_id using configuration. frequency determines the frequency of the shots. cannon determines the type of cannon. duration determines the number of game ticks during which the weapon will be available. Once the duration expires, the weapon reverts to its permanent configuration. If duration is omitted, the weapon will be permanently set to this configuration. If frequency or cannon is omitted, the ship is configured to not have any weapon.

Example:

local weapon_config = {frequency = pewpew.CannonFrequency.FREQ_10, cannon = pewpew.CannonType.DOUBLE}
local ship_id = player_helpers.new_player_ship(100fx, 200fx, 0)
pewpew.configure_player_ship_weapon(ship_id, weapon_config)

configure_player_ship_wall_trail()

pewpew.configure_player_ship_wall_trail(
ship_id: EntityId,
configuration: table {
wall_length: int
}
)

Configures a wall trail that kills everything inside when the ship it is attached to creates a loop with it. wall_length is clamped to [100, 4000]. In symbiosis, the length is 2000. If wall_length is not specified, the trail is removed.

Example:

pewpew.configure_player_ship_wall_trail(ship, {wall_length = 2000})

configure_player_ship()

pewpew.configure_player_ship(
ship_id: EntityId,
configuration: table {
swap_inputs: bool
}
)

Configures various properties of the player ship identified byid


add_damage_to_player_ship()

pewpew.add_damage_to_player_ship(
ship_id: EntityId,
damage: int
)

Reduces the amount of shield of the player that owns the ship by damage points. If the player receives damage while having 0 shields left, the player loses.


add_arrow_to_player_ship()

pewpew.add_arrow_to_player_ship(
ship_id: EntityId,
target_id: EntityId,
color: int
): int

Adds an arrow to the ship identified with ship_id pointing towards the entity identified with entity_id, and returns the identifier of the arrow. color specifies the arrow's color. The arrow is automatically removed when the target entity is destroyed.


remove_arrow_from_player_ship()

pewpew.remove_arrow_from_player_ship(
ship_id: EntityId,
arrow_id: int
)

Removes the arrow identified by arrow_id from the ship identified by ship_id.


make_player_ship_transparent()

pewpew.make_player_ship_transparent(
ship_id: EntityId,
transparency_duration: int
)

Makes the player ship transparent for transparency_duration game ticks.


set_player_ship_speed()

pewpew.set_player_ship_speed(
ship_id: EntityId,
factor: FixedPoint,
offset: FixedPoint,
duration: int
): FixedPoint

Sets and returns the effective speed of the specified player ship as a function of the base speed of the ship. By default, a player ship moves according to its base speed, which is 10 distance units per tick (in the future, different ships may have different base speeds). Assuming the base speed of the ship is S, the new effective speed will be (factor*S)+offset. duration is the number of ticks during which the effective speed will be applied. Afterwards, the ship's speed reverts to its base speed. If duration is negative, the effective speed never reverts to the base speed.


get_all_entities()

pewpew.get_all_entities(): List<EntityId>

Returns the list of the entityIDs of all the entities currently in the level. This includes the various bullets and all the custom entities.

Example:

local entities = pewpew.get_all_entities()
pewpew.print("There are " .. #entities .. " entities in the level")

get_entities_colliding_with_disk()

pewpew.get_entities_colliding_with_disk(
center_x: FixedPoint,
center_y: FixedPoint,
radius: FixedPoint
): List<EntityId>

Returns the list of collidable entities (which includes all enemies) that overlap with the given disk.

Example:

local entities = pewpew.get_entities_colliding_with_disk(100fx, 100fx, 30fx)

get_entity_count()

pewpew.get_entity_count(type: int): int

Returns the number of entities of type type that are alive.

Example:

local number_of_bafs = pewpew.get_entity_count(pewpew.EntityType.BAF)
local number_of_asteroids = pewpew.get_entity_count(pewpew.EntityType.ASTEROID)

get_entity_type()

pewpew.get_entity_type(entity_id: EntityId): int

Returns the type of the given entity.

Example:

local type = pewpew.get_entity_type(id)
if type == pewpew.EntityType.BAF then
pewpew.print("the entity is a BAF")
end

play_ambient_sound()

pewpew.play_ambient_sound(
sound_path: string,
index: int
)

Plays the sound described at sound_path at the index index.

Example:

pewpew.play_ambient_sound("/dynamic/my_custom_sound.lua", 0)

play_sound()

pewpew.play_sound(
sound_path: string,
index: int,
x: FixedPoint,
y: FixedPoint
)

Plays the sound described at sound_path at the in-game location of x,y.

Example:

pewpew.play_sound("/dynamic/my_custom_sound.lua", 0, 100fx, 100fx)

create_explosion()

pewpew.create_explosion(
x: FixedPoint,
y: FixedPoint,
color: int,
scale: FixedPoint,
particle_count: int
)

Creates an explosion of particles at the location x,y. color specifies the color of the explosion. scale describes how large the explosion will be. It should be in the range ]0, 10], with 1 being an average explosion. particle_count specifies the number of particles that make up the explosion. It must be in the range [1, 100].

Example:

pewpew.create_explosion(200fx, 100fx, 0xffffffff, 1fx, 20) -- medium explosion
pewpew.create_explosion(300fx, 100fx, 0xffffffff, 3fx, 50) -- large red explosion

add_particle()

pewpew.add_particle(
x: FixedPoint,
y: FixedPoint,
z: FixedPoint,
dx: FixedPoint,
dy: FixedPoint,
dz: FixedPoint,
color: int,
duration: int
)

Adds a particle at the given position, that moves at the given speed, with the given color and duration. The engine may not spawn all particles if are already a lot of particles alive already spawned (e.g. more than 1000)

Example:

pewpew.add_particle(10fx, 10fx, 0fx, 4fx, 0fx, 0fx, 0xffffffff, 40)

new_asteroid()

pewpew.new_asteroid(
x: FixedPoint,
y: FixedPoint
): EntityId

Creates a new Asteroid at the location x,y and returns its entityId.


new_asteroid_with_size()

pewpew.new_asteroid_with_size(
x: FixedPoint,
y: FixedPoint,
size: int
): EntityId

Creates a new Asteroid at the location x,y with an AsteroidSize given by size and returns its entityId.


new_baf()

pewpew.new_baf(
x: FixedPoint,
y: FixedPoint,
angle: FixedPoint,
speed: FixedPoint,
lifetime: int
): EntityId

Creates a new BAF at the location x,y, and returns its entityId. angle specifies the angle at which the BAF will move. speed specifies the maximum speed it will reach. lifetime indicates the number of game ticks after which the BAF is destroyed the next time it hits a wall. Specify a negative lifetime to create a BAF that lives forever.


new_baf_red()

pewpew.new_baf_red(
x: FixedPoint,
y: FixedPoint,
angle: FixedPoint,
speed: FixedPoint,
lifetime: int
): EntityId

Creates a new red BAF at the location x,y, and returns its entityId. A red BAF has more health points than a regular BAF. angle specifies the angle at which the BAF will move. speed specifies the maximum speed it will reach. lifetime indicates the number of game ticks after which the BAF is destroyed the next time it hits a wall. Specify a negative lifetime to create a BAF that lives forever.


new_baf_blue()

pewpew.new_baf_blue(
x: FixedPoint,
y: FixedPoint,
angle: FixedPoint,
speed: FixedPoint,
lifetime: int
): EntityId

Creates a new blue BAF at the location x,y, and returns its entityId. A blue BAF bounces on walls with a slightly randomized angle. angle specifies the angle at which the BAF will move. speed specifies the maximum speed it will reach. lifetime indicates the number of game ticks after which the BAF is destroyed the next time it hits a wall. Specify a negative lifetime to create a BAF that lives forever.


new_bomb()

pewpew.new_bomb(
x: FixedPoint,
y: FixedPoint,
type: int
): EntityId

Creates a new Bomb at the location x,y, and returns its entityId.

Example:

pewpew.new_bomb(10fx, 10fx, pewpew.BombType.SMALL_ATOMIZE)

new_bonus()

pewpew.new_bonus(
x: FixedPoint,
y: FixedPoint,
type: int,
config: table {
box_duration: int,
cannon: int,
frequency: int,
weapon_duration: int,
number_of_shields: int,
speed_factor: FixedPoint,
speed_offset: FixedPoint,
speed_duration: int,
taken_callback: function
}
): EntityId

Creates a new Bonus at the location x,y of the type type, and returns its entityId. For shield bonuses, the option number_of_shields determines how many shields are given out. For weapon bonuses, the options cannon, frequency, weapon_duration have the same meaning as in pewpew.configure_player_ship_weapon. For speed bonuses, the options speed_factor, speed_offset,and speed_duration have the same meaning as in set_player_speed. taken_callback is called when the bonus is taken, and is mandatory for the reinstantiation bonus. The callback receives as arguments the entity id of the bonus, the player id, and the ship's entity id. The default box duration is 400 ticks.

Example:

pewpew.new_bonus(10fx, 10fx, pewpew.BonusType.WEAPON, {cannon = pewpew.CannonType.TIC_TOC, frequency = pewpew.CannonFrequency.FREQ_5, weapon_duration = 100})
pewpew.new_bonus(10fx, 10fx, pewpew.BonusType.SHIELD, {number_of_shields = 3})

new_crowder()

pewpew.new_crowder(
x: FixedPoint,
y: FixedPoint
): EntityId

Creates a new Crowder at the location x,y, and returns its entityId.


new_floating_message()

pewpew.new_floating_message(
x: FixedPoint,
y: FixedPoint,
str: string,
config: table {
scale: FixedPoint,
dz: FixedPoint,
ticks_before_fade: int,
is_optional: bool
}
): EntityId

Creates a new floating message at the location x,y, with str as the message. The scale is a number that determines how large the message will be. 1 is the default scale. ticks_before_fade determines how many ticks occur before the message starts to fade out. is_optional can be used to tell the game if the message can be hidden depending on the user's UI settings. If not specified, scale is 1, ticks_before_fade is 30 and is_optional is false. Returns the floating message's entityId.

Example:

pewpew.new_floating_message(10fx, 10fx, "hello", {scale = 2fx, ticks_before_fade = 60, is_optional = true})

new_customizable_entity()

pewpew.new_customizable_entity(
x: FixedPoint,
y: FixedPoint
): EntityId

Creates a new customizable entity at the location x,y, and returns its entityId.


new_inertiac()

pewpew.new_inertiac(
x: FixedPoint,
y: FixedPoint,
acceleration: FixedPoint,
angle: FixedPoint
): EntityId

Creates a new Inertiac at the location x,y, and returns its entityId. The inertiac will accelerate according to acceleration. It spawns with a random velocity in a direction specified by angle.


new_kamikaze()

pewpew.new_kamikaze(
x: FixedPoint,
y: FixedPoint,
angle: FixedPoint
): EntityId

Creates a new Kamikaze at the location x,y that starts moving in the direction specified by angle.


new_mothership()

pewpew.new_mothership(
x: FixedPoint,
y: FixedPoint,
type: int,
angle: FixedPoint
): EntityId

Creates a new Mothership at the location x,y, and returns its entityId.

Example:

pewpew.new_mothership(50fx, 50fx, pewpew.MothershipType.THREE_CORNERS, fmath.tau() / 4fx)

new_mothership_bullet()

pewpew.new_mothership_bullet(
x: FixedPoint,
y: FixedPoint,
angle: FixedPoint,
speed: FixedPoint,
color: int,
large: bool
): EntityId

Creates a new mothership bullet.


new_pointonium()

pewpew.new_pointonium(
x: FixedPoint,
y: FixedPoint,
value: int
): EntityId

Creates a new Pointonium at the location x,y. Value must be 64, 128, or 256.


new_plasma_field()

pewpew.new_plasma_field(
ship_a_id: EntityId,
ship_b_id: EntityId,
config: table {
length: FixedPoint
}
): EntityId

Creates a new plasma field between ship_a and ship_b, and returns its entityId. If ship_a or ship_b is destroyed, the plasma field is destroyed as well.


new_player_ship()

pewpew.new_player_ship(
x: FixedPoint,
y: FixedPoint,
player_index: int
): EntityId

Creates a new Player Ship at the location x,y for the player identified by player_index, and returns its entityId.


new_player_bullet()

pewpew.new_player_bullet(
x: FixedPoint,
y: FixedPoint,
angle: FixedPoint,
player_index: int
): EntityId

Creates a new bullet at the location x,y with the angle angle belonging to the player at the index player_index. Returns the entityId of the bullet.


new_rolling_cube()

pewpew.new_rolling_cube(
x: FixedPoint,
y: FixedPoint
): EntityId

Creates a new Rolling Cube at the location x,y, and returns its entityId.


new_rolling_sphere()

pewpew.new_rolling_sphere(
x: FixedPoint,
y: FixedPoint,
angle: FixedPoint,
speed: FixedPoint
): EntityId

Creates a new Rolling Sphere at the location x,y, and returns its entityId.


new_spiny()

pewpew.new_spiny(
x: FixedPoint,
y: FixedPoint,
angle: FixedPoint,
attractivity: FixedPoint
): EntityId

Creates a new Spiny at the location x,y that starts moving in the direction specified by angle. attractivity specifies how much the Spiny is attracted to the closest player: 1fx is normal attractivity.


new_super_mothership()

pewpew.new_super_mothership(
x: FixedPoint,
y: FixedPoint,
type: int,
angle: FixedPoint
): EntityId

Creates a new Super Mothership at the location x,y, and returns its entityId.

Example:

pewpew.new_super_mothership(50fx, 50fx, pewpew.MothershipType.THREE_CORNERS, fmath.tau() / 4fx)

new_wary()

pewpew.new_wary(
x: FixedPoint,
y: FixedPoint
): EntityId

Creates a new Wary at the location x,y.


new_ufo()

pewpew.new_ufo(
x: FixedPoint,
y: FixedPoint,
dx: FixedPoint
): EntityId

Creates a new UFO at the location x,y moving horizontally at the speed of dx, and returns its entityId.


rolling_cube_set_enable_collisions_with_walls()

pewpew.rolling_cube_set_enable_collisions_with_walls(
entity_id: EntityId,
collide_with_walls: bool
)

Sets whether the rolling cube identified with id collides with walls. By default it does not.

Example:

local x,y = pewpew.rolling_cube_set_enable_collisions_with_walls(id, true)

ufo_set_enable_collisions_with_walls()

pewpew.ufo_set_enable_collisions_with_walls(
entity_id: EntityId,
collide_with_walls: bool
)

Sets whether the ufo identified with id collides with walls. By default it does not.

Example:

local x,y = pewpew.ufo_set_enable_collisions_with_walls(id, true)

entity_get_position()

pewpew.entity_get_position(entity_id: EntityId): FixedPoint, FixedPoint

Returns the position of the entity identified by id.

Example:

local x,y = pewpew.entity_get_position(entity_id)

entity_get_is_alive()

pewpew.entity_get_is_alive(entity_id: EntityId): bool

Returns whether the entity identified by id is alive or not.


entity_get_is_started_to_be_destroyed()

pewpew.entity_get_is_started_to_be_destroyed(entity_id: EntityId): bool

Returns whether the entity identified by id is in the process of being destroyed. Returns false if the entity does not exist.


entity_set_position()

pewpew.entity_set_position(
entity_id: EntityId,
x: FixedPoint,
y: FixedPoint
)

Sets the position of the entity identified by id to x,y


entity_set_radius()

pewpew.entity_set_radius(
entity_id: EntityId,
radius: FixedPoint
)

Sets the radius of the entity identified by id. To give you a sense of scale, motherships have a radius of 28fx.


entity_set_update_callback()

pewpew.entity_set_update_callback(
entity_id: EntityId,
callback: function
)

Sets a callback that will be called at every tick as long as the entity identified by id is alive. Remove the callback by passing a nil callback. The callbacks gets called with the entity ID.

Example:

local function my_update_callback(entity_id)
local x,y = pewpew.entity_get_position(entity_id)
pewpew.entity_set_position(entity_id, x + 2fx, y) -- move the entity to the right
end
pewpew.entity_set_update_callback(entity_id, my_update_callback)

entity_destroy()

pewpew.entity_destroy(entity_id: EntityId)

Makes the entity identified by id immediately disappear forever.


entity_react_to_weapon()

pewpew.entity_react_to_weapon(
entity_id: EntityId,
weapon: table {
type: int,
x: FixedPoint,
y: FixedPoint,
player_index: int
}
): bool

Makes the entity identified by id react to the weapon described in weapon_description. Returns whether the entity reacted to the weapon. The returned value is typically used to decide whether the weapon should continue to exist or not. In the case of an explosion, x and y should store the origin of the explosion. In the case of a bullet, x and y should store the vector of the bullet. The player identified by player_index will be assigned points. If player_index is invalid, no player will be assigned points.


entity_add_mace()

pewpew.entity_add_mace(
target_id: EntityId,
config: table {
distance: FixedPoint,
angle: FixedPoint,
rotation_speed: FixedPoint,
type: int
}
): EntityId

Adds a mace to the entity identified with entity_id. If rotation_speed exists, the mace will have a natural rotation, otherwise it will move due to inertia.


customizable_entity_set_position_interpolation()

pewpew.customizable_entity_set_position_interpolation(
entity_id: EntityId,
enable: bool
)

Sets whether the position of the mesh wil be interpolated when rendering. In general, this should be set to true if the entity will be moving.


customizable_entity_set_angle_interpolation()

pewpew.customizable_entity_set_angle_interpolation(
entity_id: EntityId,
enable: bool
)

Sets whether the angle of the mesh wil be interpolated when rendering. Angle interpolation is enabled by default.


customizable_entity_set_mesh()

pewpew.customizable_entity_set_mesh(
entity_id: EntityId,
file_path: string,
index: int
)

Sets the mesh of the customizable entity identified by id to the mesh described in the file file_path at the index index. index starts at 0. If file_path is an empty string, the mesh is removed.

Example:

local id = pewpew.new_customizable_entity(0fx, 0fx)
pewpew.customizable_entity_set_mesh(id, "/dynamic/graphics.lua", 0)

customizable_entity_set_flipping_meshes()

pewpew.customizable_entity_set_flipping_meshes(
entity_id: EntityId,
file_path: string,
index_0: int,
index_1: int
)

Similar to customizable_entity_set_mesh, but sets two meshes that will be used in alternation. By specifying 2 separate meshes, 60 fps animations can be achieved.

Example:

local id = pewpew.new_customizable_entity(0fx, 0fx)
pewpew.customizable_entity_set_flipping_meshes(id, "/dynamic/graphics.lua", 0, 1)

customizable_entity_set_mesh_color()

pewpew.customizable_entity_set_mesh_color(
entity_id: EntityId,
color: int
)

Sets the color multiplier for the mesh of the customizable entity identified by id.


customizable_entity_set_string()

pewpew.customizable_entity_set_string(
entity_id: EntityId,
text: string
)

Sets the string to be displayed as part of the mesh of the customizable entity identified by id.


customizable_entity_set_mesh_xyz()

pewpew.customizable_entity_set_mesh_xyz(
entity_id: EntityId,
x: FixedPoint,
y: FixedPoint,
z: FixedPoint
)

Sets the position of the mesh to x,y,z, relative to the center ofthe customizable entity identified by id


customizable_entity_set_mesh_z()

pewpew.customizable_entity_set_mesh_z(
entity_id: EntityId,
z: FixedPoint
)

Sets the height of the mesh of the customizable entity identified by id. A z greater to 0 makes the mesh be closer, while a z less than 0 makes the mesh be further away.


customizable_entity_set_mesh_scale()

pewpew.customizable_entity_set_mesh_scale(
entity_id: EntityId,
scale: FixedPoint
)

Sets the scale of the mesh of the customizable entity identified by id. A scale less than 1 makes the mesh appear smaller, while a scale greater than 1 makes the mesh appear larger.


customizable_entity_set_mesh_xyz_scale()

pewpew.customizable_entity_set_mesh_xyz_scale(
entity_id: EntityId,
x_scale: FixedPoint,
y_scale: FixedPoint,
z_scale: FixedPoint
)

Sets the scale of the mesh of the customizable entity identified by id along the x,y,z axis. A scale less than 1 makes the mesh appear smaller, while a scale greater than 1 makes the mesh appear larger.


customizable_entity_set_mesh_angle()

pewpew.customizable_entity_set_mesh_angle(
entity_id: EntityId,
angle: FixedPoint,
x_axis: FixedPoint,
y_axis: FixedPoint,
z_axis: FixedPoint
)

Sets the rotation angle of the mesh of the customizable entity identified by id. The rotation is applied along the axis defined by x_axis,y_axis,z_axis.

Example:

-- Rotate the entity by 45 degrees along the z_axis
pewpew.customizable_entity_set_mesh_angle(entity_id, fmath.tau() / 8fx, 0fx, 0fx, 1fx)

customizable_entity_skip_mesh_attributes_interpolation()

pewpew.customizable_entity_skip_mesh_attributes_interpolation(entity_id: EntityId)

Skips the interpolation of the mesh's attributes (x, y, z, scale_x, scale_y, scale_z, rotation) for one tick. Only applies to the attributes that were set before the call to customizable_entity_skip_mesh_attributes_interpolation


customizable_entity_configure_music_response()

pewpew.customizable_entity_configure_music_response(
entity_id: EntityId,
config: table {
color_start: int,
color_end: int,
scale_x_start: FixedPoint,
scale_x_end: FixedPoint,
scale_y_start: FixedPoint,
scale_y_end: FixedPoint,
scale_z_start: FixedPoint,
scale_z_end: FixedPoint
}
)

Configures the way the entity is going to respond to the music.

Example:

  -- Makes the entity larger
pewpew.customizable_entity_configure_music_response(entity_id, {scale_x_start = 1fx, scale_x_end = 2fx})

customizable_entity_add_rotation_to_mesh()

pewpew.customizable_entity_add_rotation_to_mesh(
entity_id: EntityId,
angle: FixedPoint,
x_axis: FixedPoint,
y_axis: FixedPoint,
z_axis: FixedPoint
)

Adds a rotation to the mesh of the customizable entity identified by id. The rotation is applied along the axis defined by x_axis,y_axis,z_axis.

Example:

-- Rotate the entity by 45 degrees along the z_axis
pewpew.customizable_entity_add_rotation_to_mesh(entity_id, fmath.tau() / 8fx, 0fx, 0fx, 1fx)

customizable_entity_set_visibility_radius()

pewpew.customizable_entity_set_visibility_radius(
entity_id: EntityId,
radius: FixedPoint
)

Sets the radius defining the visibility of the entity. This allows the game to know when an entity is actually visible, which in turns allows to massively optimize the rendering. Use the smallest value possible. If not set, the rendering radius is an unspecified large number that effectively makes the entity always be rendered, even if not visible.


customizable_entity_configure_wall_collision()

pewpew.customizable_entity_configure_wall_collision(
entity_id: EntityId,
collide_with_walls: bool,
collision_callback: function
)

collide_with_walls configures whether the entity should stop when colliding with walls. If collision_callback is not nil, it is called anytime a collision is detected. The callback gets called with the entity id of the entity withthe callback, and with the normal to the wall.

Example:

function my_wall_collision_callback(entity_id, wall_normal_x, wall_normal_y)
pewpew.print("A wall collision happened with entity " .. entity_id)
end
local id = pewpew.new_customizable_entity(100fx, 100fx)
pewpew.customizable_entity_configure_wall_collision(id, my_wall_collision_callback)

customizable_entity_set_player_collision_callback()

pewpew.customizable_entity_set_player_collision_callback(
entity_id: EntityId,
collision_callback: function
)

Sets the callback for when the customizable entity identified by id collides with a player's ship. The callback gets called with the entity id of the entity with the callback, and the player_index and ship_id that were involved in the collision. Don't forget to set a radius on the customizable entity, otherwise no collisions will be detected.

Example:

function my_collision_callback(entity_id, player_index, ship_entity_id)
pewpew.print("The entity: " .. entity_id)
pewpew.print("Collided with the ship: " .. ship_entity_id)
pewpew.print("That belongs to the player: " .. player_index)
end
local id = pewpew.new_customizable_entity(100fx, 100fx)
pewpew.customizable_entity_set_player_collision_callback(id, my_collision_callback)

customizable_entity_set_weapon_collision_callback()

pewpew.customizable_entity_set_weapon_collision_callback(
entity_id: EntityId,
weapon_collision_callback: function
)

Sets the callback for when the customizable entity identified by id collides with a player's weapon. The callback gets called with the entity_id of the entity on which the callback is set, the player_index of the player that triggered the weapon, and the type of the weapon. The callback must return a boolean saying whether the entity reacts to the weapon. In the case of a bullet, this boolean determines whether the bullet should be destroyed.

Example:

local id = pewpew.new_customizable_entity(100fx, 100fx)
pewpew.customizable_entity_set_weapon_collision_callback(id, function(entity_id, player_index, weapon_type)
pewpew.print("Collided with weapon from player: " .. player_index)
if weapon_type == pewpew.WeaponType.BULLET then
pewpew.print("Collided with bullet!")
end
return true
end)

customizable_entity_start_spawning()

pewpew.customizable_entity_start_spawning(
entity_id: EntityId,
spawning_duration: int
)

Makes the customizable entity identified by id spawn for a duration of spawning_duration game ticks.


customizable_entity_start_exploding()

pewpew.customizable_entity_start_exploding(
entity_id: EntityId,
explosion_duration: int
)

Makes the customizable entity identified by id explode for a duration of explosion_duration game ticks. After the explosion, the entity is destroyed. explosion_duration must be less than 255. Any scale applied to the entity is also applied to the explosion.


customizable_entity_set_tag()

pewpew.customizable_entity_set_tag(
entity_id: EntityId,
tag: int
)

Sets a tag on customizable entities. The tag can be read back with customizable_entity_get_tag.


customizable_entity_get_tag()

pewpew.customizable_entity_get_tag(entity_id: EntityId): int

Returns the tag that was set, or 0 if no tag was set.