|
LI2 Roguelite
|
#include <stdio.h>#include <stdlib.h>#include <time.h>#include <ncurses.h>#include "map.h"#include "cell.h"#include "player.h"#include "state.h"#include "monster.h"#include "item.h"#include "combat.h"#include "inventory.h"#include "menu.h"
Functions | |
| Map * | initMap (int width, int height) |
| Initialize a new map. More... | |
| void | freeMap (void *p) |
| Free the map structure. More... | |
| int | radius_count (State *s, int row, int col, int radius) |
| Counts the number of walls within a given radius around a specific position. More... | |
| void | generateMap (State *st) |
| Generate the map based on algorithm TODO explain more. More... | |
| void | drawMap (Map *map, int mode) |
| Draw the map according to the mode. 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 | calculateVisionAux (Map *map, int x, int y, int direction, int n) |
| Calculates the vision for one line of sight. 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 * | getCloserMonster (State *st) |
| Get the closer monster to the player. More... | |
| Monster * | getCloserUnhurtMonster (State *st) |
| Get the closer unhurt monster to the player. 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.
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 |
| void calculateVisionAux | ( | Map * | map, |
| int | x, | ||
| int | y, | ||
| int | direction, | ||
| int | n | ||
| ) |
Calculates the vision for one line of sight.
Recursive function given a starting position, a direction and a distance
| map | Map to calculate the specific line of sight |
| x | Starting x coordinate |
| y | Starting y coordinate |
| direction | Direction of the line of sight |
| n | Distance of the line of sight |
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 monster to the player.
The closer monster is the one with the minimum distance to the player. Return the first monster found if there are more than one with the same distance.
| st | State to get the closer monster |
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 |
| int radius_count | ( | State * | s, |
| int | row, | ||
| int | col, | ||
| int | radius | ||
| ) |
Counts the number of walls within a given radius around a specific position.
| s | State to count the walls |
| row | Row of the position |
| col | Column of the position |
| radius | Radius around the position |