Maint: Even more cleanup

This commit is contained in:
Linus Probert 2018-09-13 13:12:43 +02:00
parent 620a7e3ed5
commit e1b3364d88
4 changed files with 73 additions and 61 deletions

View File

@ -770,19 +770,22 @@ run_game_update(void)
map_set_current_room(gMap, &gPlayer->sprite->pos); map_set_current_room(gMap, &gPlayer->sprite->pos);
map_update(&updateData); map_update(&updateData);
bool turnSwitch = false;
if (currentTurn == PLAYER) { if (currentTurn == PLAYER) {
if (player_turn_over(gPlayer)) { if (player_turn_over(gPlayer)) {
currentTurn = MONSTER; currentTurn = MONSTER;
player_reset_steps(gPlayer); player_reset_steps(gPlayer);
map_on_new_turn(gMap); map_on_new_turn(gMap);
turnSwitch = true;
} }
} else if (currentTurn == MONSTER) { } else if (currentTurn == MONSTER) {
if (map_move_monsters(gMap, gRoomMatrix)) { if (map_move_monsters(gMap, gRoomMatrix)) {
currentTurn = PLAYER; currentTurn = PLAYER;
} }
} }
if (map_clear_expired_entities(gMap, gPlayer)) if (map_clear_expired_entities(gMap, gPlayer) || turnSwitch)
repopulate_roommatrix(); repopulate_roommatrix();
} }

View File

@ -298,7 +298,7 @@ has_collided(Monster *monster, RoomMatrix *matrix, Vector2d direction)
monster_behaviour_check_post_attack(monster); monster_behaviour_check_post_attack(monster);
} }
return space->occupied; return space->occupied || space->monster;
} }
static bool static bool

View File

@ -148,45 +148,29 @@ on_monster_collision(Player *player,
} }
static bool static void
has_collided(Player *player, RoomMatrix *matrix, Vector2d direction) player_pickup_artifacts(Player *player, RoomSpace *space)
{ {
bool collided = false; LinkedList *artifacts = space->artifacts;
while (artifacts) {
Position roomCoord = position_to_room_coords(&player->sprite->pos); player_add_artifact(player, artifacts->data);
if (roomCoord.x != matrix->roomPos.x artifacts = artifacts->next;
|| roomCoord.y != matrix->roomPos.y) { }
return collided;
} }
Position matrixPos = position_to_matrix_coords(&player->sprite->pos); static void
RoomSpace *space = &matrix->spaces[matrixPos.x][matrixPos.y]; player_interact_objects(Player *player, RoomSpace *space)
collided = space->occupied;
if (space->monster != NULL
&& (space->monster->sprite->state == SPRITE_STATE_FALLING
|| space->monster->stats.hp <= 0))
{ {
collided = false; LinkedList *objects = space->objects;
while (objects) {
object_damage(objects->data, player);
objects = objects->next;
}
} }
if (collided) { static void
player->sprite->pos.x -= TILE_DIMENSION * (int)direction.x; player_collect_items(Player *player, RoomSpace *space)
player->sprite->pos.y -= TILE_DIMENSION * (int)direction.y;
}
if (space->monster != NULL
&& space->monster->stats.hp > 0
&& space->monster->sprite->state != SPRITE_STATE_FALLING)
{ {
on_monster_collision(player, space->monster, matrix, direction);
} else if (collided) {
mixer_play_effect(BONK);
camera_shake(direction, 100);
gui_log("Ouch! There is something in the way");
}
if (space->items != NULL && !collided) {
LinkedList *items = space->items; LinkedList *items = space->items;
while (items != NULL) { while (items != NULL) {
Item *item = items->data; Item *item = items->data;
@ -195,31 +179,58 @@ has_collided(Player *player, RoomMatrix *matrix, Vector2d direction)
} }
} }
if (space->artifacts != NULL && !collided) { static void
LinkedList *artifacts = space->artifacts; player_interact_traps_and_pits(Player *player, RoomSpace *space)
while (artifacts) { {
player_add_artifact(player, artifacts->data); if (space->lethal) {
artifacts = artifacts->next;
}
}
if (space->objects && !collided) {
LinkedList *objects = space->objects;
while (objects) {
object_damage(objects->data, player);
objects = objects->next;
}
}
if (space->lethal && !collided) {
player_set_falling(player); player_set_falling(player);
} }
if (space->trap && !collided) { if (space->trap) {
trap_activate(space->trap, player); trap_activate(space->trap, player);
} }
}
return collided; static bool
player_has_collided(RoomSpace *space)
{
if (space->occupied)
return true;
return space->monster && space->monster->sprite->state != SPRITE_STATE_FALLING;
}
static bool
has_collided(Player *player, RoomMatrix *matrix, Vector2d direction)
{
Position roomCoord = position_to_room_coords(&player->sprite->pos);
if (roomCoord.x != matrix->roomPos.x || roomCoord.y != matrix->roomPos.y) {
return false;
}
Position matrixPos = position_to_matrix_coords(&player->sprite->pos);
RoomSpace *space = &matrix->spaces[matrixPos.x][matrixPos.y];
if (player_has_collided(space)) {
player->sprite->pos.x -= TILE_DIMENSION * (int)direction.x;
player->sprite->pos.y -= TILE_DIMENSION * (int)direction.y;
if (space->monster) {
on_monster_collision(player, space->monster, matrix, direction);
} else {
mixer_play_effect(BONK);
camera_shake(direction, 100);
gui_log("Ouch! There is something in the way");
}
return true;
}
else {
player_collect_items(player, space);
player_pickup_artifacts(player, space);
player_interact_objects(player, space);
player_interact_traps_and_pits(player, space);
return false;
}
} }
static void static void

View File

@ -144,8 +144,6 @@ void roommatrix_populate_from_map(RoomMatrix *rm, Map *m)
position = position =
position_to_matrix_coords(&monster->sprite->pos); position_to_matrix_coords(&monster->sprite->pos);
rm->spaces[position.x][position.y]
.occupied = true;
rm->spaces[position.x][position.y] rm->spaces[position.x][position.y]
.monster = monster; .monster = monster;
} }