Finishing the friction and the walk action

This commit is contained in:
AnonymusRaccoon
2019-12-17 23:39:09 +01:00
parent c5f8ad7935
commit 9d8e49624e
8 changed files with 21 additions and 18 deletions
+1 -2
View File
@@ -13,8 +13,7 @@
struct walk_action
{
gc_component base;
int speed;
int max_speed;
int acceleration;
int max_acceleration;
};
+3 -1
View File
@@ -29,4 +29,6 @@ int my_sqrt(int nb);
#define NCLAMP(x, y) (((x) < (y)) ? ((x) = (y)) : (x))
#define ABSCLAMP(x, y) (((x) > 0) ? CLAMP((x), (y)) : NCLAMP((x), -(y)))
#define GETSIGN(x) (((x) < 0) ? (-1) : (1))
#define GETSIGN(x) (((x) < 0) ? (-1) : (1))
#define ABS(x) ((x) > 0 ? (x) : -(x))
+3 -6
View File
@@ -16,8 +16,7 @@ static void walk_ctr(void *component, va_list args)
{
struct walk_action *cmp = (struct walk_action *)component;
cmp->speed = va_arg(args, int);
cmp->max_speed = va_arg(args, int);
cmp->acceleration = va_arg(args, int);
cmp->max_acceleration = va_arg(args, int);
}
@@ -25,8 +24,7 @@ static void walk_fdctr(gc_engine *engine, void *component, node *n)
{
struct walk_action *cmp = (struct walk_action *)component;
cmp->speed = xml_getintprop(n, "speed");
cmp->max_speed = xml_getintprop(n, "max_speed");
cmp->acceleration = xml_getintprop(n, "acceleration");
cmp->max_acceleration = xml_getintprop(n, "max_acceleration");
(void)engine;
}
@@ -58,7 +56,6 @@ const struct walk_action walk_action = {
serialize: &walk_serialize,
destroy: &component_destroy
},
speed: 0,
max_speed: 0,
acceleration: 0,
max_acceleration: 0
};
+1 -1
View File
@@ -28,9 +28,9 @@ void engine_add_buildin_systems(gc_engine *engine)
engine->get_system = &engine_get_system;
engine->add_system(engine, &parallax_system);
engine->add_system(engine, &keyboard_controller_system);
engine->add_system(engine, &friction_system);
engine->add_system(engine, &walk_system);
engine->add_system(engine, &gravity_system);
engine->add_system(engine, &friction_system);
engine->add_system(engine, new_system(&movable_system));
}
+2 -4
View File
@@ -23,11 +23,9 @@ gc_entity *entity, float dtime)
struct movable_component *mov = GETCMP(movable_component);
struct walk_action *walk = GETCMP(walk_action);
// mov->acceleration.x = 0;
mov->acceleration.x -= con->moving_left * walk->speed;
mov->acceleration.x += con->moving_right * walk->speed;
mov->acceleration.x -= con->moving_left * walk->acceleration;
mov->acceleration.x += con->moving_right * walk->acceleration;
ABSCLAMP(mov->acceleration.x, walk->max_acceleration);
ABSCLAMP(mov->velocity.x, walk->max_speed);
(void)system;
(void)dtime;
(void)engine;
+2 -2
View File
@@ -24,8 +24,8 @@ gc_entity *entity, float dtime)
if (isnan(dir.x) || isnan(dir.y))
return;
mov->acceleration.x -= fric->value * dir.x;
if (mov->acceleration.x * dir.x > -fric->value)
mov->acceleration.x -= fric->value * dir.x;
// mov->acceleration.y += fric->value * dir.y;
(void)system;
(void)engine;
+7 -2
View File
@@ -19,10 +19,15 @@
void gravity_update_entity(gc_engine *engine, void *system, \
gc_entity *entity, float dtime)
{
// struct gravity_component *grav = GETCMP(gravity_component);
struct gravity_component *grav = GETCMP(gravity_component);
struct movable_component *mov = GETCMP(movable_component);
mov->acceleration.y = -9.8;
if (mov->acceleration.y > -grav->gravity_speed) {
if (mov->acceleration.y > 0)
mov->acceleration.y -= grav->gravity_speed;
else
mov->acceleration.y = -grav->gravity_speed;
}
(void)system;
(void)dtime;
(void)engine;
+2
View File
@@ -37,6 +37,8 @@ quadtree *tree, float dtime)
mov->velocity.x = 0;
if (i.distance_down == 0 || i.distance_top == 0)
mov->velocity.y = 0;
if (mov->velocity.x != 0)
printf("Acceleration: (%+.2f, %+.2f) Velocity: (%+.2f, %+.2f)Position: (%+.2f, %+.2f)\n", mov->acceleration.x, mov->acceleration.y, mov->velocity.x, mov->velocity.y, pos->position.x, pos->position.y);
obj.rect.x = pos->position.x;
obj.rect.y = pos->position.y;
qt_update(tree, obj);