From ee56143d0d86a4f3fcca7a5a2df630a4b1bfcffd Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Sun, 14 Oct 2018 22:20:54 +0200 Subject: [PATCH] Initial implementation of the falling tiles room modifier. Incomplete and always on right now. --- src/map.c | 21 ++++++++++++++++++--- src/map.h | 3 +++ src/map_room_modifiers.h | 3 ++- src/player.c | 7 +++++++ src/roommatrix.c | 2 ++ src/roommatrix.h | 2 ++ src/sprite.c | 2 ++ 7 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/map.c b/src/map.c index e6d811f..b679a1b 100644 --- a/src/map.c +++ b/src/map.c @@ -286,15 +286,22 @@ map_update(UpdateData *data) monster = monster->next; monster_update(m, data); } + + Position roomPos = { map->currentRoom.x, map->currentRoom.y }; + Room *room = map->rooms[roomPos.x][roomPos.y]; + for (size_t i=0; i < MAP_ROOM_WIDTH; ++i) { + for (size_t j=0; j < MAP_ROOM_HEIGHT; ++j) { + sprite_update(room->tiles[i][j]->sprite, data); + } + } } void map_render(Map *map, Camera *cam) { unsigned int i, j; - Room *room; Position roomPos = { map->currentRoom.x, map->currentRoom.y }; - room = map->rooms[roomPos.x][roomPos.y]; + Room *room = map->rooms[roomPos.x][roomPos.y]; for (i=0; i < MAP_ROOM_WIDTH; ++i) { for (j=0; j < MAP_ROOM_HEIGHT; ++j) { map_tile_render(room->tiles[i][j], cam); @@ -401,7 +408,15 @@ void map_room_destroy(Room *room) free(room); } -void map_destroy(Map *map) +void +map_trigger_tile_fall(MapTile *tile) +{ + tile->sprite->state = SPRITE_STATE_FALLING; + tile->lethal = true; +} + +void +map_destroy(Map *map) { int i, j; for (i=0; i < MAP_H_ROOM_COUNT; ++i) { diff --git a/src/map.h b/src/map.h index 56a3d07..3ef2957 100644 --- a/src/map.h +++ b/src/map.h @@ -109,6 +109,9 @@ map_render_top_layer(Map*, RoomMatrix*, Camera*); void map_set_current_room(Map*, Position*); +void +map_trigger_tile_fall(MapTile *tile); + void map_destroy(Map*); diff --git a/src/map_room_modifiers.h b/src/map_room_modifiers.h index d0a8fe7..115e9a5 100644 --- a/src/map_room_modifiers.h +++ b/src/map_room_modifiers.h @@ -28,7 +28,8 @@ typedef struct RoomMatrix_t RoomMatrix; typedef enum RoomModifierType_e { RMOD_TYPE_NONE, RMOD_TYPE_WINDY, - RMOD_TYPE_FIRE + RMOD_TYPE_FIRE, + RMOD_TYPE_FALLING_TILES } RoomModifierType; typedef struct WindData { diff --git a/src/player.c b/src/player.c index 4f558e3..874f1c0 100644 --- a/src/player.c +++ b/src/player.c @@ -286,11 +286,18 @@ move(Player *player, RoomMatrix *matrix, Vector2d direction) { player_turn(player, &direction); + Position lastPos = position_to_matrix_coords(&player->sprite->pos); + player->sprite->pos.x += TILE_DIMENSION * (int) direction.x; player->sprite->pos.y += TILE_DIMENSION * (int) direction.y; if (!has_collided(player, matrix, direction)) { action_spent(player); + if (lastPos.x > 1 && + lastPos.y > 1 && + lastPos.x < 14 && + lastPos.y < 10) + map_trigger_tile_fall(matrix->spaces[lastPos.x][lastPos.y].tile); } } diff --git a/src/roommatrix.c b/src/roommatrix.c index 1420fd1..fed95ac 100644 --- a/src/roommatrix.c +++ b/src/roommatrix.c @@ -46,6 +46,7 @@ roommatrix_reset(RoomMatrix *m) space->monster = NULL; space->player = NULL; space->trap = NULL; + space->tile = NULL; while (space->items != NULL) linkedlist_pop(&space->items); while (space->artifacts != NULL) @@ -116,6 +117,7 @@ void roommatrix_populate_from_map(RoomMatrix *rm, Map *m) for (j = 0; j < MAP_ROOM_HEIGHT; ++j) { RoomSpace *space = &rm->spaces[i][j]; if (r->tiles[i][j]) { + space->tile = r->tiles[i][j]; space->occupied = r->tiles[i][j]->collider; space->lightsource = diff --git a/src/roommatrix.h b/src/roommatrix.h index 998b495..32b22e9 100644 --- a/src/roommatrix.h +++ b/src/roommatrix.h @@ -34,6 +34,7 @@ typedef struct Item_t Item; typedef struct Node LinkedList; typedef struct Trap Trap; typedef struct Object Object; +typedef struct MapTile_t MapTile; struct UpdateData; @@ -43,6 +44,7 @@ typedef struct RoomSpace { bool lightsource; bool damaging; int light; + MapTile *tile; Monster *monster; Player *player; Trap *trap; diff --git a/src/sprite.c b/src/sprite.c index a05de2d..a78cb0c 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -136,6 +136,8 @@ sprite_update(Sprite *s, UpdateData *data) s->dim.height /2 }; } + if (s->dim.width < 4) + s->hidden = true; } }