summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2015-01-07 23:13:14 +0100
committerOlivier Gayot <duskcoder@gmail.com>2015-01-07 23:32:31 +0100
commit7bb8e452b2f2349ea2fae60eaf69adbcf7a182a8 (patch)
tree933c37e748ae4364bdecda4fc4fdb54f2adaadbf
parent92dc9315b9bb8576373b1f2325a049dd5490a9f6 (diff)
the generation of the team is now generic
we can now pass any team and it will be generated. Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
-rw-r--r--menuchoixpersos.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/menuchoixpersos.c b/menuchoixpersos.c
index 91e0c7d..0d580c6 100644
--- a/menuchoixpersos.c
+++ b/menuchoixpersos.c
@@ -8,23 +8,15 @@
#include <SDL/SDL_ttf.h>
#include "players.h"
-static
-struct team_t *new_ally_team(SURFACES *surfaces,
- const enum character_class_t *classes, int cnt)
+static void init_team_players(struct team_t *team, bool left,
+ const enum character_class_t *classes, SURFACES *surfaces)
{
- 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->cpu = team->cpu;
chr->class_ = classes[i];
chr->alive = true;
@@ -65,9 +57,24 @@ struct team_t *new_ally_team(SURFACES *surfaces,
}
/* set its position */
- chr->pos.x = 20;
- chr->pos.y = (YWIN / (cnt + 1)) * (i + 1) - chr->def_surf->h / 2;
+ chr->pos.x = (left) ? 20 : XWIN - chr->surf->w - 20;
+ chr->pos.y = (YWIN / ((team->chr_cnt + 1) * 2)) * (2 * (i + 1)) - chr->surf->h / 2;
}
+}
+
+
+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);
+
+ init_team_players(team, true, classes, surfaces);
return team;
}