mirror of
https://github.com/zoriya/Twac.git
synced 2025-12-06 06:36:09 +00:00
Handling win and loose
This commit is contained in:
@@ -13,6 +13,7 @@ struct timer_component
|
||||
{
|
||||
gc_component base;
|
||||
float time_left;
|
||||
int default_value;
|
||||
};
|
||||
|
||||
extern const struct timer_component timer_component;
|
||||
@@ -21,7 +21,7 @@
|
||||
<jump_action acceleration="17000" counterforce="6000" step_count="7"/>
|
||||
<collision_component layer="11000000" />
|
||||
<friction_component value=".5" />
|
||||
<live_component count="3" />
|
||||
<live_component count="0" />
|
||||
<camerafollow_component />
|
||||
</gc_entity>
|
||||
</gc_entities>
|
||||
@@ -11,26 +11,44 @@
|
||||
#include "components/collision_component.h"
|
||||
#include "components/transform_component.h"
|
||||
#include "components/win_component.h"
|
||||
#include "components/controllable_component.h"
|
||||
#include "components/timer_component.h"
|
||||
#include "utility.h"
|
||||
#include "prefab.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void reset_timer(gc_scene *scene)
|
||||
{
|
||||
gc_entity *entity = scene->get_entity(scene, 50);
|
||||
struct timer_component *timer;
|
||||
|
||||
if (!entity)
|
||||
return;
|
||||
timer = GETCMP(timer_component);
|
||||
timer->time_left = timer->default_value;
|
||||
}
|
||||
|
||||
static void on_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)) {
|
||||
cmp->live--;
|
||||
if (cmp->live < 0) {
|
||||
if (cmp->live == 0) {
|
||||
engine->should_close = true;
|
||||
} else {
|
||||
trans->position = cmp->spawn_position;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ static void ctr(void *component, va_list args)
|
||||
struct timer_component *cmp = (struct timer_component *)component;
|
||||
|
||||
cmp->time_left = va_arg(args, double);
|
||||
cmp->default_value = cmp->time_left;
|
||||
}
|
||||
|
||||
static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
|
||||
@@ -22,6 +23,7 @@ static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
|
||||
struct timer_component *cmp = (struct timer_component *)component;
|
||||
|
||||
cmp->time_left = xml_getintprop(n, "time");
|
||||
cmp->default_value = cmp->time_left;
|
||||
(void)entity;
|
||||
(void)scene;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user