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

Go to the source code of this file.

Macros

#define MAX_PROJECTILES   20
 

Typedefs

typedef struct state State
 
typedef struct map Map
 
typedef struct projectile Projectile
 
typedef struct monster Monster
 

Functions

void throwRock (State *st)
 Function to throw a rock projectile. More...
 
void throwProjectile (State *st)
 
void drawProjectiles (Map *map)
 Draw all visible projectiles. More...
 
void updateProjectiles (State *st)
 
void freeProjectile (void *p)
 
void killMonster (State *st, int x, int y)
 Function to kill a monster with his coordinates. More...
 
int calculateDamage (int attack, int defense, int turn)
 Calculates the damage of an attack. More...
 
void monsterAttacksPlayer (State *st, Monster *monster)
 Function that attacks a player first. More...
 
void playerAttacksMonster (State *st, Monster *monster)
 Function that attacks a monster first. More...
 

Macro Definition Documentation

◆ MAX_PROJECTILES

#define MAX_PROJECTILES   20

Typedef Documentation

◆ Map

typedef struct map Map

◆ Monster

typedef struct monster Monster

◆ Projectile

typedef struct projectile Projectile

◆ State

typedef struct state State

Function Documentation

◆ calculateDamage()

int calculateDamage ( int  attack,
int  defense,
int  turn 
)

Calculates the damage of an attack.

If the st->turn % 5 == 0 the attack is a critical hit attack = attack * 1.5 1.5 is the critical hit multiplier 5 is the number of turns between critical hits

NOTE: Per example a potion of strength could increase the critical hit multiplier, or reduce the number of turns between critical hits.

The damage is calculated with the formula: damage = attack * (100 - defense) / 100

Parameters
attackThe attack of the attacker
defenseThe defense of the defender
turnThe current turn
Returns
int The damage of the attack to retrieved from the defender health

◆ drawProjectiles()

void drawProjectiles ( Map map)

Draw all visible projectiles.

Parameters
mapMap to draw visible projectiles

◆ freeProjectile()

void freeProjectile ( void *  p)

◆ killMonster()

void killMonster ( State st,
int  x,
int  y 
)

Function to kill a monster with his coordinates.

The monster is removed from the map and the monsters array

Parameters
stThe game state
xThe x coordinate of the monster
yThe y coordinate of the monster TODO: change to monster instead of coordinates

◆ monsterAttacksPlayer()

void monsterAttacksPlayer ( State st,
Monster monster 
)

Function that attacks a player first.

First the monster attacks the player, then the player attacks the monster. If the monster dies, the player earns gold and the monster is removed from the map. If the player dies, the game is over. A message is sent to the menu to be displayed in either case.

Parameters
stThe game state
monsterThe monster that attacks the player first

◆ playerAttacksMonster()

void playerAttacksMonster ( State st,
Monster monster 
)

Function that attacks a monster first.

First the player attacks the monster, then the monster attacks the player. Similar to monsterAttacksPlayer(State *st, Monster *monster) function.

Parameters
stThe game state
monsterThe monster that is attacked by the player first

◆ throwProjectile()

void throwProjectile ( State st)

◆ throwRock()

void throwRock ( State st)

Function to throw a rock projectile.

The rock is thrown in the direction the player is facing The rock is thrown until it hits a wall or a monster Update projectile position with moveProjectiles function

Parameters
stThe game state
Returns
void

◆ updateProjectiles()

void updateProjectiles ( State st)