Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 0c22da4f authored by BAROLLET Theo's avatar BAROLLET Theo
Browse files

added a custom display character to entities

parent b2821990
No related branches found
No related tags found
No related merge requests found
...@@ -21,12 +21,13 @@ void place_player(map *m, int y, int x, direction dir) { ...@@ -21,12 +21,13 @@ void place_player(map *m, int y, int x, direction dir) {
m->player_direction = dir; m->player_direction = dir;
} }
void place_entity(map *m, int y, int x, int id, int category, int *stats) { void place_entity(map *m, int y, int x, int id, int category, int *stats, char display_symbol) {
// Creates entity // Creates entity
entity * e = malloc(sizeof(entity)); entity * e = malloc(sizeof(entity));
e->id = id; e->id = id;
e->category = category; e->category = category;
e->stats = stats; e->stats = stats;
e->display_symbol = display_symbol;
// Place it on the map // Place it on the map
m->entities[coord_idx(y, x)] = e; m->entities[coord_idx(y, x)] = e;
...@@ -36,6 +37,7 @@ entity * create_entity(char type, int id) { ...@@ -36,6 +37,7 @@ entity * create_entity(char type, int id) {
entity * i = malloc(sizeof(entity)); entity * i = malloc(sizeof(entity));
i->id = id; i->id = id;
i->stats = NULL; i->stats = NULL;
i->display_symbol = type;
switch (type) { switch (type) {
case '@': i->category = FLAG; break; case '@': i->category = FLAG; break;
case 'O': case 'O':
......
...@@ -39,6 +39,7 @@ typedef struct Entity { ...@@ -39,6 +39,7 @@ typedef struct Entity {
int id; // identifier to display and use in events int id; // identifier to display and use in events
int category; // used to group in events, like monster, NPC... int category; // used to group in events, like monster, NPC...
int *stats; // any property the entity may have (life points, state...) int *stats; // any property the entity may have (life points, state...)
char display_symbol; // The symbol of the Entity on an ASCII map
} entity; } entity;
typedef struct Map { typedef struct Map {
...@@ -71,7 +72,8 @@ int player_idx(void); ...@@ -71,7 +72,8 @@ int player_idx(void);
map *current_map(void); map *current_map(void);
void place_player(map *m, int y, int x, direction dir); void place_player(map *m, int y, int x, direction dir);
void place_entity(map *m, int y, int x, int id, int category, int *stats); void place_entity(map *m, int y, int x, int id, int category, int *stats,
char display_symbol);
void free_map_stack(void); void free_map_stack(void);
......
...@@ -54,7 +54,7 @@ int main() { ...@@ -54,7 +54,7 @@ int main() {
// Init map and entities // Init map and entities
map * m = create_empty_map("main", 20, 8); map * m = create_empty_map("main", 20, 8);
place_player(m, 4, 8, UNKNOWN); place_player(m, 4, 8, UNKNOWN);
place_entity(m, 4, 3, 0, NPC, NULL); place_entity(m, 4, 3, 0, NPC, NULL, 'P');
init_buffer(&command_buffer); init_buffer(&command_buffer);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment