phantasia

Phantasia - 2D SDL3 RPG prototype.
git clone git://git.beep.wimdupont.com/phantasia.git
Log | Files | Refs | README | LICENSE

world.h (2393B)


      1 #ifndef PH_ENGINE_WORLD_H
      2 #define PH_ENGINE_WORLD_H
      3 
      4 #include <stddef.h>
      5 
      6 enum {
      7 	PH_TILE_SIZE = 16,
      8 	PH_MAX_ENTITY_TYPES = 32,
      9 	PH_MAX_ITEM_TYPES = 64,
     10 	PH_MAX_ENTITIES = 128,
     11 	PH_MAX_GROUND_ITEMS = 128,
     12 	PH_NOTICE_SIZE = 96,
     13 };
     14 
     15 typedef enum {
     16 	PH_ENTITY_PLAYER = 1,
     17 	PH_ENTITY_MONSTER,
     18 	PH_ENTITY_NPC,
     19 } PhEntityKind;
     20 
     21 typedef struct {
     22 	float x;
     23 	float y;
     24 } PhVec2;
     25 
     26 typedef struct {
     27 	int id;
     28 	const char *name;
     29 	int max_hp;
     30 	int move_speed;
     31 	int sprite_tile_x;
     32 	int sprite_tile_y;
     33 	int blocks_movement;
     34 	PhEntityKind kind;
     35 } PhEntityDef;
     36 
     37 typedef struct {
     38 	int id;
     39 	const char *name;
     40 	int value;
     41 	int power;
     42 	int talent_points;
     43 	int sprite_tile_x;
     44 	int sprite_tile_y;
     45 } PhItemDef;
     46 
     47 typedef struct {
     48 	int type_id;
     49 	PhVec2 pos;
     50 	int hp;
     51 	int facing_x;
     52 	int facing_y;
     53 	int active;
     54 } PhEntity;
     55 
     56 typedef struct {
     57 	int item_id;
     58 	PhVec2 pos;
     59 	int amount;
     60 	int active;
     61 } PhGroundItem;
     62 
     63 typedef struct {
     64 	const char *name;
     65 	int width;
     66 	int height;
     67 	unsigned char *tiles;
     68 	int owns_tiles;
     69 } PhArea;
     70 
     71 typedef struct {
     72 	PhVec2 pos;
     73 	float viewport_w;
     74 	float viewport_h;
     75 } PhCamera;
     76 
     77 typedef struct {
     78 	PhArea area;
     79 	PhCamera camera;
     80 	PhEntityDef entity_defs[PH_MAX_ENTITY_TYPES];
     81 	PhItemDef item_defs[PH_MAX_ITEM_TYPES];
     82 	PhEntity entities[PH_MAX_ENTITIES];
     83 	PhGroundItem ground_items[PH_MAX_GROUND_ITEMS];
     84 	int player_index;
     85 	int entity_def_count;
     86 	int item_def_count;
     87 	int entity_count;
     88 	int ground_item_count;
     89 	int player_talent_points;
     90 	char notice[PH_NOTICE_SIZE];
     91 	float notice_seconds;
     92 } PhWorld;
     93 
     94 typedef struct {
     95 	int move_x;
     96 	int move_y;
     97 	int interact;
     98 } PhInput;
     99 
    100 int ph_area_load(PhArea *area, const char *path);
    101 void ph_area_free(PhArea *area);
    102 
    103 void ph_world_init(PhWorld *world, PhArea area, float viewport_w, float viewport_h);
    104 int ph_world_add_entity_def(PhWorld *world, PhEntityDef def);
    105 int ph_world_add_item_def(PhWorld *world, PhItemDef def);
    106 int ph_world_spawn_entity(PhWorld *world, int type_id, PhVec2 pos);
    107 int ph_world_drop_item(PhWorld *world, int item_id, PhVec2 pos, int amount);
    108 void ph_world_set_player(PhWorld *world, int entity_index);
    109 void ph_world_tick(PhWorld *world, PhInput input, float dt);
    110 
    111 const PhEntity *ph_world_player(const PhWorld *world);
    112 const PhEntityDef *ph_world_entity_def(const PhWorld *world, int type_id);
    113 const PhItemDef *ph_world_item_def(const PhWorld *world, int item_id);
    114 int ph_area_tile_blocked(const PhArea *area, int tx, int ty);
    115 
    116 #endif