summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2015-01-10 21:33:00 +0100
committerOlivier Gayot <duskcoder@gmail.com>2015-01-10 21:37:01 +0100
commitc3e0eaf45432f62b423cee2170a09b5d1aac135b (patch)
tree71da9bdcb5b55a5fb71fab5aef524ab12c1330d4
parentd98cf9e97a61b175649fa9fe656cb8ec2874686c (diff)
allow to pass the resolution as arguments
example (for my netbook): $ ./a.out 1024 600 Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
-rw-r--r--constantes.h3
-rw-r--r--menuchoixpersos.c6
-rw-r--r--rpg.c33
-rw-r--r--rpg.h3
4 files changed, 25 insertions, 20 deletions
diff --git a/constantes.h b/constantes.h
index dc647ba..eb530f9 100644
--- a/constantes.h
+++ b/constantes.h
@@ -5,9 +5,6 @@
#define OPTIONS 1
#define QUITTER 2
-#define XWIN 1024
-#define YWIN 768
-
enum character_class_t {
CLASS_INVAL = -1,
diff --git a/menuchoixpersos.c b/menuchoixpersos.c
index 66ae603..90c36a4 100644
--- a/menuchoixpersos.c
+++ b/menuchoixpersos.c
@@ -62,7 +62,7 @@ static void init_team_players(struct team_t *team, bool left,
chr->affinities[j] = rand() % AFFINITY_COUNT;
}
- chr->pos.y = (YWIN / ((team->chr_cnt + 1) * 2)) * (2 * (i + 1)) - chr->surf->h / 2;
+ chr->pos.y = (rpg_g.screen->h / ((team->chr_cnt + 1) * 2)) * (2 * (i + 1)) - chr->surf->h / 2;
if (left) {
chr->curs = surfaces->Pcurseurallies;
@@ -70,7 +70,7 @@ static void init_team_players(struct team_t *team, bool left,
chr->pos_curs.x = chr->pos.x + chr->surf->w + 20;
} else {
chr->curs = surfaces->Pcurseurennemis;
- chr->pos.x = XWIN - chr->surf->w - 20;
+ chr->pos.x = surfaces->screen->w - chr->surf->w - 20;
chr->pos_curs.x = chr->pos.x - chr->curs->w - 20;
}
@@ -194,7 +194,7 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions)
/* display the string associated with the current character number (aka Please choose ...) */
surfaces->Ptextechoixmenu = TTF_RenderText_Blended(rpg_g.font, strings[Vnbperso], vert);
- positions->Vpositiontextemenu.x=XWIN/2-surfaces->Ptextechoixmenu->w/2;
+ positions->Vpositiontextemenu.x = surfaces->screen->w / 2 - surfaces->Ptextechoixmenu->w / 2;
SDL_BlitSurface (surfaces->Ptextechoixmenu,NULL,surfaces->Pecran,&positions->Vpositiontextemenu);
SDL_BlitSurface (surfaces->Ppretre,NULL,surfaces->Pecran,&positions->Vpositionmenupretre);
diff --git a/rpg.c b/rpg.c
index 6379f6d..f76d742 100644
--- a/rpg.c
+++ b/rpg.c
@@ -181,12 +181,12 @@ static void Finitialiserpositions (POSITIONS *positions, const SURFACES *surface
int i,y=0,z=0;
positions->Vpositionmenu.x = 0;
positions->Vpositionmenu.y = 0;
- positions->Vpositionmenupretre.x = XWIN/2 - surfaces->Ppretre->w/2;
- positions->Vpositionmenupretre.y = YWIN - 20 - surfaces->Ppretre->h;
+ positions->Vpositionmenupretre.x = surfaces->screen->w / 2 - surfaces->Ppretre->w / 2;
+ positions->Vpositionmenupretre.y = surfaces->screen->h - 20 - surfaces->Ppretre->h;
positions->Vpositionmenupaladin.x = positions->Vpositionmenupretre.x/2 - surfaces->Ppaladin->w/2;
- positions->Vpositionmenupaladin.y = YWIN - 20 - surfaces->Ppaladin->h;
- positions->Vpositionmenuvoleur.x = XWIN/4*3 - surfaces->Pvoleur->w/2;
- positions->Vpositionmenuvoleur.y = YWIN - 20 - surfaces->Pvoleur->h;
+ positions->Vpositionmenupaladin.y = surfaces->screen->h - 20 - surfaces->Ppaladin->h;
+ positions->Vpositionmenuvoleur.x = surfaces->screen->w / 4 * 3 - surfaces->Pvoleur->w / 2;
+ positions->Vpositionmenuvoleur.y = surfaces->screen->h - 20 - surfaces->Pvoleur->h;
positions->Vpositiontextemenu.y = 362;
positions->Vpositioncurseurennemis.x=1024;
positions->Vpositioncurseurennemis.y=768;
@@ -195,11 +195,11 @@ static void Finitialiserpositions (POSITIONS *positions, const SURFACES *surface
positions->Vpositioncurseurennemis.w = surfaces->Pcurseurennemis->w;
positions->Vpositioncurseurennemis.h = surfaces->Pcurseurennemis->h;
positions->Vpositioncadrecible.y = 15;
- positions->Vpositioncadrecible.x = XWIN/2-50-surfaces->Pcadrecible->w/2;
+ positions->Vpositioncadrecible.x = surfaces->screen->w / 2 - 50 - surfaces->Pcadrecible->w / 2;
positions->Vpositioncadrecible.w = surfaces->Pcadrecible->w;
positions->Vpositioncadrecible.h = surfaces->Pcadrecible->h;
- positions->Vpositioncadreactions.y = YWIN-surfaces->Pcadreactions->h;
- positions->Vpositioncadreactions.x = XWIN/2-50-surfaces->Pcadreactions->w/2;
+ positions->Vpositioncadreactions.y = surfaces->screen->h - surfaces->Pcadreactions->h;
+ positions->Vpositioncadreactions.x = surfaces->screen->w / 2 - 50 - surfaces->Pcadreactions->w / 2;
positions->Vpositioncadreactions.w = surfaces->Pcadreactions->w;
positions->Vpositioncadreactions.h = surfaces->Pcadreactions->h;
positions->Vpositionpvcible.x = 380;
@@ -233,7 +233,7 @@ static void Finitialiserpositions (POSITIONS *positions, const SURFACES *surface
positions->last_cursor = (SDL_Rect){0, 0, 0, 0};
}
-static int rpg_init(void)
+static int rpg_init(int width, int height)
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "SDL_Init: %s\n", SDL_GetError());
@@ -261,7 +261,7 @@ static int rpg_init(void)
return -1;
}
- rpg_g.screen = SDL_SetVideoMode(XWIN, YWIN, 0, SDL_HWSURFACE | SDL_DOUBLEBUF);
+ rpg_g.screen = SDL_SetVideoMode(width, height, 0, SDL_HWSURFACE | SDL_DOUBLEBUF);
if (rpg_g.screen == NULL) {
fprintf(stderr, "SDL_SetVideoMode: %s\n", SDL_GetError());
@@ -344,13 +344,18 @@ static void rpg_shutdown(void)
int main (int argc, char *argv[])
{
- /* XXX argc and argv are required in some implementations of the SDL library */
- (void) argc;
- (void) argv;
+ int width = DEFAULT_WIDTH;
+ int height = DEFAULT_HEIGHT;
+
+ /* TODO handle arguments properly */
+ if (argc >= 3) {
+ width = atoi(argv[1]);
+ height = atoi(argv[2]);
+ }
srand(time(NULL));
- if (rpg_init() >= 0) {
+ if (rpg_init(width, height) >= 0) {
Fmenuprincipal(&rpg_g.surfaces, &rpg_g.positions);
}
diff --git a/rpg.h b/rpg.h
index ff88b10..d4ae97f 100644
--- a/rpg.h
+++ b/rpg.h
@@ -6,6 +6,9 @@
#include "structures.h"
+#define DEFAULT_WIDTH 1024
+#define DEFAULT_HEIGHT 768
+
struct rpg_t {
SDL_Surface *screen;