mirror of
https://github.com/zoriya/Twac.git
synced 2025-12-06 06:36:09 +00:00
Making the timer component reset the player (really ugly)
This commit is contained in:
2
main.c
2
main.c
@@ -13,7 +13,7 @@ int usage(const char *bin)
|
|||||||
my_printf("My runner:\n\n\tUsage: %s [path_to_map]. \
|
my_printf("My runner:\n\n\tUsage: %s [path_to_map]. \
|
||||||
If no map are specified, the default one is loaded.\n\n\
|
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\
|
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);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,13 +28,20 @@ void reset_timer(gc_scene *scene)
|
|||||||
timer->time_left = timer->default_value;
|
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 live_component *cmp = GETCMP(live_component);
|
||||||
struct transform_component *trans = GETCMP(transform_component);
|
struct transform_component *trans = GETCMP(transform_component);
|
||||||
struct controllable_component *con = GETCMP(controllable_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--;
|
cmp->live--;
|
||||||
if (cmp->live == 0) {
|
if (cmp->live == 0) {
|
||||||
engine->should_close = true;
|
engine->should_close = true;
|
||||||
@@ -43,13 +50,6 @@ static void on_collide(gc_engine *engine, gc_entity *entity, int id)
|
|||||||
reset_timer(engine->scene);
|
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)
|
static void ctr(void *component, va_list args)
|
||||||
@@ -63,7 +63,7 @@ static void ctr(void *component, va_list args)
|
|||||||
col = GETCMP(collision_component);
|
col = GETCMP(collision_component);
|
||||||
trans = GETCMP(transform_component);
|
trans = GETCMP(transform_component);
|
||||||
if (col)
|
if (col)
|
||||||
add_on_collide(col, &on_collide);
|
add_on_collide(col, &live_collide);
|
||||||
if (trans)
|
if (trans)
|
||||||
cmp->spawn_position = trans->position;
|
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 \
|
return ((void)my_printf("Collision not yet setup, you should place the \
|
||||||
live component after the collision component.\n"));
|
live component after the collision component.\n"));
|
||||||
cmp->spawn_position = trans->position;
|
cmp->spawn_position = trans->position;
|
||||||
add_on_collide(col, &on_collide);
|
add_on_collide(col, &live_collide);
|
||||||
(void)scene;
|
(void)scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void live_collide(gc_engine *engine, gc_entity *entity, int id);
|
||||||
|
|
||||||
static void update_entity(gc_engine *engine, void *system, \
|
static void update_entity(gc_engine *engine, void *system, \
|
||||||
gc_entity *entity, float dtime)
|
gc_entity *entity, float dtime)
|
||||||
{
|
{
|
||||||
@@ -23,11 +25,17 @@ gc_entity *entity, float dtime)
|
|||||||
if (!rend || rend->type != GC_TXTREND)
|
if (!rend || rend->type != GC_TXTREND)
|
||||||
return;
|
return;
|
||||||
timer->time_left -= dtime;
|
timer->time_left -= dtime;
|
||||||
if (((gc_text *)rend->data)->text)
|
if (timer->time_left <= 0) {
|
||||||
free(((gc_text *)rend->data)->text);
|
entity = engine->scene->get_entity(engine->scene, 25);
|
||||||
((gc_text *)rend->data)->text = tostr((int)timer->time_left);
|
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)system;
|
||||||
(void)engine;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroy(void *system)
|
static void destroy(void *system)
|
||||||
|
|||||||
Reference in New Issue
Block a user