mirror of
https://github.com/zoriya/Twac.git
synced 2025-12-06 06:36:09 +00:00
Adding a timer
This commit is contained in:
4
Makefile
4
Makefile
@@ -13,9 +13,11 @@ SRC = main.c \
|
||||
src/components/live_component.c \
|
||||
src/components/kill_component.c \
|
||||
src/components/win_component.c \
|
||||
src/components/timer_component.c \
|
||||
src/systems/gravity_system.c \
|
||||
src/systems/walk_system.c \
|
||||
src/systems/jump_system.c
|
||||
src/systems/jump_system.c \
|
||||
src/systems/timer_system.c
|
||||
|
||||
OBJ = $(SRC:%.c=%.o)
|
||||
|
||||
|
||||
BIN
assets/fonts/roboto.ttf
Normal file
BIN
assets/fonts/roboto.ttf
Normal file
Binary file not shown.
@@ -1,4 +0,0 @@
|
||||
|
||||
|
||||
|
||||
11111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||
18
include/components/timer_component.h
Normal file
18
include/components/timer_component.h
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** gravity_component
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "component.h"
|
||||
|
||||
struct timer_component
|
||||
{
|
||||
gc_component base;
|
||||
float time_left;
|
||||
};
|
||||
|
||||
extern const struct timer_component timer_component;
|
||||
12
include/systems/timer_system.h
Normal file
12
include/systems/timer_system.h
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** texture_renderer_system
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "system.h"
|
||||
|
||||
extern const gc_system timer_system;
|
||||
Submodule lib/gamacon updated: ded85794e0...a1e4936dba
@@ -7,6 +7,7 @@
|
||||
<sprite src="assets/sprites/grass.png" />
|
||||
<sprite src="assets/sprites/player_sheet.png" />
|
||||
<music src="assets/musics/music.ogg"/>
|
||||
<font src="assets/fonts/roboto.ttf" />
|
||||
</data>
|
||||
<gc_entities>
|
||||
<gc_entity>
|
||||
@@ -54,7 +55,16 @@
|
||||
<fixed_to_cam />
|
||||
</gc_entity>
|
||||
|
||||
|
||||
<gc_entity id="50">
|
||||
<transform_component>
|
||||
<Position x="500" y="-200" />
|
||||
<Size x="1000000" y="10" />
|
||||
</transform_component>
|
||||
<renderer text="" />
|
||||
<collision_component layer="00000000" />
|
||||
<fixed_to_cam />
|
||||
<timer_component time="60"/>
|
||||
</gc_entity>
|
||||
|
||||
<gc_entity>
|
||||
<transform_component>
|
||||
|
||||
49
src/components/timer_component.c
Normal file
49
src/components/timer_component.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** Twac
|
||||
** File description:
|
||||
** timer_component
|
||||
*/
|
||||
|
||||
#include "component.h"
|
||||
#include "components/timer_component.h"
|
||||
#include "utility.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static void ctr(void *component, va_list args)
|
||||
{
|
||||
struct timer_component *cmp = (struct timer_component *)component;
|
||||
|
||||
cmp->time_left = va_arg(args, double);
|
||||
}
|
||||
|
||||
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");
|
||||
(void)entity;
|
||||
(void)scene;
|
||||
}
|
||||
|
||||
static char *serialize(void *component)
|
||||
{
|
||||
(void)component;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const struct timer_component timer_component = {
|
||||
base: {
|
||||
name: "timer_component",
|
||||
size: sizeof(struct timer_component),
|
||||
dependencies: (char *[]){
|
||||
"renderer",
|
||||
NULL
|
||||
},
|
||||
ctr: &ctr,
|
||||
fdctr: &fdctr,
|
||||
dtr: NULL,
|
||||
serialize: &serialize,
|
||||
destroy: &component_destroy
|
||||
}
|
||||
};
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "engine.h"
|
||||
#include "components/renderer.h"
|
||||
#include "runner.h"
|
||||
#include "prefab.h"
|
||||
#include "components/gravity_component.h"
|
||||
@@ -14,9 +15,11 @@
|
||||
#include "components/live_component.h"
|
||||
#include "components/kill_component.h"
|
||||
#include "components/win_component.h"
|
||||
#include "components/timer_component.h"
|
||||
#include "systems/gravity_system.h"
|
||||
#include "systems/walk_system.h"
|
||||
#include "systems/jump_system.h"
|
||||
#include "systems/timer_system.h"
|
||||
#include <SFML/System.h>
|
||||
#include <SFML/Window.h>
|
||||
|
||||
@@ -28,10 +31,12 @@ int register_customcmps(gc_engine *engine)
|
||||
engine->add_system(engine, &gravity_system);
|
||||
engine->add_system(engine, &walk_system);
|
||||
engine->add_system(engine, &jump_system);
|
||||
engine->add_system(engine, &timer_system);
|
||||
engine->finish_physics(engine);
|
||||
engine->add_component(engine, &live_component);
|
||||
engine->add_component(engine, &kill_component);
|
||||
engine->add_component(engine, &win_component);
|
||||
engine->add_component(engine, &timer_component);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
45
src/systems/timer_system.c
Normal file
45
src/systems/timer_system.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** Twac
|
||||
** File description:
|
||||
** timer_system
|
||||
*/
|
||||
|
||||
#include "entity.h"
|
||||
#include "system.h"
|
||||
#include "vector2.h"
|
||||
#include "utility.h"
|
||||
#include "components/timer_component.h"
|
||||
#include "components/renderer.h"
|
||||
#include "text.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static void update_entity(gc_engine *engine, void *system, \
|
||||
gc_entity *entity, float dtime)
|
||||
{
|
||||
struct renderer *rend = GETCMP(renderer);
|
||||
struct timer_component *timer = GETCMP(timer_component);
|
||||
|
||||
if (!rend || rend->type != GC_TXTREND)
|
||||
return;
|
||||
timer->time_left -= dtime;
|
||||
((gc_text *)rend->data)->text = tostr((int)timer->time_left);
|
||||
(void)system;
|
||||
(void)engine;
|
||||
}
|
||||
|
||||
static void destroy(void *system)
|
||||
{
|
||||
(void)system;
|
||||
}
|
||||
|
||||
const gc_system timer_system = {
|
||||
name: "timer_system",
|
||||
component_name: "timer_component",
|
||||
size: sizeof(gc_system),
|
||||
ctr: NULL,
|
||||
dtr: NULL,
|
||||
check_dependencies: &system_check_dependencies,
|
||||
update_entity: &update_entity,
|
||||
destroy: &destroy
|
||||
};
|
||||
Reference in New Issue
Block a user