Page:
Home
7
Home
Sara edited this page 2023-07-15 22:25:40 +00:00
Table of Contents
WIKI IS VERY WIP, NOT ALL FEATURES ARE DOCUMENTED
Compiling
The basic requirements to compile & run a game are:
minimal src/game.c
#include "corelib/entry.h"
void start_game() {}
void update_game() {}
void update_ui() {}
void game_exit() {}
These are the callbacks you can use to work the game's systems outside of the game world.
If these functions are not defined, the engine will fail to link.
You could build your entire game inside of these functions, and leave the rest of the engine as it is. But the engine does offer further abstractions of gameplay concepts.
World
The world allows you to submit objects to the engine to be managed, drawn, and updated. You can initialize the scene, program the game's logic inside of these game objects, and avoid complicating update_game
.
An example: src/game.c
#include "player.h"
...
void start_game() {
make_player();
}
...
src/player.h
extern void make_player();
src/player.c
#include "corelib/entry.h"
#include "corelib/world.h"
#include "corelib/render.h"
#include "corelib/input.h"
#include "corelib/math/vec.h"
static const float MAX_PLAYER_SPEED = 5;
// locally linked input states
static float input_move_x = 0.f;
static float input_move_y = 0.f;
// input callback events
static
void input_horizontal(int axis) {
input_move_x = axis;
}
static
void input_vertical(int axis) {
input_move_y = -axis;
}
static
void update_player(object_t* this) {
const float delta_time = delta_time();
NORMALIZE(input_move_x, input_move_y);
this->sprite.x += delta_time * input_move_x * MAX_PLAYER_SPEED;
this->sprite.y += delta_time * input_move_y * MAX_PLAYER_SPEED;
}
void make_player() {
// spawn an object into the world
object_t* player = make_object();
player->sprite = make_sprite("resources/player.png", 0.f, 0.f);
player->evt_update = &update_player;
// register the input callbacks
add_key_listener(SDL_SCANCODE_A, SDL_SCANCODE_D, &input_horizontal);
add_key_listener(SDL_SCANCODE_S, SDL_SCANCODE_W, &input_vertical);
}