Compare commits

...

3 Commits

2 changed files with 25 additions and 10 deletions

View File

@ -17,8 +17,7 @@
#define GRAV_ACCEL 1500
#define JUMP_SPEED 70
#define MOVE_ACCEL 1000
#define FRICTION 0.98
#define MOVE_ACCEL 1300
#ifndef TILE16_SIZE
#define PLAYER_WIDTH 30
@ -35,8 +34,9 @@
#define PLAYER_C_XOFFSET (PLAYER_WIDTH - PLAYER_C_WIDTH)
#define PLAYER_MAX_SPEED 800
#define Y_FRICTION 0.98
#define X_FRICTION 0.85
#define WATER_FRICTION 7.5
#define GROUND_X_FRICTION 5.8
#define GROUND_Y_FRICTION 1.0
#define MAX_WATER_LEVEL 4
#endif // __CONSTANTS_H

View File

@ -802,7 +802,7 @@ void friction_coefficient_update_system(Scene_t* scene)
{
// Apply water friction
// Consistent in all direction
p_ct->fric_coeff = (Vector2){-5.5, -5.5};
p_ct->fric_coeff = (Vector2){-WATER_FRICTION, -WATER_FRICTION};
}
else
{
@ -810,7 +810,7 @@ void friction_coefficient_update_system(Scene_t* scene)
// x is set to ground resistance (even in air)
// If not, then player is can go faster by bunny hopping
// which is fun but not quite beneficial here
p_ct->fric_coeff = (Vector2){-3.3, -1};
p_ct->fric_coeff = (Vector2){-GROUND_X_FRICTION, -GROUND_Y_FRICTION};
}
CPlayerState_t* p_pstate = get_component(p_ent, CPLAYERSTATE_T);
@ -917,6 +917,7 @@ void moveable_update_system(Scene_t* scene)
float remaining_distance = p_moveable->target_pos.x - p_ctransform->position.x;
if (fabs(remaining_distance) < 0.1)
{
p_ctransform->prev_position = p_moveable->prev_pos;
p_ctransform->position = p_moveable->target_pos;
p_moveable->gridmove = false;
p_bbox->solid = true;
@ -930,13 +931,19 @@ void moveable_update_system(Scene_t* scene)
p_ctransform->position.x += (remaining_distance < -p_moveable->move_speed) ? -p_moveable->move_speed : remaining_distance;
}
}
else
// Intentional. Want this check even after a gridmove to allow gridmove after that
if (!p_moveable->gridmove)
{
if (p_ctransform->prev_velocity.y <= 0) continue;
if (p_ctransform->prev_velocity.y <= 0 && p_ctransform->prev_position.x == p_ctransform->position.x) continue;
TileGrid_t tilemap = (CONTAINER_OF(scene, LevelScene_t, scene)->data).tilemap;
int tile_x = (p_ctransform->position.x + p_bbox->half_size.x) / TILE_SIZE;
int tile_y = (p_ctransform->position.y + p_bbox->size.y) / TILE_SIZE;
Vector2 point_to_check = {
.x = p_ctransform->position.x + p_bbox->half_size.x,
.y = p_ctransform->position.y + p_bbox->size.y + 5 // 5 is arbitrary, just to make sure there's a little gap
};
int tile_x = point_to_check.x / TILE_SIZE;
int tile_y = point_to_check.y / TILE_SIZE;
if (tile_y >= tilemap.height) continue;
int tile_idx = tile_y * tilemap.width + tile_x;
@ -949,6 +956,14 @@ void moveable_update_system(Scene_t* scene)
sc_map_get_64v(&scene->ent_manager.component_map[CMOVEABLE_T], other_ent_idx);
if (!sc_map_found(&scene->ent_manager.component_map[CMOVEABLE_T])) continue;
{
Entity_t* other_ent = get_entity(&scene->ent_manager, other_ent_idx);
CBBox_t* p_other_bbox = get_component(other_ent, CBBOX_COMP_T);
CTransform_t* p_other_ct = get_component(other_ent, CTRANSFORM_COMP_T);
Rectangle box = {p_other_ct->position.x, p_other_ct->position.y, p_other_bbox->size.x, p_other_bbox->size.y};
if (!point_in_AABB(point_to_check, box)) continue;
}
tile_x = (p_ctransform->position.x) / TILE_SIZE - 1;
if (tile_x >= 0 && tile_x < tilemap.width)