From 1d882c00f645623a756f4d7a290676ea1332fbb1 Mon Sep 17 00:00:00 2001 From: Damien Appert Date: Sat, 11 Sep 2010 17:33:59 +0000 Subject: modif du fichier alien.c pour 2 joueurs ... ça plante après un temps aléatoire ==> problème d'allocation mémoire ? MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///var/svn/2010-netlemmings/trunk@7 077b3477-7977-48bd-8428-443f22f7bfda --- jeu-test/aliens-1.0.2/aliens.c | 108 ++++++++++++++++++++--------- jeu-test/aliens-1.0.2/aliensOriginel.c.zip | Bin 0 -> 3897 bytes 2 files changed, 76 insertions(+), 32 deletions(-) create mode 100644 jeu-test/aliens-1.0.2/aliensOriginel.c.zip (limited to 'jeu-test') diff --git a/jeu-test/aliens-1.0.2/aliens.c b/jeu-test/aliens-1.0.2/aliens.c index 234c239..beade4f 100644 --- a/jeu-test/aliens-1.0.2/aliens.c +++ b/jeu-test/aliens-1.0.2/aliens.c @@ -47,6 +47,7 @@ #define ALIEN_SPEED 5 #define ALIEN_ODDS (1*FRAMES_PER_SEC) #define EXPLODE_TIME 4 +#define NUMBER_PLAYER 2 typedef struct { int alive; @@ -59,7 +60,7 @@ typedef struct { SDL_Surface *screen; SDL_Surface *background; /**/ -object player; +object player[NUMBER_PLAYER]; int reloading; object shots[MAX_SHOTS]; /**/ @@ -130,10 +131,17 @@ int LoadData(void) sounds[EXPLODE_WAV] = Mix_LoadWAV(DATAFILE("explode.wav")); /* Load graphics */ - player.image = LoadImage(DATAFILE("player.gif"), 1); - if ( player.image == NULL ) { + + //INFO : j'ai fai comme pour les autre objets + player[0].image = LoadImage(DATAFILE("player.gif"), 1); + if ( player[0].image == NULL ) { + printf("erreur creation player %c\n",0); return(0); } + for(i=1;iw - player.image->w)/2; - player.y = (screen->h - player.image->h) - 1; - player.facing = 0; - DrawObject(&player); + + for (i=0;iw - player[i].image->w)/(NUMBER_PLAYER+1)*(i+1); + player[i].y = (screen->h - player[i].image->h) - 1; + player[i].facing = 0; + DrawObject(&player[i]); + } + for ( i=0; iw-shots[i].image->w)/2; - shots[i].y = player.y - - shots[i].image->h; + //FIXME : c pour tester => je fais tirer les 2 joueurs en même temps + // on va rester sur le player 0 ... + shots[i].x = player[0].x + (player[0].image->w-shots[i].image->w)/2; + shots[i].y = player[0].y - shots[i].image->h; + + /*shots[i].x = player[1].x + + (player[1].image->w-shots[i].image->w)/2; + shots[i].y = player[1].y - + shots[i].image->h;*/ shots[i].alive = 1; Mix_PlayChannel(SHOT_WAV, sounds[SHOT_WAV], 0); @@ -397,21 +422,29 @@ void RunGame(void) reloading = (keys[SDLK_SPACE] == SDL_PRESSED); /* Move the player */ - player.facing = 0; + player[0].facing = 0; + player[1].facing = 0; if ( keys[SDLK_RIGHT] ) { - ++player.facing; + ++player[0].facing; } if ( keys[SDLK_LEFT] ) { - --player.facing; + --player[0].facing; } - player.x += player.facing*PLAYER_SPEED; - if ( player.x < 0 ) { - player.x = 0; - } else - if ( player.x >= (screen->w-player.image->w) ) { - player.x = (screen->w-player.image->w)-1; + if ( keys[SDLK_UP] ) { + ++player[1].facing; + } + if ( keys[SDLK_DOWN] ) { + --player[1].facing; + } + for(i=0;i= (screen->w-player[i].image->w) ) { + player[i].x = (screen->w-player[i].image->w)-1; + } } - /* Move the aliens */ for ( i=0; i