jjOBJ class JJ2+

An object of the level

Enemies, pickups, bullets, platforms, light sources and similar things placed in or spawned into the level. Every object has a slot in jjObjects, and new objects start as a copy of their template in jjObjectPresets. Besides position, speed and animation, an object carries a jjOBJ::behavior that runs once per tick, a state machine (jjOBJ::state) and handling settings that decide how it reacts to players and bullets.

Functions

void behave(BEHAVIOR::Behavior behavior = BEHAVIOR::DEFAULT, bool draw = true) partially supported
Runs a built-in behavior for the object once
void behave(jjBEHAVIOR behavior, bool draw = true)
Runs the given behavior for the object once
void behave(jjVOIDFUNCOBJ@ behavior, bool draw = true)
Runs the given behavior function for the object once
void bePlatform(float xOld, float yOld, int width = 0, int height = 0) partially supported
Lets players stand on top of the object
int beSolid(bool shouldCheckForStompingLocalPlayers = false)
Makes the object solid for players
void blast(int maxDistance, bool blastObjects) partially supported
Hurts and pushes away players near the object, like an explosion
void clearPlatform()
Releases players standing on the object
void deactivate()
Unloads the object, usually in response to STATE::DEACTIVATE
void delete()
Removes the object from the level permanently
int16 determineCurAnim(uint8 setID, uint8 animation, bool change = true)
Computes the animation index for an animation of a set
int16 determineCurAnim(ANIM::Set setID, uint8 animation, bool change = true)
Computes the animation index for an animation of a set
uint determineCurFrame(bool change = true)
Computes the frame for the current animation and frame index
bool doesCollide(const jjOBJ@ object, bool always = false) const
Checks whether the sprites of this object and another object overlap
bool doesCollide(const jjPLAYER@ player, bool always = false) const partially supported
Checks whether the sprite of this object overlaps a player
int draw() partially supported
Draws the object
int findNearestPlayer(int maxDistance) const
Finds the nearest player
int findNearestPlayer(int maxDistance, int&out foundDistance) const
Finds the nearest player and its distance
int fireBullet(uint8 eventID) const
Fires a bullet from the object
void grantPickup(jjPLAYER@ player, int frequency) const partially supported
Possibly drops a random pickup, as destroyed enemies and crates do
jjOBJ@ objectHit(jjOBJ@ target, HANDLING::Player playerHandling) partially supported
Makes this object hit another one as a bullet
void particlePixelExplosion(int style) const partially supported
Bursts the current frame of the object into pixel particles
void pathMovement() partially supported
Moves the object along a path of waypoints
void putOnGround(bool precise = false)
Moves the object down onto the ground below it
bool ricochet()
Makes a bullet bounce off
int unfreeze(int style) partially supported
Unfreezes the object

Properties

int age C++
General-purpose value, the game doesn't change it by itself
int animSpeed
Animation speed, or damage of a bullet
jjBEHAVIOR behavior partially supported
Behavior that runs for the object once per tick
HANDLING::Bullet bulletHandling partially supported
How the object reacts when a bullet touches it
bool causesRicochet partially supported
Whether bullets bounce off the object
int counter C++
General-purpose counter, mostly used by behaviors to time upcoming events
uint8 counterEnd
Smaller general-purpose counter
int creator deprecated
Creator ID and creator type combined into one number
uint16 creatorID
The ID of the object or player that created this object
CREATOR::Type creatorType
What kind of thing created this object
int16 curAnim
Animation the object takes its frames from
uint curFrame
Frame currently shown for the object
bool deactivates
Whether the object is unloaded when far away from players
int8 direction
Direction the object faces
uint8 doesHurt C++
General-purpose value, the game doesn't use it by itself
int8 energy
Remaining health of the object
uint8 eventID
Event the object was created from
int8 frameID C++
Index of the current frame within jjOBJ::curAnim
uint8 freeze
Remaining time the object stays frozen, in ticks
bool isActive read-only
Whether the object currently exists
bool isBlastable partially supported
Whether explosions affect the object
bool isFreezable partially supported
Whether ice bullets freeze the object
bool isTarget partially supported
Whether homing attacks go after the object
uint8 justHit
Ticks left of the white flash shown after a hit
int16 killAnim C++
Animation used while the object is being destroyed, in the same form as jjOBJ::curAnim
int8 light partially supported
Size of the light emitted by the object, see jjOBJ::lightType
uint8 lightType
Kind of light the object emits
int8 noHit deprecated partially supported
Legacy hit flags
const int16 objectID C++
Index of the object in jjObjects
uint8 objType deprecated partially supported
Legacy object category
int8 oldState C++
State the object was in before it got frozen
HANDLING::Player playerHandling
How the object reacts when a player touches it
uint16 points partially supported
Score the object is worth when a player destroys it
bool scriptedCollisions partially supported
Whether the script decides what happens when the object is hit
int special
General-purpose value with a meaning specific to each object
int8 state
Current state of the object
bool triggersTNT partially supported
Whether the object sets off nearby TNT
int var[uint8]
A general-purpose value of the object
float xAcc C++
Horizontal acceleration in pixels per tick squared
float xOrg C++
Horizontal position the object was created at, in pixels
float xPos C++
Current horizontal position in pixels
float xSpeed C++
Horizontal speed in pixels per tick, negative to the left
float yAcc C++
Vertical acceleration in pixels per tick squared
float yOrg C++
Vertical position the object was created at, in pixels
float yPos C++
Current vertical position in pixels
float ySpeed C++
Vertical speed in pixels per tick, negative upward

Function documentation

void jjOBJ::behave(BEHAVIOR::Behavior behavior = BEHAVIOR::DEFAULT, bool draw = true)

Runs a built-in behavior for the object once

Parameters
behavior Behavior to run
draw Whether the object should be drawn

Doesn't change jjOBJ::behavior. With BEHAVIOR::DEFAULT, the object's own behavior runs instead. Typically called from a custom behavior to reuse a built-in one.

void jjOBJ::behave(jjBEHAVIOR behavior, bool draw = true)

Runs the given behavior for the object once

Parameters
behavior Behavior to run
draw Whether the object should be drawn

Accepts any form a jjBEHAVIOR can hold and doesn't change jjOBJ::behavior.

void jjOBJ::behave(jjVOIDFUNCOBJ@ behavior, bool draw = true)

Runs the given behavior function for the object once

Parameters
behavior Function to run
draw Whether the object should be drawn

void jjOBJ::bePlatform(float xOld, float yOld, int width = 0, int height = 0)

Lets players stand on top of the object

Parameters
xOld Horizontal position of the object in the previous tick
yOld Vertical position of the object in the previous tick
width Width of the platform in pixels, 0 to derive it from the current frame
height Currently ignored

Call it every tick while the object should carry players. Only affects objects of the game driven by a script behavior.

int jjOBJ::beSolid(bool shouldCheckForStompingLocalPlayers = false)

Makes the object solid for players

Parameters
shouldCheckForStompingLocalPlayers A player buttstomping onto it is one more hit (force 1) for a behavior with scriptedCollisions
Returns -1 or 1 while a player pushes it left or right, 0 otherwise

Solid by its current frame for this tick, where it is. A player standing on it is lifted when it moves up.

void jjOBJ::blast(int maxDistance, bool blastObjects)

Hurts and pushes away players near the object, like an explosion

Parameters
maxDistance Squared radius in pixels
blastObjects Currently ignored, other objects are not affected

Every vulnerable player whose squared distance from the object in pixels is less than maxDistance loses one point of health and is knocked away from the object.

void jjOBJ::clearPlatform()

Releases players standing on the object

Call it before removing an object that used jjOBJ::bePlatform().

void jjOBJ::deactivate()

Unloads the object, usually in response to STATE::DEACTIVATE

An object placed in the level is restored to the event map, so it comes back when a player gets near again. Any other object is removed permanently.

void jjOBJ::delete()

Removes the object from the level permanently

The object stops being active immediately.

int16 jjOBJ::determineCurAnim(uint8 setID, uint8 animation, bool change = true)

Computes the animation index for an animation of a set

Parameters
setID Animation set, an ANIM::Set constant is recommended
animation Zero-based index of the animation within the set
change Whether to also store the result in jjOBJ::curAnim
Returns The computed animation, an index of jjAnimations

The result is the first animation of the set plus animation, or 0 if the set isn't available.

int16 jjOBJ::determineCurAnim(ANIM::Set setID, uint8 animation, bool change = true)

Computes the animation index for an animation of a set

Parameters
setID Animation set
animation Zero-based index of the animation within the set
change Whether to also store the result in jjOBJ::curAnim
Returns The computed animation, an index of jjAnimations

The result is the first animation of the set plus animation, or 0 if the set isn't available. The set can also be a custom one.

uint jjOBJ::determineCurFrame(bool change = true)

Computes the frame for the current animation and frame index

Parameters
change Whether to also store the result in jjOBJ::curFrame
Returns The computed frame, an index of jjAnimFrames

The result is the first frame of jjOBJ::curAnim plus jjOBJ::frameID wrapped to the length of the animation, or 0 if the animation has no frames.

bool jjOBJ::doesCollide(const jjOBJ@ object, bool always = false) const

Checks whether the sprites of this object and another object overlap

Parameters
object Object to test against
always Whether a single shared pixel is enough, otherwise a few are needed (bullets always need just one)

Compares the pixels of the current frames at the objects' positions and directions. Handling settings, scaling and rotation aren't taken into account.

bool jjOBJ::doesCollide(const jjPLAYER@ player, bool always = false) const

Checks whether the sprite of this object overlaps a player

Parameters
player Player to test against
always Currently ignored

Compares the pixels of the current frame of the object with the hitbox of the player.

int jjOBJ::draw()

Draws the object

Returns Always 0

Uses the position, direction and jjOBJ::curFrame of the object, which is enough for most objects.

int jjOBJ::findNearestPlayer(int maxDistance) const

Finds the nearest player

Parameters
maxDistance Squared search radius in pixels
Returns Index of the nearest player within the radius, or a negative number if there is none

int jjOBJ::findNearestPlayer(int maxDistance, int&out foundDistance) const

Finds the nearest player and its distance

Parameters
maxDistance Squared search radius in pixels
foundDistance out Receives the squared distance of the found player in pixels
Returns Index of the nearest player within the radius, or a negative number if there is none

int jjOBJ::fireBullet(uint8 eventID) const

Fires a bullet from the object

Parameters
eventID Event of the bullet, usually an OBJECT::Object constant
Returns Object ID of the bullet, or 0 on failure

Creates an object of the given event at the gun spot of the current frame, facing the same way as this object and with this object as its creator.

void jjOBJ::grantPickup(jjPLAYER@ player, int frequency) const

Possibly drops a random pickup, as destroyed enemies and crates do

One time in frequency, a carrot, a fast fire or a red gem falls out of the object.

jjOBJ@ jjOBJ::objectHit(jjOBJ@ target, HANDLING::Player playerHandling)

Makes this object hit another one as a bullet

Parameters
target Object being hit
playerHandling Currently ignored
Returns The target object

The game resolves the collision between the two objects as if they really touched, wherever they are, and the target's jjOBJ::energy is updated afterward.

void jjOBJ::particlePixelExplosion(int style) const

Bursts the current frame of the object into pixel particles

Parameters
style Currently ignored, every style looks the same

Same as jjAddParticlePixelExplosion() with the position, frame and direction of the object.

void jjOBJ::pathMovement()

Moves the object along a path of waypoints

void jjOBJ::putOnGround(bool precise = false)

Moves the object down onto the ground below it

Parameters
precise Whether to place the object exactly

Without precise, the result can be a few pixels off, which is fine for most objects. Also resets jjOBJ::ySpeed.

bool jjOBJ::ricochet()

Makes a bullet bounce off

Returns True if the object is a bullet and bounced, false otherwise

A bullet a script made turns around, a bullet of the game bounces off as from a wall.

int jjOBJ::unfreeze(int style)

Unfreezes the object

Parameters
style Currently ignored
Returns Value jjOBJ::freeze had before

Sets jjOBJ::freeze to 0.

Property documentation

int jjOBJ::animSpeed

Animation speed, or damage of a bullet

For bullets, how much damage they deal.

jjBEHAVIOR jjOBJ::behavior

Behavior that runs for the object once per tick

Either a BEHAVIOR::Behavior constant, a jjVOIDFUNCOBJ function or a jjBEHAVIORINTERFACE instance. Assigning to the behavior of a template in jjObjectPresets (typically in onLevelLoad()) changes every object of that event created afterward.

