From dfbdb843271c69a381eb4b140c5f7076e67756e2 Mon Sep 17 00:00:00 2001 From: bgiraudr Date: Wed, 11 May 2022 00:37:56 +0200 Subject: [PATCH] Types are now working + bugfix event on area --- assets-cg/capacites/Charge.json | 1 + assets-cg/capacites/Cheat.json | 1 + assets-cg/capacites/Soin.json | 1 + assets-cg/capacites/TestCapacite.json | 1 + assets-cg/capacites/TestCapacite2.json | 1 + assets-cg/converters.py | 8 ++++-- assets-cg/maps/testCarte.tmx | 10 ++++---- assets-cg/monsters/test.json | 1 + assets-cg/monsters/test2.json | 1 + include/capacite.h | 9 +++++-- include/game.h | 1 + include/map.h | 2 +- include/monster.h | 1 + include/player.h | 2 ++ include/stats.h | 1 + src/battle.c | 26 ++++++++++++------- src/capacite.c | 35 ++++++++++++++++++++++---- src/engine.c | 2 +- src/game.c | 33 ++++++++++++------------ src/main.c | 17 ++++++++----- src/map.c | 12 ++++++++- src/player.c | 3 ++- src/stats.c | 1 + 23 files changed, 120 insertions(+), 50 deletions(-) diff --git a/assets-cg/capacites/Charge.json b/assets-cg/capacites/Charge.json index 1beb7e0..f81677c 100644 --- a/assets-cg/capacites/Charge.json +++ b/assets-cg/capacites/Charge.json @@ -2,6 +2,7 @@ "name":"Charge", "id":2, "categorie":"PHYSICAL", + "type":"Modérateur", "pp":25, "atk":15, "precision":100 diff --git a/assets-cg/capacites/Cheat.json b/assets-cg/capacites/Cheat.json index 5218493..1ee4491 100644 --- a/assets-cg/capacites/Cheat.json +++ b/assets-cg/capacites/Cheat.json @@ -2,6 +2,7 @@ "name":"Cheat", "id":3, "categorie":"PHYSICAL", + "type":"Administrateur", "pp":25, "atk":45, "precision":100 diff --git a/assets-cg/capacites/Soin.json b/assets-cg/capacites/Soin.json index 81b6ade..a78271c 100644 --- a/assets-cg/capacites/Soin.json +++ b/assets-cg/capacites/Soin.json @@ -2,6 +2,7 @@ "name":"Soin", "id":1, "categorie":"STATUT", + "type":"Rédacteur", "pp":100, "boost_atk":15, "boost_hp":15, diff --git a/assets-cg/capacites/TestCapacite.json b/assets-cg/capacites/TestCapacite.json index dbd1569..fbd8e6f 100644 --- a/assets-cg/capacites/TestCapacite.json +++ b/assets-cg/capacites/TestCapacite.json @@ -2,6 +2,7 @@ "name":"Test capacité", "id":0, "categorie":"SPECIAL", + "type":"Labélisateur", "pp":5, "atk":20, "precision":100 diff --git a/assets-cg/capacites/TestCapacite2.json b/assets-cg/capacites/TestCapacite2.json index 0528d96..bcdf1ad 100644 --- a/assets-cg/capacites/TestCapacite2.json +++ b/assets-cg/capacites/TestCapacite2.json @@ -2,6 +2,7 @@ "name":"Test capacité2", "id":4, "categorie":"PHYSICAL", + "type":"Rédacteur", "pp":5, "atk":20, "precision":100 diff --git a/assets-cg/converters.py b/assets-cg/converters.py index e29c34d..fb41748 100644 --- a/assets-cg/converters.py +++ b/assets-cg/converters.py @@ -191,8 +191,10 @@ def parseZone(layer): zone += fxconv.u32(origin[1]) zone += fxconv.u32(to[0]) zone += fxconv.u32(to[1]) - zone += fxconv.string(i["properties"][0]["value"]) #event - print(i["properties"][0]["value"]) + + event = bytes(i["properties"][0]["value"], "utf-8") + event += bytes(128 - len(event)) + zone += event #event monsters = bytes() zone += fxconv.u32(int(i["properties"][1]["value"]) if i["properties"][1]["value"] != "" else -1) #level @@ -229,6 +231,7 @@ def convert_capa(input, output, params, target): id_categorie = ["STATUT", "PHYSICAL", "SPECIAL"] move += fxconv.string(data["name"]) + move += fxconv.string(data["type"]) move += fxconv.u32(data["id"]) move += fxconv.u32(id_categorie.index(categorie)) move += fxconv.u32(data["pp"]) @@ -261,6 +264,7 @@ def convert_monster(input, output, params, target): stats = fxconv.Structure() if len(data["stats"]) != 6: raise Exception(f"convert_monster : Les statistiques de {data['name']} sont mauvaises") + stats+=fxconv.string(data["type"]) stats+=fxconv.u32(data["stats"]["atk"]) stats+=fxconv.u32(data["stats"]["def"]) stats+=fxconv.u32(data["stats"]["pv"]) diff --git a/assets-cg/maps/testCarte.tmx b/assets-cg/maps/testCarte.tmx index 3333c74..9d307ca 100644 --- a/assets-cg/maps/testCarte.tmx +++ b/assets-cg/maps/testCarte.tmx @@ -1,5 +1,5 @@ - + @@ -216,16 +216,16 @@ - + - + - - + + diff --git a/assets-cg/monsters/test.json b/assets-cg/monsters/test.json index 23521d1..2eff763 100644 --- a/assets-cg/monsters/test.json +++ b/assets-cg/monsters/test.json @@ -2,6 +2,7 @@ "name":"test", "sprite":"test", "id":1, + "type":"Labélisateur", "stats":{ "atk":10, "def":10, diff --git a/assets-cg/monsters/test2.json b/assets-cg/monsters/test2.json index 2573783..7ef4303 100644 --- a/assets-cg/monsters/test2.json +++ b/assets-cg/monsters/test2.json @@ -2,6 +2,7 @@ "name":"Citron", "sprite":"test2", "id":2, + "type":"Modérateur", "stats":{ "atk":80, "def":5, diff --git a/include/capacite.h b/include/capacite.h index 2da5124..793d87d 100644 --- a/include/capacite.h +++ b/include/capacite.h @@ -3,6 +3,7 @@ struct Move { char *name; + char *type; int id; int categorie; int init_pp; @@ -28,7 +29,10 @@ enum status { HEAL, ATK, DEF, - MULTIPLE + MULTIPLE, + SUPER_EFFECTIVE, + LESS_EFFECTIVE, + NOT_EFFECTIVE }; enum categorie { @@ -48,4 +52,5 @@ struct Move *get_move_id_pointer(int id); float crit(struct Stats *attacker); int is_crit(); int is_miss(struct Move *move); -int self_effect(struct Stats *stats, struct Move *move); \ No newline at end of file +int self_effect(struct Stats *stats, struct Move *move); +float stab(char *type, char *move); \ No newline at end of file diff --git a/include/game.h b/include/game.h index b658727..ee12c3b 100644 --- a/include/game.h +++ b/include/game.h @@ -18,6 +18,7 @@ enum action { DIR_UP, DIR_RIGHT, ACTION_SHIFT, + ACTION_MENU, ACTION_ALPHA, ACTION_OPTN, ACTION_F1, diff --git a/include/map.h b/include/map.h index 408e1f6..1f4b511 100644 --- a/include/map.h +++ b/include/map.h @@ -11,7 +11,7 @@ struct Teleporter { struct Zone { int start_x, start_y; int end_x, end_y; - char *event; + char event[128]; int level; int nbMonsters; short *monsters; diff --git a/include/monster.h b/include/monster.h index e9e2e38..b11f282 100644 --- a/include/monster.h +++ b/include/monster.h @@ -4,6 +4,7 @@ #include "capacite.h" #include "game.h" #include +#include "type.h" struct Monster { char *name; diff --git a/include/player.h b/include/player.h index 0e96554..b15f7cd 100644 --- a/include/player.h +++ b/include/player.h @@ -6,6 +6,7 @@ #include "capacite.h" #include "inventory.h" #include "define.h" +#include "type.h" struct Player { /*current position of the player on the map - Tile*/ @@ -17,6 +18,7 @@ struct Player { struct Stats stats; struct Move *moves[NB_PLAYER_MOVES]; struct Inventory inventory; + struct Type type; /*player mid - offset pixels*/ int x_mid, y_mid; /*the direction the player facing to*/ diff --git a/include/stats.h b/include/stats.h index ee6438d..1b59be0 100644 --- a/include/stats.h +++ b/include/stats.h @@ -1,6 +1,7 @@ #pragma once struct Stats { + char* type; int atk; int def; int pv; diff --git a/src/battle.c b/src/battle.c index e6cea88..2882cdd 100644 --- a/src/battle.c +++ b/src/battle.c @@ -8,6 +8,7 @@ #include "capacite.h" #include "player.h" #include "monster.h" +#include "talkable.h" #include extern bopti_image_t img_dialogue; @@ -92,6 +93,15 @@ void check_move_status(int status, struct Player *player, struct Monster *monste case MULTIPLE: draw_status(name, "améliore ses statistiques !"); break; + case SUPER_EFFECTIVE: + draw_status(name, "utilise une attaque super efficace !"); + break; + case LESS_EFFECTIVE: + draw_status(name, "utilise une attaque peu efficace"); + break; + case NOT_EFFECTIVE: + draw_status(name, "utilise une attaque non efficace..."); + break; } dupdate(); @@ -105,8 +115,7 @@ void finish_battle(int status, struct Game *game, struct Monster *monster) { //gain d'xp int xp = ceil((monster->stats->xp*monster->stats->level*1.5)/7); - dimage(42,DHEIGHT-75,&img_dialogue); - dprint(50,DHEIGHT-47, C_BLACK, "Vous remportez %d points d'experience", xp); + format_text(50, DHEIGHT-47, C_BLACK, "Vous remportez %d points d'experience", xp); dupdate(); wait_for_input(KEY_SHIFT); @@ -114,8 +123,7 @@ void finish_battle(int status, struct Game *game, struct Monster *monster) { } else if(status == LOSE) { draw_battle(game->player, monster); - dimage(42,DHEIGHT-75,&img_dialogue); - dprint(50,DHEIGHT-47,C_BLACK,"%s a eu raison de vous !", monster->name); + format_text(50, DHEIGHT-47, C_BLACK, "%s a eu raison de vous !", monster->name); dupdate(); wait_for_input(KEY_SHIFT); game->player->stats.pv = 0; @@ -188,6 +196,7 @@ void draw_battle(struct Player *player, struct Monster *monster) { dprint(333,124,C_BLACK,"%d",player->stats.level); dprint(246,124,C_BLACK,"%d/%d", player->stats.pv, player->stats.max_pv); + dtext(340,115,C_BLUE, player->stats.type); int posHPmonster = (float)monster->stats->pv / monster->stats->max_pv * WIDTH_HP; dprint(2,8,C_BLACK,"%s",monster->name); @@ -202,20 +211,19 @@ void draw_battle(struct Player *player, struct Monster *monster) { drect(48,23,48+posHPmonster,27,mcolor); dprint(90,9,C_BLACK,"%d",monster->stats->level); dprint(127,11,C_BLACK,"%d/%d", monster->stats->pv, monster->stats->max_pv); + dtext(92,0,C_BLUE, monster->stats->type); dimage(265,10,monster->sprite); } void draw_executed_move(struct Move *move, struct Monster *monster, int is_monster) { - dimage(42,DHEIGHT-75,&img_dialogue); if(is_monster) { - dprint(50,DHEIGHT-47, C_BLACK, "%s lance %s !", monster->name, move->name); + format_text(50, DHEIGHT-47, C_BLACK, "%s lance %s !", monster->name, move->name); } else { - dprint(50,DHEIGHT-47, C_BLACK, "Vous lancez %s !", move->name); + format_text(50, DHEIGHT-47, C_BLACK, "Vous lancez %s !", move->name); } } void draw_status(char *name, char *message) { - dimage(42,DHEIGHT-75,&img_dialogue); - dprint(50,DHEIGHT-47, C_BLACK, "%s %s", name, message); + format_text(50, DHEIGHT-47, C_BLACK, "%s %s", name, message); } \ No newline at end of file diff --git a/src/capacite.c b/src/capacite.c index 9a46dcb..2abd4a9 100644 --- a/src/capacite.c +++ b/src/capacite.c @@ -7,6 +7,7 @@ #include "capacite.h" #include "util.h" +#include "type.h" extern struct Capacities capacities; @@ -31,6 +32,7 @@ struct Move *get_move_id_pointer(int id) { struct Move *copy_move(struct Move move) { struct Move *copyMove = malloc(sizeof(struct Move)); copyMove->name = move.name; + copyMove->type = move.type; copyMove->init_pp = move.init_pp; copyMove->id = move.id; copyMove->categorie = move.categorie; @@ -67,6 +69,7 @@ void draw_move(int x, int y, int x2, int y2, struct Move *move) { dprint(x+15, y2-17, C_BLACK, "ATK : %d", move->atk); dprint(x+70, y2-17, C_BLACK, "PRE : %d", move->precision); } + dtext(x+50, y+15, C_BLUE, move->type); } void draw_classic_move(int x, int y, struct Move *move) { @@ -81,13 +84,19 @@ int execute_move(struct Stats *player_stats, struct Stats *monster_stats, struct return MISS; } + float typeEffect; if(ismonster) { player_stats->pv-=calc_damage(monster_stats, player_stats, move); + typeEffect = getTypeEffect(getTypeFromName(move->type), getTypeFromName(player_stats->type)); } else { move->pp--; monster_stats->pv-=calc_damage(player_stats, monster_stats, move); + typeEffect = getTypeEffect(getTypeFromName(move->type), getTypeFromName(monster_stats->type)); } + if(typeEffect == 2) return SUPER_EFFECTIVE; + if(typeEffect == 0.5) return LESS_EFFECTIVE; + if(typeEffect == 0) return NOT_EFFECTIVE; if(is_crit()) return CRIT; } else { if(ismonster) { @@ -102,11 +111,27 @@ int execute_move(struct Stats *player_stats, struct Stats *monster_stats, struct } int calc_damage(struct Stats *attacker, struct Stats *target, struct Move *move) { - if(move->categorie == PHYSICAL) - return floor((floor(((2*attacker->level / 5 + 2) * attacker->atk * move->atk / target->def) / 50) + 2)*crit(attacker)); - if(move->categorie == SPECIAL) - return floor((floor(((2*attacker->level / 5 + 2) * attacker->spe_atk * move->atk / target->spe_def) / 50) + 2)*crit(attacker)); - return 0; + int atk =1, def = 1; + if(move->categorie == PHYSICAL) { + atk = attacker->atk; + def = target->def; + } else if(move->categorie == SPECIAL) { + atk = attacker->spe_atk; + def = target->spe_def; + } + + if(getTypeEffect(getTypeFromName(move->type), getTypeFromName(target->type)) == 0) return 0; + return floor((floor(((2*attacker->level / 5 + 2) * atk * + move->atk + *getTypeEffect(getTypeFromName(move->type), getTypeFromName(target->type)) + *stab(attacker->type, move->type) + / def) + / 50) + 2)*crit(attacker)); +} + +float stab(char *type, char *move) { + if(!strcmp(type, move)) return 1.5f; + return 1.0f; } int is_crit() { diff --git a/src/engine.c b/src/engine.c index ff4410b..5885c2d 100644 --- a/src/engine.c +++ b/src/engine.c @@ -135,7 +135,7 @@ void engine_action(struct Game *game, int action) { } if(action == ACTION_F2) { //add_item_to_inventory(game, &game->player->inventory, get_item_id(1)); - srand(game->player->pos.x * game->player->pos.y); + // srand(game->player->pos.x * game->player->pos.y); drawTypeEffects(getTypeFromId(rand_range(1,5))); } if(action == ACTION_OPTN) { diff --git a/src/game.c b/src/game.c index 5d653f1..2518506 100644 --- a/src/game.c +++ b/src/game.c @@ -23,23 +23,22 @@ int get_inputs(void) { int opt = GETKEY_DEFAULT & GETKEY_REP_ARROWS; int timeout = 1; - while(1) { + key_event_t ev = getkey_opt(opt, &timeout); + if(ev.type == KEYEV_NONE) return -1; + int key = ev.key; + if(key == KEY_MENU) return ACTION_MENU; - key_event_t ev = getkey_opt(opt, &timeout); - if(ev.type == KEYEV_NONE) return -1; - int key = ev.key; + /*direction*/ + if(key == KEY_DOWN) return DIR_DOWN; + if(key == KEY_RIGHT) return DIR_RIGHT; + if(key == KEY_UP) return DIR_UP; + if(key == KEY_LEFT) return DIR_LEFT; - /*direction*/ - if(key == KEY_DOWN) return DIR_DOWN; - if(key == KEY_RIGHT) return DIR_RIGHT; - if(key == KEY_UP) return DIR_UP; - if(key == KEY_LEFT) return DIR_LEFT; - - /*action key*/ - if(key == KEY_SHIFT) return ACTION_SHIFT; - if(key == KEY_ALPHA) return ACTION_ALPHA; - if(key == KEY_OPTN) return ACTION_OPTN; - if(key == KEY_F1) return ACTION_F1; - if(key == KEY_F2) return ACTION_F2; - } + /*action key*/ + if(key == KEY_SHIFT) return ACTION_SHIFT; + if(key == KEY_ALPHA) return ACTION_ALPHA; + if(key == KEY_OPTN) return ACTION_OPTN; + if(key == KEY_F1) return ACTION_F1; + if(key == KEY_F2) return ACTION_F2; + return -1; } diff --git a/src/main.c b/src/main.c index c391eea..93d95d7 100644 --- a/src/main.c +++ b/src/main.c @@ -42,19 +42,24 @@ int main(void) { dupdate_set_hook(GINT_CALL(take_capture)); /*Main loop*/ - while(!keydown(KEY_MENU)) { + while(1) { while(!tick) sleep(); tick = 0; engine_draw(&game); dupdate(); - int action = get_inputs(); - if(action >= 0 && action <= 3) - engine_move(&game, action); - else if(action >= 4) { - engine_action(&game, action); + int action = 0; + while(action != -1) { + action = get_inputs(); + if(action == ACTION_MENU) break; + if(action >= DIR_DOWN && action <= DIR_RIGHT) + engine_move(&game, action); + else if(action >= ACTION_SHIFT) { + engine_action(&game, action); + } } + if(action == ACTION_MENU) break; engine_tick(&game, ENGINE_TICK); } diff --git a/src/map.c b/src/map.c index 84ec366..51de169 100644 --- a/src/map.c +++ b/src/map.c @@ -13,6 +13,16 @@ struct Map *maps[] = { &map_2, }; +struct Zone default_zone = { + .start_x = 0, + .start_y = 0, + .end_x = 0, + .end_y = 0, + .event = "", + .level = -1, + .nbMonsters = 0 +}; + /*check if a tile is walkable*/ int map_walkable(struct Map const *map, int x, int y) { int tile = map->info_map[x + map->w * y]; @@ -84,5 +94,5 @@ struct Zone get_zone(struct Player *player, struct Map *map) { struct Zone zone = map->zones[i]; if(zone.start_x <= posx && zone.start_y <= posy && zone.end_x >= posx && zone.end_y >= posy) return zone; } - return map->zones[0]; + return default_zone; } \ No newline at end of file diff --git a/src/player.c b/src/player.c index 41c9480..576cf95 100644 --- a/src/player.c +++ b/src/player.c @@ -28,7 +28,8 @@ struct Player init_player(void) { struct Stats stats = { .level = 1, - .xp = 0 + .xp = 0, + .type = "Rédacteur" }; struct Inventory inventory = { diff --git a/src/stats.c b/src/stats.c index a0dcc71..dd066de 100644 --- a/src/stats.c +++ b/src/stats.c @@ -15,6 +15,7 @@ void draw_stats(struct Stats stats) { dprint(300,120,C_BLACK,"ATKS : %d",stats.spe_atk); dprint(300,140,C_BLACK,"DEFS : %d",stats.spe_def); dprint(300,160,C_BLACK,"LVLUP : %d",(int)(pow(stats.level+1, 3.03))-stats.xp); + dprint(300, 180, C_BLUE, stats.type); } void set_stats_level_from(const struct Stats *from, struct Stats *to) {