Add bomb crates

Changelog:
- Crates can spawn bombs
- bombs does nothing now
scene_man
En Yi 2023-07-02 20:37:16 +08:00
parent fe2bcdf8cd
commit a4900a001b
4 changed files with 70 additions and 22 deletions

View File

@ -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;

View File

@ -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

View File

@ -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
);
@ -1140,6 +1146,8 @@ void global_external_forces_system(Scene_t* scene)
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
uint8_t edges = check_bbox_edges(
@ -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(
@ -1715,6 +1722,8 @@ void hitbox_update_system(Scene_t* scene)
hurtbox_pos, p_other_hurtbox->size, &overlap
)
)
{
if (p_hitbox->atk > p_other_hurtbox->def)
{
if (p_other_ent->m_tag == CRATES_ENT_TAG)
{
@ -1737,6 +1746,7 @@ void hitbox_update_system(Scene_t* scene)
}
}
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;

View File

@ -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;
}