Compare commits

...

3 Commits

Author SHA1 Message Date
En Yi 0c52718695 Update water flow rendering logic 2023-07-26 23:16:50 +08:00
En Yi 2e368704ce Fix water runner interaction
- Add null check for bbox for moveable check
- Null after free when freeing runner
2023-07-25 20:43:39 +08:00
En Yi f81029b482 Add shape factor to control upthrust and friction 2023-07-25 20:39:42 +08:00
6 changed files with 36 additions and 10 deletions

View File

@ -115,15 +115,14 @@ static void level_scene_render_func(Scene_t* scene)
if (
bot <= tilemap.n_tiles
&& tilemap.tiles[bot].water_level < MAX_WATER_LEVEL
&& tilemap.tiles[i].water_level == 0
)
{
if (i % tilemap.width != 0 && tilemap.tiles[left].wet)
if (i % tilemap.width != 0 && tilemap.tiles[left].wet && (tilemap.tiles[bot].solid == SOLID || tilemap.tiles[bot-1].solid == SOLID))
{
DrawLineEx((Vector2){x, bot_line}, (Vector2){x + TILE_SIZE / 2, bot_line}, SURFACE_THICKNESS, ColorAlpha(BLUE, 0.7));
}
if (right % tilemap.width != 0 && tilemap.tiles[right].wet)
if (right % tilemap.width != 0 && tilemap.tiles[right].wet && (tilemap.tiles[bot].solid == SOLID || tilemap.tiles[bot+1].solid == SOLID))
{
DrawLineEx((Vector2){x + TILE_SIZE / 2, bot_line}, (Vector2){x + TILE_SIZE, bot_line}, SURFACE_THICKNESS, ColorAlpha(BLUE, 0.7));
}
@ -562,7 +561,8 @@ static void toggle_block_system(Scene_t* scene)
new_type = tilemap.tiles[tile_idx].tile_type;
if (tilemap.tiles[tile_idx].water_level < MAX_WATER_LEVEL)
{
tilemap.tiles[tile_idx].water_level++;
tilemap.tiles[tile_idx].water_level = MAX_WATER_LEVEL;
tilemap.tiles[tile_idx].wet = false;
}
break;
case TOGGLE_AIR_POCKET:

View File

@ -48,6 +48,7 @@ typedef struct _CTransform_t {
Vector2 velocity;
Vector2 accel;
Vector2 fric_coeff;
Vector2 shape_factor;
int8_t grav_delay;
int8_t grav_timer;
MovementMode_t movement_mode;

View File

@ -896,7 +896,7 @@ void global_external_forces_system(Scene_t* scene)
if (point_in_AABB(player_center, box))
{
p_ctransform->accel = Vector2Add(p_ctransform->accel, UPTHRUST);
p_ctransform->accel = Vector2Multiply(Vector2Add(p_ctransform->accel, UPTHRUST), p_ctransform->shape_factor);
}
}
}
@ -906,7 +906,10 @@ void global_external_forces_system(Scene_t* scene)
// Friction
p_ctransform->accel = Vector2Add(
p_ctransform->accel,
Vector2Multiply(p_ctransform->fric_coeff, p_ctransform->velocity)
Vector2Multiply(
Vector2Multiply(p_ctransform->fric_coeff, p_ctransform->velocity),
p_ctransform->shape_factor
)
);
if (p_bbox == NULL) continue; //Do not proceed if no bbox
@ -1025,14 +1028,20 @@ void moveable_update_system(Scene_t* scene)
{
Entity_t* other_ent = get_entity(&scene->ent_manager, idx_to_check);
CBBox_t* p_other_bbox = get_component(other_ent, CBBOX_COMP_T);
if (p_other_bbox != NULL)
{
any_solid |= p_other_bbox->solid;
}
}
sc_map_foreach_key(&tilemap.tiles[tile_idx2].entities_set, idx_to_check)
{
Entity_t* other_ent = get_entity(&scene->ent_manager, idx_to_check);
CBBox_t* p_other_bbox = get_component(other_ent, CBBOX_COMP_T);
if (p_other_bbox != NULL)
{
any_solid |= p_other_bbox->solid;
}
}
if (!any_solid)
{
can_move = true;
@ -1054,14 +1063,20 @@ void moveable_update_system(Scene_t* scene)
{
Entity_t* other_ent = get_entity(&scene->ent_manager, idx_to_check);
CBBox_t* p_other_bbox = get_component(other_ent, CBBOX_COMP_T);
if (p_other_bbox != NULL)
{
any_solid |= p_other_bbox->solid;
}
}
sc_map_foreach_key(&tilemap.tiles[tile_idx2].entities_set, idx_to_check)
{
Entity_t* other_ent = get_entity(&scene->ent_manager, idx_to_check);
CBBox_t* p_other_bbox = get_component(other_ent, CBBOX_COMP_T);
if (p_other_bbox != NULL)
{
any_solid |= p_other_bbox->solid;
}
}
if (!any_solid)
{
can_move = true;

View File

@ -13,6 +13,7 @@ Entity_t* create_crate(EntityManager_t* ent_manager, Assets_t* assets, bool meta
CTransform_t* p_ctransform = add_component(p_crate, CTRANSFORM_COMP_T);
p_ctransform->grav_delay = 5;
p_ctransform->shape_factor = metal ? (Vector2){0.7,0.7} : (Vector2){0.8,0.8} ;
add_component(p_crate, CMOVEMENTSTATE_T);
add_component(p_crate, CTILECOORD_COMP_T);
CHurtbox_t* p_hurtbox = add_component(p_crate, CHURTBOX_T);
@ -41,6 +42,7 @@ Entity_t* create_boulder(EntityManager_t* ent_manager, Assets_t* assets)
CTransform_t* p_ctransform = add_component(p_boulder, CTRANSFORM_COMP_T);
p_ctransform->grav_delay = 5;
p_ctransform->active = true;
p_ctransform->shape_factor = (Vector2){0.6, 0.6};
add_component(p_boulder, CMOVEMENTSTATE_T);
add_component(p_boulder, CTILECOORD_COMP_T);
CMoveable_t* p_cmove = add_component(p_boulder, CMOVEABLE_T);
@ -107,6 +109,7 @@ Entity_t* create_bomb(EntityManager_t* ent_manager, Assets_t* assets, Vector2 la
CTransform_t* p_ctransform = add_component(p_bomb, CTRANSFORM_COMP_T);
p_ctransform->active = true;
p_ctransform->shape_factor = (Vector2){0.1, 0.1};
p_ctransform->movement_mode = REGULAR_MOVEMENT;
p_ctransform->position.x += (TILE_SIZE - 25) / 2;
p_ctransform->position.y += (TILE_SIZE - 25) / 2;

View File

@ -61,6 +61,7 @@ Entity_t* create_player(EntityManager_t* ent_manager, Assets_t* assets)
set_bbox(p_bbox, PLAYER_WIDTH, PLAYER_HEIGHT);
CTransform_t* p_ct = add_component(p_ent, CTRANSFORM_COMP_T);
p_ct->active = true;
p_ct->shape_factor = (Vector2){1, 1};
CJump_t* p_cjump = add_component(p_ent, CJUMP_COMP_T);
p_cjump->jump_speed = 680;

View File

@ -40,7 +40,9 @@ void free_water_runner(Entity_t* ent, EntityManager_t* ent_manager)
{
CWaterRunner_t* p_crunner = get_component(ent, CWATERRUNNER_T);
free(p_crunner->bfs_tilemap.tilemap);
p_crunner->bfs_tilemap.tilemap = NULL;
free(p_crunner->visited);
p_crunner->visited = NULL;
sc_queue_term(&p_crunner->bfs_queue);
remove_entity(ent_manager, ent->m_id);
}
@ -293,6 +295,10 @@ void update_water_runner_system(Scene_t* scene)
{
p_crunner->counter++;
}
else
{
curr_tile->wet = false;
}
}