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
|
|
|
|
|
|
|
int jumpCount; // Number of times the player has jumped since leaving ground
|
2024-03-01 14:37:59 +08:00
|
|
|
// (Initial jump does not count)
|
|
|
|
bool onGround; // If the player is on the ground?
|
|
|
|
bool moveLeft, moveRight; // If the player is moving left/right?
|
|
|
|
} 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;
|
|
|
|
} 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);
|
|
|
|
|
2024-03-01 14:37:59 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|