Adding the level up system

This commit is contained in:
Anonymus Raccoon
2020-05-03 14:17:31 +02:00
parent 198c349910
commit 3edf33980f
5 changed files with 36 additions and 7 deletions
+1 -1
View File
@@ -36,7 +36,7 @@
<keyboard_controller left="16" right="3" up="25" down="18" />
<map_movement />
<map_linker x="63" y="19" solid="false" centered="true"/>
<xp_component xp="20"/>
<xp_component xp="0"/>
<health_component max_health="25"/>
<player_component fight_rate="5%" />
<particule_component type="1" nb_particules_max="15" lifetime="60" texture="stone" />
+16
View File
@@ -5,9 +5,24 @@
** xp methods
*/
#include <components/health_component.h>
#include "components/xp_component.h"
#include "engine.h"
void level_up(gc_engine *engine)
{
gc_entity *player = engine->scene->get_entity(engine->scene, 50);
struct health_component *health;
if (!player)
return;
health = GETCMP(player, health_component);
if (!health)
return;
health->health_max += 15;
health->health = health->health_max;
}
void xp_add(struct xp_component *this, gc_engine *engine, \
unsigned int amount)
{
@@ -17,6 +32,7 @@ unsigned int amount)
if (this->xp >= 100) {
this->full = true;
this->xp = 100;
level_up(engine);
}
engine->trigger_event(engine, "xp_add", this->xp, amount);
}
+1 -2
View File
@@ -38,8 +38,6 @@ void combat_end(gc_engine *engine, bool has_won)
gc_entity *player = this->game_scene->get_entity(this->game_scene, 50);
struct dialog_manager *dialog = GETSYS(engine, dialog_manager);
if (!this->current_enemy || !player || ! player_combat || !dialog)
return;
set_combat_player(engine, player_combat, player);
engine->change_scene(engine, this->game_scene);
this->game_scene = NULL;
@@ -53,6 +51,7 @@ void combat_end(gc_engine *engine, bool has_won)
controllable_set_can_move(engine->scene, false);
prefab_load(engine, "prefabs/win.gcprefab");
}
engine->trigger_event(engine, "combat_ended", this->current_enemy, has_won);
this->current_enemy = NULL;
}
+17 -3
View File
@@ -7,6 +7,8 @@
#include <components/tag_component.h>
#include <systems/sfml_renderer_system.h>
#include <enemy.h>
#include <components/xp_component.h>
#include "my.h"
#include "prefab.h"
#include "keybindings.h"
@@ -43,9 +45,19 @@ static void key_pressed(gc_engine *engine, va_list args)
toggle_inventory(engine);
}
static void update_entity(gc_engine *engine, void *system, gc_entity *entity, \
float dtime)
static void combat_ended(gc_engine *engine, va_list args)
{
struct enemy *enemy = va_arg(args, struct enemy *);
bool has_won = va_arg(args, int);
gc_entity *player = engine->scene->get_entity(engine->scene, 50);
struct xp_component *xp;
if (!player || !has_won)
return;
xp = GETCMP(player, xp_component);
if (!xp)
return;
xp_add(xp, engine, 10);
}
static void ctr(void *system, va_list list)
@@ -54,6 +66,7 @@ static void ctr(void *system, va_list list)
struct game_manager_system *this = system;
engine->add_event_listener(engine, "key_pressed", &key_pressed);
engine->add_event_listener(engine, "combat_ended", &combat_ended);
this->has_message = false;
this->is_inventory = false;
}
@@ -61,6 +74,7 @@ static void ctr(void *system, va_list list)
static void dtr(void *system, gc_engine *engine)
{
engine->remove_event_listener(engine, "key_pressed", &key_pressed);
engine->remove_event_listener(engine, "combat_ended", &combat_ended);
}
const struct game_manager_system game_manager_system = {
@@ -71,7 +85,7 @@ const struct game_manager_system game_manager_system = {
ctr: &ctr,
dtr: &dtr,
check_dependencies: &system_check_dependencies,
update_entity: &update_entity,
update_entity: NULL,
destroy: &system_destroy
},
is_inventory: false