Compare commits
No commits in common. "256ea02d0b671154cc3d85c9f5ce934831b1f363" and "fe2bcdf8cdc9da6096ce6cc8914973a227f368e6" have entirely different histories.
256ea02d0b
...
fe2bcdf8cd
|
@ -21,11 +21,10 @@ enum EntitySpawnSelection {
|
||||||
SPAWN_CRATE_ARROW_R,
|
SPAWN_CRATE_ARROW_R,
|
||||||
SPAWN_CRATE_ARROW_U,
|
SPAWN_CRATE_ARROW_U,
|
||||||
SPAWN_CRATE_ARROW_D,
|
SPAWN_CRATE_ARROW_D,
|
||||||
SPAWN_CRATE_BOMB,
|
|
||||||
SPAWN_BOULDER,
|
SPAWN_BOULDER,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAX_SPAWN_TYPE 12
|
#define MAX_SPAWN_TYPE 11
|
||||||
static unsigned int current_spawn_selection = 0;
|
static unsigned int current_spawn_selection = 0;
|
||||||
static bool metal_toggle = false;
|
static bool metal_toggle = false;
|
||||||
|
|
||||||
|
@ -196,9 +195,6 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
BLACK
|
BLACK
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case CONTAINER_BOMB:
|
|
||||||
DrawCircleV(Vector2Add(p_ct->position, p_bbox->half_size), p_bbox->half_size.x, BLACK);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -291,7 +287,7 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
const Color crate_colour = metal_toggle ? GRAY : BROWN;
|
const Color crate_colour = metal_toggle ? GRAY : BROWN;
|
||||||
const Color draw_colour[MAX_SPAWN_TYPE] = {
|
const Color draw_colour[MAX_SPAWN_TYPE] = {
|
||||||
BLACK, MAROON, ORANGE, ColorAlpha(RAYWHITE, 0.5), ColorAlpha(BLUE, 0.5),
|
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)
|
ColorAlpha(RAYWHITE, 0.5)
|
||||||
};
|
};
|
||||||
for (uint8_t i = 0; i < MAX_SPAWN_TYPE; ++i)
|
for (uint8_t i = 0; i < MAX_SPAWN_TYPE; ++i)
|
||||||
|
@ -344,9 +340,6 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
BLACK
|
BLACK
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case SPAWN_CRATE_BOMB:
|
|
||||||
DrawCircleV(Vector2Add(draw_pos, half_size), half_size.x, BLACK);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
draw_pos.x += SELECTION_TILE_SIZE;
|
draw_pos.x += SELECTION_TILE_SIZE;
|
||||||
|
@ -403,9 +396,6 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
BLACK
|
BLACK
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case SPAWN_CRATE_BOMB:
|
|
||||||
DrawCircleV(Vector2Add(draw_pos, half_size), half_size.x, BLACK);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For DEBUG
|
// For DEBUG
|
||||||
|
@ -530,9 +520,6 @@ static void toggle_block_system(Scene_t* scene)
|
||||||
case SPAWN_CRATE_ARROW_D:
|
case SPAWN_CRATE_ARROW_D:
|
||||||
spawn_crate(scene, tile_idx, metal_toggle, CONTAINER_DOWN_ARROW);
|
spawn_crate(scene, tile_idx, metal_toggle, CONTAINER_DOWN_ARROW);
|
||||||
break;
|
break;
|
||||||
case SPAWN_CRATE_BOMB:
|
|
||||||
spawn_crate(scene, tile_idx, metal_toggle, CONTAINER_BOMB);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
change_a_tile(&tilemap, tile_idx, new_type);
|
change_a_tile(&tilemap, tile_idx, new_type);
|
||||||
last_tile_idx = tile_idx;
|
last_tile_idx = tile_idx;
|
||||||
|
@ -660,7 +647,6 @@ void init_level_scene(LevelScene_t* scene)
|
||||||
sc_array_add(&scene->scene.systems, &state_transition_update_system);
|
sc_array_add(&scene->scene.systems, &state_transition_update_system);
|
||||||
sc_array_add(&scene->scene.systems, &player_ground_air_transition_system);
|
sc_array_add(&scene->scene.systems, &player_ground_air_transition_system);
|
||||||
sc_array_add(&scene->scene.systems, &container_destroy_system);
|
sc_array_add(&scene->scene.systems, &container_destroy_system);
|
||||||
sc_array_add(&scene->scene.systems, &lifetimer_update_system);
|
|
||||||
sc_array_add(&scene->scene.systems, &sprite_animation_system);
|
sc_array_add(&scene->scene.systems, &sprite_animation_system);
|
||||||
sc_array_add(&scene->scene.systems, &camera_update_system);
|
sc_array_add(&scene->scene.systems, &camera_update_system);
|
||||||
sc_array_add(&scene->scene.systems, &player_dir_reset_system);
|
sc_array_add(&scene->scene.systems, &player_dir_reset_system);
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include "sc/queue/sc_queue.h"
|
#include "sc/queue/sc_queue.h"
|
||||||
|
|
||||||
#define N_TAGS 8
|
#define N_TAGS 8
|
||||||
#define N_COMPONENTS 12
|
#define N_COMPONENTS 11
|
||||||
#define MAX_COMP_POOL_SIZE 1024
|
#define MAX_COMP_POOL_SIZE 1024
|
||||||
typedef struct EntityManager EntityManager_t;
|
typedef struct EntityManager EntityManager_t;
|
||||||
typedef struct Entity Entity_t;
|
typedef struct Entity Entity_t;
|
||||||
|
@ -24,7 +24,6 @@ typedef enum ComponentEnum {
|
||||||
CHURTBOX_T,
|
CHURTBOX_T,
|
||||||
CSPRITE_T,
|
CSPRITE_T,
|
||||||
CMOVEABLE_T,
|
CMOVEABLE_T,
|
||||||
CLIFETIMER_T,
|
|
||||||
} ComponentEnum_t;
|
} ComponentEnum_t;
|
||||||
|
|
||||||
typedef enum MovementMode {
|
typedef enum MovementMode {
|
||||||
|
@ -95,7 +94,6 @@ typedef enum ContainerItem {
|
||||||
CONTAINER_DOWN_ARROW,
|
CONTAINER_DOWN_ARROW,
|
||||||
CONTAINER_COIN,
|
CONTAINER_COIN,
|
||||||
CONTAINER_BOMB,
|
CONTAINER_BOMB,
|
||||||
CONTAINER_EXPLOSION,
|
|
||||||
} ContainerItem_t;
|
} ContainerItem_t;
|
||||||
|
|
||||||
typedef enum ContainerMaterial {
|
typedef enum ContainerMaterial {
|
||||||
|
@ -119,14 +117,8 @@ typedef struct _CHurtbox_t {
|
||||||
Vector2 offset;
|
Vector2 offset;
|
||||||
Vector2 size;
|
Vector2 size;
|
||||||
uint8_t def;
|
uint8_t def;
|
||||||
unsigned int damage_src;
|
|
||||||
} CHurtbox_t;
|
} CHurtbox_t;
|
||||||
|
|
||||||
typedef struct _CLifeTimer_t {
|
|
||||||
uint8_t timer;
|
|
||||||
uint8_t life_time;
|
|
||||||
} CLifeTimer_t;
|
|
||||||
|
|
||||||
// Credits to bedroomcoders.co.uk for this
|
// Credits to bedroomcoders.co.uk for this
|
||||||
typedef struct Sprite {
|
typedef struct Sprite {
|
||||||
Texture2D* texture;
|
Texture2D* texture;
|
||||||
|
@ -178,22 +170,6 @@ struct Entity {
|
||||||
EntityManager_t* manager;
|
EntityManager_t* manager;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum EntityUpdateEvent
|
|
||||||
{
|
|
||||||
COMP_ADDTION,
|
|
||||||
COMP_DELETION,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct EntityUpdateEventInfo
|
|
||||||
{
|
|
||||||
unsigned long e_id;
|
|
||||||
ComponentEnum_t comp_type;
|
|
||||||
unsigned long c_id;
|
|
||||||
enum EntityUpdateEvent evt_type;
|
|
||||||
};
|
|
||||||
|
|
||||||
sc_queue_def(struct EntityUpdateEventInfo, ent_evt);
|
|
||||||
|
|
||||||
struct EntityManager {
|
struct EntityManager {
|
||||||
// All fields are Read-Only
|
// All fields are Read-Only
|
||||||
struct sc_map_64v entities; // ent id : entity
|
struct sc_map_64v entities; // ent id : entity
|
||||||
|
@ -201,7 +177,6 @@ struct EntityManager {
|
||||||
struct sc_map_64v component_map[N_COMPONENTS]; // [{ent id: comp}, ...]
|
struct sc_map_64v component_map[N_COMPONENTS]; // [{ent id: comp}, ...]
|
||||||
struct sc_queue_uint to_add;
|
struct sc_queue_uint to_add;
|
||||||
struct sc_queue_uint to_remove;
|
struct sc_queue_uint to_remove;
|
||||||
struct sc_queue_ent_evt to_update;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void init_entity_manager(EntityManager_t* p_manager);
|
void init_entity_manager(EntityManager_t* p_manager);
|
||||||
|
|
|
@ -13,7 +13,6 @@ void init_entity_manager(EntityManager_t* p_manager)
|
||||||
}
|
}
|
||||||
sc_queue_init(&p_manager->to_add);
|
sc_queue_init(&p_manager->to_add);
|
||||||
sc_queue_init(&p_manager->to_remove);
|
sc_queue_init(&p_manager->to_remove);
|
||||||
sc_queue_init(&p_manager->to_update);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_entity_manager(EntityManager_t* p_manager)
|
void update_entity_manager(EntityManager_t* p_manager)
|
||||||
|
@ -29,14 +28,16 @@ void update_entity_manager(EntityManager_t* p_manager)
|
||||||
if (!p_entity) continue;
|
if (!p_entity) continue;
|
||||||
for (size_t i = 0; i < N_COMPONENTS; ++i)
|
for (size_t i = 0; i < N_COMPONENTS; ++i)
|
||||||
{
|
{
|
||||||
remove_component(p_entity, i);
|
if (p_entity->components[i] == MAX_COMP_POOL_SIZE) continue;
|
||||||
|
|
||||||
|
free_component_to_mempool((ComponentEnum_t)i, p_entity->components[i]);
|
||||||
|
sc_map_del_64v(&p_manager->component_map[i], e_idx);
|
||||||
|
sc_map_del_64v(&p_manager->entities_map[p_entity->m_tag], e_idx);
|
||||||
}
|
}
|
||||||
sc_map_del_64v(&p_manager->entities_map[p_entity->m_tag], e_idx);
|
|
||||||
free_entity_to_mempool(e_idx);
|
free_entity_to_mempool(e_idx);
|
||||||
sc_map_del_64v(&p_manager->entities, e_idx);
|
sc_map_del_64v(&p_manager->entities, e_idx);
|
||||||
}
|
}
|
||||||
sc_queue_clear(&p_manager->to_remove);
|
sc_queue_clear(&p_manager->to_remove);
|
||||||
|
|
||||||
sc_queue_foreach (&p_manager->to_add, e_idx)
|
sc_queue_foreach (&p_manager->to_add, e_idx)
|
||||||
{
|
{
|
||||||
Entity_t *p_entity = get_entity_wtih_id(e_idx);
|
Entity_t *p_entity = get_entity_wtih_id(e_idx);
|
||||||
|
@ -44,22 +45,6 @@ void update_entity_manager(EntityManager_t* p_manager)
|
||||||
sc_map_put_64v(&p_manager->entities_map[p_entity->m_tag], e_idx, (void *)p_entity);
|
sc_map_put_64v(&p_manager->entities_map[p_entity->m_tag], e_idx, (void *)p_entity);
|
||||||
}
|
}
|
||||||
sc_queue_clear(&p_manager->to_add);
|
sc_queue_clear(&p_manager->to_add);
|
||||||
|
|
||||||
struct EntityUpdateEventInfo evt;
|
|
||||||
sc_queue_foreach (&p_manager->to_update, evt)
|
|
||||||
{
|
|
||||||
switch(evt.evt_type)
|
|
||||||
{
|
|
||||||
case COMP_ADDTION:
|
|
||||||
sc_map_put_64v(&p_manager->component_map[evt.comp_type], evt.e_id, get_component_wtih_id(evt.comp_type, evt.c_id));
|
|
||||||
break;
|
|
||||||
case COMP_DELETION:
|
|
||||||
sc_map_del_64v(&p_manager->component_map[evt.comp_type], evt.e_id);
|
|
||||||
free_component_to_mempool(evt.comp_type, evt.c_id);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sc_queue_clear(&p_manager->to_add);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_entity_manager(EntityManager_t* p_manager)
|
void clear_entity_manager(EntityManager_t* p_manager)
|
||||||
|
@ -87,7 +72,6 @@ void free_entity_manager(EntityManager_t* p_manager)
|
||||||
}
|
}
|
||||||
sc_queue_term(&p_manager->to_add);
|
sc_queue_term(&p_manager->to_add);
|
||||||
sc_queue_term(&p_manager->to_remove);
|
sc_queue_term(&p_manager->to_remove);
|
||||||
sc_queue_term(&p_manager->to_update);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity_t *add_entity(EntityManager_t* p_manager, unsigned int tag)
|
Entity_t *add_entity(EntityManager_t* p_manager, unsigned int tag)
|
||||||
|
@ -123,15 +107,17 @@ Entity_t* get_entity(EntityManager_t* p_manager, unsigned long id)
|
||||||
return p_entity;
|
return p_entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Components are not expected to be removed
|
||||||
|
// So, no need to extra steps to deal with iterator invalidation
|
||||||
void* add_component(Entity_t* p_entity, ComponentEnum_t comp_type)
|
void* add_component(Entity_t* p_entity, ComponentEnum_t comp_type)
|
||||||
{
|
{
|
||||||
|
unsigned long comp_type_idx = (unsigned long)comp_type;
|
||||||
unsigned long comp_idx = 0;
|
unsigned long comp_idx = 0;
|
||||||
void* p_comp = new_component_from_mempool(comp_type, &comp_idx);
|
void* p_comp = new_component_from_mempool(comp_type, &comp_idx);
|
||||||
if (p_comp)
|
if (p_comp)
|
||||||
{
|
{
|
||||||
p_entity->components[comp_type] = comp_idx;
|
p_entity->components[comp_type] = comp_idx;
|
||||||
struct EntityUpdateEventInfo evt = (struct EntityUpdateEventInfo){p_entity->m_id, comp_type, comp_idx, COMP_ADDTION};
|
sc_map_put_64v(&p_entity->manager->component_map[comp_type_idx], p_entity->m_id, p_comp);
|
||||||
sc_queue_add_last(&p_entity->manager->to_update, evt);
|
|
||||||
}
|
}
|
||||||
return p_comp;
|
return p_comp;
|
||||||
}
|
}
|
||||||
|
@ -139,14 +125,15 @@ void* add_component(Entity_t* p_entity, ComponentEnum_t comp_type)
|
||||||
void* get_component(Entity_t *p_entity, ComponentEnum_t comp_type)
|
void* get_component(Entity_t *p_entity, ComponentEnum_t comp_type)
|
||||||
{
|
{
|
||||||
unsigned long comp_type_idx = (unsigned long)comp_type;
|
unsigned long comp_type_idx = (unsigned long)comp_type;
|
||||||
unsigned long c_idx = p_entity->components[comp_type_idx];
|
void * p_comp = sc_map_get_64v(&p_entity->manager->component_map[comp_type_idx], p_entity->m_id);
|
||||||
if (c_idx == MAX_COMP_POOL_SIZE) return NULL;
|
if (!sc_map_found(&p_entity->manager->component_map[comp_type_idx])) return NULL;
|
||||||
return get_component_wtih_id(comp_type, c_idx);
|
return p_comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove_component(Entity_t *p_entity, ComponentEnum_t comp_type)
|
void remove_component(Entity_t *p_entity, ComponentEnum_t comp_type)
|
||||||
{
|
{
|
||||||
|
unsigned long comp_type_idx = (unsigned long)comp_type;
|
||||||
if (p_entity->components[comp_type] == MAX_COMP_POOL_SIZE) return;
|
if (p_entity->components[comp_type] == MAX_COMP_POOL_SIZE) return;
|
||||||
struct EntityUpdateEventInfo evt = (struct EntityUpdateEventInfo){p_entity->m_id, comp_type, p_entity->components[comp_type] , COMP_DELETION};
|
sc_map_del_64v(&p_entity->manager->component_map[comp_type_idx], p_entity->m_id);
|
||||||
sc_queue_add_last(&p_entity->manager->to_update, evt);
|
free_component_to_mempool(comp_type, p_entity->components[comp_type]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ static CHitBoxes_t chitboxes_buffer[MAX_COMP_POOL_SIZE];
|
||||||
static CHurtbox_t churtbox_buffer[MAX_COMP_POOL_SIZE];
|
static CHurtbox_t churtbox_buffer[MAX_COMP_POOL_SIZE];
|
||||||
static CSprite_t csprite_buffer[MAX_COMP_POOL_SIZE];
|
static CSprite_t csprite_buffer[MAX_COMP_POOL_SIZE];
|
||||||
static CMoveable_t cmoveable_buffer[MAX_COMP_POOL_SIZE];
|
static CMoveable_t cmoveable_buffer[MAX_COMP_POOL_SIZE];
|
||||||
static CLifeTimer_t clifetimer_buffer[MAX_COMP_POOL_SIZE];
|
|
||||||
|
|
||||||
typedef struct ULongCircBuffer {
|
typedef struct ULongCircBuffer {
|
||||||
unsigned long* buffer; // data buffer
|
unsigned long* buffer; // data buffer
|
||||||
|
@ -89,7 +88,6 @@ static MemPool_t comp_mempools[N_COMPONENTS] = {
|
||||||
{churtbox_buffer, MAX_COMP_POOL_SIZE, sizeof(CHurtbox_t), NULL, {0}},
|
{churtbox_buffer, MAX_COMP_POOL_SIZE, sizeof(CHurtbox_t), NULL, {0}},
|
||||||
{csprite_buffer, MAX_COMP_POOL_SIZE, sizeof(CSprite_t), NULL, {0}},
|
{csprite_buffer, MAX_COMP_POOL_SIZE, sizeof(CSprite_t), NULL, {0}},
|
||||||
{cmoveable_buffer, MAX_COMP_POOL_SIZE, sizeof(CMoveable_t), NULL, {0}},
|
{cmoveable_buffer, MAX_COMP_POOL_SIZE, sizeof(CMoveable_t), NULL, {0}},
|
||||||
{clifetimer_buffer, MAX_COMP_POOL_SIZE, sizeof(CLifeTimer_t), NULL, {0}},
|
|
||||||
};
|
};
|
||||||
static MemPool_t ent_mempool = {
|
static MemPool_t ent_mempool = {
|
||||||
.buffer = entity_buffer,
|
.buffer = entity_buffer,
|
||||||
|
|
|
@ -8,7 +8,7 @@ typedef enum EntityTag {
|
||||||
ENEMY_ENT_TAG,
|
ENEMY_ENT_TAG,
|
||||||
CRATES_ENT_TAG,
|
CRATES_ENT_TAG,
|
||||||
BOULDER_ENT_TAG,
|
BOULDER_ENT_TAG,
|
||||||
DESTRUCTABLE_ENT_TAG,
|
ARROW_ENT_TAG,
|
||||||
} EntityTag_t;
|
} EntityTag_t;
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,7 +17,5 @@ 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_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_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_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);
|
|
||||||
Entity_t* create_explosion(EntityManager_t* ent_manager, Assets_t* assets);
|
|
||||||
|
|
||||||
#endif // __ENT_IMPL_H
|
#endif // __ENT_IMPL_H
|
||||||
|
|
|
@ -1114,12 +1114,6 @@ void global_external_forces_system(Scene_t* scene)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 half_size = {0, 0};
|
|
||||||
if (p_bbox != NULL)
|
|
||||||
{
|
|
||||||
half_size = p_bbox->half_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(p_mstate->ground_state & 1))
|
if (!(p_mstate->ground_state & 1))
|
||||||
{
|
{
|
||||||
// Only apply upthrust if center is in water
|
// Only apply upthrust if center is in water
|
||||||
|
@ -1127,8 +1121,8 @@ void global_external_forces_system(Scene_t* scene)
|
||||||
if (p_mstate->water_state & 1)
|
if (p_mstate->water_state & 1)
|
||||||
{
|
{
|
||||||
unsigned int tile_idx = get_tile_idx(
|
unsigned int tile_idx = get_tile_idx(
|
||||||
p_ctransform->position.x + half_size.x,
|
p_ctransform->position.x + p_bbox->half_size.x,
|
||||||
p_ctransform->position.y + half_size.y,
|
p_ctransform->position.y + p_bbox->half_size.y,
|
||||||
data->tilemap.width
|
data->tilemap.width
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1146,8 +1140,6 @@ void global_external_forces_system(Scene_t* scene)
|
||||||
Vector2Multiply(p_ctransform->fric_coeff, p_ctransform->velocity)
|
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
|
// Zero out acceleration for contacts with sturdy entites and tiles
|
||||||
uint8_t edges = check_bbox_edges(
|
uint8_t edges = check_bbox_edges(
|
||||||
|
@ -1675,7 +1667,6 @@ void hitbox_update_system(Scene_t* scene)
|
||||||
for (unsigned int tile_x = tile_x1; tile_x <= tile_x2; tile_x++)
|
for (unsigned int tile_x = tile_x1; tile_x <= tile_x2; tile_x++)
|
||||||
{
|
{
|
||||||
unsigned int tile_idx = tile_y * tilemap.width + tile_x;
|
unsigned int tile_idx = tile_y * tilemap.width + tile_x;
|
||||||
if (tile_idx >= tilemap.n_tiles) break;
|
|
||||||
unsigned int other_ent_idx;
|
unsigned int other_ent_idx;
|
||||||
Entity_t* p_other_ent;
|
Entity_t* p_other_ent;
|
||||||
Vector2 overlap;
|
Vector2 overlap;
|
||||||
|
@ -1716,6 +1707,7 @@ void hitbox_update_system(Scene_t* scene)
|
||||||
if (p_other_hurtbox == NULL) continue;
|
if (p_other_hurtbox == NULL) continue;
|
||||||
CTransform_t* p_other_ct = get_component(p_other_ent, CTRANSFORM_COMP_T);
|
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);
|
Vector2 hurtbox_pos = Vector2Add(p_other_ct->position, p_other_hurtbox->offset);
|
||||||
|
if (p_hitbox->atk <= p_other_hurtbox->def) continue;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
find_AABB_overlap(
|
find_AABB_overlap(
|
||||||
|
@ -1724,31 +1716,27 @@ void hitbox_update_system(Scene_t* scene)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (p_hitbox->atk > p_other_hurtbox->def)
|
if (p_other_ent->m_tag == CRATES_ENT_TAG)
|
||||||
{
|
{
|
||||||
p_other_hurtbox->damage_src = ent_idx;
|
|
||||||
if (p_other_ent->m_tag == CRATES_ENT_TAG)
|
|
||||||
{
|
|
||||||
|
|
||||||
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
||||||
CPlayerState_t* p_pstate = get_component(p_ent, CPLAYERSTATE_T);
|
CPlayerState_t* p_pstate = get_component(p_ent, CPLAYERSTATE_T);
|
||||||
if (
|
if (
|
||||||
p_pstate != NULL
|
p_pstate != NULL
|
||||||
&& p_ctransform->position.y + p_bbox->size.y <= p_other_ct->position.y
|
&& p_ctransform->position.y + p_bbox->size.y <= p_other_ct->position.y
|
||||||
)
|
)
|
||||||
|
{
|
||||||
|
p_ctransform->velocity.y = -400;
|
||||||
|
if (p_pstate->jump_pressed)
|
||||||
{
|
{
|
||||||
p_ctransform->velocity.y = -400;
|
p_ctransform->velocity.y = -600;
|
||||||
if (p_pstate->jump_pressed)
|
CJump_t * p_cjump = get_component(p_ent, CJUMP_COMP_T);
|
||||||
{
|
p_cjump->short_hop = false;
|
||||||
p_ctransform->velocity.y = -600;
|
p_cjump->jumped = true;
|
||||||
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)
|
if (p_hitbox->one_hit)
|
||||||
{
|
{
|
||||||
|
@ -1813,14 +1801,6 @@ void container_destroy_system(Scene_t* scene)
|
||||||
Entity_t* p_ent = get_entity(&scene->ent_manager, ent_idx);
|
Entity_t* p_ent = get_entity(&scene->ent_manager, ent_idx);
|
||||||
if (!p_ent->m_alive)
|
if (!p_ent->m_alive)
|
||||||
{
|
{
|
||||||
|
|
||||||
Entity_t* dmg_src = NULL;
|
|
||||||
CHurtbox_t* p_hurtbox = get_component(p_ent, CHURTBOX_T);
|
|
||||||
if(p_hurtbox != NULL)
|
|
||||||
{
|
|
||||||
dmg_src = get_entity(&scene->ent_manager, p_hurtbox->damage_src);
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity_t* new_ent;
|
Entity_t* new_ent;
|
||||||
switch (p_container->item)
|
switch (p_container->item)
|
||||||
{
|
{
|
||||||
|
@ -1836,32 +1816,6 @@ void container_destroy_system(Scene_t* scene)
|
||||||
case CONTAINER_DOWN_ARROW:
|
case CONTAINER_DOWN_ARROW:
|
||||||
new_ent = create_arrow(&scene->ent_manager, &scene->engine->assets, 3);
|
new_ent = create_arrow(&scene->ent_manager, &scene->engine->assets, 3);
|
||||||
break;
|
break;
|
||||||
case CONTAINER_BOMB:
|
|
||||||
if (dmg_src != NULL && dmg_src->m_tag == PLAYER_ENT_TAG)
|
|
||||||
{
|
|
||||||
const CTransform_t* p_ctransform = get_component(p_ent, CTRANSFORM_COMP_T);
|
|
||||||
const CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
|
||||||
const CTransform_t* dmg_src_ctransform = get_component(dmg_src, CTRANSFORM_COMP_T);
|
|
||||||
const CBBox_t* dmg_src_bbox = get_component(dmg_src, CBBOX_COMP_T);
|
|
||||||
Vector2 launch_dir = {0, -1};
|
|
||||||
if (dmg_src_ctransform->position.x + dmg_src_bbox->size.x <= p_ctransform->position.x)
|
|
||||||
{
|
|
||||||
launch_dir.x = 1;
|
|
||||||
}
|
|
||||||
else if (dmg_src_ctransform->position.x >= p_ctransform->position.x + p_bbox->size.x)
|
|
||||||
{
|
|
||||||
launch_dir.x = -1;
|
|
||||||
}
|
|
||||||
new_ent = create_bomb(&scene->ent_manager, &scene->engine->assets, launch_dir);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
new_ent = create_explosion(&scene->ent_manager, &scene->engine->assets);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CONTAINER_EXPLOSION:
|
|
||||||
new_ent = create_explosion(&scene->ent_manager, &scene->engine->assets);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
new_ent = NULL;
|
new_ent = NULL;
|
||||||
break;
|
break;
|
||||||
|
@ -1870,28 +1824,12 @@ void container_destroy_system(Scene_t* scene)
|
||||||
{
|
{
|
||||||
CTransform_t* new_p_ct = get_component(new_ent, CTRANSFORM_COMP_T);
|
CTransform_t* new_p_ct = get_component(new_ent, CTRANSFORM_COMP_T);
|
||||||
CTransform_t* p_ct = get_component(p_ent, CTRANSFORM_COMP_T);
|
CTransform_t* p_ct = get_component(p_ent, CTRANSFORM_COMP_T);
|
||||||
new_p_ct->position = Vector2Add(new_p_ct->position, p_ct->position);
|
memcpy(&new_p_ct->position, &p_ct->position, sizeof(Vector2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lifetimer_update_system(Scene_t* scene)
|
|
||||||
{
|
|
||||||
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
|
|
||||||
TileGrid_t tilemap = data->tilemap;
|
|
||||||
unsigned int ent_idx;
|
|
||||||
CLifeTimer_t* p_lifetimer;
|
|
||||||
sc_map_foreach(&scene->ent_manager.component_map[CLIFETIMER_T], ent_idx, p_lifetimer)
|
|
||||||
{
|
|
||||||
p_lifetimer->life_time--;
|
|
||||||
if (p_lifetimer->life_time == 0)
|
|
||||||
{
|
|
||||||
remove_entity_from_tilemap(&scene->ent_manager, &tilemap, get_entity(&scene->ent_manager, ent_idx));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sprite_animation_system(Scene_t* scene)
|
void sprite_animation_system(Scene_t* scene)
|
||||||
{
|
{
|
||||||
unsigned int ent_idx;
|
unsigned int ent_idx;
|
||||||
|
|
|
@ -23,7 +23,6 @@ void camera_update_system(Scene_t* scene);
|
||||||
void container_destroy_system(Scene_t* scene);
|
void container_destroy_system(Scene_t* scene);
|
||||||
void player_dir_reset_system(Scene_t* scene);
|
void player_dir_reset_system(Scene_t* scene);
|
||||||
void player_respawn_system(Scene_t* scene);
|
void player_respawn_system(Scene_t* scene);
|
||||||
void lifetimer_update_system(Scene_t* scene);
|
|
||||||
void spike_collision_system(Scene_t* scene);
|
void spike_collision_system(Scene_t* scene);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "ent_impl.h"
|
#include "ent_impl.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "raymath.h"
|
|
||||||
|
|
||||||
Entity_t* create_crate(EntityManager_t* ent_manager, Assets_t* assets, bool metal, ContainerItem_t item)
|
Entity_t* create_crate(EntityManager_t* ent_manager, Assets_t* assets, bool metal, ContainerItem_t item)
|
||||||
{
|
{
|
||||||
|
@ -52,7 +51,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* create_arrow(EntityManager_t* ent_manager, Assets_t* assets, uint8_t dir)
|
||||||
{
|
{
|
||||||
Entity_t* p_arrow = add_entity(ent_manager, DESTRUCTABLE_ENT_TAG);
|
Entity_t* p_arrow = add_entity(ent_manager, ARROW_ENT_TAG);
|
||||||
add_component(p_arrow, CTILECOORD_COMP_T);
|
add_component(p_arrow, CTILECOORD_COMP_T);
|
||||||
CHitBoxes_t* p_hitbox = add_component(p_arrow, CHITBOXES_T);
|
CHitBoxes_t* p_hitbox = add_component(p_arrow, CHITBOXES_T);
|
||||||
p_hitbox->n_boxes = 1;
|
p_hitbox->n_boxes = 1;
|
||||||
|
@ -87,49 +86,3 @@ Entity_t* create_arrow(EntityManager_t* ent_manager, Assets_t* assets, uint8_t d
|
||||||
|
|
||||||
return p_arrow;
|
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, 25, 25};
|
|
||||||
|
|
||||||
p_hitbox->atk = 0;
|
|
||||||
p_hitbox->one_hit = true;
|
|
||||||
|
|
||||||
CContainer_t* p_container = add_component(p_bomb, CCONTAINER_T);
|
|
||||||
p_container->item = CONTAINER_EXPLOSION;
|
|
||||||
|
|
||||||
CTransform_t* p_ctransform = add_component(p_bomb, CTRANSFORM_COMP_T);
|
|
||||||
p_ctransform->active = true;
|
|
||||||
p_ctransform->movement_mode = REGULAR_MOVEMENT;
|
|
||||||
p_ctransform->position.x += (TILE_SIZE - 25) / 2;
|
|
||||||
p_ctransform->position.y += (TILE_SIZE - 25) / 2;
|
|
||||||
|
|
||||||
p_ctransform->velocity = Vector2Scale(Vector2Normalize(launch_dir), 500);
|
|
||||||
return p_bomb;
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity_t* create_explosion(EntityManager_t* ent_manager, Assets_t* assets)
|
|
||||||
{
|
|
||||||
Entity_t* p_explosion = add_entity(ent_manager, DESTRUCTABLE_ENT_TAG);
|
|
||||||
add_component(p_explosion, CTILECOORD_COMP_T);
|
|
||||||
CHitBoxes_t* p_hitbox = add_component(p_explosion, CHITBOXES_T);
|
|
||||||
p_hitbox->n_boxes = 1;
|
|
||||||
|
|
||||||
p_hitbox->atk = 3;
|
|
||||||
|
|
||||||
CTransform_t* p_ctransform = add_component(p_explosion, CTRANSFORM_COMP_T);
|
|
||||||
p_ctransform->movement_mode = KINEMATIC_MOVEMENT;
|
|
||||||
p_ctransform->active = true;
|
|
||||||
p_ctransform->position.x -= 15;
|
|
||||||
p_ctransform->position.y -= 15;
|
|
||||||
p_hitbox->boxes[0] = (Rectangle){0, 0, TILE_SIZE + 30, TILE_SIZE + 30};
|
|
||||||
|
|
||||||
CLifeTimer_t* p_clifetimer = add_component(p_explosion, CLIFETIMER_T);
|
|
||||||
p_clifetimer->life_time = 3;
|
|
||||||
return p_explosion;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue