From e7459aa2bc19b78a935806fc3d881670de2feb94 Mon Sep 17 00:00:00 2001
From: AnonymusRaccoon
Date: Thu, 9 Jan 2020 17:19:28 +0100
Subject: [PATCH] Adding walk animations
---
include/components/walk_action.h | 1 +
lib/gamacon | 2 +-
lib/xmlparser | 2 +-
prefabs/player.gcprefab | 5 ++++-
src/components/walk_component.c | 2 ++
src/systems/jump_system.c | 1 -
src/systems/walk_system.c | 29 +++++++++++++++++++++--------
7 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/include/components/walk_action.h b/include/components/walk_action.h
index 21540bb..ff98e03 100644
--- a/include/components/walk_action.h
+++ b/include/components/walk_action.h
@@ -14,6 +14,7 @@ struct walk_action
{
gc_component base;
int acceleration;
+ int idle;
};
extern const struct walk_action walk_action;
\ No newline at end of file
diff --git a/lib/gamacon b/lib/gamacon
index 55c2b11..8366455 160000
--- a/lib/gamacon
+++ b/lib/gamacon
@@ -1 +1 @@
-Subproject commit 55c2b117e225a1c7530a8caa1b2b405ae12a5ea4
+Subproject commit 836645532a46f3f88be73301380b5405f112ce26
diff --git a/lib/xmlparser b/lib/xmlparser
index f7750c3..05fec3b 160000
--- a/lib/xmlparser
+++ b/lib/xmlparser
@@ -1 +1 @@
-Subproject commit f7750c3d72f0eee4ba81a5d94e2a918f22826f38
+Subproject commit 05fec3bfffe8820943b8609c3aa0b0b72de9c12f
diff --git a/prefabs/player.gcprefab b/prefabs/player.gcprefab
index 19ca7fd..08fbfd6 100644
--- a/prefabs/player.gcprefab
+++ b/prefabs/player.gcprefab
@@ -6,12 +6,15 @@
+
+
+
-
+
diff --git a/src/components/walk_component.c b/src/components/walk_component.c
index ba4bccc..f887ef6 100644
--- a/src/components/walk_component.c
+++ b/src/components/walk_component.c
@@ -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;
}
diff --git a/src/systems/jump_system.c b/src/systems/jump_system.c
index 9d2094e..5efbb68 100644
--- a/src/systems/jump_system.c
+++ b/src/systems/jump_system.c
@@ -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--;
diff --git a/src/systems/walk_system.c b/src/systems/walk_system.c
index ce4bb31..576ec3f 100644
--- a/src/systems/walk_system.c
+++ b/src/systems/walk_system.c
@@ -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
-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)