diff --git a/scenes/editor_scene.c b/scenes/editor_scene.c index e6d4d51..9c5ff2e 100644 --- a/scenes/editor_scene.c +++ b/scenes/editor_scene.c @@ -21,10 +21,11 @@ enum EntitySpawnSelection { SPAWN_CRATE_ARROW_R, SPAWN_CRATE_ARROW_U, SPAWN_CRATE_ARROW_D, + SPAWN_CRATE_BOMB, SPAWN_BOULDER, }; -#define MAX_SPAWN_TYPE 11 +#define MAX_SPAWN_TYPE 12 static unsigned int current_spawn_selection = 0; static bool metal_toggle = false; @@ -195,6 +196,9 @@ static void level_scene_render_func(Scene_t* scene) BLACK ); break; + case CONTAINER_BOMB: + DrawCircleV(Vector2Add(p_ct->position, p_bbox->half_size), p_bbox->half_size.x, BLACK); + break; default: break; } @@ -287,7 +291,7 @@ static void level_scene_render_func(Scene_t* scene) const Color crate_colour = metal_toggle ? GRAY : BROWN; const Color draw_colour[MAX_SPAWN_TYPE] = { BLACK, MAROON, ORANGE, ColorAlpha(RAYWHITE, 0.5), ColorAlpha(BLUE, 0.5), - crate_colour, crate_colour, crate_colour, crate_colour, crate_colour, + crate_colour, crate_colour, crate_colour, crate_colour, crate_colour, crate_colour, ColorAlpha(RAYWHITE, 0.5) }; for (uint8_t i = 0; i < MAX_SPAWN_TYPE; ++i) @@ -340,6 +344,9 @@ static void level_scene_render_func(Scene_t* scene) BLACK ); break; + case SPAWN_CRATE_BOMB: + DrawCircleV(Vector2Add(draw_pos, half_size), half_size.x, BLACK); + break; } } draw_pos.x += SELECTION_TILE_SIZE; @@ -396,6 +403,9 @@ static void level_scene_render_func(Scene_t* scene) BLACK ); break; + case SPAWN_CRATE_BOMB: + DrawCircleV(Vector2Add(draw_pos, half_size), half_size.x, BLACK); + break; } // For DEBUG @@ -520,6 +530,9 @@ static void toggle_block_system(Scene_t* scene) case SPAWN_CRATE_ARROW_D: spawn_crate(scene, tile_idx, metal_toggle, CONTAINER_DOWN_ARROW); break; + case SPAWN_CRATE_BOMB: + spawn_crate(scene, tile_idx, metal_toggle, CONTAINER_BOMB); + break; } change_a_tile(&tilemap, tile_idx, new_type); last_tile_idx = tile_idx; diff --git a/scenes/ent_impl.h b/scenes/ent_impl.h index b07ffec..df96643 100644 --- a/scenes/ent_impl.h +++ b/scenes/ent_impl.h @@ -8,7 +8,7 @@ typedef enum EntityTag { ENEMY_ENT_TAG, CRATES_ENT_TAG, BOULDER_ENT_TAG, - ARROW_ENT_TAG, + DESTRUCTABLE_ENT_TAG, } EntityTag_t; @@ -17,5 +17,6 @@ Entity_t* create_player(EntityManager_t* ent_manager, Assets_t* assets); Entity_t* create_crate(EntityManager_t* ent_manager, Assets_t* assets, bool metal, ContainerItem_t item); Entity_t* create_boulder(EntityManager_t* ent_manager, Assets_t* assets); Entity_t* create_arrow(EntityManager_t* ent_manager, Assets_t* assets, uint8_t dir); +Entity_t* create_bomb(EntityManager_t* ent_manager, Assets_t* assets, Vector2 launch_dir); #endif // __ENT_IMPL_H diff --git a/scenes/game_systems.c b/scenes/game_systems.c index 7b7fab2..879b212 100644 --- a/scenes/game_systems.c +++ b/scenes/game_systems.c @@ -1114,6 +1114,12 @@ void global_external_forces_system(Scene_t* scene) continue; } + Vector2 half_size = {0, 0}; + if (p_bbox != NULL) + { + half_size = p_bbox->half_size; + } + if (!(p_mstate->ground_state & 1)) { // Only apply upthrust if center is in water @@ -1121,8 +1127,8 @@ void global_external_forces_system(Scene_t* scene) if (p_mstate->water_state & 1) { 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, + p_ctransform->position.x + half_size.x, + p_ctransform->position.y + half_size.y, data->tilemap.width ); @@ -1139,6 +1145,8 @@ void global_external_forces_system(Scene_t* scene) p_ctransform->accel, Vector2Multiply(p_ctransform->fric_coeff, p_ctransform->velocity) ); + + if (p_bbox == NULL) continue; //Do not proceed if no bbox // Zero out acceleration for contacts with sturdy entites and tiles @@ -1707,7 +1715,6 @@ void hitbox_update_system(Scene_t* scene) if (p_other_hurtbox == NULL) continue; CTransform_t* p_other_ct = get_component(p_other_ent, CTRANSFORM_COMP_T); Vector2 hurtbox_pos = Vector2Add(p_other_ct->position, p_other_hurtbox->offset); - if (p_hitbox->atk <= p_other_hurtbox->def) continue; if ( find_AABB_overlap( @@ -1716,27 +1723,30 @@ void hitbox_update_system(Scene_t* scene) ) ) { - if (p_other_ent->m_tag == CRATES_ENT_TAG) + if (p_hitbox->atk > p_other_hurtbox->def) { - - CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T); - CPlayerState_t* p_pstate = get_component(p_ent, CPLAYERSTATE_T); - if ( - p_pstate != NULL - && p_ctransform->position.y + p_bbox->size.y <= p_other_ct->position.y - ) + if (p_other_ent->m_tag == CRATES_ENT_TAG) { - p_ctransform->velocity.y = -400; - if (p_pstate->jump_pressed) + + CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T); + CPlayerState_t* p_pstate = get_component(p_ent, CPLAYERSTATE_T); + if ( + p_pstate != NULL + && p_ctransform->position.y + p_bbox->size.y <= p_other_ct->position.y + ) { - p_ctransform->velocity.y = -600; - CJump_t * p_cjump = get_component(p_ent, CJUMP_COMP_T); - p_cjump->short_hop = false; - p_cjump->jumped = true; + p_ctransform->velocity.y = -400; + if (p_pstate->jump_pressed) + { + p_ctransform->velocity.y = -600; + CJump_t * p_cjump = get_component(p_ent, CJUMP_COMP_T); + p_cjump->short_hop = false; + p_cjump->jumped = true; + } } } + remove_entity_from_tilemap(&scene->ent_manager, &tilemap, p_other_ent); } - remove_entity_from_tilemap(&scene->ent_manager, &tilemap, p_other_ent); if (p_hitbox->one_hit) { @@ -1816,6 +1826,9 @@ void container_destroy_system(Scene_t* scene) case CONTAINER_DOWN_ARROW: new_ent = create_arrow(&scene->ent_manager, &scene->engine->assets, 3); break; + case CONTAINER_BOMB: + new_ent = create_bomb(&scene->ent_manager, &scene->engine->assets, (Vector2){0, -1}); + break; default: new_ent = NULL; break; diff --git a/scenes/items_ent.c b/scenes/items_ent.c index d540bb1..34ec182 100644 --- a/scenes/items_ent.c +++ b/scenes/items_ent.c @@ -1,5 +1,6 @@ #include "ent_impl.h" #include "constants.h" +#include "raymath.h" Entity_t* create_crate(EntityManager_t* ent_manager, Assets_t* assets, bool metal, ContainerItem_t item) { @@ -51,7 +52,7 @@ Entity_t* create_boulder(EntityManager_t* ent_manager, Assets_t* assets) Entity_t* create_arrow(EntityManager_t* ent_manager, Assets_t* assets, uint8_t dir) { - Entity_t* p_arrow = add_entity(ent_manager, ARROW_ENT_TAG); + Entity_t* p_arrow = add_entity(ent_manager, DESTRUCTABLE_ENT_TAG); add_component(p_arrow, CTILECOORD_COMP_T); CHitBoxes_t* p_hitbox = add_component(p_arrow, CHITBOXES_T); p_hitbox->n_boxes = 1; @@ -86,3 +87,23 @@ Entity_t* create_arrow(EntityManager_t* ent_manager, Assets_t* assets, uint8_t d return p_arrow; } + +Entity_t* create_bomb(EntityManager_t* ent_manager, Assets_t* assets, Vector2 launch_dir) +{ + Entity_t* p_bomb = add_entity(ent_manager, DESTRUCTABLE_ENT_TAG); + add_component(p_bomb, CTILECOORD_COMP_T); + add_component(p_bomb, CMOVEMENTSTATE_T); + CHitBoxes_t* p_hitbox = add_component(p_bomb, CHITBOXES_T); + p_hitbox->n_boxes = 1; + p_hitbox->boxes[0] = (Rectangle){0, 0, TILE_SIZE, TILE_SIZE}; + + p_hitbox->atk = 0; + p_hitbox->one_hit = true; + + CTransform_t* p_ctransform = add_component(p_bomb, CTRANSFORM_COMP_T); + p_ctransform->active = true; + p_ctransform->movement_mode = REGULAR_MOVEMENT; + + p_ctransform->velocity = Vector2Scale(Vector2Normalize(launch_dir), 500); + return p_bomb; +}