Compare commits

..

No commits in common. "62c74fe545c267cfe03b7a5cba199d9767b37856" and "6097ec6e0d62475ef8aa5e0c1c284dbdd53c2567" have entirely different histories.

3 changed files with 22 additions and 43 deletions

View File

@ -160,7 +160,6 @@ typedef struct _CWaterRunner {
int32_t current_tile; int32_t current_tile;
int32_t target_tile; int32_t target_tile;
int32_t fill_idx; int32_t fill_idx;
int16_t fill_range[2];
uint8_t movement_delay; uint8_t movement_delay;
int16_t counter; int16_t counter;
}CWaterRunner_t; }CWaterRunner_t;

View File

@ -182,6 +182,9 @@ void update_water_runner_system(Scene_t* scene)
p_crunner->bfs_tilemap.tilemap[i].from = -1; p_crunner->bfs_tilemap.tilemap[i].from = -1;
p_crunner->bfs_tilemap.tilemap[i].reachable = false; p_crunner->bfs_tilemap.tilemap[i].reachable = false;
} }
p_crunner->state = BFS_START;
// Want the fallthough
case BFS_START:
p_crunner->state = LOWEST_POINT_SEARCH; p_crunner->state = LOWEST_POINT_SEARCH;
// Want the fallthough // Want the fallthough
case LOWEST_POINT_SEARCH: case LOWEST_POINT_SEARCH:
@ -229,7 +232,7 @@ void update_water_runner_system(Scene_t* scene)
{ {
if (tilemap.tiles[p_crunner->current_tile].water_level == tilemap.max_water_level) if (tilemap.tiles[p_crunner->current_tile].water_level == tilemap.max_water_level)
{ {
p_crunner->state = BFS_RESET; p_crunner->state = FILL_COMPLETE;
break; break;
} }
int start_tile = int start_tile =
@ -243,29 +246,19 @@ void update_water_runner_system(Scene_t* scene)
int32_t lowest_tile = p_crunner->current_tile; int32_t lowest_tile = p_crunner->current_tile;
runner_BFS(&tilemap, p_crunner, &lowest_tile, p_crunner->current_tile); runner_BFS(&tilemap, p_crunner, &lowest_tile, p_crunner->current_tile);
p_crunner->counter = 0;
for (int i = 0; i < p_crunner->bfs_tilemap.width; ++i) for (int i = 0; i < p_crunner->bfs_tilemap.width; ++i)
{ {
Tile_t* curr_tile = tilemap.tiles + start_tile + i;
if ( if (
p_crunner->bfs_tilemap.tilemap[start_tile + i].reachable p_crunner->bfs_tilemap.tilemap[start_tile + i].reachable
&& curr_tile->water_level < tilemap.max_water_level
) )
{ {
p_crunner->fill_range[0] = i; p_crunner->counter++;
break;
} }
} }
for (int i = p_crunner->bfs_tilemap.width - 1; i >= 0; --i) p_crunner->fill_idx = 0;
{
if (
p_crunner->bfs_tilemap.tilemap[start_tile + i].reachable
)
{
p_crunner->fill_range[1] = i;
break;
}
}
p_crunner->fill_idx = p_crunner->fill_range[0];
p_crunner->counter = 0;
p_crunner->state = SCANLINE_FILL; p_crunner->state = SCANLINE_FILL;
} }
break; break;
@ -279,30 +272,24 @@ void update_water_runner_system(Scene_t* scene)
Tile_t* curr_tile = tilemap.tiles + curr_idx; Tile_t* curr_tile = tilemap.tiles + curr_idx;
if ( if (
p_crunner->bfs_tilemap.tilemap[curr_idx].reachable p_crunner->bfs_tilemap.tilemap[curr_idx].reachable
&& curr_tile->water_level < tilemap.max_water_level
) )
{
if (curr_tile->water_level < tilemap.max_water_level)
{ {
curr_tile->water_level++; curr_tile->water_level++;
} if (curr_tile->water_level == tilemap.max_water_level)
if (curr_tile->water_level != tilemap.max_water_level)
{ {
p_crunner->counter++; p_crunner->counter--;
} }
} }
p_crunner->fill_idx++;
if (p_crunner->fill_idx > p_crunner->fill_range[1])
{
if (p_crunner->counter == 0) if (p_crunner->counter == 0)
{ {
p_crunner->state = BFS_RESET; p_crunner->state = BFS_RESET;
break; break;
} }
p_crunner->counter = 0;
p_crunner->fill_idx = p_crunner->fill_range[0]; p_crunner->fill_idx++;
} p_crunner->fill_idx %= p_crunner->bfs_tilemap.width;
} }
} }
break; break;

View File

@ -55,18 +55,11 @@ static void level_scene_render_func(Scene_t* scene)
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, BLACK); DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, BLACK);
} }
//if (tilemap.tiles[i].water_level > 0) if (tilemap.tiles[i].water_level > 0)
{ {
float water_height = tilemap.tiles[i].water_level * 1.0f / tilemap.max_water_level;
// Draw water tile // Draw water tile
Color water_colour = ColorAlpha(BLUE, 0.5); Color water_colour = ColorAlpha(BLUE, 0.5);
DrawRectangle( DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, water_colour);
x,
y + (1.0f - water_height) * TILE_SIZE,
TILE_SIZE,
water_height * TILE_SIZE,
water_colour
);
} }
} }
@ -362,7 +355,7 @@ int main(void)
scene.data.tilemap.width = DEFAULT_MAP_WIDTH; scene.data.tilemap.width = DEFAULT_MAP_WIDTH;
scene.data.tilemap.height = DEFAULT_MAP_HEIGHT; scene.data.tilemap.height = DEFAULT_MAP_HEIGHT;
scene.data.tilemap.tile_size = TILE_SIZE; scene.data.tilemap.tile_size = TILE_SIZE;
scene.data.tilemap.max_water_level = 4; scene.data.tilemap.max_water_level = 1;
scene.data.tilemap.n_tiles = scene.data.tilemap.width * scene.data.tilemap.height; scene.data.tilemap.n_tiles = scene.data.tilemap.width * scene.data.tilemap.height;
assert(scene.data.tilemap.n_tiles <= MAX_N_TILES); assert(scene.data.tilemap.n_tiles <= MAX_N_TILES);
scene.data.tilemap.tiles = all_tiles; scene.data.tilemap.tiles = all_tiles;