Compare commits
2 Commits
0fb48ff6a6
...
e177798bd7
| Author | SHA1 | Date |
|---|---|---|
|
|
e177798bd7 | |
|
|
f13c278bd2 |
|
|
@ -1 +1 @@
|
|||
Subproject commit af462380762093bee9e471799c7ce31732a4b248
|
||||
Subproject commit b63a67eb84262ea6e9883089cfc622d0a67f74cf
|
||||
|
|
@ -7,8 +7,10 @@
|
|||
|
||||
typedef struct physics_system_data_t {
|
||||
transform_component_data_t *transform_component_data;
|
||||
fvector2d_t target_velocity;
|
||||
fvector2d_t velocity;
|
||||
float speed;
|
||||
float smoothing_factor;
|
||||
} physics_system_data_t;
|
||||
|
||||
int physics_system_init(component_t *component);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ typedef struct sprite_component_data_t {
|
|||
texture_t *texture;
|
||||
|
||||
rect_t src_rect;
|
||||
rect_t dst_rect;
|
||||
frect_t dst_rect;
|
||||
|
||||
bool flip;
|
||||
} sprite_component_data_t;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ int transform_component_update(component_t *component);
|
|||
|
||||
#if DEBUG >= 2
|
||||
int transform_component_draw(component_t *component);
|
||||
#endif
|
||||
#endif // DEBUG >= 2
|
||||
|
||||
int transform_component_destroy(component_t *component);
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@ int physics_system_init(component_t *component)
|
|||
component_data->transform_component_data = entity_get_component(component->entity, TRANSFORM_COMPONENT)->component_data;
|
||||
if(!component_data->transform_component_data) return EXIT_FAILURE;
|
||||
|
||||
component_data->target_velocity = (fvector2d_t) {
|
||||
.x = 0.0f,
|
||||
.y = 0.0f
|
||||
};
|
||||
|
||||
component_data->velocity = (fvector2d_t) {
|
||||
.x = 0.0f,
|
||||
.y = 0.0f
|
||||
|
|
@ -18,6 +23,8 @@ int physics_system_init(component_t *component)
|
|||
|
||||
component_data->speed = 0.0f;
|
||||
|
||||
component_data->smoothing_factor = 1.0f;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -26,6 +33,9 @@ int physics_system_update(component_t *component)
|
|||
physics_system_data_t *component_data = component->component_data;
|
||||
transform_component_data_t *transform_component_data = component_data->transform_component_data;
|
||||
|
||||
component_data->velocity.x = lerp(component_data->velocity.x, component_data->target_velocity.x, component_data->smoothing_factor);
|
||||
component_data->velocity.y = lerp(component_data->velocity.y, component_data->target_velocity.y, component_data->smoothing_factor);
|
||||
|
||||
transform_component_data->bounds.x += component_data->velocity.x * component_data->speed * (float)game.delta_time_ms / 1000.0f;
|
||||
transform_component_data->bounds.y += component_data->velocity.y * component_data->speed * (float)game.delta_time_ms / 1000.0f;
|
||||
|
||||
|
|
|
|||
|
|
@ -65,15 +65,15 @@ static inline void player_system_set_velocity(player_system_data_t *system_data)
|
|||
|
||||
if((system_data->state & PLAYER_MOVING) != (system_data->last_state & PLAYER_MOVING))
|
||||
{
|
||||
physics_system_data->velocity.x =
|
||||
physics_system_data->target_velocity.x =
|
||||
(float)((system_data->state & PLAYER_MOVING_RIGHT) >> 3) - (float)((system_data->state & PLAYER_MOVING_LEFT) >> 2);
|
||||
physics_system_data->velocity.y =
|
||||
physics_system_data->target_velocity.y =
|
||||
(float)((system_data->state & PLAYER_MOVING_DOWN) >> 1) - (float)(system_data->state & PLAYER_MOVING_UP);
|
||||
|
||||
if(f_is_not_zero(physics_system_data->velocity.x) && f_is_not_zero(physics_system_data->velocity.y))
|
||||
if(f_is_not_zero(physics_system_data->target_velocity.x) && f_is_not_zero(physics_system_data->target_velocity.y))
|
||||
{
|
||||
physics_system_data->velocity.x *= 0.707106781186548f;
|
||||
physics_system_data->velocity.y *= 0.707106781186548f;
|
||||
physics_system_data->target_velocity.x *= 0.707106781186548f;
|
||||
physics_system_data->target_velocity.y *= 0.707106781186548f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ inline int sprite_component_init(component_t *component)
|
|||
component_data->src_rect.x = 0.0f;
|
||||
component_data->src_rect.y = 0.0f;
|
||||
|
||||
frect_to_rect(&transform_component_data->bounds, &component_data->dst_rect);
|
||||
|
||||
component_data->flip = false;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
@ -30,7 +28,7 @@ inline int sprite_component_init(component_t *component)
|
|||
inline int sprite_component_update(component_t *component)
|
||||
{
|
||||
sprite_component_data_t *component_data = component->component_data;
|
||||
frect_to_rect(&component_data->transform_component_data->bounds, &component_data->dst_rect);
|
||||
component_data->dst_rect = component_data->transform_component_data->bounds;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ int transform_component_init(component_t *component)
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
inline int transform_component_update(component_t *component)
|
||||
inline int transform_component_update(component_t *component __attribute__((unused)))
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue