From 8b5189e0fd414c81dd141cfed3fc26fb8804898d Mon Sep 17 00:00:00 2001 From: Anonymus Raccoon Date: Wed, 29 Apr 2020 12:18:01 +0200 Subject: [PATCH] Loading a game over screen on loose --- src/combat/attacks.c | 6 +++--- src/systems/combat_manager.c | 3 +++ src/systems/combat_methods.c | 12 ++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/combat/attacks.c b/src/combat/attacks.c index 28f9443..b6a3405 100644 --- a/src/combat/attacks.c +++ b/src/combat/attacks.c @@ -26,7 +26,7 @@ void uppercut(gc_engine *engine, gc_entity *from, gc_entity *enemy) max = 20 - this->last_damage; else max = 10; - this->last_damage = MIN(random() % max, 10); + this->last_damage = MAX(MIN(random() % max, 10), 0); this->last_damage *= inv && inv->inventory_upgrades[2] ? 1 : 1.5; this->last_attack = "uppercut"; rem_health(enemy_health, engine, this->last_damage); @@ -46,7 +46,7 @@ void water_jet(gc_engine *engine, gc_entity *from, gc_entity *enemy) max = 20 - this->last_damage; else max = 10; - this->last_damage = MIN(random() % max, 10); + this->last_damage = MAX(MIN(random() % max, 10), 0); this->last_damage *= inv && inv->inventory_upgrades[1] ? 1 : 1.5; this->last_attack = "water_jet"; rem_health(enemy_health, engine, this->last_damage); @@ -66,7 +66,7 @@ void fireball(gc_engine *engine, gc_entity *from, gc_entity *enemy) max = 20 - this->last_damage; else max = 10; - this->last_damage = MIN(random() % max, 10); + this->last_damage = MAX(MIN(random() % max, 10), 0); this->last_damage *= inv && inv->inventory_upgrades[0] ? 1 : 1.5; this->last_attack = "fireball"; rem_health(enemy_health, engine, this->last_damage); diff --git a/src/systems/combat_manager.c b/src/systems/combat_manager.c index 5e594f5..95844c7 100644 --- a/src/systems/combat_manager.c +++ b/src/systems/combat_manager.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "engine.h" #include "my.h" #include "components/dialog_holder.h" @@ -48,6 +49,8 @@ void combat_end(gc_engine *engine, bool has_won) this->state = ATTACK; dialog->dialog_id = -1; dialog->input_id = -1; + if (!has_won) + prefab_load(engine, "prefabs/game_over.gcprefab"); } static void update_entity(gc_engine *engine, void *system, gc_entity *entity, \ diff --git a/src/systems/combat_methods.c b/src/systems/combat_methods.c index 57f4ed4..5e33161 100644 --- a/src/systems/combat_methods.c +++ b/src/systems/combat_methods.c @@ -79,8 +79,6 @@ void attack_callback(gc_engine *engine, int index) if (!li || !get_player_and_enemy(scene, &player_entity, &enemy)) return; - if (GETCMP(player_entity, health_component)->dead) - combat_end(engine, false); if (!(player = GETCMP(player_entity, attack_component))) return; if (player->attacks[index].run) @@ -101,15 +99,17 @@ gc_scene *scene, gc_engine *engine) if (!player_entity) return; - player = GETCMP(player_entity, attack_component); - if (!player) + if (GETCMP(player_entity, health_component)->dead) { + combat_end(engine, false); return; - if (player->attacks) { + } + if (!(player = GETCMP(player_entity, attack_component))) + return; + if (player->attacks) for (i = 0; player->attacks[i].name && i < 4; i++) { inputs[i].text = player->attacks[i].name; inputs[i].callback = &attack_callback; } - } inputs[i].text = NULL; dialog_add_line(dialog, NULL, ATTACK_TEXT, inputs); this->state = ATTACKING;