Mentions légales du service

Skip to content
Snippets Groups Projects
map.h 2.35 KiB
Newer Older
#ifndef MAP_H
#define MAP_H

#define DEACTIVATED 0
#define ACTIVATED 1

typedef enum Direction { UP, DOWN, LEFT, RIGHT, UNKNOWN } direction;
typedef enum Floortype {
  EMPTY,      // unknown/unreachable
  GRASS,      // standard floor ' '
  WALL,       // (obstacle) '-' or '|' or '+'
  WATER,      // can be used in event to drown the player '~'
  DOOR,       // (obstacle) '[' or ']'
  TARGET,     // can be used in events 'T'
  FLOORTYPE_N // last one to know how many types there are
} floortype;

typedef enum Entitytype {
  FLAG,     // can be used as goal '@'
  SWI,      // switch to activate 'O' or 'X'
  MONSTER,  // generic monster 'M'
  NPC,      // generic NPC 'A'
  PUSHABLE, // (obstacle/can't walk on it) a block that can be pushed like in
            // sokoban 'B'
  TRAP,     // an invisible trap '_',
  ITEM,     // generic item 'I'
  ENTITY_N  // last one to know how many types there are
#include "agdbentures.h"

SZCZEPANSKI Marin's avatar
SZCZEPANSKI Marin committed
typedef struct Tile {
  int category;  // identifier to display the tile
  bool obstacle; // whether the player can move on it or not
SZCZEPANSKI Marin's avatar
SZCZEPANSKI Marin committed
typedef struct Entity {
  int id;       // identifier to display and use in events
  int category; // used to group in events, like monster, NPC...
  int *stats;   // any property the entity may have (life points, state...)
  char display_symbol; // The symbol of the Entity on an ASCII map
SZCZEPANSKI Marin's avatar
SZCZEPANSKI Marin committed
typedef struct Map {
  char *name;   // shop, overworld, dungeon_Nth_level...
  tile **floor; // immobile floor
  entity *
      *entities; // ennemies, NPCs, items, switches... anything used by events
  int width;     // map size
  int height;
  int player_x; // player position & direction
  int player_y;
  direction player_direction;
} map;

#define MAX_MAPS 256

SZCZEPANSKI Marin's avatar
SZCZEPANSKI Marin committed
typedef struct Map_stack {
  map maps[MAX_MAPS];
  int length;
} map_stack;

void init_map_stack(void);
map *load_map(const char *name, const char *data);
map *create_empty_map(const char *name, const int width, const int height);
map *unload_map(void);

int coord_idx(int y, int x);
int player_idx(void);

map *current_map(void);

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,
                  char display_symbol);
void free_map_stack(void);
bool is_obstacle(int y, int x);
// displays the current map in ASCII
void show_map(void);