Adds posibility for daggers hitting walls to be recoverable.
This commit is contained in:
parent
4e1050dc8a
commit
2a80434547
|
@ -100,3 +100,12 @@ position_in_roommatrix(const Position *pos)
|
||||||
&& pos->y >= 0
|
&& pos->y >= 0
|
||||||
&& pos->y < MAP_ROOM_HEIGHT;
|
&& pos->y < MAP_ROOM_HEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Position
|
||||||
|
position_to_tile_pos(const Position *p)
|
||||||
|
{
|
||||||
|
return (Position) {
|
||||||
|
p->x - (p->x % TILE_DIMENSION),
|
||||||
|
p->y - (p->y % TILE_DIMENSION)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -26,22 +26,47 @@ typedef struct {
|
||||||
int y;
|
int y;
|
||||||
} Position;
|
} Position;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return a matrix coord position for a given position
|
||||||
|
*/
|
||||||
Position
|
Position
|
||||||
position_to_matrix_coords(Position*);
|
position_to_matrix_coords(Position*);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the room coord for the room containing the given position
|
||||||
|
*/
|
||||||
Position
|
Position
|
||||||
position_to_room_coords(Position*);
|
position_to_room_coords(Position*);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check is a position is within a given room
|
||||||
|
*/
|
||||||
bool
|
bool
|
||||||
position_in_room(Position *pos, Position *roomPos);
|
position_in_room(Position *pos, Position *roomPos);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if two positions are equal
|
||||||
|
*/
|
||||||
bool
|
bool
|
||||||
position_equals(const Position*, const Position*);
|
position_equals(const Position*, const Position*);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if two positions are separated by equal
|
||||||
|
* or less of the provided distance.
|
||||||
|
*/
|
||||||
bool
|
bool
|
||||||
position_proximity(unsigned int distance, const Position*, const Position*);
|
position_proximity(unsigned int distance, const Position*, const Position*);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if a matrix coord is still within the matrix
|
||||||
|
*/
|
||||||
bool
|
bool
|
||||||
position_in_roommatrix(const Position*);
|
position_in_roommatrix(const Position*);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the tile position for the given world position
|
||||||
|
*/
|
||||||
|
Position
|
||||||
|
position_to_tile_pos(const Position*);
|
||||||
|
|
||||||
#endif // POSITION_H_
|
#endif // POSITION_H_
|
||||||
|
|
|
@ -68,6 +68,24 @@ projectile_create(void)
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Position
|
||||||
|
get_collision_pos_for(Projectile *p)
|
||||||
|
{
|
||||||
|
Position collisionPos = p->sprite->pos;
|
||||||
|
if (p->velocity.x > 0) collisionPos.x += TILE_DIMENSION;
|
||||||
|
if(p->velocity.y > 0) collisionPos.y += TILE_DIMENSION;
|
||||||
|
return collisionPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Position
|
||||||
|
get_projectile_pos_for(Projectile *p)
|
||||||
|
{
|
||||||
|
Position projectilePos = p->sprite->pos;
|
||||||
|
if (p->velocity.x < 0) projectilePos.x += TILE_DIMENSION;
|
||||||
|
if (p->velocity.y < 0) projectilePos.y += TILE_DIMENSION;
|
||||||
|
return projectilePos;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
projectile_update(Projectile *p, UpdateData *data)
|
projectile_update(Projectile *p, UpdateData *data)
|
||||||
{
|
{
|
||||||
|
@ -79,12 +97,7 @@ projectile_update(Projectile *p, UpdateData *data)
|
||||||
if (timer_get_ticks(p->lifetime) > 2000)
|
if (timer_get_ticks(p->lifetime) > 2000)
|
||||||
p->alive = false;
|
p->alive = false;
|
||||||
|
|
||||||
Position collisionPos = p->sprite->pos;
|
Position collisionPos = get_collision_pos_for(p);
|
||||||
if (p->velocity.x > 0)
|
|
||||||
collisionPos.x += TILE_DIMENSION;
|
|
||||||
if(p->velocity.y > 0)
|
|
||||||
collisionPos.y += TILE_DIMENSION;
|
|
||||||
|
|
||||||
if (!position_in_room(&collisionPos, &data->map->currentRoom)) {
|
if (!position_in_room(&collisionPos, &data->map->currentRoom)) {
|
||||||
p->alive = false;
|
p->alive = false;
|
||||||
return;
|
return;
|
||||||
|
@ -102,6 +115,7 @@ projectile_update(Projectile *p, UpdateData *data)
|
||||||
if (space->player)
|
if (space->player)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Position projectilePos = get_projectile_pos_for(p);
|
||||||
if (space->monster) {
|
if (space->monster) {
|
||||||
Stats tmpStats = data->player->stats;
|
Stats tmpStats = data->player->stats;
|
||||||
tmpStats.dmg *= 2;
|
tmpStats.dmg *= 2;
|
||||||
|
@ -115,13 +129,15 @@ projectile_update(Projectile *p, UpdateData *data)
|
||||||
monster_hit(space->monster, dmg);
|
monster_hit(space->monster, dmg);
|
||||||
player_monster_kill_check(data->player, space->monster);
|
player_monster_kill_check(data->player, space->monster);
|
||||||
alive = player_has_artifact(data->player, PIERCING_DAGGERS) > p->collisionCount;
|
alive = player_has_artifact(data->player, PIERCING_DAGGERS) > p->collisionCount;
|
||||||
|
projectilePos = space->monster->sprite->pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
mixer_play_effect(SWORD_HIT);
|
||||||
if (!alive && get_random(5) <= player_has_artifact(data->player, DAGGER_RECOVERY)) {
|
if (!alive && get_random(5) <= player_has_artifact(data->player, DAGGER_RECOVERY)) {
|
||||||
Item *item = item_builder_build_item(DAGGER, 1);
|
Item *item = item_builder_build_item(DAGGER, 1);
|
||||||
item->sprite->pos = space->monster->sprite->pos;
|
item->sprite->pos = position_to_tile_pos(&projectilePos);
|
||||||
linkedlist_append(&data->map->items, item);
|
linkedlist_append(&data->map->items, item);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
mixer_play_effect(SWORD_HIT);
|
|
||||||
p->alive = alive;
|
p->alive = alive;
|
||||||
p->collisionCount++;
|
p->collisionCount++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue