JacksEscape/Component_Physics.h

61 lines
1.1 KiB
C
Raw Normal View History

2024-02-29 11:22:52 +08:00
#pragma once
2024-02-29 16:17:55 +08:00
#include "util/tree.h"
#include "util/vector.h"
2024-02-29 11:22:52 +08:00
#include "Types.h"
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
2024-02-29 16:17:55 +08:00
typedef struct _Entity Entity;
extern double physics_Gravity;
2024-02-29 11:22:52 +08:00
typedef struct {
Entity *super;
2024-02-29 16:17:55 +08:00
Vec2 position;
Vec2 velocity;
2024-02-29 11:22:52 +08:00
} Component_Position;
// Box is relative to Position if exists
// if not, Box is absolute
//
// Moving hitboxes only hits fixed hitboxes
typedef struct {
Entity *super;
2024-02-29 16:17:55 +08:00
Box2 box;
bool fixed;
2024-02-29 11:22:52 +08:00
} Component_Hitbox;
2024-02-29 16:17:55 +08:00
// Physics manager
typedef struct {
// Every Position & Hitbox components
tree_Tree *pos, *hit;
vector_Vector *flaggedDelete;
} System_Physics;
// Returns an empty physics system.
System_Physics *physics_NewSystem();
// Frees a physics system.
void physics_DeleteSystem(System_Physics *sys);
// Adds an entity.
void physics_AddEntity(System_Physics *sys, Entity *e);
// Deletes an entity.
void physics_DeleteEntity(System_Physics *sys, uintptr_t id);
// Advance is called on every frame.
void physics_Advance(System_Physics *sys, Duration deltaTime);
2024-02-29 11:22:52 +08:00
#ifdef __cplusplus
}
#endif