Adding a win detection

This commit is contained in:
AnonymusRaccoon
2020-01-09 17:59:32 +01:00
parent d63edfb128
commit 487c224ad1
7 changed files with 66 additions and 7 deletions
+1
View File
@@ -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
+12
View File
@@ -0,0 +1,12 @@
/*
** EPITECH PROJECT, 2019
** Gamacon
** File description:
** gravity_component
*/
#pragma once
#include "component.h"
extern const struct gc_component win_component;
+8
View File
@@ -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>
+1 -1
View File
@@ -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
View File
@@ -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;
}
}
+32
View File
@@ -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
};
+2
View File
@@ -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);
}