JacksEscape/player.h

73 lines
1.8 KiB
C
Raw Normal View History

2024-03-01 14:37:59 +08:00
#pragma once
2024-03-05 11:40:42 +08:00
#include "types.h"
2024-03-01 14:37:59 +08:00
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _Entity Entity;
// Player controller component.
// Only one entity should have this.
typedef struct {
Entity *super;
2024-03-01 17:09:24 +08:00
2024-03-05 15:20:32 +08:00
int faceDirection; // +1 for right, -1 for left
TimePoint lastDash;
int dashCount; // Number of dashes the player did since in air
int jumpCount; // Number of times the player has jumped since leaving ground
// (Initial jump does not count)
double storedSpeedY; // Speed stored in the middle of a dash
bool onGround; // If the player is on the ground?
bool moveLeft, moveRight; // If the player is moving left/right?
2024-03-30 21:25:39 +08:00
Vec2 hazardRespawn; // Where the last hazard respawn is
2024-03-01 14:37:59 +08:00
} Component_Player;
2024-03-01 17:09:24 +08:00
typedef struct _App App;
2024-03-01 14:37:59 +08:00
// Player controller instance.
// Reads input from the app.
typedef struct {
2024-03-01 17:09:24 +08:00
App *super;
2024-03-01 14:37:59 +08:00
// The player in the world.
// Control is paused if equals NULL.
Component_Player *player;
2024-04-14 14:34:01 +08:00
// Cutoff Y position.
// If the player is lower than this position, the player is environment harmed.
double cutoff;
2024-03-01 14:37:59 +08:00
} System_Player;
2024-03-01 17:09:24 +08:00
System_Player *player_NewSystem(App *super);
void player_DeleteSystem(System_Player *sys);
// Adds an entity.
void player_AddEntity(System_Player *sys, Entity *e);
// Deletes an entity.
void player_DeleteEntity(System_Player *sys, uintptr_t id);
// Called on every frame.
void player_Advance(System_Player *sys, Duration deltaTime);
// Harm the player.
// The player is hit backwards, releasing a puff of smoke.
//
// To be implemented
// void player_Harm(System_Player *sys, Vec2 source);
// Hazard harm the player.
// The player is teleported to the hazard respawn point.
void player_HazardHarm(System_Player *sys);
2024-03-01 14:37:59 +08:00
#ifdef __cplusplus
}
#endif