mirror of
https://github.com/zoriya/ForecastingVillage.git
synced 2026-05-26 07:59:58 +00:00
merge player.gcprefab resolve
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -26,7 +26,9 @@ SRC = src/main.c \
|
||||
src/map_editor/selectors.c \
|
||||
src/map_editor/toolbar.c \
|
||||
src/components/health_component.c \
|
||||
src/components/health_methods.c
|
||||
src/components/health_methods.c \
|
||||
src/components/xp_component.c \
|
||||
src/components/xp_methods.c
|
||||
|
||||
OBJ = $(SRC:%.c=%.o)
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
|
||||
typedef enum display_type
|
||||
{
|
||||
SELECT_TILE_DISPLAY
|
||||
SELECT_TILE_DISPLAY,
|
||||
xp_display
|
||||
} display_type_enum;
|
||||
|
||||
struct game_display
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** xp_component
|
||||
*/
|
||||
|
||||
#ifndef MY_RPG_HEALTH_COMPONENT_H
|
||||
#define MY_RPG_HEALTH_COMPONENT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "component.h"
|
||||
|
||||
struct xp_component
|
||||
{
|
||||
gc_component base;
|
||||
int xp;
|
||||
bool full;
|
||||
};
|
||||
|
||||
void xp_add(struct xp_component *this, gc_engine *engine, \
|
||||
unsigned int amount);
|
||||
void xp_rem(struct xp_component *this, gc_engine *engine, \
|
||||
unsigned int amount);
|
||||
|
||||
extern const struct xp_component xp_component;
|
||||
|
||||
#endif //MY_RPG_HEALTH_COMPONENT_H
|
||||
@@ -151,7 +151,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>
|
||||
+21
-21
@@ -18,24 +18,24 @@
|
||||
<animation name="walk_down_right" frame_count="6" frame_rate="10">
|
||||
<Rect top="1344" left="138" />
|
||||
</animation>
|
||||
|
||||
<animation name="walk_down" frame_count="6" frame_rate="10">
|
||||
<Rect top="0" left="138" />
|
||||
</animation>
|
||||
<animation name="walk_up" frame_count="6" frame_rate="10">
|
||||
<Rect top="768" left="138" />
|
||||
</animation>
|
||||
<animation name="walk_right" frame_count="6" frame_rate="10">
|
||||
<Rect top="1152" left="138" />
|
||||
</animation>
|
||||
<animation name="walk_left" frame_count="6" frame_rate="10">
|
||||
<Rect top="384" left="138" />
|
||||
</animation>
|
||||
</renderer>
|
||||
<camerafollow_component/>
|
||||
<controllable_component />
|
||||
<keyboard_controller left="16" right="3" up="25" down="18" />
|
||||
<map_movement />
|
||||
<map_linker x="1" y="1" solid="false" />
|
||||
</gc_entity>
|
||||
</gc_entities>
|
||||
<animation name="walk_down" frame_count="6" frame_rate="10">
|
||||
<Rect top="0" left="138" />
|
||||
</animation>
|
||||
<animation name="walk_up" frame_count="6" frame_rate="10">
|
||||
<Rect top="768" left="138" />
|
||||
</animation>
|
||||
<animation name="walk_right" frame_count="6" frame_rate="10">
|
||||
<Rect top="1152" left="138" />
|
||||
</animation>
|
||||
<animation name="walk_left" frame_count="6" frame_rate="10">
|
||||
<Rect top="384" left="138" />
|
||||
</animation>
|
||||
</renderer>
|
||||
<camerafollow_component/>
|
||||
<controllable_component />
|
||||
<keyboard_controller left="16" right="3" up="25" down="18" />
|
||||
<map_movement />
|
||||
<map_linker x="1" y="1" solid="false" />
|
||||
<xp_component xp="20"/>
|
||||
</gc_entity>
|
||||
</gc_entities>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** My3D
|
||||
** File description:
|
||||
** xp component
|
||||
*/
|
||||
|
||||
#include "xml.h"
|
||||
#include "component.h"
|
||||
#include "components/xp_component.h"
|
||||
|
||||
static void ctr(void *component, va_list args)
|
||||
{
|
||||
struct xp_component *cmp = (struct xp_component *)\
|
||||
component;
|
||||
cmp->xp = va_arg(args, int);
|
||||
cmp->full = false;
|
||||
}
|
||||
|
||||
static void fdctr(gc_entity *entity, gc_scene *scene, \
|
||||
void *component, node *n)
|
||||
{
|
||||
struct xp_component *cmp = (struct xp_component *)\
|
||||
component;
|
||||
|
||||
cmp->xp = xml_getintprop(n, "xp");
|
||||
cmp->full = false;
|
||||
}
|
||||
|
||||
static void dtr(void *component)
|
||||
{
|
||||
(void)component;
|
||||
}
|
||||
|
||||
static char *serialize(void *component)
|
||||
{
|
||||
(void)component;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const struct xp_component xp_component = {
|
||||
base: {
|
||||
name: "xp_component",
|
||||
size: sizeof(struct xp_component),
|
||||
dependencies: (char *[]){
|
||||
NULL
|
||||
},
|
||||
ctr: &ctr,
|
||||
fdctr: &fdctr,
|
||||
dtr: &dtr,
|
||||
serialize: &serialize,
|
||||
destroy: &component_destroy
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** My3D
|
||||
** File description:
|
||||
** xp methods
|
||||
*/
|
||||
|
||||
#include "components/xp_component.h"
|
||||
#include "engine.h"
|
||||
|
||||
void xp_add(struct xp_component *this, gc_engine *engine, \
|
||||
unsigned int amount)
|
||||
{
|
||||
if (this->full)
|
||||
return;
|
||||
this->xp += amount;
|
||||
if (this->xp >= 100) {
|
||||
this->full = true;
|
||||
this->xp = 100;
|
||||
}
|
||||
engine->trigger_event(engine, "xp_add", this->xp, amount);
|
||||
}
|
||||
|
||||
void xp_rem(struct xp_component *this, gc_engine *engine, \
|
||||
unsigned int amount)
|
||||
{
|
||||
this->xp -= amount;
|
||||
engine->trigger_event(engine, "xp_rem", this->xp, amount);
|
||||
}
|
||||
@@ -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), \
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user