diff options
author | Damien Appert <dappert> | 2010-09-11 17:33:59 +0000 |
---|---|---|
committer | Damien Appert <dappert> | 2010-09-11 17:33:59 +0000 |
commit | 1d882c00f645623a756f4d7a290676ea1332fbb1 (patch) | |
tree | b8b067fed2a650e74e3f78765806e4f7197ec950 /jeu-test | |
parent | a30f4467cdb9d4e8e306d7f77fea9041ec6191e3 (diff) | |
download | 2010-netlemmings-1d882c00f645623a756f4d7a290676ea1332fbb1.tar.gz 2010-netlemmings-1d882c00f645623a756f4d7a290676ea1332fbb1.tar.bz2 2010-netlemmings-1d882c00f645623a756f4d7a290676ea1332fbb1.zip |
modif du fichier alien.c pour 2 joueurs ... ça plante après un temps aléatoire ==> problème d'allocation mémoire ?
git-svn-id: file:///var/svn/2010-netlemmings/trunk@7 077b3477-7977-48bd-8428-443f22f7bfda
Diffstat (limited to 'jeu-test')
-rw-r--r-- | jeu-test/aliens-1.0.2/aliens.c | 108 | ||||
-rw-r--r-- | jeu-test/aliens-1.0.2/aliensOriginel.c.zip | bin | 0 -> 3897 bytes |
2 files changed, 76 insertions, 32 deletions
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;i<NUMBER_PLAYER;++i){ + player[i].image = player[0].image; + } + shots[0].image = LoadImage(DATAFILE("shot.gif"), 0); if ( shots[0].image == NULL ) { return(0); @@ -175,7 +183,10 @@ void FreeData(void) } /* Free graphics */ - SDL_FreeSurface(player.image); + SDL_FreeSurface(player[0].image); + //FIXME: ligne utile ? + //SDL_FreeSurface(player[1].image); + SDL_FreeSurface(shots[0].image); SDL_FreeSurface(aliens[0].image); SDL_FreeSurface(explosions[0].image); @@ -318,11 +329,16 @@ void RunGame(void) SDL_UpdateRect(screen, 0, 0, 0, 0); /* Initialize the objects */ - player.alive = 1; - player.x = (screen->w - player.image->w)/2; - player.y = (screen->h - player.image->h) - 1; - player.facing = 0; - DrawObject(&player); + + for (i=0;i<NUMBER_PLAYER;++i){ + player[i].alive = 1; + //TODO : verif les bornes et les positions + player[i].x = (screen->w - 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; i<MAX_SHOTS; ++i ) { shots[i].alive = 0; @@ -334,7 +350,8 @@ void RunGame(void) DrawObject(&aliens[0]); UpdateScreen(); - while ( player.alive ) { + //FIXME faire pour tous les player + while ( player[0].alive && player[1].alive ) { /* Wait for the next frame */ WaitFrame(); @@ -356,7 +373,10 @@ void RunGame(void) EraseObject(&aliens[i]); } } - EraseObject(&player); + for (i=0;i<NUMBER_PLAYER;++i){ + EraseObject(&player[i]); + } + for ( i=0; i<MAX_ALIENS+1; ++i ) { if ( explosions[i].alive ) { EraseObject(&explosions[i]); @@ -384,10 +404,15 @@ void RunGame(void) } } if ( i != MAX_SHOTS ) { - shots[i].x = player.x + - (player.image->w-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<NUMBER_PLAYER;++i){ + player[i].x += player[i].facing*PLAYER_SPEED; + if ( player[i].x < 0 ) { + player[i].x = 0; + } else + if ( player[i].x >= (screen->w-player[i].image->w) ) { + player[i].x = (screen->w-player[i].image->w)-1; + } } - /* Move the aliens */ for ( i=0; i<MAX_ALIENS; ++i ) { if ( aliens[i].alive ) { @@ -458,14 +491,22 @@ void RunGame(void) } } for ( i=0; i<MAX_ALIENS; ++i ) { - if ( aliens[i].alive && Collide(&player, &aliens[i]) ) { + if ( aliens[i].alive && Collide(&player[i], &aliens[i]) ) { aliens[i].alive = 0; explosions[i].x = aliens[i].x; explosions[i].y = aliens[i].y; explosions[i].alive = EXPLODE_TIME; - player.alive = 0; - explosions[MAX_ALIENS].x = player.x; - explosions[MAX_ALIENS].y = player.y; + //FIXME lol hey les aliens doivent exploser sur la case des players :p + // suicide collectif + // sinon faire pour tous les players + player[0].alive = 0; + player[1].alive = 1; + explosions[MAX_ALIENS].x = player[0].x; + explosions[MAX_ALIENS].y = player[0].y; + + explosions[MAX_ALIENS].x = player[1].x; + explosions[MAX_ALIENS].y = player[1].y; + explosions[MAX_ALIENS].alive = EXPLODE_TIME; Mix_PlayChannel(EXPLODE_WAV, sounds[EXPLODE_WAV], 0); @@ -483,8 +524,10 @@ void RunGame(void) DrawObject(&shots[i]); } } - if ( player.alive ) { - DrawObject(&player); + for(i=0;i<NUMBER_PLAYER;++i){ + if ( player[i].alive ) { + DrawObject(&player[i]); + } } for ( i=0; i<MAX_ALIENS+1; ++i ) { if ( explosions[i].alive ) { @@ -506,7 +549,8 @@ void RunGame(void) /* Check for keyboard abort */ if ( keys[SDLK_ESCAPE] == SDL_PRESSED ) { - player.alive = 0; + player[0].alive = 0; + player[1].alive = 0; } } diff --git a/jeu-test/aliens-1.0.2/aliensOriginel.c.zip b/jeu-test/aliens-1.0.2/aliensOriginel.c.zip Binary files differnew file mode 100644 index 0000000..b8c50b7 --- /dev/null +++ b/jeu-test/aliens-1.0.2/aliensOriginel.c.zip |