diff options
author | Olivier Gayot <og@satcom1.com> | 2016-09-04 17:59:59 +0200 |
---|---|---|
committer | Olivier Gayot <og@satcom1.com> | 2016-09-04 18:00:35 +0200 |
commit | 3b3ed255a05eb0a0a3ed2886c010b952c1b1bd8c (patch) | |
tree | f08b104c4d62095835d1ab5a6332356b251bad01 | |
parent | 0a58c87f21ec0717e17318528a7c252c9d0997e7 (diff) |
Signed-off-by: Olivier Gayot <og@satcom1.com>
-rw-r--r-- | battle.c | 26 | ||||
-rw-r--r-- | battle.h | 17 | ||||
-rw-r--r-- | map.c | 15 |
3 files changed, 52 insertions, 6 deletions
@@ -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 */ @@ -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 } |