LI2 Roguelite
Classes | Typedefs | Functions
combat.c File Reference
#include <stdlib.h>
#include <ncurses.h>
#include "combat.h"
#include "state.h"
#include "map.h"
#include "cell.h"
#include "player.h"
#include "monster.h"
#include "item.h"
#include "inventory.h"
#include "menu.h"
Include dependency graph for combat.c:

Classes

struct  projectile
 (private) Structure of a thrown projectile More...
 

Typedefs

typedef struct projectile Projectile
 (private) Structure of a thrown projectile More...
 

Functions

ProjectileinitProjectile (int x, int y, int direction, int range, int effect, int damage, char symbol, int color)
 Initializes a new projectile. More...
 
void moveProjectile (Projectile *p)
 Moves a projectile. Reduces the number of turns left by 1. More...
 
void insertProjectile (Map *map, Projectile *p)
 Inserts a projectile into the map. More...
 
void removeProjectile (Map *map, int index)
 Removes a projectile from the map. More...
 
void explodeProjectile (State *st, Projectile *projectile)
 Explodes a projectile. More...
 
void updateProjectile (State *st, Projectile *projectile, int index)
 Updates a projectile within the game state. More...
 
void updateProjectiles (State *st)
 
void freeProjectile (void *p)
 
void throwRock (State *st)
 Function to throw a rock projectile. More...
 
void throwSmokebomb (State *st)
 Function to throw a smoke bomb projectile. More...
 
void throwFirebomb (State *st)
 Function to throw a fire bomb projectile. More...
 
void throwIcebomb (State *st)
 Function to throw an ice bomb projectile. More...
 
void throwProjectile (State *st)
 
void drawProjectile (Projectile *p)
 Draw a projectile. More...
 
void drawProjectiles (Map *map)
 Draw all visible projectiles. More...
 
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...
 

Typedef Documentation

◆ Projectile

typedef struct projectile Projectile

(private) Structure of a thrown projectile

Parameters
xThe current x coordinate of the projectile
yThe current y coordinate of the projectile
directionThe ongoing direction of the projectile
turns_leftThe number of turns left for the projectile to disappear/have an effect
effectThe effect of the projectile
damageThe damage of the projectile
colorThe color of the projectile

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

◆ drawProjectile()

void drawProjectile ( Projectile p)

Draw a projectile.

Parameters
pProjectile to draw

◆ drawProjectiles()

void drawProjectiles ( Map map)

Draw all visible projectiles.

Parameters
mapMap to draw visible projectiles

◆ explodeProjectile()

void explodeProjectile ( State st,
Projectile projectile 
)

Explodes a projectile.

The explosion is a star shape with radius 5 Various effects are applied to the cells within the explosion

TODO: visual effects for monsters

Parameters
stThe game state
projectileThe projectile to explode

◆ freeProjectile()

void freeProjectile ( void *  p)

◆ initProjectile()

Projectile* initProjectile ( int  x,
int  y,
int  direction,
int  range,
int  effect,
int  damage,
char  symbol,
int  color 
)

Initializes a new projectile.

Parameters
xThe x coordinate of the projectile
yThe y coordinate of the projectile
directionThe direction of the projectile
rangeThe range of the projectile
effectThe effect of the projectile
damageThe damage of the projectile
symbolThe symbol of the projectile
colorThe color of the projectile
Returns
Projectile* The initialized projectile

◆ insertProjectile()

void insertProjectile ( Map map,
Projectile p 
)

Inserts a projectile into the map.

Parameters
mapThe map to insert the projectile
pThe projectile to insert

◆ 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

◆ moveProjectile()

void moveProjectile ( Projectile p)

Moves a projectile. Reduces the number of turns left by 1.

Parameters
pThe projectile to move
Returns
void

◆ 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

◆ removeProjectile()

void removeProjectile ( Map map,
int  index 
)

Removes a projectile from the map.

Parameters
mapThe map to remove the projectile
indexThe index of the projectile in the map

◆ throwFirebomb()

void throwFirebomb ( State st)

Function to throw a fire bomb projectile.

The fire bomb is thrown in the direction the player is facing The fire bomb is thrown until it hits a wall or a monster

Parameters
stThe game state
Returns
void

◆ throwIcebomb()

void throwIcebomb ( State st)

Function to throw an ice bomb projectile.

The ice bomb is thrown in the direction the player is facing The ice bomb is thrown until it hits a wall or a monster

Parameters
stThe game state
Returns
void

◆ 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

◆ throwSmokebomb()

void throwSmokebomb ( State st)

Function to throw a smoke bomb projectile.

The smoke bomb is thrown in the direction the player is facing The smoke bomb is thrown until it hits a wall or a monster

Parameters
stThe game state
Returns
void

◆ updateProjectile()

void updateProjectile ( State st,
Projectile projectile,
int  index 
)

Updates a projectile within the game state.

Parameters
stThe game state
projectileThe projectile to update
indexThe index of the projectile in the map

◆ updateProjectiles()

void updateProjectiles ( State st)