mirror of
https://github.com/zoriya/Twac.git
synced 2026-06-05 03:09:55 +00:00
Adding a live/respawn system
This commit is contained in:
@@ -10,6 +10,8 @@ SRC = main.c \
|
||||
src/components/gravity_component.c \
|
||||
src/components/walk_component.c \
|
||||
src/components/jump_component.c \
|
||||
src/components/live_component.c \
|
||||
src/components/kill_component.c \
|
||||
src/systems/gravity_system.c \
|
||||
src/systems/walk_system.c \
|
||||
src/systems/jump_system.c
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** gravity_component
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "component.h"
|
||||
|
||||
struct kill_component
|
||||
{
|
||||
gc_component base;
|
||||
};
|
||||
|
||||
extern const struct kill_component kill_component;
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** gravity_component
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "component.h"
|
||||
|
||||
struct live_component
|
||||
{
|
||||
gc_component base;
|
||||
int live;
|
||||
gc_vector2 spawn_position;
|
||||
};
|
||||
|
||||
extern const struct live_component live_component;
|
||||
+1
-1
Submodule lib/gamacon updated: 7903b83a26...b8245b3f5d
@@ -52,6 +52,15 @@
|
||||
<fixed_to_cam />
|
||||
</gc_entity>
|
||||
|
||||
<gc_entity>
|
||||
<transform_component>
|
||||
<Position x="-500" y="-200" />
|
||||
<Size x="10000" y="10" />
|
||||
</transform_component>
|
||||
<collision_component layer="11000000" />
|
||||
<kill_component />
|
||||
</gc_entity>
|
||||
|
||||
<gc_entity>
|
||||
<transform_component>
|
||||
<Position x="200" y="100" />
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<jump_action acceleration="17000" counterforce="6000" step_count="7"/>
|
||||
<collision_component layer="11000000" />
|
||||
<friction_component value=".5" />
|
||||
<live_component count="3" />
|
||||
<camerafollow_component />
|
||||
</gc_entity>
|
||||
</gc_entities>
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** Twac
|
||||
** File description:
|
||||
** kill_component
|
||||
*/
|
||||
|
||||
|
||||
#include "component.h"
|
||||
#include "components/kill_component.h"
|
||||
#include "utility.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static char *serialize(void *component)
|
||||
{
|
||||
(void)component;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const struct kill_component kill_component = {
|
||||
base: {
|
||||
name: "kill_component",
|
||||
size: sizeof(struct kill_component),
|
||||
dependencies: (char *[]){
|
||||
"movable_component",
|
||||
"transform_component",
|
||||
NULL
|
||||
},
|
||||
ctr: NULL,
|
||||
fdctr: NULL,
|
||||
dtr: NULL,
|
||||
serialize: &serialize,
|
||||
destroy: &component_destroy
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** live_component
|
||||
*/
|
||||
|
||||
#include "xml.h"
|
||||
#include "component.h"
|
||||
#include "components/live_component.h"
|
||||
#include "components/collision_component.h"
|
||||
#include "components/transform_component.h"
|
||||
#include "utility.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
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) {
|
||||
exit(0); //SHOULD CHANGE THAT TO A SWITCH TO THE MENU
|
||||
} else {
|
||||
trans->position = cmp->spawn_position;
|
||||
}
|
||||
}
|
||||
|
||||
static void ctr(void *component, va_list args)
|
||||
{
|
||||
struct live_component *cmp = (struct live_component *)component;
|
||||
gc_entity *entity = va_arg(args, gc_entity *);
|
||||
struct collision_component *col;
|
||||
struct transform_component *trans;
|
||||
|
||||
if (entity) {
|
||||
col = GETCMP(collision_component);
|
||||
trans = GETCMP(transform_component);
|
||||
if (col)
|
||||
add_on_collide(col, &on_collide);
|
||||
if (trans)
|
||||
cmp->spawn_position = trans->position;
|
||||
}
|
||||
cmp->live = va_arg(args, int);
|
||||
}
|
||||
|
||||
static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
|
||||
{
|
||||
struct live_component *cmp = (struct live_component *)component;
|
||||
struct transform_component *trans = GETCMP(transform_component);
|
||||
struct collision_component *col = GETCMP(collision_component);
|
||||
|
||||
cmp->live = xml_getintprop(n, "count");
|
||||
if (!trans)
|
||||
return ((void)my_printf("Transform not yet setup, you should place the \
|
||||
live component after the collision component.\n"));
|
||||
if (!col)
|
||||
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);
|
||||
(void)scene;
|
||||
}
|
||||
|
||||
static void dtr(void *component)
|
||||
{
|
||||
(void)component;
|
||||
}
|
||||
|
||||
static char *serialize(void *component)
|
||||
{
|
||||
(void)component;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const struct live_component live_component = {
|
||||
base: {
|
||||
name: "live_component",
|
||||
size: sizeof(struct live_component),
|
||||
dependencies: (char *[]){
|
||||
"transform_component",
|
||||
"collision_component",
|
||||
NULL
|
||||
},
|
||||
ctr: &ctr,
|
||||
fdctr: &fdctr,
|
||||
dtr: &dtr,
|
||||
serialize: &serialize,
|
||||
destroy: &component_destroy
|
||||
},
|
||||
live: 3
|
||||
};
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "components/gravity_component.h"
|
||||
#include "components/walk_action.h"
|
||||
#include "components/jump_action.h"
|
||||
#include "components/live_component.h"
|
||||
#include "components/kill_component.h"
|
||||
#include "systems/gravity_system.h"
|
||||
#include "systems/walk_system.h"
|
||||
#include "systems/jump_system.h"
|
||||
@@ -24,6 +26,8 @@ int register_customcmps(gc_engine *engine)
|
||||
engine->add_system(engine, &walk_system);
|
||||
engine->add_system(engine, &jump_system);
|
||||
engine->finish_physics(engine);
|
||||
engine->add_component(engine, &live_component);
|
||||
engine->add_component(engine, &kill_component);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user