Making the timer component reset the player (really ugly)

This commit is contained in:
Anonymus Raccoon
2020-01-12 17:14:30 +01:00
parent a448374162
commit c13ff04eec
3 changed files with 24 additions and 16 deletions

2
main.c
View File

@@ -13,7 +13,7 @@ int usage(const char *bin)
my_printf("My runner:\n\n\tUsage: %s [path_to_map]. \
If no map are specified, the default one is loaded.\n\n\
Moves:\n\tQ or D to move to the left or right\n\t\
SPACE to jump\n", bin);
SPACE to jump (you can release the jump before the end to jump lower)\n", bin);
return (0);
}

View File

@@ -28,13 +28,20 @@ void reset_timer(gc_scene *scene)
timer->time_left = timer->default_value;
}
static void on_collide(gc_engine *engine, gc_entity *entity, int id)
void live_collide(gc_engine *engine, gc_entity *entity, int id)
{
struct live_component *cmp = GETCMP(live_component);
struct transform_component *trans = GETCMP(transform_component);
struct controllable_component *con = GETCMP(controllable_component);
if (GETCOLCMP(kill_component)) {
if (GETCOLCMP(win_component)) {
prefab_load(engine, "prefabs/winscreen.gcprefab");
entity->remove_component(engine->scene, entity, "keyboard_controller");
con->jumping = false;
con->moving_left = false;
con->moving_right = false;
}
else if (GETCOLCMP(kill_component) || id == -1) {
cmp->live--;
if (cmp->live == 0) {
engine->should_close = true;
@@ -43,13 +50,6 @@ static void on_collide(gc_engine *engine, gc_entity *entity, int id)
reset_timer(engine->scene);
}
}
if (GETCOLCMP(win_component)) {
prefab_load(engine, "prefabs/winscreen.gcprefab");
entity->remove_component(engine->scene, entity, "keyboard_controller");
con->jumping = false;
con->moving_left = false;
con->moving_right = false;
}
}
static void ctr(void *component, va_list args)
@@ -63,7 +63,7 @@ static void ctr(void *component, va_list args)
col = GETCMP(collision_component);
trans = GETCMP(transform_component);
if (col)
add_on_collide(col, &on_collide);
add_on_collide(col, &live_collide);
if (trans)
cmp->spawn_position = trans->position;
}
@@ -84,7 +84,7 @@ live component after the collision component.\n"));
return ((void)my_printf("Collision not yet setup, you should place the \
live component after the collision component.\n"));
cmp->spawn_position = trans->position;
add_on_collide(col, &on_collide);
add_on_collide(col, &live_collide);
(void)scene;
}

View File

@@ -14,6 +14,8 @@
#include "text.h"
#include <stdlib.h>
void live_collide(gc_engine *engine, gc_entity *entity, int id);
static void update_entity(gc_engine *engine, void *system, \
gc_entity *entity, float dtime)
{
@@ -23,11 +25,17 @@ gc_entity *entity, float dtime)
if (!rend || rend->type != GC_TXTREND)
return;
timer->time_left -= dtime;
if (((gc_text *)rend->data)->text)
free(((gc_text *)rend->data)->text);
((gc_text *)rend->data)->text = tostr((int)timer->time_left);
if (timer->time_left <= 0) {
entity = engine->scene->get_entity(engine->scene, 25);
if (!entity || !entity->get_component(entity, "keyboard_controller"))
return;
live_collide(engine, entity, -1);
} else {
if (((gc_text *)rend->data)->text)
free(((gc_text *)rend->data)->text);
((gc_text *)rend->data)->text = tostr((int)timer->time_left);
}
(void)system;
(void)engine;
}
static void destroy(void *system)