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