HANDLING::Bullet jjOBJ::bulletHandling

How the object reacts when a bullet touches it

bool jjOBJ::causesRicochet

Whether bullets bounce off the object

uint8 jjOBJ::counterEnd

Smaller general-purpose counter

For bullets, how long they fly before they explode.

int jjOBJ::creator

Creator ID and creator type combined into one number

Use jjOBJ::creatorID and jjOBJ::creatorType instead.

uint16 jjOBJ::creatorID

The ID of the object or player that created this object

An index of jjObjects or jjPlayers, depending on jjOBJ::creatorType, or 0 if no creator is known.

CREATOR::Type jjOBJ::creatorType

What kind of thing created this object

CREATOR::OBJECT for an object made by another object, CREATOR::PLAYER for one made by a player, or CREATOR::LEVEL for one placed in the level.

int16 jjOBJ::curAnim

Animation the object takes its frames from

An index of jjAnimations. Use jjOBJ::determineCurAnim() to get the value for an animation of a set.

uint jjOBJ::curFrame

Frame currently shown for the object

An index of jjAnimFrames that combines jjOBJ::curAnim and jjOBJ::frameID. Use jjOBJ::determineCurFrame() to compute it.

bool jjOBJ::deactivates

Whether the object is unloaded when far away from players

When true, the object enters STATE::DEACTIVATE once it gets too far from players. An object placed in the level then comes back, reset, when a player gets near again.

int8 jjOBJ::direction

Direction the object faces

Zero or positive for right, negative for left.

int8 jjOBJ::energy

Remaining health of the object

For enemies, the number of hits the object can still take.

uint8 jjOBJ::eventID

Event the object was created from

Usually compared with OBJECT::Object constants. It is the only reliable way to tell what kind of object this is, so changing it may make the object behave unexpectedly.

uint8 jjOBJ::freeze

Remaining time the object stays frozen, in ticks

0 when the object isn't frozen. Built-in behaviors count it down, custom behaviors have to do so themselves.

bool jjOBJ::isActive read-only

Whether the object currently exists

False for a free slot of jjObjects or an object that has been deleted, which is the same as its jjOBJ::behavior being BEHAVIOR::INACTIVE. Deleted objects stop being active immediately, even though the game removes them only at the end of the frame.

bool jjOBJ::isBlastable

Whether explosions affect the object

bool jjOBJ::isFreezable

Whether ice bullets freeze the object

When false, ice bullets hit the object like any other bullet.

bool jjOBJ::isTarget

Whether homing attacks go after the object

uint8 jjOBJ::justHit

Ticks left of the white flash shown after a hit

While non-zero, the object is drawn in a single color. The game counts it down by itself.

int8 jjOBJ::light

Size of the light emitted by the object, see jjOBJ::lightType

uint8 jjOBJ::lightType

Kind of light the object emits

One of the LIGHT::Type constants, its size is given by jjOBJ::light.

HANDLING::Player jjOBJ::playerHandling

How the object reacts when a player touches it

For example, HANDLING::ENEMY hurts the player, HANDLING::PICKUP is collected and HANDLING::SPECIAL runs code specific to the object. Bullets use HANDLING::PLAYERBULLET or HANDLING::ENEMYBULLET.

uint16 jjOBJ::points

Score the object is worth when a player destroys it

bool jjOBJ::scriptedCollisions

Whether the script decides what happens when the object is hit

When true and jjOBJ::playerHandling is HANDLING::PICKUP or HANDLING::SPECIAL, collisions with players and bullets call onObjectHit() of the object's behavior class, or the global onObjectHit() function, instead of the game's own handling.

int jjOBJ::special

General-purpose value with a meaning specific to each object

For bullets, the animation used when they are fired upward.

int8 jjOBJ::state

Current state of the object

One of the STATE::State constants, for example STATE::START for a new object or STATE::KILL for one that has been destroyed.

bool jjOBJ::triggersTNT

Whether the object sets off nearby TNT

int jjOBJ::var[uint8]

A general-purpose value of the object

Each object has a small array of integers that behaviors use for anything they need. Indices 0 to 15 are available, reading other ones gives 0 and writing them has no effect.