diff --git a/include/components/jump_action.h b/include/components/jump_action.h index 30486b3..142bbfa 100644 --- a/include/components/jump_action.h +++ b/include/components/jump_action.h @@ -14,6 +14,8 @@ struct jump_action { gc_component base; int acceleration; + int counterforce; + bool contered; }; extern const struct jump_action jump_action; \ No newline at end of file diff --git a/prefabs/player.gcprefab b/prefabs/player.gcprefab index eaa8540..3ebce1d 100644 --- a/prefabs/player.gcprefab +++ b/prefabs/player.gcprefab @@ -12,7 +12,7 @@ - + diff --git a/src/components/jump_component.c b/src/components/jump_component.c index 279684c..9fb0aa9 100644 --- a/src/components/jump_component.c +++ b/src/components/jump_component.c @@ -24,6 +24,7 @@ static void fdctr(gc_scene *scene, void *component, node *n) struct jump_action *cmp = (struct jump_action *)component; cmp->acceleration = xml_getintprop(n, "acceleration"); + cmp->counterforce = xml_getintprop(n, "counterforce"); (void)scene; } diff --git a/src/systems/jump_system.c b/src/systems/jump_system.c index 8b4fec2..106ebc0 100644 --- a/src/systems/jump_system.c +++ b/src/systems/jump_system.c @@ -25,8 +25,13 @@ gc_entity *entity, float dtime) struct movable_component *mov = GETCMP(movable_component); struct jump_action *jump = GETCMP(jump_action); - if (col->distance_down == 0) + if (col->distance_down == 0) { mov->acceleration.y += con->jumping * jump->acceleration; + jump->contered = false; + } else if (!jump->contered && mov->acceleration.y > 0 && !con->jumping) { + jump->contered = true; + mov->acceleration.y = MAX(mov->acceleration.y - jump->counterforce, 0); + } (void)system; (void)dtime; (void)engine;