adding and print xp systeme

This commit is contained in:
Ragot mathis
2020-04-15 17:20:06 +02:00
parent c30a5581ad
commit 70f990ee68
8 changed files with 45 additions and 10 deletions
+2
View File
@@ -280,6 +280,8 @@ add_executable(my_rpg
src/systems/game_display_system.c
include/map_editor.h
lib/gamacon/include/sfml_init.h
src/components/xp_component.c
src/components/xp_methods.c
)
add_compile_options(-W -Wall -Wextra -Wshadow)
+2 -1
View File
@@ -9,7 +9,8 @@
typedef enum display_type
{
SELECT_TILE_DISPLAY
SELECT_TILE_DISPLAY,
xp_display
} display_type_enum;
struct game_display
+2 -2
View File
@@ -18,9 +18,9 @@ struct xp_component
bool full;
};
void add_xp(struct xp_component *this, gc_engine *engine, \
void xp_add(struct xp_component *this, gc_engine *engine, \
unsigned int amount);
void rem_xp(struct xp_component *this, gc_engine *engine, \
void xp_rem(struct xp_component *this, gc_engine *engine, \
unsigned int amount);
extern const struct xp_component xp_component;
+4 -2
View File
@@ -156,7 +156,9 @@
<panel src="main_ui_game" x="3%" y="2%" width="30%" height="15%" centered="false"/>
<text text="20/20" x="10%" y="6%" centered="false"/>
<text text="0/100" x="10%" y="14%" centered="false"/>
<text text="/20" x="13%" y="6%" centered="false"/>
<text text="10/100" x="14%" y="14%" centered="false">
<game_display stats="xp"/>
</text>
</gc_entities>
</gc_scene>
+8
View File
@@ -26,10 +26,18 @@ static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
struct renderer *rend = GETCMP(entity, renderer);
char *display_type = xml_gettempprop(n, "stats");
if (!display_type) {
my_printf("Please select properties\n");
return;
}
if (!my_strcmp(display_type, "selected_tile")) {
cmp->type = SELECT_TILE_DISPLAY;
return;
}
if (!my_strcmp(display_type, "xp")) {
cmp->type = xp_display;
return;
}
}
static void dtr(void *component)
+7 -5
View File
@@ -8,20 +8,22 @@
#include "components/xp_component.h"
#include "engine.h"
void add_xp(struct xp_component *this, gc_engine *engine, \
void xp_add(struct xp_component *this, gc_engine *engine, \
unsigned int amount)
{
if (this->full)
return;
this->xp += amount;
if (this->xp >= 100)
if (this->xp >= 100) {
this->full = true;
engine->trigger_event(engine, "add_xp", this->xp, amount);
this->xp = 100;
}
engine->trigger_event(engine, "xp_add", this->xp, amount);
}
void rem_xp(struct xp_component *this, gc_engine *engine, \
void xp_rem(struct xp_component *this, gc_engine *engine, \
unsigned int amount)
{
this->xp -= amount;
engine->trigger_event(engine, "rem_xp", this->xp, amount);
engine->trigger_event(engine, "xp_rem", this->xp, amount);
}
+2
View File
@@ -20,6 +20,7 @@
#include "components/game_display.h"
#include "my.h"
#include "map_editor.h"
#include "components/xp_component.h"
const struct callback callbacks[] = {
{"start_button", &start_button},
@@ -64,6 +65,7 @@ int register_customcmps(gc_engine *engine, bool map_editor)
engine->add_component(engine, &map_manager_component);
engine->add_component(engine, &game_display);
engine->add_system(engine, &game_display_system);
engine->add_component(engine, &xp_component);
engine->finish_physics(engine);
for (int i = 0; callbacks[i].func; i++)
engine->add_callback(engine, my_strdup(callbacks[i].name), \
+18
View File
@@ -10,6 +10,7 @@
#include <stddef.h>
#include "components/game_display.h"
#include "components/game_manager.h"
#include "components/xp_component.h"
#include "map_editor.h"
#include "text.h"
#include "components/renderer.h"
@@ -27,6 +28,19 @@ void display_current_texture(gc_scene *scene, struct renderer *rend)
((gc_sprite *)rend->data)->texture = map->selected_texture;
}
void display_current_xp(gc_scene *scene, struct renderer *rend)
{
gc_entity *player = scene->get_entity(scene, 50);
struct xp_component *xp;
static char str[10];
if (!player)
return;
xp = GETCMP(player, xp_component);
snprintf(str, 10, "%d/100", xp->xp);
((gc_text *)rend->data)->text = str;
}
static void update_entity(gc_engine *engine, void *system, gc_entity *entity, \
float dtime)
{
@@ -38,6 +52,10 @@ float dtime)
display_current_texture(scene, rend);
return;
}
if (disp->type == xp_display && rend->type == GC_TXTREND) {
display_current_xp(scene, rend);
return;
}
}
static void destroy(void *system, gc_engine *engine)