Raquet / Wiki / v1x / The Actors System
The most complicated thing in Raquet are the Actors. I don't like making things more complicated than they need to be, and I wanted to keep Raquet as bare bones as possible, but when making a game you're gonna need to do something like this anyway, so why not include it?
Actors are a structure of different common game variables that can be accessed and modified easily. This page will be documenting everything an Actor can do, so it's gonna be one of the larger pages.
To create an actor, we need to create it as a pointer to an actor. If you're not familar with pointers, don't worry, nobody is.
Actor* act_placeface;
After creating an Actor, we need to allocate it, and usually we also want to initialize it:
act_placeface = Raquet_AllocateActor();
Raquet_CreateActor(act_placeface, chr_placeface);
Raquet_AllocateActor()
simply does some magical computer stuff (Allocating memory), while Raquet_CreateActor()
initializes all variables in an Actor to their default values. Passing a Raquet_CHR
value into the 2nd parameter will assign that sprite to the Actor, and will automatically assign a collision box to the height and width of the Raquet_CHR
.
After we create an actor, we can draw it on screen using the Raquet_DrawActor()
function.
Raquet_DrawActor(act_placeface);
We pass the actor we want to draw into the function, and it will be drawn on screen.
The following text lists all values that can be accessed and modified with an actor.
typedef struct Actor
{
// Where we are in virtual space
Raquet_Point position;
// How we're displayed
Raquet_CHR chr; // Current CHR
Raquet_Point origin; // Our Origin Point (x, y) default is (0, 0)
int width; // How wide we are (default is the width of the sprite)
int height; // How tall we are (default is the height of the sprite)
int angle; // Angle of the Actor, rotated around its origin
SDL_RendererFlip flip; // The Flip of the Actor
Raquet_BoundingBox bbox; // Bounding box
} Actor;
position
contains an x and y value which determines are where we are in the world relative to the Camera.
chr
is the current CHR we're displaying.
origin
contains an x and y value of the origin point of our image.
width
is how wide the actor is drawn onto the screen.
height
is how tall the actor is drawn onto the screen.
angle
is the angle of the actor's sprite, rotated around its origin.
flip
contains an SDL_RendererFlip value that controls how the sprite is flipped.
bbox
is the bounding box of our actor (contains an x, y, width, and height. x and y are always from the top left of the CHR, not the origin).
If I wanted to modify the x value of an Actor, I could do it like so:
act_placeface->position.x = 5;
For actors, we use ->
instead of .
when accessing values because it's a pointer (haha get it?). But when accessing values that contain values (e.g. the bounding box) we would do it like so:
act_placeface->bbox.x1 = 2;
act_placeface->bbox.y2 = 2;
act_placeface->bbox.width = 4;
act_placeface->bbox.height = 4;
When we're done using an Actor, we need to unload it from memory, we do this by calling Raquet_DestroyActor()
Raquet_DestroyActor(act_placeface);
Sadly, there are no explosions (yet).