Fix ladder spawning solid issue

Changelog:
- Add checks for ladder's solidity when spawning/despawning ladders
- Move crouch state check into player movement system
- Add ladder state for later implementation
scene_man
En Yi 2023-05-06 12:19:15 +08:00
parent b9a0bfe7b1
commit c44696c1f8
3 changed files with 8 additions and 1 deletions

View File

@ -38,6 +38,7 @@ typedef struct _CTransform_t {
typedef struct _CMovementState_t {
uint8_t ground_state;
uint8_t water_state;
bool ladder_state;
} CMovementState_t;
// This is to store the occupying tiles

View File

@ -287,6 +287,11 @@ static void toggle_block_system(Scene_t* scene)
tilemap.tiles[tile_idx].solid = NOT_SOLID;
}
}
int down_tile = tile_idx + tilemap.width;
if (down_tile < MAX_N_TILES && tilemap.tiles[down_tile].tile_type == LADDER)
{
tilemap.tiles[down_tile].solid = (tilemap.tiles[tile_idx].tile_type != LADDER)? ONE_WAY : NOT_SOLID;
}
tilemap.tiles[tile_idx].water_level = 0;
break;
case SPAWN_CRATE:
@ -334,7 +339,7 @@ void level_do_action(Scene_t* scene, ActionType_t action, bool pressed)
break;
case ACTION_DOWN:
p_playerstate->player_dir.y = (pressed)? 1 : 0;
p_playerstate->is_crouch |= (pressed)? 0b10 : 0;
//p_playerstate->is_crouch |= (pressed)? 0b10 : 0;
break;
case ACTION_LEFT:
p_playerstate->player_dir.x = (pressed)? -1 : 0;

View File

@ -316,6 +316,7 @@ void player_movement_input_system(Scene_t* scene)
bool in_water = (p_mstate->water_state & 1);
if (!in_water)
{
p_pstate->is_crouch |= (p_pstate->player_dir.y > 0)? 0b10 : 0;
p_pstate->player_dir.y = 0;
p_ctransform->accel = Vector2Scale(Vector2Normalize(p_pstate->player_dir), MOVE_ACCEL);
}