Compare commits
No commits in common. "8eb07b489b03b71f37eb8caab2fbf57817c69c40" and "f27eff973113bd82e20768730d65b74334ac6976" have entirely different histories.
8eb07b489b
...
f27eff9731
|
|
@ -1 +1 @@
|
||||||
Subproject commit 2179c7eb94e8c563d2a0dbe8b3e9048cf2e27512
|
Subproject commit a8aacc04ef2bff71e9ba340673216ea94454f3ea
|
||||||
|
|
@ -9,7 +9,7 @@ COMPONENT(INTERACT_COMPONENT, interact_component, DRAW)
|
||||||
#else
|
#else
|
||||||
COMPONENT(TRANSFORM_COMPONENT, transform_component, NO_DRAW)
|
COMPONENT(TRANSFORM_COMPONENT, transform_component, NO_DRAW)
|
||||||
COMPONENT(HITBOX_COMPONENT, hitbox_component, NO_DRAW)
|
COMPONENT(HITBOX_COMPONENT, hitbox_component, NO_DRAW)
|
||||||
COMPONENT(INTERACT_COMPONENT, interact_component, NO_DRAW)
|
COMPONENT(INTERACT_COMPONENT, interct_component, NO_DRAW)
|
||||||
#endif // DEBUG >= 2
|
#endif // DEBUG >= 2
|
||||||
|
|
||||||
COMPONENT(PHYSICS_SYSTEM, physics_system, NO_DRAW)
|
COMPONENT(PHYSICS_SYSTEM, physics_system, NO_DRAW)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ typedef struct interact_component_data_t {
|
||||||
fvector2d_t position;
|
fvector2d_t position;
|
||||||
fvector2d_t scale;
|
fvector2d_t scale;
|
||||||
frect_t bounds;
|
frect_t bounds;
|
||||||
bool activated;
|
|
||||||
} interact_component_data_t;
|
} interact_component_data_t;
|
||||||
|
|
||||||
int interact_component_init(component_t *component);
|
int interact_component_init(component_t *component);
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,6 @@ inline int interact_component_init(component_t *component)
|
||||||
.y = 1.0f
|
.y = 1.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
component_data->activated = true;
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ inline int physics_system_init(component_t *component)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only for this file
|
||||||
// Args : physics_system_data_t *system_data, size_t entity_id
|
// Args : physics_system_data_t *system_data, size_t entity_id
|
||||||
static inline int action_detect_solve_entities_collision(elem_t *elem, va_list args)
|
static inline int action_detect_solve_entities_collision(elem_t *elem, va_list args)
|
||||||
{
|
{
|
||||||
|
|
@ -115,7 +116,7 @@ int physics_system_update(component_t *component)
|
||||||
system_data->velocity.y = lerp(system_data->velocity.y, system_data->target_velocity.y, system_data->smoothing_factor);
|
system_data->velocity.y = lerp(system_data->velocity.y, system_data->target_velocity.y, system_data->smoothing_factor);
|
||||||
|
|
||||||
if(hitbox_component_data->activated)
|
if(hitbox_component_data->activated)
|
||||||
if(linked_list_for_each(&game.entity_manager.entities, action_detect_solve_entities_collision, system_data, component->entity->id)) return EXIT_FAILURE;
|
linked_list_for_each(&game.entity_manager.entities, action_detect_solve_entities_collision, system_data, component->entity->id);
|
||||||
|
|
||||||
transform_component_data->bounds.x += system_data->velocity.x * system_data->speed * (float)game.delta_time_ms / 1000.0f;
|
transform_component_data->bounds.x += system_data->velocity.x * system_data->speed * (float)game.delta_time_ms / 1000.0f;
|
||||||
transform_component_data->bounds.y += system_data->velocity.y * system_data->speed * (float)game.delta_time_ms / 1000.0f;
|
transform_component_data->bounds.y += system_data->velocity.y * system_data->speed * (float)game.delta_time_ms / 1000.0f;
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
#include "player_system.h"
|
#include "player_system.h"
|
||||||
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "sprite_component.h"
|
|
||||||
#include "animation_system.h"
|
#include "animation_system.h"
|
||||||
#include "interact_component.h"
|
#include "sprite_component.h"
|
||||||
#include "physics_system.h"
|
#include "physics_system.h"
|
||||||
#include "memory_alloc.h"
|
#include "memory_alloc.h"
|
||||||
#include "errors.h"
|
|
||||||
|
|
||||||
inline int player_system_init(component_t *component)
|
inline int player_system_init(component_t *component)
|
||||||
{
|
{
|
||||||
|
|
@ -46,23 +44,7 @@ inline int player_system_init(component_t *component)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void player_system_get_inputs(player_system_data_t *system_data);
|
// Only for this file
|
||||||
static void player_system_set_velocity(player_system_data_t *system_data);
|
|
||||||
static int player_system_set_animation_and_speed(player_system_data_t *system_data);
|
|
||||||
static int player_system_process_interaction(player_system_data_t *system_data);
|
|
||||||
|
|
||||||
inline int player_system_update(component_t *component)
|
|
||||||
{
|
|
||||||
player_system_data_t *system_data = component->data;
|
|
||||||
|
|
||||||
player_system_get_inputs(system_data);
|
|
||||||
player_system_set_velocity(system_data);
|
|
||||||
if(player_system_set_animation_and_speed(system_data)) return EXIT_FAILURE;
|
|
||||||
if(player_system_process_interaction(system_data)) return EXIT_FAILURE;
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void player_system_get_inputs(player_system_data_t *system_data)
|
static inline void player_system_get_inputs(player_system_data_t *system_data)
|
||||||
{
|
{
|
||||||
system_data->last_state = system_data->state;
|
system_data->last_state = system_data->state;
|
||||||
|
|
@ -93,6 +75,7 @@ static inline void player_system_get_inputs(player_system_data_t *system_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only for this file
|
||||||
static inline void player_system_set_velocity(player_system_data_t *system_data)
|
static inline void player_system_set_velocity(player_system_data_t *system_data)
|
||||||
{
|
{
|
||||||
physics_system_data_t *physics_system_data = system_data->physics_system_data;
|
physics_system_data_t *physics_system_data = system_data->physics_system_data;
|
||||||
|
|
@ -112,6 +95,7 @@ static inline void player_system_set_velocity(player_system_data_t *system_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only for this file
|
||||||
static inline int player_system_set_animation_and_speed(player_system_data_t *system_data)
|
static inline int player_system_set_animation_and_speed(player_system_data_t *system_data)
|
||||||
{
|
{
|
||||||
animation_system_data_t *animation_system_data = system_data->animation_system_data;
|
animation_system_data_t *animation_system_data = system_data->animation_system_data;
|
||||||
|
|
@ -160,38 +144,13 @@ static inline int player_system_set_animation_and_speed(player_system_data_t *sy
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Args : player_system_data_t *system_data
|
inline int player_system_update(component_t *component)
|
||||||
static inline int action_detect_activate_interact(elem_t *elem, va_list args)
|
|
||||||
{
|
{
|
||||||
const entity_t *target_entity = elem->data;
|
player_system_data_t *system_data = component->data;
|
||||||
const player_system_data_t *system_data = va_arg(args, player_system_data_t *);
|
|
||||||
|
|
||||||
const component_t *target_interact_component = entity_get_component(target_entity, INTERACT_COMPONENT);
|
player_system_get_inputs(system_data);
|
||||||
if(!target_interact_component) return EXIT_SUCCESS;
|
player_system_set_velocity(system_data);
|
||||||
|
if(player_system_set_animation_and_speed(system_data)) return EXIT_FAILURE;
|
||||||
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 = &((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++);
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int player_system_process_interaction(player_system_data_t *system_data)
|
|
||||||
{
|
|
||||||
if(game.events.keys[KEY_INTERACT])
|
|
||||||
{
|
|
||||||
if(linked_list_for_each(&game.entity_manager.entities, action_detect_activate_interact, system_data)) return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,12 +94,12 @@ int game_init(void)
|
||||||
|
|
||||||
((interact_component_data_t *)component->data)->position = (fvector2d_t) {
|
((interact_component_data_t *)component->data)->position = (fvector2d_t) {
|
||||||
.x = 0.5f,
|
.x = 0.5f,
|
||||||
.y = 2.0f
|
.y = 4.0f / 3.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
((interact_component_data_t *)component->data)->scale = (fvector2d_t) {
|
((interact_component_data_t *)component->data)->scale = (fvector2d_t) {
|
||||||
.x = 2.0f / 3.0f,
|
.x = 2.0f / 3.0f,
|
||||||
.y = 5.0f / 6.0f
|
.y = 0.7f
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ======== Door ======== */
|
/* ======== Door ======== */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue