Compare commits

...

7 Commits

Author SHA1 Message Date
En Yi 26eeec5638 Hack a method to lock key in game 2023-11-22 22:52:21 +08:00
En Yi d62b862ebe Make player hitbox bigger 2023-11-22 21:41:43 +08:00
En Yi 96d389a69a Fix mistake in ground check 2023-11-22 21:41:06 +08:00
En Yi 21dab8b9a8 Adjust camera base height on crate jumping 2023-11-22 21:40:50 +08:00
En Yi 72235f7522 Play box land sfc for chests as well 2023-11-22 21:13:10 +08:00
En Yi 1311c2f0b7 Fix ground check
Use line check instead of box check
2023-11-22 21:04:00 +08:00
En Yi 09ee7aa4b3 Fix weird air and bubbling behaviour
Changelog:
- Air timer decays on point check instead of water state
- Bubbling is also starts with this point check
- This is so that it is consistent that bubbles == air going down
2023-11-22 20:51:29 +08:00
4 changed files with 58 additions and 54 deletions

View File

@ -177,21 +177,20 @@ uint8_t check_collision_offset(Entity_t* p_ent, Vector2 pos, Vector2 bbox_sz, Ti
bool check_on_ground(Entity_t* p_ent, Vector2 pos, Vector2 prev_pos, Vector2 bbox_sz, TileGrid_t* grid)
{
//return check_collision_at(ent_idx, pos, bbox_sz, grid, (Vector2){0, 1}, p_manager);
Vector2 new_pos = Vector2Add(pos, (Vector2){0, 1});
CollideEntity_t ent = {
.p_ent = p_ent,
.bbox = (Rectangle){new_pos.x, new_pos.y + bbox_sz.y - 1, bbox_sz.x, 1},
.bbox = (Rectangle){new_pos.x, new_pos.y + bbox_sz.y, bbox_sz.x, 1},
.prev_bbox = (Rectangle){prev_pos.x, prev_pos.y, bbox_sz.x, bbox_sz.y},
.area = (TileArea_t){
.tile_x1 = (new_pos.x) / grid->tile_size,
.tile_y1 = (new_pos.y + bbox_sz.y - 1) / grid->tile_size,
.tile_x2 = (new_pos.x + bbox_sz.x - 1) / grid->tile_size,
.tile_y2 = (new_pos.y + bbox_sz.y - 1) / grid->tile_size
.tile_y1 = (new_pos.y + bbox_sz.y) / grid->tile_size,
.tile_x2 = (new_pos.x + bbox_sz.x) / grid->tile_size,
.tile_y2 = (new_pos.y + bbox_sz.y) / grid->tile_size
}
};
return check_collision(&ent, grid, true);
return check_collision_line(&ent, grid, true) == 1;
}
uint8_t check_bbox_edges(

View File

@ -5,6 +5,10 @@
#include <unistd.h>
#if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h>
#include <emscripten/html5.h>
EM_BOOL keyDownCallback(int eventType, const EmscriptenKeyboardEvent *event, void* userData) {
return true; // Just preventDefault everything lol
}
#endif
Scene_t* scenes[1];
@ -72,6 +76,8 @@ int main(void)
#if defined(PLATFORM_WEB)
puts("Setting emscripten main loop");
emscripten_set_keypress_callback("#canvas", NULL, 1, keyDownCallback);
emscripten_set_keydown_callback("#canvas", NULL, 1, keyDownCallback);
emscripten_set_main_loop(update_loop, 0, 1);
#else
puts("Regular main loop");

View File

@ -581,9 +581,8 @@ void player_bbox_update_system(Scene_t* scene)
}
CHitBoxes_t* p_hitbox = get_component(p_player, CHITBOXES_T);
p_hitbox->boxes[0].height = p_bbox->size.y + 2;
//p_hitbox->boxes[1].y = p_bbox->size.y / 4;
p_hitbox->boxes[1].height = p_bbox->size.y - 1;
p_hitbox->boxes[0].height = p_bbox->size.y + 4;
p_hitbox->boxes[1].height = p_bbox->size.y;
CHurtbox_t* p_hurtbox = get_component(p_player, CHURTBOX_T);
p_hurtbox->size = p_bbox->size;
}
@ -1473,7 +1472,7 @@ void state_transition_update_system(Scene_t* scene)
{
play_sfx(scene->engine, BOULDER_LAND_SFX);
}
else if (p_ent->m_tag == CRATES_ENT_TAG)
else if (p_ent->m_tag == CRATES_ENT_TAG || p_ent->m_tag == CHEST_ENT_TAG)
{
play_sfx(scene->engine, WOOD_LAND_SFX);
}
@ -1494,33 +1493,6 @@ void state_transition_update_system(Scene_t* scene)
}
if (p_mstate->water_state & 1)
{
CEmitter_t* p_emitter = get_component(p_ent, CEMITTER_T);
if (p_emitter != NULL)
{
if (!is_emitter_handle_alive(&scene->part_sys, p_emitter->handle))
{
Vector2 new_pos = p_ctransform->position;
new_pos.y += p_bbox->half_size.y;
ParticleEmitter_t emitter = {
.spr = get_sprite(&scene->engine->assets, "p_water"),
.config = get_emitter_conf(&scene->engine->assets, "pe_bubbling"),
.position = new_pos,
.n_particles = 5,
.user_data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data),
.update_func = &floating_particle_system_update,
.emitter_update_func = &check_in_water,
};
p_emitter->handle = play_particle_emitter(&scene->part_sys, &emitter);
}
else
{
play_emitter_handle(&scene->part_sys, p_emitter->handle);
}
}
}
}
}
@ -1619,8 +1591,8 @@ void hitbox_update_system(Scene_t* scene)
unsigned int tile_x1 = (hitbox_pos.x) / TILE_SIZE;
unsigned int tile_y1 = (hitbox_pos.y) / TILE_SIZE;
unsigned int tile_x2 = (hitbox_pos.x + p_hitbox->boxes[i].width - 1) / TILE_SIZE;
unsigned int tile_y2 = (hitbox_pos.y + p_hitbox->boxes[i].height - 1) / TILE_SIZE;
unsigned int tile_x2 = (hitbox_pos.x + p_hitbox->boxes[i].width) / TILE_SIZE;
unsigned int tile_y2 = (hitbox_pos.y + p_hitbox->boxes[i].height) / TILE_SIZE;
tile_x2 = (tile_x2 >= tilemap.width) ? tilemap.width - 1 : tile_x2;
tile_y2 = (tile_y2 >= tilemap.height) ? tilemap.width - 1 : tile_y2;
@ -1702,6 +1674,10 @@ void hitbox_update_system(Scene_t* scene)
p_cjump->short_hop = false;
p_cjump->jumped = true;
}
if (p_ent->m_tag == PLAYER_ENT_TAG)
{
data->camera.base_y = p_ctransform->position.y;
}
}
else if (p_ctransform->position.y >= p_other_ct->position.y + p_other_bbox->size.y)
{
@ -1928,7 +1904,7 @@ void airtimer_update_system(Scene_t* scene)
if (p_ctransform == NULL || p_bbox == NULL || p_movement == NULL) continue;
Vector2 point_to_check = {
(p_movement->x_dir == 0) ? p_ctransform->position.x : p_ctransform->position.x + p_bbox->size.x,
p_ctransform->position.x + p_bbox->half_size.x,
p_ctransform->position.y + p_bbox->half_size.y / 2,
};
@ -1943,19 +1919,43 @@ void airtimer_update_system(Scene_t* scene)
int tile_y = tile_idx / tilemap.width;
uint32_t water_height = data->tilemap.tiles[tile_idx].water_level * WATER_BBOX_STEP;
Vector2 tl = {tile_x * data->tilemap.tile_size, (tile_y + 1) * data->tilemap.tile_size - water_height};
in_water |= point_in_AABB(
point_to_check,
(Rectangle){tl.x, tl.y, tilemap.tile_size, water_height}
);
in_water |= point_in_AABB(
point_to_check,
(Rectangle){tl.x, tl.y, tilemap.tile_size, water_height}
);
if (!in_water)
{
p_air->curr_count = p_air->max_count;
p_air->curr_ftimer = p_air->max_ftimer * 2; // Lengthen the first
}
if (p_movement->water_state & 1)
else
{
CEmitter_t* p_emitter = get_component(p_ent, CEMITTER_T);
if (p_emitter != NULL)
{
if (!is_emitter_handle_alive(&scene->part_sys, p_emitter->handle))
{
Vector2 new_pos = p_ctransform->position;
new_pos.y += p_bbox->half_size.y;
ParticleEmitter_t emitter = {
.spr = get_sprite(&scene->engine->assets, "p_water"),
.config = get_emitter_conf(&scene->engine->assets, "pe_bubbling"),
.position = new_pos,
.n_particles = 5,
.user_data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data),
.update_func = &floating_particle_system_update,
.emitter_update_func = &check_in_water,
};
p_emitter->handle = play_particle_emitter(&scene->part_sys, &emitter);
}
else
{
play_emitter_handle(&scene->part_sys, p_emitter->handle);
}
}
if (p_air->curr_ftimer > p_air->decay_rate)
{
p_air->curr_ftimer -= p_air->decay_rate;
@ -1989,7 +1989,6 @@ void airtimer_update_system(Scene_t* scene)
destroy_entity(scene, &tilemap, get_entity(&scene->ent_manager, ent_idx));
}
}
}
}
}
@ -2052,7 +2051,7 @@ void camera_update_system(Scene_t* scene)
|| (p_pstate->ladder_state & 1)
)
{
data->camera.base_y = p_ctransform->position.y;
data->camera.base_y = p_ctransform->position.y;
}
if (p_ctransform->position.y >= data->camera.base_y)
{

View File

@ -81,15 +81,15 @@ Entity_t* create_player(EntityManager_t* ent_manager)
p_hitbox->n_boxes = 2;
p_hitbox->boxes[0] = (Rectangle) {
.x = 0,
.y = -1,
.width = p_bbox->size.x - 1,
.height = p_bbox->size.y + 2,
.y = -2,
.width = p_bbox->size.x,
.height = p_bbox->size.y + 4,
};
p_hitbox->boxes[1] = (Rectangle) {
.x = -1,
.x = -2,
.y = 0,
.width = p_bbox->size.x + 2,
.height = p_bbox->size.y - 1,
.width = p_bbox->size.x + 4,
.height = p_bbox->size.y,
};
p_hitbox->atk = 2;
CHurtbox_t* p_hurtbox = add_component(p_ent, CHURTBOX_T);