BosonX/src/game.h

99 lines
2.6 KiB
C

#ifndef __GAME_H__
# define __GAME_H__
#include "util.h"
#include "render.h"
#include "level.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;
/* 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;
/* 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 =======//
/* TODO: Energy -> speed multiplier, skin, others? */
};
/* Dynamic information about one or multiple attempts at a single level. */
struct game
{
level_t 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;
};
/* Initialize constants for the game. */
void game_init(void);
/* Angle, in radians, of a platform arc (2π / PLATFORM_COUNT). */
consteval num space_platform_arc()
{
return num(2 * 3.14159 / PLATFORM_COUNT);
}
/* Distance between the center of the world and a platform's plane. */
num space_platform_distance(void);
/* Position, in world units, of a flat platform in the specified platform slot
(0..PLATFORM_COUNT-1) that has its near side at the specified depth z. */
struct prect space_platform_position(int platform_slot, num z);
#endif /* __GAME_H__ */