mirror of
https://github.com/zoriya/Twac.git
synced 2026-06-06 03:45:51 +00:00
Adding a win detection
This commit is contained in:
@@ -12,6 +12,7 @@ SRC = main.c \
|
||||
src/components/jump_component.c \
|
||||
src/components/live_component.c \
|
||||
src/components/kill_component.c \
|
||||
src/components/win_component.c \
|
||||
src/systems/gravity_system.c \
|
||||
src/systems/walk_system.c \
|
||||
src/systems/jump_system.c
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** gravity_component
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "component.h"
|
||||
|
||||
extern const struct gc_component win_component;
|
||||
@@ -62,6 +62,14 @@
|
||||
<collision_component layer="11000000" />
|
||||
<kill_component />
|
||||
</gc_entity>
|
||||
<gc_entity>
|
||||
<transform_component>
|
||||
<Position x="1000" y="400" />
|
||||
<Size x="1" y="1000" />
|
||||
</transform_component>
|
||||
<collision_component layer="11000000" />
|
||||
<win_component />
|
||||
</gc_entity>
|
||||
|
||||
<gc_entity>
|
||||
<transform_component>
|
||||
|
||||
@@ -22,7 +22,7 @@ const struct kill_component kill_component = {
|
||||
name: "kill_component",
|
||||
size: sizeof(struct kill_component),
|
||||
dependencies: (char *[]){
|
||||
"movable_component",
|
||||
"collision_component",
|
||||
"transform_component",
|
||||
NULL
|
||||
},
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "components/live_component.h"
|
||||
#include "components/collision_component.h"
|
||||
#include "components/transform_component.h"
|
||||
#include "components/win_component.h"
|
||||
#include "utility.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -18,13 +19,16 @@ 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);
|
||||
|
||||
if (!GETCOLCMP(kill_component))
|
||||
return;
|
||||
cmp->live--;
|
||||
if (cmp->live < 0) {
|
||||
if (GETCOLCMP(kill_component)) {
|
||||
cmp->live--;
|
||||
if (cmp->live < 0) {
|
||||
exit(0);
|
||||
} else {
|
||||
trans->position = cmp->spawn_position;
|
||||
}
|
||||
}
|
||||
if (GETCOLCMP(win_component)) {
|
||||
exit(0);
|
||||
} else {
|
||||
trans->position = cmp->spawn_position;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** Twac
|
||||
** File description:
|
||||
** win_component
|
||||
*/
|
||||
|
||||
#include "component.h"
|
||||
#include "components/win_component.h"
|
||||
#include "utility.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static char *serialize(void *component)
|
||||
{
|
||||
(void)component;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const struct gc_component win_component = {
|
||||
name: "win_component",
|
||||
size: sizeof(struct gc_component),
|
||||
dependencies: (char *[]){
|
||||
"collision_component",
|
||||
"transform_component",
|
||||
NULL
|
||||
},
|
||||
ctr: NULL,
|
||||
fdctr: NULL,
|
||||
dtr: NULL,
|
||||
serialize: &serialize,
|
||||
destroy: &component_destroy
|
||||
};
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "components/jump_action.h"
|
||||
#include "components/live_component.h"
|
||||
#include "components/kill_component.h"
|
||||
#include "components/win_component.h"
|
||||
#include "systems/gravity_system.h"
|
||||
#include "systems/walk_system.h"
|
||||
#include "systems/jump_system.h"
|
||||
@@ -28,6 +29,7 @@ int register_customcmps(gc_engine *engine)
|
||||
engine->finish_physics(engine);
|
||||
engine->add_component(engine, &live_component);
|
||||
engine->add_component(engine, &kill_component);
|
||||
engine->add_component(engine, &win_component);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user