BosonX/src/game.h

142 lines
4.1 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 */
Collided, /* Death animation */
} stance;
/* Determine the player's animation and frame. */
void get_anim(struct anim **anim, int *frame);
/* Current animation frame (fractional for variable animation speed). */
num frame;
/* Current blue platform animation state */
num blueanim;
/* 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 cylinder (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;
/* Time in the death animation. */
num t_death;
struct {
bool footer; /* Show performance footer */
bool invincible; /* Invincibility hack */
} 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);
}
/* Distance between the center of the world cylinder and the center point of a
platform at default height. This is almost equal to the cylinder's radius,
but not quite, because the platform's edges touch the cylinder and the
platform itself cuts into it. */
num space_cylinder_quasiradius(void);
/* Position, in world units, of the provided platform. */
struct prect space_platform_position(struct platform const *p);
struct frect space_block_position(struct platform const *p);
struct prect space_block_top_position(struct platform const *p);
struct srect space_wall_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. */
struct platform *game_platform_under_player(struct game *game,
struct player const *player);
/* Returns the block platform that the player is hitting, if any. */
struct platform *game_block_hitting_player(struct game *game,
struct player const *player);
#endif /* __GAME_H__ */