Movement
Brasa moves the instances by itself on every step: it adds hspeed to x and vspeed to y, after applying gravity and friction. You only set the speeds.
Angles are in degrees: 0 = right, 90 = up, 180 = left, 270 = down.
Properties
Section titled “Properties”| Property | Type | What it is |
|---|---|---|
hspeed |
float |
Horizontal speed, in pixels per step. Positive = right. |
vspeed |
float |
Vertical speed, in pixels per step. Positive = down. |
gravity |
float |
Acceleration per step in the direction gravityDirection. 0 = no gravity. |
gravityDirection |
float |
Direction of the gravity in degrees. Default 270 (downwards). |
friction |
float |
How much the total speed decreases per step, until it stops (without reversing direction). |
maxFallSpeed |
float |
The fall limit: downward vspeed never goes past it. Going up is not limited. 0 = no limit. |
In the editor, these four are in the Física (physics) section of the object’s Inspector and are already set when onSpawn runs.
Functions
Section titled “Functions”| Function | What it does | Example |
|---|---|---|
float speed() const |
The current speed (the length of hspeed and vspeed together). |
if (speed() > 4) ... |
void setSpeed(float value) |
Changes the speed, keeping the direction. | setSpeed(3); |
float direction() const |
The direction of the movement, from 0 to 360 degrees. | float d = direction(); |
void setDirection(float degrees) |
Points the movement at an angle, keeping the speed. | setDirection(90); |
void push(float degrees, float force) |
Adds speed in a direction. | push(90, 6); // upward push |
void moveToward(float targetX, float targetY, float velocity) |
Points at a spot and sets the speed. | moveToward(player.x, player.y, 1.5f); |
bool moveAndStop(float dx, float dy) |
Moves dx, dy pixel by pixel and stops against a solid, zeroing the speed on that axis. Returns true if it hit. |
moveAndStop(dx, 0); |
bool moveAndStop() |
The platformer default: applies gravity and friction and moves by hspeed/vspeed, stopping at solids. Call it once in onUpdate. |
moveAndStop(); |
bool onGround() |
true if there is a solid 1 pixel below the collision box. |
if (pressed("pular") && onGround()) vspeed = -4.5f; |
bool hitFloor() const |
After moveAndStop: it hit the floor, going down. |
if (hitFloor()) ... |
bool hitCeiling() const |
After moveAndStop: it hit the ceiling, going up. |
if (hitCeiling()) ... |
bool hitWall() const |
After moveAndStop: it hit a wall, on either side. |
if (hitWall()) flipX = !flipX; |
bool hitWallLeft() const, bool hitWallRight() const |
The same, only for the wall on the left or on the right. | if (hitWallLeft()) ... |
The hit... functions describe the last call to moveAndStop and hold until the next one. See Platformer.
- The direction is remembered even with the instance stopped, so
setSpeed(2)after stopping moves it the same way again. - When
moveAndStopmoves on a step, the automatic movement byhspeed/vspeedis skipped on that step, so it doesn’t move twice. moveAndStopmoves at most 4096 pixels per axis in one call. Whoever starts inside a solid can get out, but can’t go further in.- For walls, check Sólido (solid) on the wall object. See Collisions.
