Compare commits

..

No commits in common. "a1101cd95166c1557376f6fbb656d25a5f1183bd" and "7ce3894c79f24d775ee915f6f759e4b1d7b55f48" have entirely different histories.

3 changed files with 23 additions and 65 deletions

View File

@ -435,7 +435,6 @@ void init_level_scene(LevelScene_t* scene)
sc_array_add(&scene->scene.systems, &sprite_animation_system); sc_array_add(&scene->scene.systems, &sprite_animation_system);
sc_array_add(&scene->scene.systems, &camera_update_system); sc_array_add(&scene->scene.systems, &camera_update_system);
sc_array_add(&scene->scene.systems, &player_dir_reset_system); sc_array_add(&scene->scene.systems, &player_dir_reset_system);
sc_array_add(&scene->scene.systems, &player_respawn_system);
sc_array_add(&scene->scene.systems, &toggle_block_system); sc_array_add(&scene->scene.systems, &toggle_block_system);
// This avoid graphical glitch, not essential // This avoid graphical glitch, not essential

View File

@ -96,7 +96,7 @@ static uint8_t check_collision(const CollideEntity_t* ent, TileGrid_t* grid, boo
} }
// TODO: This should be a point collision check, not an AABB check // TODO: This should be a point collision check, not an AABB check
static bool check_collision_offset( static bool check_collision_at(
Entity_t* p_ent, Vector2 pos, Vector2 bbox_sz, Entity_t* p_ent, Vector2 pos, Vector2 bbox_sz,
TileGrid_t* grid, Vector2 offset TileGrid_t* grid, Vector2 offset
) )
@ -202,7 +202,7 @@ static bool check_collision_and_move(
Vector2 point_to_test = {0}; Vector2 point_to_test = {0};
point_to_test.x = p_ct->position.x; point_to_test.x = p_ct->position.x;
point_to_test.y = other_pos->y - p_bbox->size.y + 1; point_to_test.y = other_pos->y - p_bbox->size.y + 1;
if (!check_collision_offset(ent, point_to_test, p_bbox->size, tilemap, (Vector2){0})) if (!check_collision_at(ent, point_to_test, p_bbox->size, tilemap, (Vector2){0}))
{ {
p_ct->position = point_to_test; p_ct->position = point_to_test;
goto collision_end; goto collision_end;
@ -210,7 +210,7 @@ static bool check_collision_and_move(
point_to_test.x = other_pos->x - p_bbox->size.x + 1; point_to_test.x = other_pos->x - p_bbox->size.x + 1;
point_to_test.y = p_ct->position.y; point_to_test.y = p_ct->position.y;
if (!check_collision_offset(ent, point_to_test, p_bbox->size, tilemap, (Vector2){0})) if (!check_collision_at(ent, point_to_test, p_bbox->size, tilemap, (Vector2){0}))
{ {
p_ct->position = point_to_test; p_ct->position = point_to_test;
goto collision_end; goto collision_end;
@ -218,7 +218,7 @@ static bool check_collision_and_move(
point_to_test.x = other_pos->x + other_bbox.x - 1; point_to_test.x = other_pos->x + other_bbox.x - 1;
point_to_test.y = p_ct->position.y; point_to_test.y = p_ct->position.y;
if (!check_collision_offset(ent, point_to_test, p_bbox->size, tilemap, (Vector2){0})) if (!check_collision_at(ent, point_to_test, p_bbox->size, tilemap, (Vector2){0}))
{ {
p_ct->position = point_to_test; p_ct->position = point_to_test;
goto collision_end; goto collision_end;
@ -226,7 +226,7 @@ static bool check_collision_and_move(
point_to_test.x = p_ct->position.x; point_to_test.x = p_ct->position.x;
point_to_test.y = other_pos->y + other_bbox.y - 1; point_to_test.y = other_pos->y + other_bbox.y - 1;
if (!check_collision_offset(ent, point_to_test, p_bbox->size, tilemap, (Vector2){0})) if (!check_collision_at(ent, point_to_test, p_bbox->size, tilemap, (Vector2){0}))
{ {
p_ct->position = point_to_test; p_ct->position = point_to_test;
goto collision_end; goto collision_end;
@ -353,22 +353,6 @@ static Vector2 shift_bbox(Vector2 bbox, Vector2 new_bbox, AnchorPoint_t anchor)
return offset; return offset;
} }
void player_respawn_system(Scene_t* scene)
{
Entity_t* p_player;
sc_map_foreach_value(&scene->ent_manager.entities_map[PLAYER_ENT_TAG], p_player)
{
if (!p_player->m_alive)
{
p_player->m_alive = true;
CTransform_t* p_ctransform = get_component(p_player, CTRANSFORM_COMP_T);
memset(&p_ctransform->position, 0, sizeof(p_ctransform->position));
memset(&p_ctransform->velocity, 0, sizeof(p_ctransform->velocity));
memset(&p_ctransform->accel, 0, sizeof(p_ctransform->accel));
}
}
}
void player_dir_reset_system(Scene_t* scene) void player_dir_reset_system(Scene_t* scene)
{ {
CPlayerState_t* p_pstate; CPlayerState_t* p_pstate;
@ -406,10 +390,15 @@ void player_movement_input_system(Scene_t* scene)
p_ctransform->position.y + p_bbox->half_size.y, p_ctransform->position.y + p_bbox->half_size.y,
data->tilemap.width data->tilemap.width
); );
if (tilemap.tiles[tile_idx].tile_type == LADDER && p_ctransform->velocity.y >= 0) if (tilemap.tiles[tile_idx].tile_type == LADDER)
{ {
p_pstate->ladder_state = true; p_pstate->ladder_state = true;
p_ctransform->position.y--;
//p_ctransform->position.x = (tile_idx % tilemap.width) * TILE_SIZE;
if (p_mstate->ground_state & 1)
{
p_ctransform->position.y--;
}
} }
} }
else if (p_pstate->player_dir.y > 0) else if (p_pstate->player_dir.y > 0)
@ -435,7 +424,11 @@ void player_movement_input_system(Scene_t* scene)
if (tile_idx < tilemap.n_tiles && tilemap.tiles[tile_idx].tile_type == LADDER) if (tile_idx < tilemap.n_tiles && tilemap.tiles[tile_idx].tile_type == LADDER)
{ {
p_pstate->ladder_state = true; p_pstate->ladder_state = true;
p_ctransform->position.y++; //p_ctransform->position.x = (tile_idx % tilemap.width) * TILE_SIZE;
if (p_mstate->ground_state & 1)
{
p_ctransform->position.y += TILE_SIZE / 2;
}
} }
} }
} }
@ -458,10 +451,6 @@ void player_movement_input_system(Scene_t* scene)
{ {
p_ctransform->velocity.y = p_pstate->player_dir.y * 150; p_ctransform->velocity.y = p_pstate->player_dir.y * 150;
p_ctransform->velocity.x = p_pstate->player_dir.x * 40; p_ctransform->velocity.x = p_pstate->player_dir.x * 40;
if (p_pstate->player_dir.y != 0)
{
p_ctransform->position.x = tile_x * TILE_SIZE + 1;
}
} }
} }
@ -593,7 +582,7 @@ void player_bbox_update_system(Scene_t* scene)
} }
if ( if (
!check_collision_offset( !check_collision_at(
p_player, p_ctransform->position, new_bbox, p_player, p_ctransform->position, new_bbox,
&tilemap, offset &tilemap, offset
) )
@ -628,44 +617,15 @@ void player_crushing_system(Scene_t* scene)
.area = (TileArea_t){ .area = (TileArea_t){
.tile_x1 = (p_ctransform->position.x) / TILE_SIZE, .tile_x1 = (p_ctransform->position.x) / TILE_SIZE,
.tile_y1 = (p_ctransform->position.y) / TILE_SIZE, .tile_y1 = (p_ctransform->position.y) / TILE_SIZE,
.tile_x2 = (p_ctransform->position.x) / TILE_SIZE, .tile_x2 = (p_ctransform->position.x + p_bbox->size.x - 1) / TILE_SIZE,
.tile_y2 = (p_ctransform->position.y + p_bbox->size.y - 1) / TILE_SIZE, .tile_y2 = (p_ctransform->position.y + p_bbox->size.y - 1) / TILE_SIZE,
}, },
}; };
if (check_collision(&ent, &tilemap, false) == 1)
// Mostly identical to edge check function
// Except we want collision instead of just touching
uint8_t detected = 0;
// Left
detected |= (check_collision(&ent, &tilemap, false) ? 1 : 0);
//Right
ent.area.tile_x1 = (p_ctransform->position.x + p_bbox->size.x - 1) / TILE_SIZE;
ent.area.tile_x2 = ent.area.tile_x1;
detected |= (check_collision(&ent, &tilemap, false) ? 1 : 0) << 1;
if (detected == 0b11)
{ {
p_player->m_alive = false; memset(&p_ctransform->position, 0, sizeof(p_ctransform->position));
return; memset(&p_ctransform->velocity, 0, sizeof(p_ctransform->velocity));
} memset(&p_ctransform->accel, 0, sizeof(p_ctransform->accel));
detected = 0;
// Up
ent.area.tile_x1 = (p_ctransform->position.x) / TILE_SIZE,
ent.area.tile_y1 = (p_ctransform->position.y - 1) / TILE_SIZE,
ent.area.tile_y2 = ent.area.tile_y1;
detected |= (check_collision(&ent, &tilemap, false) ? 1 : 0) << 1;
// Down
ent.area.tile_y1 = (p_ctransform->position.y + p_bbox->size.y - 1) / TILE_SIZE,
ent.area.tile_y2 = ent.area.tile_y1;
detected |= (check_collision(&ent, &tilemap, true) ? 1 : 0);
//if (check_collision(&ent, &tilemap, false) == 1)
if (detected == 0b11)
{
p_player->m_alive = false;
return; return;
} }
} }

View File

@ -20,5 +20,4 @@ void hitbox_update_system(Scene_t* scene);
void sprite_animation_system(Scene_t* scene); void sprite_animation_system(Scene_t* scene);
void camera_update_system(Scene_t* scene); void camera_update_system(Scene_t* scene);
void player_dir_reset_system(Scene_t* scene); void player_dir_reset_system(Scene_t* scene);
void player_respawn_system(Scene_t* scene);
#endif // __GAME_SYSTEMS_H #endif // __GAME_SYSTEMS_H