LI2 Roguelite
Classes | Typedefs | Functions
map.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  map
 Structure that represents a map in the game. More...
 

Typedefs

typedef struct state State
 
typedef struct cell Cell
 
typedef struct item Item
 
typedef struct player Player
 
typedef struct projectile Projectile
 
typedef struct monster Monster
 
typedef struct map Map
 Structure that represents a map in the game. More...
 

Functions

MapinitMap (int width, int height)
 Initialize a new map. More...
 
void freeMap (void *p)
 Free the map structure. More...
 
void drawMap (Map *map, int mode)
 Draw the map according to the mode. More...
 
void generateMap (State *st)
 Generate the map based on algorithm TODO explain more. More...
 
void getPlayerInitialPosition (Map *map, int *x, int *y)
 Get the player initial (3x3 empty space) More...
 
void getRandomCoordinates (Map *map, int *x, int *y)
 Get random coordinates for monsters. More...
 
void calculateDistances (Map *map, int x, int y)
 Calculate the distances from the player to all the cells, also updates the effect and effect_duration and color of the effected cells. Finally updates the is_visible field in the cells. More...
 
void calculateVision (Map *map, Player *player)
 Calculate the vision of the player and updates the is_visible and was_visible field in the cells. More...
 
void distributeItems (Map *map, Item **items, int nr_items)
 Distribute the items on the map. More...
 
void pickUpItem (State *st)
 Get the item on the player position. More...
 
MonstergetCloserUnhurtMonster (State *st)
 Get the closer unhurt monster to the player. More...
 

Typedef Documentation

◆ Cell

typedef struct cell Cell

◆ Item

typedef struct item Item

◆ Map

typedef struct map Map

Structure that represents a map in the game.

A map is a 2D array of cells with a width and a height. It also contains an array of items distributed in the map.

Parameters
widthWidth of the map (number of columns)
heightHeight of the map (number of rows)
cells2D array of cells
has_menuDoes the map have a menu? yes if MENU_HEIGHT > 3 * height
itemsArray of items in the map
nr_itemsNumber of items in the map
projectilesArray of projectiles in the map
nr_projectilesNumber of projectiles in the map

◆ Monster

typedef struct monster Monster

◆ Player

typedef struct player Player

◆ Projectile

typedef struct projectile Projectile

◆ State

typedef struct state State

Function Documentation

◆ calculateDistances()

void calculateDistances ( Map map,
int  x,
int  y 
)

Calculate the distances from the player to all the cells, also updates the effect and effect_duration and color of the effected cells. Finally updates the is_visible field in the cells.

The distance is calculated as the maximum between the x and y distance

Parameters
mapMap to calculate
xStarting x coordinate
yStarting y coordinate

◆ calculateVision()

void calculateVision ( Map map,
Player player 
)

Calculate the vision of the player and updates the is_visible and was_visible field in the cells.

Uses the calculateVisionAux() function to calculate the vision for all eight directions

Based on the player vision width calculates the number adjacent lines of sight

Parameters
mapMap to calculate the vision
playerPlayer to calculate the vision

◆ distributeItems()

void distributeItems ( Map map,
Item **  items,
int  nr_items 
)

Distribute the items on the map.

Distribute the items randomly on the map, avoiding the player, monsters and other items

Parameters
mapMap to distribute the items
itemsArray of items to distribute
nr_itemsNumber of items in the array

◆ drawMap()

void drawMap ( Map map,
int  mode 
)

Draw the map according to the mode.

NOTE: This could be improved by only drawing the cells that have changed This could be implemented by storing bool value in a cell, per example: is_changed

Parameters
mapMap to draw
modenormal mode, vision mode or distance mode
Returns
void

◆ freeMap()

void freeMap ( void *  p)

Free the map structure.

Parameters
pa pointer to the map to free
Returns
void

◆ generateMap()

void generateMap ( State st)

Generate the map based on algorithm TODO explain more.

  • Top, bottom, left and right walls
  • Fill the rest with a 40% chance of generating walls

Saves a (int**) map twice

Parameters
stState to generate the map
Returns
void

◆ getCloserUnhurtMonster()

Monster* getCloserUnhurtMonster ( State st)

Get the closer unhurt monster to the player.

The closer monster is the one with the minimum distance to the player. Except if the monster is hurt or too close to the player (2 cells away). This function is used to determine which monster to ear.

Parameters
stState to get the monster
Returns
Monster* A close monster unhurt and 3+ cells away

◆ getPlayerInitialPosition()

void getPlayerInitialPosition ( Map map,
int *  x,
int *  y 
)

Get the player initial (3x3 empty space)

Parameters
mapMap to get the player initial position
xreturns the x coordinate
yreturns the y coordinate
Returns
void

◆ getRandomCoordinates()

void getRandomCoordinates ( Map map,
int *  x,
int *  y 
)

Get random coordinates for monsters.

Parameters
mapMap to get the random coordinates
xreturns the x coordinate
yreturns the y coordinate

◆ initMap()

Map* initMap ( int  width,
int  height 
)

Initialize a new map.

Allocates memory for the map and its cells, items and projectiles arrays.

Parameters
widthMap width
heightMap height
Returns
Map pointer to the new map

◆ pickUpItem()

void pickUpItem ( State st)

Get the item on the player position.

Removes the item from the map, adds it to the player inventory and equips it if there's no equipped item.

Also sends a message to the menu.

Parameters
stThe game state