|
LI2 Roguelite
|

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 | |
| Map * | initMap (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... | |
| Monster * | getCloserUnhurtMonster (State *st) |
| Get the closer unhurt monster to the player. More... | |
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.
| width | Width of the map (number of columns) |
| height | Height of the map (number of rows) |
| cells | 2D array of cells |
| has_menu | Does the map have a menu? yes if MENU_HEIGHT > 3 * height |
| items | Array of items in the map |
| nr_items | Number of items in the map |
| projectiles | Array of projectiles in the map |
| nr_projectiles | Number of projectiles in the map |
| typedef struct projectile Projectile |
| 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
| map | Map to calculate |
| x | Starting x coordinate |
| y | Starting y coordinate |
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
| map | Map to calculate the vision |
| player | Player to calculate the vision |
Distribute the items on the map.
Distribute the items randomly on the map, avoiding the player, monsters and other items
| map | Map to distribute the items |
| items | Array of items to distribute |
| nr_items | Number of items in the array |
| 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
| map | Map to draw |
| mode | normal mode, vision mode or distance mode |
| void freeMap | ( | void * | p | ) |
Free the map structure.
| p | a pointer to the map to free |
| void generateMap | ( | State * | st | ) |
Generate the map based on algorithm TODO explain more.
Saves a (int**) map twice
| st | State to generate the map |
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.
| st | State to get the monster |
| void getPlayerInitialPosition | ( | Map * | map, |
| int * | x, | ||
| int * | y | ||
| ) |
Get the player initial (3x3 empty space)
| map | Map to get the player initial position |
| x | returns the x coordinate |
| y | returns the y coordinate |
| void getRandomCoordinates | ( | Map * | map, |
| int * | x, | ||
| int * | y | ||
| ) |
Get random coordinates for monsters.
| map | Map to get the random coordinates |
| x | returns the x coordinate |
| y | returns the y coordinate |
| Map* initMap | ( | int | width, |
| int | height | ||
| ) |
Initialize a new map.
Allocates memory for the map and its cells, items and projectiles arrays.
| width | Map width |
| height | Map height |
| 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.
| st | The game state |