#ifndef JNR_PHYSICS_H
#define JNR_PHYSICS_H

#include <stdbool.h>
#include "config.h"
#include "util/vec2.h"

/* Forward declaration */
typedef struct Tilemap Tilemap;

typedef struct Body {
    Vec2  pos;              /* top-left of AABB                */
    Vec2  vel;              /* pixels per second               */
    Vec2  size;             /* AABB dimensions                 */
    float gravity_scale;    /* 0 for flying, 1 for normal      */
    bool  on_ground;
    bool  on_ceiling;
    bool  on_wall_left;
    bool  on_wall_right;
} Body;

void physics_init(void);

/* Set / get the current world gravity (pixels/s^2) */
void  physics_set_gravity(float gravity);
float physics_get_gravity(void);

/* Set / get the current horizontal wind force (pixels/s^2, +=right) */
void  physics_set_wind(float wind);
float physics_get_wind(void);

/* Move body, apply gravity, resolve against tilemap */
void physics_update(Body *body, float dt, const Tilemap *map);

/* Simple AABB overlap test between two bodies */
bool physics_overlap(const Body *a, const Body *b);

/* Check if two AABBs defined by pos+size overlap */
bool physics_aabb_overlap(Vec2 pos_a, Vec2 size_a, Vec2 pos_b, Vec2 size_b);

#endif /* JNR_PHYSICS_H */
