Compare commits

..

No commits in common. "27d5a151d165e15f5ffa03da56b691049d8ef1d6" and "06d2d6f8ad56933fb8c43b136a085865f71d7821" have entirely different histories.

8 changed files with 12 additions and 49 deletions

@ -1 +1 @@
Subproject commit 2e180b6832978ebd7c211a863a9c2007f3a7c591
Subproject commit 571bb9699df2b281157a68217ea490482bccd729

View File

@ -9,11 +9,9 @@
typedef struct hitbox_component_data_t {
transform_component_data_t *transform_component_data;
fvector2d_t position;
fvector2d_t scale;
frect_t bounds;
bool activated;
} hitbox_component_data_t;

View File

@ -6,22 +6,11 @@
#include "vector2d.h"
#include "errors.h"
typedef enum interact_type_t {
INTERACT_BUTTON,
INTERACT_TOGGLE
} interact_type_t;
typedef struct interact_component_data_t {
transform_component_data_t *transform_component_data;
fvector2d_t position;
fvector2d_t scale;
frect_t bounds;
size_t topic_id;
interact_type_t type;
size_t event_payload;
bool activated;
} interact_component_data_t;
@ -35,6 +24,4 @@ int interact_component_draw(const component_t *component);
int interact_component_destroy(component_t *component);
inline int interact_component_set_topic(interact_component_data_t *component_data, size_t id);
#endif // TRANSFORM_COMPONENT_H

View File

@ -9,7 +9,6 @@
typedef struct physics_system_data_t {
transform_component_data_t *transform_component_data;
hitbox_component_data_t *hitbox_component_data;
fvector2d_t target_velocity;
fvector2d_t velocity;
float speed;

View File

@ -9,8 +9,10 @@ typedef struct sprite_component_data_t {
transform_component_data_t *transform_component_data;
texture_t *texture;
rect_t src_rect;
frect_t dst_rect;
bool flip;
} sprite_component_data_t;

View File

@ -1,7 +1,6 @@
#include "interact_component.h"
#include "game.h"
#include "event_bus.h"
#include "memory_alloc.h"
#include "errors.h"
@ -21,18 +20,12 @@ inline int interact_component_init(component_t *component)
.x = 0.0f,
.y = 0.0f
};
component_data->scale = (fvector2d_t) {
.x = 1.0f,
.y = 1.0f
};
component_data->topic_id = 0;
component_data->type = INTERACT_TOGGLE;
component_data->event_payload = 0;
if(event_bus_new_topic(&game.event_bus, component_data->topic_id, 1)) return EXIT_FAILURE;
component_data->activated = true;
return EXIT_SUCCESS;
@ -72,12 +65,3 @@ inline int interact_component_destroy(component_t *component)
return EXIT_SUCCESS;
}
inline int interact_component_set_topic(interact_component_data_t *component_data, size_t id)
{
if(event_bus_change_topic_id(&game.event_bus, component_data->topic_id, id)) return EXIT_FAILURE;
component_data->topic_id = id;
return EXIT_SUCCESS;
}

View File

@ -169,21 +169,18 @@ static inline int action_detect_activate_interact(elem_t *elem, va_list args)
const component_t *target_interact_component = entity_get_component(target_entity, INTERACT_COMPONENT);
if(!target_interact_component) return EXIT_SUCCESS;
const interact_component_data_t *target_interact_component_data = target_interact_component->data;
if(!target_interact_component_data->activated)
if(!((interact_component_data_t *)target_interact_component->data)->activated)
{
return EXIT_SUCCESS;
}
const frect_t *hitbox_bounds = &system_data->physics_system_data->hitbox_component_data->bounds;
const frect_t *target_interact_bounds = &target_interact_component_data->bounds;
const frect_t *target_interact_bounds = &((interact_component_data_t *)target_interact_component->data)->bounds;
if(fhas_intersection(hitbox_bounds, target_interact_bounds))
{
static size_t i = 0;
debug_printf("Interact n*%lu", i++);
if(event_bus_publish(&game.event_bus, target_interact_component_data->topic_id, (void *)&target_interact_component_data->event_payload)) return EXIT_FAILURE;
}
return EXIT_SUCCESS;
@ -191,15 +188,11 @@ static inline int action_detect_activate_interact(elem_t *elem, va_list args)
static inline int player_system_process_interaction(player_system_data_t *system_data)
{
static bool last_state = false;
if(game.events.keys[KEY_INTERACT] && !last_state)
if(game.events.keys[KEY_INTERACT])
{
if(linked_list_for_each(&game.entity_manager.entities, action_detect_activate_interact, system_data)) return EXIT_FAILURE;
}
last_state = game.events.keys[KEY_INTERACT];
return EXIT_SUCCESS;
}

View File

@ -4,8 +4,6 @@
#include "display.h"
#include "asset_manager.h"
#include "ecs.h"
#include "event_bus.h"
#include "inputs.h"
#include "components.h"
#include "errors.h"
@ -14,9 +12,8 @@ int game_init(void)
game.is_running = false;
if(display_init()) return EXIT_FAILURE;
if(asset_manager_init(&game.asset_manager)) return EXIT_FAILURE;
event_bus_init(&game.event_bus);
entity_manager_init(&game.entity_manager);
if(asset_manager_load_asset(&game.asset_manager, "dummy_sheet", ASSET_TEXTURE)) return EXIT_FAILURE;
if(asset_manager_load_asset(&game.asset_manager, "player_idle_sheet", ASSET_TEXTURE)) return EXIT_FAILURE;
@ -26,6 +23,8 @@ int game_init(void)
if(asset_manager_load_asset(&game.asset_manager, "barred_door_sheet", ASSET_TEXTURE)) return EXIT_FAILURE;
if(asset_manager_load_asset(&game.asset_manager, "tileset", ASSET_TEXTURE)) return EXIT_FAILURE;
entity_manager_init(&game.entity_manager);
/* ======== Player ======== */
entity_t *player_entity = entity_manager_new_entity(&game.entity_manager, 0);
if(!player_entity) return EXIT_FAILURE;
@ -189,8 +188,9 @@ int game_render(void)
int game_exit(void)
{
entity_manager_exit(&game.entity_manager);
event_bus_exit(&game.event_bus);
if(asset_manager_exit(&game.asset_manager)) return EXIT_FAILURE;
display_exit();
return EXIT_SUCCESS;