Compare commits

..

No commits in common. "9eb46d0e571923cfc7a1003b1dd4c3c2035a37c4" and "d59c90295870f52c1961dec95ece985d8d54791a" have entirely different histories.

3 changed files with 7 additions and 134 deletions

View File

@ -66,7 +66,6 @@ typedef struct _CPlayerState_t {
Vector2 player_dir;
uint8_t jump_pressed;
uint8_t is_crouch;
bool ladder_state;
} CPlayerState_t;
typedef enum ContainerItem {

View File

@ -12,7 +12,6 @@ static Tile_t all_tiles[MAX_N_TILES] = {0};
enum EntitySpawnSelection {
TOGGLE_TILE = 0,
TOGGLE_ONEWAY,
TOGGLE_LADDER,
SPAWN_CRATE,
SPAWN_METAL_CRATE,
};
@ -48,16 +47,10 @@ static void level_scene_render_func(Scene_t* scene)
{
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, MAROON);
}
else if (tilemap.tiles[i].tile_type == LADDER)
{
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, ORANGE);
}
if (tilemap.tiles[i].water_level > 0)
else if (tilemap.tiles[i].water_level > 0)
{
// Draw water tile
Color water_colour = ColorAlpha(BLUE, 0.5);
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, water_colour);
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, BLUE);
}
}
@ -160,8 +153,6 @@ static void level_scene_render_func(Scene_t* scene)
DrawText(buffer, tilemap.width * TILE_SIZE + 1, 90, 12, BLACK);
sprintf(buffer, "Water: %s", p_mstate->water_state & 1? "YES":"NO");
DrawText(buffer, tilemap.width * TILE_SIZE + 1, 120, 12, BLACK);
sprintf(buffer, "Ladder: %u", p_pstate->ladder_state);
DrawText(buffer, tilemap.width * TILE_SIZE + 1, 150, 12, BLACK);
}
sprintf(buffer, "Spawn Entity: %u", current_spawn_selection);
DrawText(buffer, tilemap.width * TILE_SIZE + 1, 240, 12, BLACK);
@ -270,31 +261,7 @@ static void toggle_block_system(Scene_t* scene)
tilemap.tiles[tile_idx].tile_type = ONEWAY_TILE;
tilemap.tiles[tile_idx].solid = ONE_WAY;
}
break;
case TOGGLE_LADDER:
if (tilemap.tiles[tile_idx].tile_type == LADDER)
{
tilemap.tiles[tile_idx].tile_type = EMPTY_TILE;
tilemap.tiles[tile_idx].solid = NOT_SOLID;
}
else
{
tilemap.tiles[tile_idx].tile_type = LADDER;
int up_tile = tile_idx - tilemap.width;
if (up_tile > 0 && tilemap.tiles[up_tile].tile_type != LADDER)
{
tilemap.tiles[tile_idx].solid = ONE_WAY;
}
else
{
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:
spawn_crate(scene, tile_idx, false);
@ -341,6 +308,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;
break;
case ACTION_LEFT:
p_playerstate->player_dir.x = (pressed)? -1 : 0;

View File

@ -313,85 +313,9 @@ void player_movement_input_system(Scene_t* scene)
CJump_t* p_cjump = get_component(&scene->ent_manager, p_player, CJUMP_COMP_T);
CMovementState_t* p_mstate = get_component(&scene->ent_manager, p_player, CMOVEMENTSTATE_T);
// Ladder handling
if (!p_pstate->ladder_state)
{
if (p_pstate->player_dir.y < 0)
{
unsigned int tile_idx = get_tile_idx(
p_ctransform->position.x + p_bbox->half_size.x,
p_ctransform->position.y + p_bbox->half_size.y,
data->tilemap.width
);
if (tilemap.tiles[tile_idx].tile_type == LADDER)
{
p_pstate->ladder_state = true;
//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)
{
unsigned int tile_idx;
if (p_mstate->ground_state & 1)
{
tile_idx = get_tile_idx(
p_ctransform->position.x + p_bbox->half_size.x,
p_ctransform->position.y + p_bbox->size.y,
data->tilemap.width
);
}
else
{
tile_idx = get_tile_idx(
p_ctransform->position.x + p_bbox->half_size.x,
p_ctransform->position.y + p_bbox->half_size.y,
data->tilemap.width
);
}
if (tile_idx < tilemap.n_tiles && tilemap.tiles[tile_idx].tile_type == LADDER)
{
p_pstate->ladder_state = true;
//p_ctransform->position.x = (tile_idx % tilemap.width) * TILE_SIZE;
if (p_mstate->ground_state & 1)
{
p_ctransform->position.y += TILE_SIZE / 2;
}
}
}
}
else
{
unsigned int tile_x = (p_ctransform->position.x + p_bbox->half_size.x) / TILE_SIZE;
unsigned int tile_y1 = (p_ctransform->position.y + p_bbox->half_size.y) / TILE_SIZE;
unsigned int tile_y2 = (p_ctransform->position.y + p_bbox->size.y) / TILE_SIZE;
p_pstate->ladder_state = false;
if (!(p_mstate->ground_state & 1))
{
for(unsigned int tile_y = tile_y1; tile_y <= tile_y2; tile_y++)
{
unsigned int tile_idx = tile_y * tilemap.width + tile_x;
p_pstate->ladder_state |= tilemap.tiles[tile_idx].tile_type == LADDER;
}
}
if (p_pstate->ladder_state)
{
p_ctransform->velocity.y = p_pstate->player_dir.y * 150;
p_ctransform->velocity.x = p_pstate->player_dir.x * 40;
}
}
bool in_water = (p_mstate->water_state & 1);
p_pstate->is_crouch |= (p_pstate->player_dir.y > 0)? 0b10 : 0;
if (!in_water)
{
p_pstate->player_dir.y = 0;
p_ctransform->accel = Vector2Scale(Vector2Normalize(p_pstate->player_dir), MOVE_ACCEL);
}
@ -443,18 +367,10 @@ void player_movement_input_system(Scene_t* scene)
// Check if possible to jump when jump is pressed
if (p_pstate->jump_pressed && p_cjump->jumps > 0 && p_cjump->jump_ready)
{
p_pstate->ladder_state = false;
p_cjump->jumps--;
if (!in_water)
{
if (p_mstate->ground_state & 1)
{
p_ctransform->velocity.y = -p_cjump->jump_speed;
}
else
{
p_ctransform->velocity.y = -p_cjump->jump_speed / 1.4;
}
p_ctransform->velocity.y = -p_cjump->jump_speed;
}
else
{
@ -502,7 +418,7 @@ void player_bbox_update_system(Scene_t* scene)
}
else
{
if ((p_mstate->water_state & 1) && !p_pstate->ladder_state)
if (p_mstate->water_state & 1)
{
new_bbox.x = PLAYER_C_WIDTH;
new_bbox.y = PLAYER_C_HEIGHT;
@ -787,16 +703,6 @@ void global_external_forces_system(Scene_t* scene)
}
}
CPlayerState_t* p_pstate;
sc_map_foreach(&scene->ent_manager.component_map[CPLAYERSTATE_T], ent_idx, p_pstate)
{
Entity_t* p_ent = get_entity(&scene->ent_manager, ent_idx);
CTransform_t* p_ctransform = get_component(&scene->ent_manager, p_ent, CTRANSFORM_COMP_T);
if (p_pstate->ladder_state)
{
p_ctransform->accel = (Vector2){0,0};
}
}
}
void movement_update_system(Scene_t* scene)
@ -846,7 +752,7 @@ void player_ground_air_transition_system(Scene_t* scene)
// Handle Ground<->Air Transition
bool in_water = (p_mstate->water_state & 1);
// Landing or in water
if ((p_mstate->ground_state & 1 || in_water || p_pstate->ladder_state) && !p_pstate->jump_pressed )
if ((p_mstate->ground_state & 1 || in_water) && !p_pstate->jump_pressed )
{
// Recover jumps
p_cjump->jumps = p_cjump->max_jumps;