From 45d54652a8005ccae2466a0e4757017c7b337e3b Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Wed, 7 Jan 2015 21:43:18 +0100 Subject: use a team / character model instead of an array of personnages Signed-off-by: Olivier Gayot --- menuchoixpersos.c | 88 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 26 deletions(-) (limited to 'menuchoixpersos.c') diff --git a/menuchoixpersos.c b/menuchoixpersos.c index 7790255..05e1a0a 100644 --- a/menuchoixpersos.c +++ b/menuchoixpersos.c @@ -6,6 +6,63 @@ #include "prototypes.h" #include #include +#include "players.h" + +static +struct team_t *new_ally_team(SURFACES *surfaces, + const enum character_class_t *classes, int cnt) +{ + struct team_t *team = malloc(sizeof(struct team_t)); + + team->name = "Team Player"; + team->cpu = false; + team->chr_cnt = cnt; + team->chrs = malloc(sizeof(struct character_t) * team->chr_cnt); + + for (int i = 0; i < team->chr_cnt; i++) { + struct character_t *chr = &team->chrs[i]; + + chr->name = "Player"; + chr->cpu = false; + chr->team = team; + chr->class_ = classes[i]; + chr->alive = true; + + switch (chr->class_) { + case CLASS_PALADIN: + chr->def_surf = surfaces->Ppaladin; + chr->red_surf = surfaces->red_paladin; + break; + case CLASS_PRIEST: + chr->def_surf = surfaces->Ppretre; + chr->red_surf = surfaces->red_priest; + break; + case CLASS_THIEF: + chr->def_surf = surfaces->Pvoleur; + chr->red_surf = surfaces->red_thief; + break; + default: + abort(); + } + + chr->surf = chr->def_surf; + + chr->hp = base_stats_g[chr->class_].hp; + chr->max_hp = base_stats_g[chr->class_].hp; + chr->mp = base_stats_g[chr->class_].mp; + chr->max_mp = base_stats_g[chr->class_].mp; + chr->magic = base_stats_g[chr->class_].magic; + chr->strength = base_stats_g[chr->class_].strength; + chr->defense = base_stats_g[chr->class_].defense; + chr->spirit = base_stats_g[chr->class_].spirit; + + /* set its position */ + chr->pos.x = 20; + chr->pos.y = (YWIN / (cnt + 1)) * (i + 1) - chr->def_surf->h / 2; + } + + return team; +} void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) { @@ -13,7 +70,8 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) int Vchoix = PALADIN; SDL_Color vert; bool continuer = true; - PERSONNAGES persos[3]; + struct team_t *ally_team; + enum character_class_t chr_classes[3]; ENNEMIS ennemis[5]; SDL_Event event; int Vnbperso = 0; @@ -84,7 +142,7 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) break; case SDLK_RETURN: case SDLK_f: - persos[Vnbperso++].classe = Vchoix; + chr_classes[Vnbperso++] = Vchoix; continuer = false; break; default: @@ -96,8 +154,8 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) } TTF_CloseFont (police); SDL_Flip(surfaces->Pecran); - Fremplirpersos2 (surfaces,persos); - Fmap(surfaces,positions,persos,ennemis); + ally_team = new_ally_team(surfaces, chr_classes, 3); + Fmap(surfaces,positions, ally_team,ennemis); } void Fchangersurlignage2 (int Vchoix, SURFACES *surfaces, POSITIONS *positions) @@ -115,28 +173,6 @@ void Fchangersurlignage2 (int Vchoix, SURFACES *surfaces, POSITIONS *positions) SDL_Flip (surfaces->Pecran); } -void Fremplirpersos2 (SURFACES *surfaces, PERSONNAGES persos[]) -{ - - int i; - - for (i = 0; i < 3; i++) { - switch (persos[i].classe) { - case PALADIN: - surfaces->Tperso[i] = surfaces->Ppaladin; - break; - case PRETRE: - surfaces->Tperso[i] = surfaces->Ppretre; - break; - case VOLEUR: - surfaces->Tperso[i] = surfaces->Pvoleur; - break; - default: - abort(); - } - } -} - void Fremplirennemis (SURFACES *surfaces,int Vnbennemis,ENNEMIS ennemis[]) { -- cgit v1.2.3