BosonX/src/game.h

132 lines
3.5 KiB
C

#ifndef __GAME_H__
# define __GAME_H__
#include "util.h"
#include "render.h"
#include "level.h"
#include <gint/display.h>
#include <libprof.h>
/* A player's movement and data information. */
struct player
{
//======= Movement =======//
/* Position in the level (world units). */
num z;
/* Movement speed along the z axis (world units/s, ≥ 0). */
num vz;
/* Current platform; when rotating, platform the player jumped from
(0..PLATFORM_COUNT-1) */
int platform;
/* Player's current movement stance. */
enum {
Running, /* Running on the ground */
Jumping, /* Jumping, with jump key still pressed */
Falling, /* Falling, typically after releasing jump key */
} stance;
/* Determine the player's animation and frame. */
void get_anim(struct anim **anim, int *frame);
/* Current animation frame. */
int frame;
/* Whether the player is airborne. */
bool airborne() const { return this->stance != Running; }
/* Jump direction.
* when not jumping: 0
* when jumping, while rotating: -1, 0 or +1
* when jumping, after rotating: 0 */
int jump_dir;
/* Time spent jumping (s). */
num jump_t;
/* Key to watch to end the jump. */
int jump_key;
/* Current height relative to current platform (world units). */
num height;
/* Vertical speed (world units/s). */
num vheight;
/* Player angle relative to -y around +z (depends on the current platform,
plus some extra during rotations). */
num world_angle() const;
vec2 world_angle_vector() const;
/* Full player position in 3D space. */
vec3 pos() const;
/* Unit vectors in the directions of movement, accounting for player's
rotation around the world cylinder. */
vec3 forward() const;
vec3 backward() const;
vec3 up() const;
vec3 down() const;
//======= Data =======//
/* Energy collected, in percent */
num energy_percent;
/* TODO: Skin, others? */
};
/* Dynamic information about one or multiple attempts at a single level. */
struct game
{
struct level level;
struct player player;
struct camera camera;
/* Absolute time spent in the level. */
num t;
/* Number of sections passed. */
int sections_passed;
struct {
bool footer; /* Show performance footer */
} debug;
struct {
prof_t effect_bpp;
} perf;
};
//======= Functions on the game world space =======//
/* Initialize constants for the game. */
void space_init(void);
/* Angle, in radians, of a platform arc (2π / PLATFORM_COUNT). */
consteval num space_platform_arc()
{
return num(2 * 3.14159 / PLATFORM_COUNT);
}
/* Height (in world coordinates in the range [-LEVEL_RADIUS..0]) of a platform
whose height value in the `struct platform` is given as parameter. */
num space_platform_height(int height_value);
/* Distance between the center of the world and a platform's plane. */
num space_platform_distance(void);
/* Position, in world units, of the provided flat platform. */
struct prect space_platform_position(struct platform const *p);
//======= Game management =======//
/* Advance in the level by discarding platforms that have been passed. */
void game_advance(struct game *game);
/* Get platform height at the provided position. */
num game_height_at(struct game *game, num z, int face);
/* Returns the platform on which the player is running, if any. */
const struct platform *game_platform_under_player(struct game const *game,
struct player const *player);
#endif /* __GAME_H__ */