Adding walk animations

This commit is contained in:
AnonymusRaccoon
2020-01-09 17:19:28 +01:00
parent a707be08fb
commit e7459aa2bc
7 changed files with 30 additions and 12 deletions
+1
View File
@@ -14,6 +14,7 @@ struct walk_action
{
gc_component base;
int acceleration;
int idle;
};
extern const struct walk_action walk_action;
+4 -1
View File
@@ -6,12 +6,15 @@
</transform_component>
<renderer src="assets/sprites/player_sheet.png">
<Rect width="80" height="100" top="0" left="0" />
<animation name="walk" frame_count="2" frame_rate="10">
<Rect left="80" />
</animation>
</renderer>
<movable_component />
<controllable_component />
<gravity_component force="6250" />
<keyboard_controller left="16" right="3" jump="57" />
<walk_action acceleration="3000" />
<walk_action acceleration="3000" idle_trigger="10" />
<jump_action acceleration="17000" counterforce="6000" step_count="7"/>
<collision_component layer="11000000" />
<friction_component value=".5" />
+2
View File
@@ -17,6 +17,7 @@ static void ctr(void *component, va_list args)
struct walk_action *cmp = (struct walk_action *)component;
cmp->acceleration = va_arg(args, int);
cmp->idle = va_arg(args, int);
}
static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
@@ -24,6 +25,7 @@ static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
struct walk_action *cmp = (struct walk_action *)component;
cmp->acceleration = xml_getintprop(n, "acceleration");
cmp->idle = xml_getintprop(n, "idle_trigger");
(void)scene;
(void)entity;
}
-1
View File
@@ -33,7 +33,6 @@ gc_entity *entity, float dtime)
jump->contered = true;
jump->step = 0;
}
if (jump->step > 0) {
mov->acceleration.y += jump->acceleration;
jump->step--;
+21 -8
View File
@@ -9,27 +9,40 @@
#include "system.h"
#include "texture.h"
#include "vector2.h"
#include "sprite.h"
#include "component.h"
#include "components/movable_component.h"
#include "components/controllable_component.h"
#include "components/walk_action.h"
#include "components/renderer.h"
#include "utility.h"
#include <stddef.h>
void walk_update_entity(gc_engine *engine, void *system, \
gc_entity *entity, float dtime)
void walk_update_entity(gc_engine *engine __attribute__((unused)), \
void *system __attribute__((unused)), gc_entity *entity, \
float dtime __attribute__((unused)))
{
struct controllable_component *con = GETCMP(controllable_component);
struct movable_component *mov = GETCMP(movable_component);
struct walk_action *walk = GETCMP(walk_action);
struct walk_action *wal = GETCMP(walk_action);
struct renderer *rend = GETCMP(renderer);
if (con->moving_left)
mov->acceleration.x -= walk->acceleration;
mov->acceleration.x -= wal->acceleration;
if (con->moving_right)
mov->acceleration.x += walk->acceleration;
(void)system;
(void)dtime;
(void)engine;
mov->acceleration.x += wal->acceleration;
if (rend) {
if (mov->velocity.x < 0)
SET_SIGN(((gc_animholder *)rend->data)->sprite->scale.x, -1);
else
SET_SIGN(((gc_animholder *)rend->data)->sprite->scale.x, 1);
if (rend->type != GC_ANIMREND)
return;
if (con->moving_left != con->moving_right)
rend_set_anim(rend, "walk");
else if (-wal->idle <= mov->velocity.x && mov->velocity.x <= wal->idle)
rend_set_anim(rend, "none");
}
}
void walk_destroy(void *system)