Ludum Dare 29
HackSoc's entry for the Ludum Dare Jam 29
|
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <math.h>
#include "mob.h"
#include "level.h"
#include "utils.h"
#include "effect.h"
#include "player.h"
Functions | |
bool | move_mob (Mob *mob, unsigned int x, unsigned int y) |
bool | move_mob_relative (Mob *mob, int xdiff, int ydiff) |
void | attack_mob (Mob *attacker, Mob *defender) |
bool | damage_mob (Mob *mob, unsigned int damage) |
Mob * | kill_mob (Mob *mob) |
bool | can_see_point (Level *level, unsigned int x0, unsigned int y0, unsigned int x, unsigned int y) |
bool | can_see (Mob *mob, unsigned int x, unsigned int y) |
bool | can_see_other (Mob *moba, Mob *mobb) |
void | simple_enemy_turn (Mob *enemy) |
bool | move_mob_level (Mob *mob, bool toprev) |
Attack a mob, modified by the weapon of the attacker and the armour of the defender.
attacker | The mob doing the attacking. |
defender | The mob being attacked. |
bool can_see | ( | Mob * | mob, |
unsigned int | x, | ||
unsigned int | y | ||
) |
Determine if a mob can see the given point.
Note: as this will be primarily used to render the level, a better version might be to operate on a 2d array of three-state variables ("visible", "blocked", and "unknown"), and just iterate the algorithm with different starting points until every point is known. This would avoid the need to check each individual point, possibly duplicating work.
mob | The mob |
x | The target X coordinate |
y | The target Y coordinate |
Wrapper for can_see, to determine if a mob can see another mob.
moba | One of the mobs |
mobb | The other. It really doesn't matter which way around they are. |
bool can_see_point | ( | Level * | level, |
unsigned int | x0, | ||
unsigned int | y0, | ||
unsigned int | x, | ||
unsigned int | y | ||
) |
Determine if one point can be seen from another. All points are visible unless there is a wall in the way. This uses Bresenham's line algorithm to determine line-of-sight.
level | The level to check |
x0 | The starting X |
y0 | The starting Y |
x | The target X |
y | The target Y |
bool damage_mob | ( | Mob * | mob, |
unsigned int | damage | ||
) |
Damage a mob.
mob | Entity to damage. |
damage | Amount of damage to apply to the mob. |
Kill a mob - free it, and remove it from the lists.
mob | The mob to kill |
bool move_mob | ( | Mob * | mob, |
unsigned int | x, | ||
unsigned int | y | ||
) |
Move the given mob to the new coordinates.
mob | Entity to move. |
x | Target x position. |
y | Target y position. |
bool move_mob_level | ( | Mob * | mob, |
bool | toprev | ||
) |
Moves the given mod to the next or previous level.
mob | Mob to move. |
toprev | Determines which direction the movement is in. If true, the movement is to the previous level, otherwise to the next. |
bool move_mob_relative | ( | Mob * | mob, |
int | xdiff, | ||
int | ydiff | ||
) |
Move a mob by a relative position
mob | Entity to move. |
xdiff | x-coordinate difference. |
ydiff | y-coordinate difference. |
void simple_enemy_turn | ( | Mob * | enemy | ) |
A very simple enemy: move towards the player, and damage them if adjacent.
enemy | Entity to move. |