Adding attacks to the combat system

This commit is contained in:
Anonymus Raccoon
2020-04-28 16:04:13 +02:00
parent eff62fe3f5
commit 9540aaf0d5
11 changed files with 125 additions and 37 deletions
+2 -1
View File
@@ -10,6 +10,7 @@
#include "entity.h"
void set_combat_player(gc_entity *main_player, gc_entity *combat_player);
void set_combat_player(gc_engine *engine, gc_entity *main_player, \
gc_entity *combat_player);
#endif //MY_RPG_PLAYER_UTILITIES_H
+1
View File
@@ -59,5 +59,6 @@ void fireball(gc_engine *engine, gc_entity *from, gc_entity *enemy);
void uppercut(gc_engine *engine, gc_entity *from, gc_entity *enemy);
void water_jet(gc_engine *engine, gc_entity *from, gc_entity *enemy);
void shield(gc_engine *engine, gc_entity *from, gc_entity *enemy);
void ennemie_attack(gc_engine *engine, gc_entity *from, gc_entity *enemy);
void load_attacks(gc_scene *scene);
+2
View File
@@ -29,6 +29,8 @@ struct combat_manager {
struct enemy *current_enemy;
struct attack_holder *next_enemy_attack;
enum combat_state state;
char *last_attack;
int last_damage;
};
extern const struct combat_manager combat_manager;
+24 -16
View File
@@ -7,6 +7,7 @@
<sprite name="enemy_holder" src="assets/ui/enemy.png" />
<sprite name="panel" src="assets/ui/panel.png" />
<sprite name="main_ui_game" src="assets/ui/health_and_xp.png" />
<sprite name="player" src="assets/sprites/player_spritesheet.png" />
<sprite name="bee" src="assets/sprites/bee.png" />
</data>
@@ -25,22 +26,6 @@
</dialog_holder>
</gc_entity>
<gc_entity id="50">
<transform_component>
<Position x="0" y="300" />
</transform_component>
<map_linker x="0" y="0" />
<player_component />
<attack_component>
<attack name="Uppercut" />
<attack name="Water grenade" />
<attack name="Fireball" />
<attack name="Shield" />
</attack_component>
<xp_component xp="3"/>
<health_component max_health="3"/>
</gc_entity>
<panel src="enemy_holder" x="75%" y="20%" width="30%" height="%" />
<panel src="player_holder" x="45%" y="80%" width="45%" height="20%" reverse_y="true" />
<panel src="main_ui_game" x="3%" y="2%" width="30%" height="15%" centered="false"/>
@@ -52,5 +37,28 @@
<text text="Loading" x="80%" y="65%" centered="false">
<game_display stats="health"/>
</text>
<gc_entity id="50">
<transform_component>
<Size x="100" y="100" />
</transform_component>
<map_linker x="0" y="0" />
<player_component />
<attack_component>
<attack name="Uppercut" />
<attack name="Water jet" />
<attack name="Fireball" />
<attack name="Shield" />
</attack_component>
<renderer src="player">
<Rect height="147" width="138" top="960" left="138" />
<animation name="uppercut" frame_count="6" frame_rate="10">
<Rect top="960" left="138" />
</animation>
</renderer>
<fixed_to_cam x="45%" y="70%" />
<xp_component xp="3"/>
<health_component max_health="3"/>
</gc_entity>
</gc_entities>
</gc_scene>
+1 -1
View File
@@ -10,7 +10,7 @@
<fixed_to_cam x="75%" y="20%" />
<combat_holder name="bee" />
<attack_component>
<attack name="Fireball"/>
<attack name="Aerial attack"/>
</attack_component>
<health_component max_health="12"/>
</gc_entity>
+72 -5
View File
@@ -5,27 +5,94 @@
** fireball.c
*/
#include <components/health_component.h>
#include <systems/combat_manager.h>
#include <systems/game_manager_system.h>
#include <stdlib.h>
#include <utility.h>
#include "components/health_component.h"
#include "engine.h"
#include "renderer.h"
void uppercut(gc_engine *engine, gc_entity *from, gc_entity *enemy)
{
struct combat_manager *this = GETSYS(engine, combat_manager);
struct game_manager_system *inv = GETSYS(engine, game_manager_system);
struct health_component *enemy_health = GETCMP(enemy, health_component);
struct renderer *rend = GETCMP(from, renderer);
int max;
rem_health(enemy_health, engine, 10);
if (this->last_attack && my_strcmp(this->last_attack, "uppercut"))
max = 20 - this->last_damage;
else
max = 10;
this->last_damage = MAX(random() % max, 10);
this->last_attack = "uppercut";
rem_health(enemy_health, engine, this->last_damage);
if (rend)
rend_set_anim(rend, "uppercut");
}
void water_jet(gc_engine *engine, gc_entity *from, gc_entity *enemy)
{
printf("water_grenade\n");
struct combat_manager *this = GETSYS(engine, combat_manager);
struct game_manager_system *inv = GETSYS(engine, game_manager_system);
struct health_component *enemy_health = GETCMP(enemy, health_component);
struct renderer *rend = GETCMP(from, renderer);
int max;
if (this->last_attack && my_strcmp(this->last_attack, "water_jet"))
max = 20 - this->last_damage;
else
max = 10;
this->last_damage = MAX(random() % max, 10);
this->last_attack = "water_jet";
rem_health(enemy_health, engine, this->last_damage);
if (rend)
rend_set_anim(rend, "water_jet");
}
void fireball(gc_engine *engine, gc_entity *from, gc_entity *enemy)
{
printf("FIREBALL\n");
struct combat_manager *this = GETSYS(engine, combat_manager);
struct game_manager_system *inv = GETSYS(engine, game_manager_system);
struct health_component *enemy_health = GETCMP(enemy, health_component);
struct renderer *rend = GETCMP(from, renderer);
int max;
if (this->last_attack && my_strcmp(this->last_attack, "fireball"))
max = 20 - this->last_damage;
else
max = 10;
this->last_damage = MAX(random() % max, 10);
this->last_attack = "fireball";
rem_health(enemy_health, engine, this->last_damage);
if (rend)
rend_set_anim(rend, "fireball");
}
void shield(gc_engine *engine, gc_entity *from, gc_entity *enemy)
{
printf("shield\n");
struct combat_manager *this = GETSYS(engine, combat_manager);
struct game_manager_system *inv = GETSYS(engine, game_manager_system);
struct health_component *enemy_health = GETCMP(enemy, health_component);
struct renderer *rend = GETCMP(from, renderer);
this->last_damage = 50;
this->last_attack = "shield";
if (rend)
rend_set_anim(rend, "shield");
}
void ennemie_attack(gc_engine *engine, gc_entity *from, gc_entity *enemy)
{
struct combat_manager *this = GETSYS(engine, combat_manager);
struct health_component *enemy_health = GETCMP(enemy, health_component);
struct renderer *rend = GETCMP(from, renderer);
float amount = random() % 10;
if (this->last_attack && !my_strcmp(this->last_attack, "shield"))
amount /= (float)this->last_damage / 100;
rem_health(enemy_health, engine, (int)amount);
if (rend)
rend_set_anim(rend, "attack");
}
+2 -1
View File
@@ -64,8 +64,9 @@ const struct callback map_editor_callbacks[] = {
const struct gc_data attacks[] = {
{"attack", "Uppercut", &uppercut, NULL},
{"attack", "Fireball", &fireball, NULL},
{"attack", "Water Jet", &water_jet, NULL},
{"attack", "Water jet", &water_jet, NULL},
{"attack", "Shield", &shield, NULL},
{"attack", "Aerial attack", &ennemie_attack, NULL},
{NULL, NULL, NULL, NULL}
};
+12 -9
View File
@@ -5,19 +5,22 @@
** game_loader
*/
#include <systems/combat_manager.h>
#include "components//health_component.h"
#include "entity.h"
void set_combat_player(gc_entity *main_player, gc_entity *combat_player)
void set_combat_player(gc_engine *engine, gc_entity *player, gc_entity *cbt)
{
struct health_component *h_cmp_main = \
GETCMP(main_player, health_component);
struct health_component *h_cmp_combat = \
GETCMP(combat_player, health_component);
struct health_component *main = GETCMP(player, health_component);
struct health_component *combat = GETCMP(cbt, health_component);
struct combat_manager *this = GETSYS(engine, combat_manager);
if (!h_cmp_main || !h_cmp_combat)
this->last_attack = NULL;
this->last_damage = 0;
if (!main || !combat)
return;
h_cmp_combat->health_max = h_cmp_main->health_max;
h_cmp_combat->health = h_cmp_main->health;
h_cmp_combat->dead = h_cmp_main->dead;
combat->health_max = main->health_max;
combat->health = main->health;
combat->dead = main->dead;
}
+1 -1
View File
@@ -38,7 +38,7 @@ void combat_end(gc_engine *engine, bool has_won)
if (!this->current_enemy || !player || ! player_combat || !dialog)
return;
set_combat_player(player_combat, player);
set_combat_player(engine, player_combat, player);
this->current_enemy = NULL;
engine->change_scene(engine, this->game_scene);
engine->trigger_event(engine, "combat_ended", this->current_enemy, has_won);
+7 -2
View File
@@ -7,6 +7,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <components/renderer.h>
#include "systems/combat_manager.h"
#include "tile.h"
#include "prefab.h"
@@ -34,7 +35,7 @@ void combat_start(gc_engine *engine, char *enemy_name)
}
this->state = ATTACK;
this->game_scene = engine->scene;
set_combat_player(player, player_combat);
set_combat_player(engine, player, player_combat);
engine->scene = NULL;
engine->change_scene(engine, scene);
load_attacks(scene);
@@ -119,12 +120,16 @@ void defend_callback(gc_engine *engine)
struct combat_manager *this = GETSYS(engine, combat_manager);
gc_entity *player = NULL;
gc_entity *enemy = NULL;
struct renderer *rend;
if (!get_player_and_enemy(engine->scene, &player, &enemy))
return;
rend = GETCMP(player, renderer);
if (rend)
rend_set_anim(rend, "none");
if (GETCMP(enemy, health_component)->dead)
combat_end(engine, true);
if (this->next_enemy_attack->run)
else if (this->next_enemy_attack->run)
this->next_enemy_attack->run(engine, enemy, player);
this->state = ATTACK;
}