summaryrefslogtreecommitdiff
path: root/jeu-test
diff options
context:
space:
mode:
authorDamien Appert <dappert>2010-09-12 09:16:38 +0000
committerDamien Appert <dappert>2010-09-12 09:16:38 +0000
commitcd8db6ca8ab66daf42b842f160a5b2ff6469224e (patch)
tree9e3c0c9ccba48cbfb1f030f26a366745a6290c17 /jeu-test
parenteecc234013c0edef66197837dc94d07d7002f783 (diff)
download2010-netlemmings-cd8db6ca8ab66daf42b842f160a5b2ff6469224e.tar.gz
2010-netlemmings-cd8db6ca8ab66daf42b842f160a5b2ff6469224e.tar.bz2
2010-netlemmings-cd8db6ca8ab66daf42b842f160a5b2ff6469224e.zip
finition du jeu alien en multi en local jusqu'à 4 joueurs
git-svn-id: file:///var/svn/2010-netlemmings/trunk@9 077b3477-7977-48bd-8428-443f22f7bfda
Diffstat (limited to 'jeu-test')
-rw-r--r--jeu-test/aliens-1.0.2/aliens.c115
1 files changed, 65 insertions, 50 deletions
diff --git a/jeu-test/aliens-1.0.2/aliens.c b/jeu-test/aliens-1.0.2/aliens.c
index 05b6a0d..f08177f 100644
--- a/jeu-test/aliens-1.0.2/aliens.c
+++ b/jeu-test/aliens-1.0.2/aliens.c
@@ -54,7 +54,8 @@
#define KEY_IDX_RIGHT 1
#define KEY_IDX_FIRE 2
-int keymap[NUMBER_PLAYER][KEYS_COUNT] = {{SDLK_LEFT,SDLK_RIGHT,SDLK_UP},{SDLK_q,SDLK_d,SDLK_z}};
+int keymap[][KEYS_COUNT] = {{SDLK_q,SDLK_d,SDLK_z},{SDLK_LEFT,SDLK_RIGHT,SDLK_UP}
+,{SDLK_f,SDLK_h,SDLK_t},{SDLK_j,SDLK_l,SDLK_i}};
typedef struct {
int alive;
@@ -69,7 +70,7 @@ SDL_Surface *background;
/**/
object player[NUMBER_PLAYER];
int reloading[NUMBER_PLAYER];
-object shots[MAX_SHOTS];
+object shots[MAX_SHOTS][NUMBER_PLAYER];
/**/
object aliens[MAX_ALIENS];
/**/
@@ -118,7 +119,8 @@ SDL_Surface *LoadImage(char *datafile, int transparent)
}
int LoadData(void)
{
- int i;
+ int i,j;
+ SDL_Surface *firstShot;
/* Load sounds */
#if defined(PLAY_MOD) || defined(PLAY_MID)
@@ -139,7 +141,7 @@ int LoadData(void)
/* Load graphics */
- //INFO : j'ai fai comme pour les autre objets
+ //INFO : j'ai fais comme pour les autres objets
player[0].image = LoadImage(DATAFILE("player.gif"), 1);
if ( player[0].image == NULL ) {
printf("erreur creation player %c\n",0);
@@ -149,12 +151,14 @@ int LoadData(void)
player[i].image = player[0].image;
}
- shots[0].image = LoadImage(DATAFILE("shot.gif"), 0);
- if ( shots[0].image == NULL ) {
+ firstShot = LoadImage(DATAFILE("shot.gif"), 0);
+ if ( firstShot == NULL ) {
return(0);
}
- for ( i=1; i<MAX_SHOTS; ++i ) {
- shots[i].image = shots[0].image;
+ for(j=0;j<NUMBER_PLAYER;++j){
+ for ( i=0; i<MAX_SHOTS; ++i ) {
+ shots[i][j].image = firstShot;
+ }
}
aliens[0].image = LoadImage(DATAFILE("alien.gif"), 1);
if ( aliens[0].image == NULL ) {
@@ -191,7 +195,7 @@ void FreeData(void)
/* Free graphics */
SDL_FreeSurface(player[0].image);
- SDL_FreeSurface(shots[0].image);
+ SDL_FreeSurface(shots[0][0].image);
SDL_FreeSurface(aliens[0].image);
SDL_FreeSurface(explosions[0].image);
SDL_FreeSurface(background);
@@ -314,16 +318,16 @@ void WaitFrame(void)
int players_alive(object *p) {
int i;
- for (i=0;i<NUMBER_PLAYER;i++) {
- if (player[i].alive==0) { return 0; }
+ for (i=0;i<NUMBER_PLAYER;++i) {
+ if (player[i].alive==1) { return 1; }
}
- return 1;
+ return 0;
}
/* This of course can be optimized :-) */
void RunGame(void)
{
- int i, j;
+ int i,j,k;
SDL_Event event;
Uint8 *keys;
@@ -350,9 +354,10 @@ void RunGame(void)
DrawObject(&player[i]);
}
-
- for ( i=0; i<MAX_SHOTS; ++i ) {
- shots[i].alive = 0;
+ for(j=0;j<NUMBER_PLAYER;++j){
+ for ( i=0; i<MAX_SHOTS; ++i ) {
+ shots[i][j].alive = 0;
+ }
}
for ( i=0; i<MAX_ALIENS; ++i ) {
aliens[i].alive = 0;
@@ -373,9 +378,11 @@ void RunGame(void)
keys = SDL_GetKeyState(NULL);
/* Erase everything from the screen */
- for ( i=0; i<MAX_SHOTS; ++i ) {
- if ( shots[i].alive ) {
- EraseObject(&shots[i]);
+ for(j=0;j<NUMBER_PLAYER;++j){
+ for ( i=0; i<MAX_SHOTS; ++i ) {
+ if ( shots[i][j].alive ) {
+ EraseObject(&shots[i][j]);
+ }
}
}
for ( i=0; i<MAX_ALIENS; ++i ) {
@@ -407,18 +414,19 @@ void RunGame(void)
/* Create new shots */
for (j=0;j<NUMBER_PLAYER;++j){
+ if (!player[j].alive) {continue;}
if ( ! reloading[j] ) {
if ( keys[keymap[j][KEY_IDX_FIRE]] == SDL_PRESSED ) {
for ( i=0; i<MAX_SHOTS; ++i ) {
- if ( ! shots[i].alive ) {
+ if ( ! shots[i][j].alive ) {
break;
}
}
if ( i != MAX_SHOTS ) {
- //FIXME : shots[] doit être par joueur
- shots[i].x = player[j].x + (player[j].image->w-shots[i].image->w)/2;
- shots[i].y = player[j].y - shots[i].image->h;
- shots[i].alive = 1;
+ //FIXME : nombre de munition limite pour les 2 joueurs ?
+ shots[i][j].x = player[j].x + (player[j].image->w-shots[i][j].image->w)/2;
+ shots[i][j].y = player[j].y - shots[i][j].image->h;
+ shots[i][j].alive = 1;
Mix_PlayChannel(SHOT_WAV, sounds[SHOT_WAV], 0);
}
}
@@ -428,6 +436,7 @@ void RunGame(void)
/* Move players */
for(i=0;i<NUMBER_PLAYER;++i){
+ if (!player[i].alive) {continue;}
player[i].facing=0;
if ( keys[keymap[i][KEY_IDX_LEFT]] ) player[i].facing--;
if ( keys[keymap[i][KEY_IDX_RIGHT]] ) player[i].facing++;
@@ -460,44 +469,48 @@ void RunGame(void)
}
/* Move the shots */
- for ( i=0; i<MAX_SHOTS; ++i ) {
- if ( shots[i].alive ) {
- shots[i].y -= SHOT_SPEED;
- if ( shots[i].y < 0 ) {
- shots[i].alive = 0;
+ for(j=0;j<NUMBER_PLAYER;++j){
+ for ( i=0; i<MAX_SHOTS; ++i ) {
+ if ( shots[i][j].alive ) {
+ shots[i][j].y -= SHOT_SPEED;
+ if ( shots[i][j].y < 0 ) {
+ shots[i][j].alive = 0;
+ }
}
}
}
/* Detect collisions */
- for ( j=0; j<MAX_SHOTS; ++j ) {
- for ( i=0; i<MAX_ALIENS; ++i ) {
- if ( shots[j].alive && aliens[i].alive &&
- Collide(&shots[j], &aliens[i]) ) {
- aliens[i].alive = 0;
- explosions[i].x = aliens[i].x;
- explosions[i].y = aliens[i].y;
- explosions[i].alive = EXPLODE_TIME;
- Mix_PlayChannel(EXPLODE_WAV,
- sounds[EXPLODE_WAV], 0);
- shots[j].alive = 0;
- break;
+ for(k=0;k<NUMBER_PLAYER;++k){
+ for ( j=0; j<MAX_SHOTS; ++j ) {
+ for ( i=0; i<MAX_ALIENS; ++i ) {
+ if ( shots[j][k].alive && aliens[i].alive &&
+ Collide(&shots[j][k], &aliens[i]) ) {
+ aliens[i].alive = 0;
+ explosions[i].x = aliens[i].x;
+ explosions[i].y = aliens[i].y;
+ explosions[i].alive = EXPLODE_TIME;
+ Mix_PlayChannel(EXPLODE_WAV,
+ sounds[EXPLODE_WAV], 0);
+ shots[j][k].alive = 0;
+ break;
+ }
}
}
}
// FIXME : Visiblement cette détection de collision chie car l'alien passe à travers les players puis fais planter le jeu quan dil sors de l'écran (erreur X car le sprite est hors de l'écran)
- for ( j=0; i<NUMBER_PLAYER; ++j ) {
+ for ( j=0; j<NUMBER_PLAYER; ++j ) {
for ( i=0; i<MAX_ALIENS; ++i ) {
- if ( aliens[i].alive && Collide(&player[j], &aliens[i]) ) {
+ if ( aliens[i].alive && player[j].alive && Collide(&player[j], &aliens[i]) ) {
aliens[i].alive = 0;
explosions[i].x = aliens[i].x;
explosions[i].y = aliens[i].y;
explosions[i].alive = EXPLODE_TIME;
- player[i].alive = 0;
+ player[j].alive = 0;
- explosions[MAX_ALIENS].x = player[i].x;
- explosions[MAX_ALIENS].y = player[i].y;
+ explosions[MAX_ALIENS].x = player[j].x;
+ explosions[MAX_ALIENS].y = player[j].y;
explosions[MAX_ALIENS].alive = EXPLODE_TIME;
Mix_PlayChannel(EXPLODE_WAV, sounds[EXPLODE_WAV], 0);
@@ -511,11 +524,13 @@ void RunGame(void)
DrawObject(&aliens[i]);
}
}
- for ( i=0; i<MAX_SHOTS; ++i ) {
- if ( shots[i].alive ) {
- DrawObject(&shots[i]);
+ for(j=0;j<NUMBER_PLAYER;++j){
+ for ( i=0; i<MAX_SHOTS; ++i ) {
+ if ( shots[i][j].alive ) {
+ DrawObject(&shots[i][j]);
+ }
}
- }
+ }
for(i=0;i<NUMBER_PLAYER;++i){
if ( player[i].alive ) {
DrawObject(&player[i]);