Adding a jump hold

This commit is contained in:
AnonymusRaccoon
2020-01-03 18:57:54 +01:00
parent fca902986a
commit af7fbefa57
4 changed files with 10 additions and 2 deletions
+2
View File
@@ -14,6 +14,8 @@ struct jump_action
{
gc_component base;
int acceleration;
int counterforce;
bool contered;
};
extern const struct jump_action jump_action;
+1 -1
View File
@@ -12,7 +12,7 @@
<gravity_component speed="2000" />
<keyboard_controller left="16" right="3" jump="57" />
<walk_action acceleration="3000" max_acceleration="10000" />
<jump_action acceleration="7000"/>
<jump_action acceleration="7000" counterforce="6000"/>
<friction_component value=".7" />
<collision_component />
</gc_entity>
+1
View File
@@ -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;
}
+6 -1
View File
@@ -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;