From 6509b33c5a6858def954f06eb1893d87e0c942c0 Mon Sep 17 00:00:00 2001 From: En Yi Date: Sat, 9 Nov 2024 23:40:54 +0800 Subject: [PATCH] Rework urchin collision with crates Changelog: - Fix error in urchin spawning in main game - Reduce urchin's collision box - Adjust crate destruction: - Delay with arrows and bombs, instant with anything else --- scenes/game_systems.c | 15 ++++----------- scenes/items_ent.c | 7 ++++--- scenes/scene_systems.c | 2 +- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/scenes/game_systems.c b/scenes/game_systems.c index ef49b77..4fc0b49 100644 --- a/scenes/game_systems.c +++ b/scenes/game_systems.c @@ -1730,21 +1730,14 @@ void hitbox_update_system(Scene_t* scene) { remove_component(p_other_ent, CHURTBOX_T); CLifeTimer_t* p_clifetimer = add_component(p_other_ent, CLIFETIMER_T); - if (p_other_ent->m_tag == CRATES_ENT_TAG) + if (p_other_ent->m_tag == CRATES_ENT_TAG + && (p_ent->m_tag == ARROW_ENT_TAG || p_ent->m_tag == DESTRUCTABLE_ENT_TAG)) { - CContainer_t* p_container = get_component(p_other_ent, CCONTAINER_T); - if (p_container->item == CONTAINER_BOMB) - { - p_clifetimer->life_time = 0.1f; - } - else - { - p_clifetimer->life_time = 0.1f; - } + p_clifetimer->life_time = 0.1f; } else { - p_clifetimer->life_time = 0.05f; + p_clifetimer->life_time = 0.01f; } } } diff --git a/scenes/items_ent.c b/scenes/items_ent.c index e7ef902..3a92b5e 100644 --- a/scenes/items_ent.c +++ b/scenes/items_ent.c @@ -5,7 +5,7 @@ #include "raymath.h" static SpriteRenderInfo_t item_sprite_map[22] = {0}; - +#define URCHIN_OFFSET 6 bool init_item_creation(Assets_t* assets) { item_sprite_map[0].sprite = get_sprite(assets, "w_crate"); @@ -46,6 +46,7 @@ bool init_item_creation(Assets_t* assets) item_sprite_map[20].src_anchor = AP_BOT_CENTER; item_sprite_map[20].offset = (Vector2){0, TILE_SIZE >> 1}; item_sprite_map[21].sprite = get_sprite(assets, "urchin"); + item_sprite_map[21].offset = (Vector2){-URCHIN_OFFSET, -URCHIN_OFFSET}; return true; } @@ -254,7 +255,7 @@ Entity_t* create_urchin(EntityManager_t* ent_manager) if (p_urchin == NULL) return NULL; CBBox_t* p_bbox = add_component(p_urchin, CBBOX_COMP_T); - set_bbox(p_bbox, TILE_SIZE-2, TILE_SIZE-2); + set_bbox(p_bbox, TILE_SIZE-(URCHIN_OFFSET<<1), TILE_SIZE-(URCHIN_OFFSET<<1)); CTransform_t* p_ctransform = add_component(p_urchin, CTRANSFORM_COMP_T); p_ctransform->movement_mode = KINEMATIC_MOVEMENT; @@ -272,7 +273,7 @@ Entity_t* create_urchin(EntityManager_t* ent_manager) CHitBoxes_t* p_hitbox = add_component(p_urchin, CHITBOXES_T); p_hitbox->n_boxes = 1; - p_hitbox->boxes[0] = (Rectangle) {-1,-1,TILE_SIZE,TILE_SIZE}; + p_hitbox->boxes[0] = (Rectangle) {-(URCHIN_OFFSET>>1),-(URCHIN_OFFSET>>1),TILE_SIZE-URCHIN_OFFSET,TILE_SIZE-URCHIN_OFFSET}; p_hitbox->atk = 2; CSprite_t* p_cspr = add_component(p_urchin, CSPRITE_T); diff --git a/scenes/scene_systems.c b/scenes/scene_systems.c index a0e05b5..376c078 100644 --- a/scenes/scene_systems.c +++ b/scenes/scene_systems.c @@ -228,7 +228,7 @@ bool load_level_tilemap(LevelScene_t* scene, unsigned int level_num) CBBox_t* p_bbox = get_component(ent, CBBOX_COMP_T); ent->position.x = (i % scene->data.tilemap.width) * scene->data.tilemap.tile_size + (scene->data.tilemap.tile_size >> 1) - p_bbox->half_size.x; - ent->position.y = (i / scene->data.tilemap.width) * scene->data.tilemap.tile_size + (scene->data.tilemap.tile_size >> 1) + (scene->data.tilemap.tile_size >> 1) - p_bbox->half_size.y; + ent->position.y = (int)(i / scene->data.tilemap.width) * scene->data.tilemap.tile_size + (scene->data.tilemap.tile_size >> 1) - p_bbox->half_size.y; uint8_t spd_encoding = lvl_map.tiles[i].tile_type - 25; float angle = 45.0f / 180.0f * PI * ((spd_encoding >> 2) & 7);