Initial implementation of the falling tiles room modifier.

Incomplete and always on right now.
This commit is contained in:
Linus Probert 2018-10-14 22:20:54 +02:00
parent f65bdd0f13
commit ee56143d0d
7 changed files with 36 additions and 4 deletions

View File

@ -286,15 +286,22 @@ map_update(UpdateData *data)
monster = monster->next; monster = monster->next;
monster_update(m, data); 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) void map_render(Map *map, Camera *cam)
{ {
unsigned int i, j; unsigned int i, j;
Room *room;
Position roomPos = { map->currentRoom.x, map->currentRoom.y }; 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 (i=0; i < MAP_ROOM_WIDTH; ++i) {
for (j=0; j < MAP_ROOM_HEIGHT; ++j) { for (j=0; j < MAP_ROOM_HEIGHT; ++j) {
map_tile_render(room->tiles[i][j], cam); map_tile_render(room->tiles[i][j], cam);
@ -401,7 +408,15 @@ void map_room_destroy(Room *room)
free(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; int i, j;
for (i=0; i < MAP_H_ROOM_COUNT; ++i) { for (i=0; i < MAP_H_ROOM_COUNT; ++i) {

View File

@ -109,6 +109,9 @@ map_render_top_layer(Map*, RoomMatrix*, Camera*);
void void
map_set_current_room(Map*, Position*); map_set_current_room(Map*, Position*);
void
map_trigger_tile_fall(MapTile *tile);
void void
map_destroy(Map*); map_destroy(Map*);

View File

@ -28,7 +28,8 @@ typedef struct RoomMatrix_t RoomMatrix;
typedef enum RoomModifierType_e { typedef enum RoomModifierType_e {
RMOD_TYPE_NONE, RMOD_TYPE_NONE,
RMOD_TYPE_WINDY, RMOD_TYPE_WINDY,
RMOD_TYPE_FIRE RMOD_TYPE_FIRE,
RMOD_TYPE_FALLING_TILES
} RoomModifierType; } RoomModifierType;
typedef struct WindData { typedef struct WindData {

View File

@ -286,11 +286,18 @@ move(Player *player, RoomMatrix *matrix, Vector2d direction)
{ {
player_turn(player, &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.x += TILE_DIMENSION * (int) direction.x;
player->sprite->pos.y += TILE_DIMENSION * (int) direction.y; player->sprite->pos.y += TILE_DIMENSION * (int) direction.y;
if (!has_collided(player, matrix, direction)) { if (!has_collided(player, matrix, direction)) {
action_spent(player); 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);
} }
} }

View File

@ -46,6 +46,7 @@ roommatrix_reset(RoomMatrix *m)
space->monster = NULL; space->monster = NULL;
space->player = NULL; space->player = NULL;
space->trap = NULL; space->trap = NULL;
space->tile = NULL;
while (space->items != NULL) while (space->items != NULL)
linkedlist_pop(&space->items); linkedlist_pop(&space->items);
while (space->artifacts != NULL) 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) { for (j = 0; j < MAP_ROOM_HEIGHT; ++j) {
RoomSpace *space = &rm->spaces[i][j]; RoomSpace *space = &rm->spaces[i][j];
if (r->tiles[i][j]) { if (r->tiles[i][j]) {
space->tile = r->tiles[i][j];
space->occupied = space->occupied =
r->tiles[i][j]->collider; r->tiles[i][j]->collider;
space->lightsource = space->lightsource =

View File

@ -34,6 +34,7 @@ typedef struct Item_t Item;
typedef struct Node LinkedList; typedef struct Node LinkedList;
typedef struct Trap Trap; typedef struct Trap Trap;
typedef struct Object Object; typedef struct Object Object;
typedef struct MapTile_t MapTile;
struct UpdateData; struct UpdateData;
@ -43,6 +44,7 @@ typedef struct RoomSpace {
bool lightsource; bool lightsource;
bool damaging; bool damaging;
int light; int light;
MapTile *tile;
Monster *monster; Monster *monster;
Player *player; Player *player;
Trap *trap; Trap *trap;

View File

@ -136,6 +136,8 @@ sprite_update(Sprite *s, UpdateData *data)
s->dim.height /2 s->dim.height /2
}; };
} }
if (s->dim.width < 4)
s->hidden = true;
} }
} }