mirror of
https://github.com/zoriya/ForecastingVillage.git
synced 2026-05-28 17:04:44 +00:00
Adding the level up system
This commit is contained in:
+1
-1
Submodule lib/gamacon updated: 800efd3c0f...cc4bf3295b
@@ -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" />
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user