summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--battle.c26
-rw-r--r--battle.h17
-rw-r--r--map.c15
3 files changed, 52 insertions, 6 deletions
diff --git a/battle.c b/battle.c
index 874d27a..44764b7 100644
--- a/battle.c
+++ b/battle.c
@@ -1,3 +1,5 @@
+#include "battle.h"
+
#include "rpg.h"
#include "structures.h"
@@ -462,11 +464,29 @@ static bool is_battle_over(const struct team_t *t1, const struct team_t *t2)
return get_first_alive_character(t2) == NULL;
}
-int battle(struct team_t *t1, struct team_t *t2)
+int battle_init(struct battle_t *battle, struct team_t *t1, struct team_t *t2)
{
+ battle->t1 = t1;
+ battle->t2 = t2;
+
+ battle->background = rpg_g.surfaces.background;
+
+ return 0;
+}
+
+void battle_close(struct battle_t *battle)
+{
+ (void) battle;
+}
+
+int battle_run(struct battle_t *battle)
+{
+ struct team_t *t1 = battle->t1;
+ struct team_t *t2 = battle->t2;
+
struct team_t *playing_team;
- SDL_BlitSurface(rpg_g.surfaces.background, NULL, rpg_g.screen, NULL);
+ SDL_BlitSurface(battle->background, NULL, rpg_g.screen, NULL);
/* compute whether the allies or the enemies should begin */
playing_team = (rand() % 2) ? t1 : t2;
@@ -498,7 +518,7 @@ int battle(struct team_t *t1, struct team_t *t2)
SDL_Delay(1000);
- SDL_BlitSurface(rpg_g.surfaces.background, &rpg_g.positions.degats,
+ SDL_BlitSurface(battle->background, &rpg_g.positions.degats,
rpg_g.screen, &rpg_g.positions.degats);
SDL_Flip(rpg_g.screen);
diff --git a/battle.h b/battle.h
new file mode 100644
index 0000000..962f4b3
--- /dev/null
+++ b/battle.h
@@ -0,0 +1,17 @@
+#ifndef BATTLE_H
+#define BATTLE_H
+
+#include "players.h"
+
+struct battle_t {
+ struct team_t *t1;
+ struct team_t *t2;
+
+ SDL_Surface *background;
+};
+
+int battle_init(struct battle_t *battle, struct team_t *t1, struct team_t *t2);
+int battle_run(struct battle_t *battle);
+void battle_close(struct battle_t *battle);
+
+#endif /* BATTLE_H */
diff --git a/map.c b/map.c
index 6783873..d2e2c30 100644
--- a/map.c
+++ b/map.c
@@ -1,7 +1,8 @@
-#include <stdio.h>
-#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
+
+#include "battle.h"
+
#include "constantes.h"
#include "structures.h"
#include "prototypes.h"
@@ -46,7 +47,15 @@ void Fmap (SURFACES*surfaces, POSITIONS* positions,
(void) surfaces;
(void) positions;
- battle(t1, t2);
+ struct battle_t battle;
+
+ if (battle_init(&battle, t1, t2) < 0) {
+ return;
+ }
+
+ battle_run(&battle);
+
+ battle_close(&battle);
#endif
}