#include "item.h"
#include "level.h"
#include "utils.h"
#include "list.h"
Go to the source code of this file.
|
bool | move_mob (struct Mob *mob, unsigned int x, unsigned int y) |
|
bool | move_mob_relative (struct Mob *mob, int xdiff, int ydiff) |
|
bool | move_mob_level (Mob *mob, bool toprev) |
|
bool | damage_mob (struct Mob *mob, unsigned int amount) |
|
void | attack_mob (Mob *attacker, Mob *defender) |
|
struct Mob * | kill_mob (struct Mob *mob) |
|
bool | can_see_point (struct Level *level, unsigned int x0, unsigned int y0, unsigned int x, unsigned int y) |
|
bool | can_see (struct Mob *mob, unsigned int x, unsigned int y) |
|
bool | can_see_other (struct Mob *moba, struct Mob *mobb) |
|
void | simple_enemy_turn (Mob *enemy) |
|
A mob is something which roams around the world, they are tied to a level, and all the mobs in one level form a doubly-linked list. There are a couple of callbacks associated with them to determine what happens in certain situations.
void attack_mob |
( |
Mob * |
attacker, |
|
|
Mob * |
defender |
|
) |
| |
Attack a mob, modified by the weapon of the attacker and the armour of the defender.
- Parameters
-
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.
- Parameters
-
mob | The mob |
x | The target X coordinate |
y | The target Y coordinate |
bool can_see_other |
( |
Mob * |
moba, |
|
|
Mob * |
mobb |
|
) |
| |
Wrapper for can_see, to determine if a mob can see another mob.
- Parameters
-
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.
- Parameters
-
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.
- Parameters
-
mob | Entity to damage. |
damage | Amount of damage to apply to the mob. |
- Returns
- If this killed the mob, a mob is dead if its health drops to zero or below.
struct Mob* kill_mob |
( |
Mob * |
mob | ) |
|
Kill a mob - free it, and remove it from the lists.
- Parameters
-
- Returns
- The next mob in the list, or NULL
bool move_mob |
( |
Mob * |
mob, |
|
|
unsigned int |
x, |
|
|
unsigned int |
y |
|
) |
| |
Move the given mob to the new coordinates.
- Parameters
-
mob | Entity to move. |
x | Target x position. |
y | Target y position. |
- Returns
- false if the given space can't be moved into.
bool move_mob_level |
( |
Mob * |
mob, |
|
|
bool |
toprev |
|
) |
| |
Moves the given mod to the next or previous level.
- Parameters
-
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. |
- Returns
- If the mob moved sucessfully.
bool move_mob_relative |
( |
Mob * |
mob, |
|
|
int |
xdiff, |
|
|
int |
ydiff |
|
) |
| |
Move a mob by a relative position
- Parameters
-
mob | Entity to move. |
xdiff | x-coordinate difference. |
ydiff | y-coordinate difference. |
- Returns
- If the mob was moved successfully.
void simple_enemy_turn |
( |
Mob * |
enemy | ) |
|
A very simple enemy: move towards the player, and damage them if adjacent.
- Parameters
-