summaryrefslogtreecommitdiff
path: root/sdl-test
diff options
context:
space:
mode:
authorDamien Appert <dappert>2010-10-22 08:34:47 +0000
committerDamien Appert <dappert>2010-10-22 08:34:47 +0000
commiteb6c3e70bf4144dedb31686821c94c943f13a71b (patch)
tree3ca99ab9812b055bb7e79a729a47050202f8ed75 /sdl-test
parenta4ae58a9200752a643edd1813d204bfd2f1c73a0 (diff)
download2010-netlemmings-eb6c3e70bf4144dedb31686821c94c943f13a71b.tar.gz
2010-netlemmings-eb6c3e70bf4144dedb31686821c94c943f13a71b.tar.bz2
2010-netlemmings-eb6c3e70bf4144dedb31686821c94c943f13a71b.zip
maj gestion lemming
git-svn-id: file:///var/svn/2010-netlemmings/trunk@105 077b3477-7977-48bd-8428-443f22f7bfda
Diffstat (limited to 'sdl-test')
-rw-r--r--sdl-test/SDL_tuto/TestParserLemmingsLVL/lvlTest01.ini24
-rw-r--r--sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy4647
2 files changed, 2435 insertions, 2236 deletions
diff --git a/sdl-test/SDL_tuto/TestParserLemmingsLVL/lvlTest01.ini b/sdl-test/SDL_tuto/TestParserLemmingsLVL/lvlTest01.ini
index 88d12ba..c1a1be7 100644
--- a/sdl-test/SDL_tuto/TestParserLemmingsLVL/lvlTest01.ini
+++ b/sdl-test/SDL_tuto/TestParserLemmingsLVL/lvlTest01.ini
@@ -17,23 +17,23 @@ style = brick
# Objects
# id, xpos, ypos, paint mode (), upside down (0,1)
# paint modes: 8=VIS_ON_TERRAIN, 4=NO_OVERWRITE, 0=FULL (only one value possible)
-#object_0 = 7, 748, 86, 4 , 0
-object_2 = 1, 600, 0, 4, 0
-#object_4 = 5, 516, 200, 8, 0
+object_0 = 7, 748, 86, 4 , 0
+object_2 = 1, 600, 50, 0, 0
+#object_4 = 5, 516, 200, 4, 0
#object_3 = 5, 200, 200, 0, 0
# Terrain
# id, xpos, ypos, modifier
# modifier: 8=NO_OVERWRITE, 4=UPSIDE_DOWN, 2=REMOVE (combining allowed, 0=FULL)
-#terrain_0 = 26, 300, 150, 0
-#terrain_1 = 26, 364, 150, 0
-#terrain_2 = 26, 428, 150, 0
-#terrain_3 = 26, 492, 150, 0
-#terrain_4 = 26, 556, 150, 0
-#terrain_5 = 26, 620, 150, 0
-#terrain_6 = 26, 684, 150, 0
-#terrain_7 = 26, 748, 150, 0
-#terrain_8 = 46, 600, 0, 0
+terrain_0 = 26, 300, 150, 0
+terrain_1 = 26, 364, 150, 0
+terrain_2 = 26, 428, 150, 0
+terrain_3 = 26, 492, 150, 0
+terrain_4 = 26, 556, 150, 0
+terrain_5 = 26, 620, 150, 0
+terrain_6 = 26, 684, 150, 0
+terrain_7 = 26, 748, 150, 0
+terrain_8 = 46, 600, 0, 0
#Steel
diff --git a/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy b/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy
index 81ced89..6bc63c6 100644
--- a/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy
+++ b/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy
@@ -11,7 +11,7 @@
#include <stdlib.h>
/** time per frame in microseconds - this is the timing everything else is based on */
-#define FPS 30
+#define FPS 150
/** redraw animated level obejcts every 3rd frame (about 100ms) */
#define ANIM_STEP_FPS 3
@@ -89,22 +89,22 @@
Uint32 ccc_tHidden = 0xff236b8e; // Bleu Acier
// new formule
Uint32 ccc_tBrick = 0xff00edaa;//0x00ed4f; // vert
- Uint32 ccc_Empty = 0x00000000;
+ Uint32 ccc_bgStencil = 0x00000000;
// object
- Uint32 ccc_oPassive = 0xff6b8ebb;//0x6b8e23; // Vert olive clair
+ Uint32 ccc_oPassive = 0x6b8ebb;//0x6b8e23; // Vert olive clair
- Uint32 ccc_oNoDigLeft = 0x00ff7fbb;//0xff7f00; // Thé
- Uint32 ccc_oNoDigRight = 0x00d987bb;//0xd98719; // Ocre
+ Uint32 ccc_oNoDigLeft = 0xff7fbb;//0xff7f00; // Thé
+ Uint32 ccc_oNoDigRight = 0xd987bb;//0xd98719; // Ocre
- Uint32 ccc_oTrapDrown = 0x007fffbb;//0x7fff00;// Vert de Hooker
- Uint32 ccc_oTrapAndNoLem = 0xff8c17bb;//0x8c1717; // Ecarlate
- Uint32 ccc_oTrapAndLem = 0xffa62abb;//0xa62a2a; // Brun
+ Uint32 ccc_oTrapDrown = 0x7fffbb;//0x7fff00;// Vert de Hooker
+ Uint32 ccc_oTrapAndNoLem = 0x8c17bb;//0x8c1717; // Ecarlate
+ Uint32 ccc_oTrapAndLem = 0xa62abb;//0xa62a2a; // Brun
- Uint32 ccc_oExit = 0xffd9d9bb;//0xd9d919; // Blond
- Uint32 ccc_oEntry = 0xff855ebb;//0x855e42; // Bronze
+ Uint32 ccc_oExit = 0xd9d9bb;//0xd9d919; // Blond
+ Uint32 ccc_oEntry = 0x855ebb;//0x855e42; // Bronze
- Uint32 ccc_oUnknow = 0xffffffbb;//0xffffff; // Blanc
+ Uint32 ccc_oUnknow = 0xffffbb;//0xffffff; // Blanc
// steel
@@ -115,7 +115,7 @@
Uint32 ccc_error = 0xff666669;
// lemming
- Uint32 ccc_lWalk_on = 0xffff1dcc;
+ Uint32 ccc_lWalk_on = 0xff00edaa;
Uint32 ccc_lStopper = 0xffffaacc;
@@ -487,8 +487,12 @@
int paint_terrain (struct gameInit *gInit, int choix);
+ int paint_manip(SDL_Surface *spr,SDL_Rect from,SDL_Surface *t,SDL_Rect to,Uint32 ccc_t, Uint32 ccc_spr, int mode);
+
int paint_objet (struct gameInit *gInit, int cptFps);
+ int paint_objet_stencil (struct gameInit *gInit, int cptFps);
+
int supprLem (struct gameInit *gInit, int cptFps);
int paint_lemming (struct gameInit *gInit, int cptFps);
@@ -520,6 +524,8 @@
int mouse_action (struct gameInit *gInit, int x, int y, int camX , int camY);
int lancement();
+
+ int test_blit(SDL_Surface *spr,SDL_Rect* from,SDL_Surface *t,SDL_Rect* to);
int paint_stencil=0;
@@ -1037,21 +1043,21 @@ inline Uint32 get_pixel32( int x, int y, SDL_Surface *surface )
//Recupere le pixel demande
/*printf("out get_pixel32 !! => (((y %d * surface->w %d ) + x %d) => %d >= surface->h %d *surface->w %d = %d)\n",y,surface->w,x,(y * surface->w ) + x,surface->h,surface->w,surface->h*surface->w);*/
-/* if ( surface==NULL ) { printf("ludo1\n"); return (ccc_error); }
- if ( pixels==NULL ) {
- printf("ludo2\n");
- return (ccc_error); }
+ /* if ( surface==NULL ) { printf("ludo1\n"); return (ccc_error); }
+ if ( pixels==NULL ) {
+ printf("ludo2\n");
+ return (ccc_error); }
- if((((y * surface->w ) + x) >= surface->h*surface->w)||
- (((y * surface->w ) + x) < 0)){
- if(y==surface->h){printf("get C'EST PAS ASSEZ GROS POUR TOI !!!! y=surface->h\n");
- return (ccc_error);}
- printf("out get_pixel32 !! => (((y %d * surface->w %d ) + x %d) => %d >= surface->h %d *surface->w %d = %d)\n",y,surface->w,x,(y * surface->w ) + x,surface->h,surface->w,surface->h*surface->w);
- return (ccc_error);
- }
- */
+ if((((y * surface->w ) + x) >= surface->h*surface->w)||
+ (((y * surface->w ) + x) < 0)){
+ if(y==surface->h){printf("get C'EST PAS ASSEZ GROS POUR TOI !!!! y=surface->h\n");
+ return (ccc_error);}
+ printf("out get_pixel32 !! => (((y %d * surface->w %d ) + x %d) => %d >= surface->h %d *surface->w %d = %d)\n",y,surface->w,x,(y * surface->w ) + x,surface->h,surface->w,surface->h*surface->w);
+ return (ccc_error);
+ }
+ */
- return pixels[ ( y * surface->w ) + x ];
+ return pixels[ ( y * surface->w ) + x ];
}
@@ -1063,10 +1069,10 @@ inline int putPixel(SDL_Surface *surface,Uint16 x,Uint16 y,Uint32 colori)
/* pointeur vers le pixel a remplacer */
/* if((((y * surface->w ) + x) >= surface->h*surface->w)||
(((y * surface->w ) + x) < 0)){
- printf("out putPixel !! => (((y %d * surface->w %d ) + x %d) => %d >= surface->h %d *surface->w %d = %d)\n",y,surface->w,x,(y * surface->w ) + x,surface->h,surface->w,surface->h*surface->w);
- return (101);
- }
-*/
+ printf("out putPixel !! => (((y %d * surface->w %d ) + x %d) => %d >= surface->h %d *surface->w %d = %d)\n",y,surface->w,x,(y * surface->w ) + x,surface->h,surface->w,surface->h*surface->w);
+ return (101);
+ }
+ */
if(y==surface->h){printf("put C'EST PAS ASSEZ GROS POUR TOI !!!! y=surface->h\n");
return (100);}
Uint8 *p = ((Uint8 *)surface->pixels) + y * surface->pitch + x * bpp;
@@ -1114,7 +1120,7 @@ int checkPixelDOWN(int nbr, int x, int y){
int yb;
if (x<0 || x >= LEVEL_WIDTH)
- return 0;
+ {return 0;}
yb = y + 1;
for(res=0;res<nbr;++res){
@@ -1127,1427 +1133,1438 @@ int checkPixelDOWN(int nbr, int x, int y){
if(err==ccc_error){return 113;}
if((err&0xbb)!=0xbb){
- if((err&ccc_lWalk_on)!=ccc_Empty){
+ //if((err&ccc_lWalk_on)!=ccc_bgStencil){
+ if((err&ccc_lWalk_on)!=ccc_bgStencil){
return res;
}
}
}
- return res;
+ return res;
}
//return number of free pixels above the lemming
int checkPixelUP(int nbr, int x, int y, int size ){
- int res;
- int err;
- int ym;
+ int res;
+ int err;
+ int ym;
- if (x<0 || x >= LEVEL_WIDTH)
- return 0;
+ if (x<0 || x >= LEVEL_WIDTH)
+ return 0;
- ym=midY(y,size);
+ ym=midY(y,size);
- for(res=0;res<nbr;++res){
- if(ym-res <= 0){
- return -1;//splat
- }
+ for(res=0;res<nbr;++res){
+ if(ym-res <= 0){
+ return -1;//splat
+ }
- putPixel(pSpr_Lem,x,ym-res,ccc_green);
+ putPixel(pSpr_Lem,x,ym-res,ccc_green);
- err=get_pixel32(x,ym-res,pStencil);
- if(err==ccc_error){return 113;}
+ err=get_pixel32(x,ym-res,pStencil);
+ if(err==ccc_error){return 113;}
- if((err&0xbb)!=0xbb){
- if((err&ccc_lWalk_on)!=ccc_Empty){
- return res;
+ if((err&0xbb)!=0xbb){
+ if((err|ccc_lWalk_on)!=ccc_bgStencil){
+ return res;
+ }
}
- }
- }
- return res;
-}
+ }
+ return res;
+ }
-//return true if Lemming has fallen to/through the bottom of the level, false otherwise
-int outOfLowerMap(int y) {
- if (y >= LEVEL_HEIGHT) {
- printf("Play Sound SND_DIE\n");
- //GameController.sound.play(GameController.SND_DIE);
- return 1;
+ //return true if Lemming has fallen to/through the bottom of the level, false otherwise
+ int outOfLowerMap(int y) {
+ if (y >= LEVEL_HEIGHT) {
+ printf("Play Sound SND_DIE\n");
+ //GameController.sound.play(GameController.SND_DIE);
+ return 1;
+ }
+ return 0;
}
- return 0;
-}
-//return number of pixels of walkable ground above the Lemmings foot.
-int aboveGround(int x, int y) {
+ //return number of pixels of walkable ground above the Lemmings foot.
+ int aboveGround(int x, int y) {
- int res=0;
- int err;
+ int res=0;
+ int err;
- if (x<0 || x >= LEVEL_WIDTH)
- return LEVEL_HEIGHT-1;
+ if (x<0 || x >= LEVEL_WIDTH)
+ return LEVEL_HEIGHT-1;
- if (y >= LEVEL_HEIGHT)
- return LEVEL_HEIGHT-1;
+ if (y >= LEVEL_HEIGHT)
+ return LEVEL_HEIGHT-1;
- for(res=0;res<WALKER_OBSTACLE_HEIGHT;++res){
- if(y-res<0){
- return WALKER_OBSTACLE_HEIGHT +1;// forbid leaving level to the top
- }
+ for(res=0;res<WALKER_OBSTACLE_HEIGHT;++res){
+ if(y-res<0){
+ return WALKER_OBSTACLE_HEIGHT +1;// forbid leaving level to the top
+ }
- putPixel(pSpr_Lem,x,y-res,ccc_cyan);
+ putPixel(pSpr_Lem,x,y-res,ccc_cyan);
- err=get_pixel32(x,y-res,pStencil);
- if(err==ccc_error){return 114;}
+ err=get_pixel32(x,y-res,pStencil);
+ if(err==ccc_error){return 114;}
- if((err&0xbb)!=0xbb){
- if(err!=(ccc_lWalk_on & ccc_Empty)){
- return res;
+ if((err&0xbb)!=0xbb){
+ //if(err!=(ccc_lWalk_on & ccc_bgStencil)){
+ if((err|ccc_lWalk_on)!=ccc_bgStencil){
+ return res;
+ }
+ }
}
+ return res;
+ }
+ //return Position inside lemming which is used for collisions
+ int midY(int y, int size) {
+ return y - size;
}
- }
- return res;
-}
-//return Position inside lemming which is used for collisions
-int midY(int y, int size) {
- return y - size;
-}
-
-//return true if climber reached a plateau he can walk on, false otherwise
-int reachedPlateau(int x, int y, int size, int dir) {
-
- int ym;
- int err;
- if (x<2 || x >= LEVEL_WIDTH-2)
- return 0;
+ //return true if climber reached a plateau he can walk on, false otherwise
+ int reachedPlateau(int x, int y, int size, int dir) {
- ym = midY(y,size);
- if (ym>= LEVEL_HEIGHT || ym<0)
- return 0;
+ int ym;
+ int err;
- if (dir == 0)//LEFT
- x -= 2;
- else
- x += 2;
+ if (x<2 || x >= LEVEL_WIDTH-2)
+ return 0;
- putPixel(pSpr_Lem,x,y,ccc_yellow);
+ ym = midY(y,size);
+ if (ym>= LEVEL_HEIGHT || ym<0)
+ return 0;
- err=get_pixel32(x,y,pStencil);
- if(err==ccc_error){return 115;}
- if((err&0xbb)!=0xbb){
- if(err!=(ccc_lWalk_on & ccc_Empty)){
- return 1;
- }
- }
- return 0;
-}
+ if (dir == 0)//LEFT
+ x -= 2;
+ else
+ x += 2;
-int explode(int x, int y, int size){
- printf("Play Sound SND_EXPLODE\n");
- //GameController.sound.play(GameController.SND_EXPLODE);
-}
+ putPixel(pSpr_Lem,x,y,ccc_yellow);
-//return stencil value from the middle of the lemming
-int stencilMid(int x, int y, int size) {
- Uint32 err;
- int ym = midY(y,size);
- if (x>0 && x<LEVEL_WIDTH && ym > 0 && ym < LEVEL_HEIGHT){
+ err=get_pixel32(x,y,pStencil);
+ if(err==ccc_error){return 115;}
+ if((err&0xbb)!=0xbb){
+ //if(err!=(ccc_lWalk_on & ccc_bgStencil)){
+ if((err|ccc_lWalk_on)!=ccc_bgStencil){
+ return 1;
+ }
+ }
+ return 0;
+ }
- putPixel(pSpr_Lem,x,y,0xff00ff);
- err=get_pixel32(x,ym,pStencil);
- }
- else {
- err = ccc_Empty;
- }
- return err;
-}
+ int explode(int x, int y, int size){
+ printf("Play Sound SND_EXPLODE\n");
+ //GameController.sound.play(GameController.SND_EXPLODE);
+ }
-// Check if a Lemming is to be turned by a stopper/blocker
-// return true if Lemming is to be turned, false otherwise
-int turnedByStopper(int x, int y, int size, int dir) {
- int s ;
- Uint32 err;
- err=stencilMid(x,y,size);
- if(err==ccc_error){return 116;}
- s=err&ccc_lStopper;
-
- if (s == ccc_lStopperLeft && dir==1) {//Right
- //LEFT;
- return 0;
- }
- if (s == ccc_lStopperRight && dir==0) {//Left
- //RIGHT
- return 1;
- }
- return 2;
-}
+ //return stencil value from the middle of the lemming
+ int stencilMid(int x, int y, int size) {
+ Uint32 err;
+ int ym = midY(y,size);
+ if (x>0 && x<LEVEL_WIDTH && ym > 0 && ym < LEVEL_HEIGHT){
-int stateLemming(struct gameInit *gInit){
-
- struct listeSimplementChainee *k;
- SDL_Surface *sfT;
- int boom=0;
- int flip=0;
- int free=0;
- int fx=0;
- int fy=0;
- int fs=0;
- int lh=0;
- int lw=0;
- int lState=0;
- int fa;
- int checkMask;
- int sx;
- int sy;
- int idx;
- int maxF;
- int err;
- int levitation;
- int oldX;
- int oldType;
- int newType;
-
- k=gInit->l.ll;
- while(k != NULL){
- if((k->ID<LEM_JOB)||(k->ID>19)){
-
- fx=gInit->mapI.lemmingDATA[k->ID].footX;
- fy=gInit->mapI.lemmingDATA[k->ID].footY;
- fs=gInit->mapI.lemmingDATA[k->ID].footSize;
- lState=gInit->mapI.lemmingDATA[k->ID].state;
-
- sfT = gInit->mapI.map.tabGif[gInit->mapI.map.tiles*2 + gInit->mapI.map.tilesObjet*2 +gInit->mapI.map.tilesSteel +(k->ID)*2+(k->data.pl->dir) + ADD_OBJ];
-
- lh=sfT->h/lState;
- lw=sfT->w;
-
- oldX=k->x;
- oldType=k->ID;
- newType=k->ID;
-
- // cooldown before lemming boom
- switch(k->data.pl->CptBoom){
- case 0: boom=1;break;
- case 404: break;
- default: --k->data.pl->CptBoom;
+ putPixel(pSpr_Lem,x,y,0xff00ff);
+ err=get_pixel32(x,ym,pStencil);
+ }
+ else {
+ err = ccc_bgStencil;
+ }
+ return err;
}
- //flipDirBorder
- if (k->data.pl->dir==1) {//right
- if (k->x<0) {
- k->x=0;
- flip = 1;
- } else if (k->x >= LEVEL_WIDTH) {
- k->x = LEVEL_WIDTH-1;
- flip = 1;
+ // Check if a Lemming is to be turned by a stopper/blocker
+ // return true if Lemming is to be turned, false otherwise
+ int turnedByStopper(int x, int y, int size, int dir) {
+ int s ;
+ Uint32 err;
+ err=stencilMid(x,y,size);
+ if(err==ccc_error){return 116;}
+ s=err&ccc_lStopper;
+
+ if (s == ccc_lStopperLeft && dir==1) {//Right
+ //LEFT;
+ return 0;
}
+ if (s == ccc_lStopperRight && dir==0) {//Left
+ //RIGHT
+ return 1;
+ }
+ return 2;
}
- //if (selectCtr>0) {selectCtr--;}
- if (flip) {k->data.pl->dir = (k->data.pl->dir==1) ? 0 : 1 ;}
-
- switch(k->ID){
- case 3 : // climber_to_walker
- {printf("climber_to_walker ->");
- if(boom){
- explode (k->x+fx,k->y+fy,fs);
- k->ID=10;//BOMBER
- break;
- }
- } break;
- case 1 : // faller
- {printf("faller ->");
- if(boom){
- explode (k->x+fx,k->y+fy,fs);
- k->ID=10;//BOMBER
- break;
- }
- free=checkPixelDOWN(FALLER_STEP, k->x+fx,k->y+fy);
- if(free==113){return 113;}
- if(free==FALL_DISTANCE_FORCE_FALL)
- {k->y += FALLER_STEP;}
- else
- {k->y += free;} // max: FALLER_STEP
-
- err=outOfLowerMap(k->y+fy);
- if(err==114){return 114;}
- if(err==0){
- k->data.pl->cptFall+=free;
- // check conversion to floater
- if((k->data.pl->floater==1)&&
- (k->data.pl->cptFall>= FALL_DISTANCE_FLOAT)){
- k->ID=22;//FLOATER_START
- k->data.pl->cptFall2 = 0;// used for parachute opening "jump" up
- } else if(free==0) {// check ground hit
- if(k->data.pl->cptFall > gInit->mapI.MaxFallDistance){
- k->ID=5;//SPLAT
- } else {
- k->ID=0;//WALKER
- k->data.pl->cptFall=0;
- }
- }
- } else {
- k->ID=17;
- }
- break;
- }
- case 16 : // JUMPER
- { printf("JUMPER ->");
- if(boom){
- k->ID=10;//BOMBER
- if(!gInit->mapI.nuke){
- printf("Play Sound SND_EXPLODE\n");
- //GameController.sound.play(GameController.SND_EXPLODE);
- }
- break;
- }
- // check collision with stopper
- err=turnedByStopper(k->x+fx,k->y+fy,fs,k->data.pl->dir);
- if(err==116){return 116;}
- if(err!=2){
- k->data.pl->dir=err;
- break;
+
+ int stateLemming(struct gameInit *gInit){
+
+ struct listeSimplementChainee *k;
+ struct listeSimplementChainee *o;
+ SDL_Surface *sfT;
+ int boom=0;
+ int flip=0;
+ int free=0;
+ int fx=0;
+ int fy=0;
+ int fs=0;
+ int lh=0;
+ int lw=0;
+ int lState=0;
+ int fa;
+ int checkMask;
+ int sx;
+ int sy;
+ int idx;
+ int maxF;
+ int err;
+ int levitation;
+ int oldX;
+ int oldType;
+ int newType;
+ int newID;
+
+ k=gInit->l.ll;
+ while(k != NULL){
+ if((k->ID<LEM_JOB)||(k->ID>19)){
+
+ switch(k->ID){
+ case 20: newID=10;break;
+ case 21: newID=6;break;
+ case 22: newID=4;break;
+ default: newID=k->ID;break;
}
- err = aboveGround(k->x+fx,k->y+fy);
- if(err==114){return 114;}
- levitation=err;
- if (levitation > JUMPER_STEP)
- {k->y -= JUMPER_STEP;}
- else {
- // conversion to walker
- k->y -= levitation;
- k->ID=0; //WALKER;
+
+ fx=gInit->mapI.lemmingDATA[newID].footX;
+ fy=gInit->mapI.lemmingDATA[newID].footY;
+ fs=gInit->mapI.lemmingDATA[newID].footSize;
+ lState=gInit->mapI.lemmingDATA[newID].state;
+
+ sfT = gInit->mapI.map.tabGif[gInit->mapI.map.tiles*2 + gInit->mapI.map.tilesObjet*2 +gInit->mapI.map.tilesSteel +(newID)*2+(k->data.pl->dir) + ADD_OBJ];
+
+ lh=sfT->h/lState;
+ lw=sfT->w;
+
+ oldX=k->x;
+ oldType=k->ID;
+ newType=k->ID;
+
+ // cooldown before lemming boom
+ switch(k->data.pl->CptBoom){
+ case 0: boom=1;break;
+ case 404: break;
+ default: --k->data.pl->CptBoom;
}
- }
- break;
- case 0: // WALKER
- { printf("WALKER ->");
- if(boom){
- k->ID=10;//BOMBER
- if(!gInit->mapI.nuke){
- printf("Play Sound SND_EXPLODE\n");
- //GameController.sound.play(GameController.SND_EXPLODE);
+
+ //flipDirBorder
+ if (k->data.pl->dir==1) {//right
+ if (k->x<0) {
+ k->x=0;
+ flip = 1;
+ } else if (k->x >= LEVEL_WIDTH) {
+ k->x = LEVEL_WIDTH-1;
+ flip = 1;
}
- break;
- }
- // check collision with stopper
- err=turnedByStopper(k->x+fx,k->y+fy,fs,k->data.pl->dir);
- if(err==116){return 116;}
- if(err!=2){
- k->data.pl->dir=err;
- break;
}
- k->x += (k->data.pl->dir==1)? WALKER_STEP : -WALKER_STEP;
- // check
- free=checkPixelDOWN(FALLER_STEP, k->x+fx,k->y+fy);
- if(free==113){return 113;}
- if(free==FALL_DISTANCE_FORCE_FALL)
- {k->y += FALLER_STEP;}
- else
- {
- k->y += free; // max: FALLER_STEP
- k->data.pl->cptFall=free;
- }
- err = aboveGround(k->x+fx,k->y+fy);
- if(err==114){return 137;}
- levitation=err;
- if((levitation < WALKER_OBSTACLE_HEIGHT) && ((k->y+fy+lh/2)>0))
- {
- if (levitation >= JUMPER_STEP)
- {
- k->y -= JUMPER_STEP;
- k->ID = 16;
- break;
- }
- else {
- // conversion to jumper
- k->y -= levitation;
- }
- } else {
- k->x=oldX;
- if(k->data.pl->climber==1){
- k->ID=2; // CLIMBER
+ //if (selectCtr>0) {selectCtr--;}
+ if (flip) {k->data.pl->dir = (k->data.pl->dir==1) ? 0 : 1 ;}
+
+ switch(k->ID){
+ case 3 : // climber_to_walker
+ {printf("climber_to_walker ->");
+ if(boom){
+ explode (k->x+fx,k->y+fy,fs);
+ k->ID=10;//BOMBER
+ break;
+ }
+ } break;
+ case 1 : // faller
+ {printf("faller ->");
+ if(boom){
+ explode (k->x+fx,k->y+fy,fs);
+ k->ID=10;//BOMBER
+ break;
+ }
+ free=checkPixelDOWN(FALLER_STEP, k->x+fx,k->y+fy);
+ if(free==113){return 113;}
+ if(free==FALL_DISTANCE_FORCE_FALL)
+ {k->y += FALLER_STEP;}
+ else
+ {k->y += free;} // max: FALLER_STEP
+
+ err=outOfLowerMap(k->y+fy);
+ if(err==114){return 114;}
+ if(err==0){
+ k->data.pl->cptFall+=free;
+ // check conversion to floater
+ if((k->data.pl->floater==1)&&
+ (k->data.pl->cptFall>= FALL_DISTANCE_FLOAT)){
+ k->ID=22;//FLOATER_START
+ k->data.pl->cptFall2 = 0;// used for parachute opening "jump" up
+ } else if(free==0) {// check ground hit
+ if(k->data.pl->cptFall > gInit->mapI.MaxFallDistance){
+ k->ID=5;//SPLAT
+ } else {
+ k->ID=0;//WALKER
+ k->data.pl->cptFall=0;
+ }
+ }
+ } else {
+ k->ID=17;
+ }
+ break;
+ }
+ case 16 : // JUMPER
+ { printf("JUMPER ->");
+ if(boom){
+ k->ID=10;//BOMBER
+ if(!gInit->mapI.nuke){
+ printf("Play Sound SND_EXPLODE\n");
+ //GameController.sound.play(GameController.SND_EXPLODE);
+ }
+ break;
+ }
+ // check collision with stopper
+ err=turnedByStopper(k->x+fx,k->y+fy,fs,k->data.pl->dir);
+ if(err==116){return 116;}
+ if(err!=2){
+ k->data.pl->dir=err;
+ break;
+ }
+ err = aboveGround(k->x+fx,k->y+fy);
+ if(err==114){return 114;}
+ levitation=err;
+ if (levitation > JUMPER_STEP)
+ {k->y -= JUMPER_STEP;}
+ else {
+ // conversion to walker
+ k->y -= levitation;
+ k->ID=0; //WALKER;
+ }
+ }
break;
- } else {
- k->data.pl->dir = (k->data.pl->dir==1) ? 0 : 1 ;
- }
- }
- if(free>0){
- // check for conversion to faller
- k->data.pl->cptFall += FALLER_STEP;
- if(free >= FALL_DISTANCE_FALL){
- k->ID=1; // FALLER
- }
- }
- break;
- }
- case 22: // FLOATER_START
- printf("FLOATER_START ->");
- if(boom){
- explode (k->x+fx,k->y+fy,fs);
- k->ID=10;//BOMBER
- break;
- }
- switch (k->data.pl->cptFall2++) {
- case 0:
- case 1: // keep falling with faller speed
- case 2: k->y += FALLER_STEP-FLOATER_STEP;
- break;
- case 3: k->y -= FLOATER_STEP-1; // decelerate a little
- break;
- case 4:
- case 5:
- case 6:
- case 7: k->y -= FLOATER_STEP; // decelerate some more
- break;
- default:
- k->ID=4;//FLOATER;
- }
-
- case 4 : //FLOATER
- printf("FLOATER ->");
- if(boom){
- explode (k->x+fx,k->y+fy,fs);
- k->ID=10;//BOMBER
- break;
- }
- free=checkPixelDOWN(FALLER_STEP, k->x+fx,k->y+fy);
- if(free==113){return 113;}
- if(free==FALL_DISTANCE_FORCE_FALL)
- {k->y += FALLER_STEP;}
- else
- {k->y += free;} // max: FALLER_STEP
-
- err=outOfLowerMap(k->y+fy);
- if(err==114){return 114;}
- if(err==0){
- k->data.pl->cptFall+=free;
- if(free==0){
- k->ID=0;//WALKER
- k->data.pl->cptFall=0;
- }
- } else {
- k->ID=17;
- }
- break;
+ case 0: // WALKER
+ { printf("WALKER ->");
+ if(boom){
+ k->ID=10;//BOMBER
+ if(!gInit->mapI.nuke){
+ printf("Play Sound SND_EXPLODE\n");
+ //GameController.sound.play(GameController.SND_EXPLODE);
+ }
+ break;
+ }
+ // check collision with stopper
+ err=turnedByStopper(k->x+fx,k->y+fy,fs,k->data.pl->dir);
+ if(err==116){return 116;}
+ if(err!=2){
+ k->data.pl->dir=err;
+ break;
+ }
+ k->x += (k->data.pl->dir==1)? WALKER_STEP : -WALKER_STEP;
+ // check
+ free=checkPixelDOWN(FALL_DISTANCE_FALL, k->x+fx,k->y+fy);
+ if(free==113){return 113;}
+ if(free==FALL_DISTANCE_FORCE_FALL)
+ {k->y += FALLER_STEP;}
+ else
+ {
+ k->y += free; // max: FALLER_STEP
+ k->data.pl->cptFall=free;
+ }
+ err = aboveGround(k->x+fx,k->y+fy);
+ if(err==114){return 137;}
+ levitation=err;
+ printf("levitation %d free %d \n",levitation,free);
+ if((levitation < WALKER_OBSTACLE_HEIGHT) && ((k->y+fy+lh/2)>0))
+ {
+ if (levitation >= JUMPER_STEP)
+ {
+ k->y -= JUMPER_STEP;
+ k->ID = 16;
+ break;
+ }
+ else {
+ // conversion to jumper
+ k->y -= levitation;
+ }
+ } else {
+ k->x=oldX;
+ if(k->data.pl->climber==1){
+ k->ID=2; // CLIMBER
+ break;
+ } else {
+ k->data.pl->dir = (k->data.pl->dir==1) ? 0 : 1 ;
+ }
+ }
+ if(free>0){
+ // check for conversion to faller
+ k->data.pl->cptFall += FALLER_STEP;
+ if(free >= FALL_DISTANCE_FALL){
+ k->ID=1; // FALLER
+ }
+ }
+ break;
+ }
+ case 22: // FLOATER_START
+ printf("FLOATER_START ->");
+ if(boom){
+ explode (k->x+fx,k->y+fy,fs);
+ k->ID=10;//BOMBER
+ break;
+ }
+ switch (k->data.pl->cptFall2++) {
+ case 0:
+ case 1: // keep falling with faller speed
+ case 2: k->y += FALLER_STEP-FLOATER_STEP;
+ break;
+ case 3: k->y -= FLOATER_STEP-1; // decelerate a little
+ break;
+ case 4:
+ case 5:
+ case 6:
+ case 7: k->y -= FLOATER_STEP; // decelerate some more
+ break;
+ default:
+ k->ID=4;//FLOATER;
+ }
- case 2 : // CLIMBER
- printf("CLIMBER ->");
- if(boom){
- explode (k->x+fx,k->y+fy,fs);
- k->ID=10;//BOMBER
- break;
- }
+ case 4 : //FLOATER
+ printf("FLOATER ->");
+ if(boom){
+ explode (k->x+fx,k->y+fy,fs);
+ k->ID=10;//BOMBER
+ break;
+ }
+ free=checkPixelDOWN(FALLER_STEP, k->x+fx,k->y+fy);
+ if(free==113){return 113;}
+ if(free==FALL_DISTANCE_FORCE_FALL)
+ {k->y += FALLER_STEP;}
+ else
+ {k->y += free;} // max: FALLER_STEP
+
+ err=outOfLowerMap(k->y+fy);
+ if(err==114){return 114;}
+ if(err==0){
+ k->data.pl->cptFall+=free;
+ if(free==0){
+ k->ID=0;//WALKER
+ k->data.pl->cptFall=0;
+ }
+ } else {
+ k->ID=17;
+ }
+ break;
- if ( (++(k->data.pl->cptFall) & 1) == 1) // only every other step
- {k->y -= CLIMBER_STEP;}
- err=checkPixelUP(2,k->x+fx,k->y+fy,fs);
- if(err==113){return 127;}
- if (midY(k->y+fy,fs) < 0 || err<2) {
- k->data.pl->dir = (k->data.pl->dir==1) ? 0 : 1 ;
- k->ID=1; //FALLER;
- k->data.pl->cptFall = 0;
- } else {
- err=reachedPlateau(k->x+fx,k->y+fy,fs,k->data.pl->dir);
- if (err==115){return 115;}
- if(err) {
- k->data.pl->cptFall = 0;
- k->ID=3; //CLIMBER_TO_WALKER;
- }
- }
- break;
+ case 2 : // CLIMBER
+ printf("CLIMBER ->");
+ if(boom){
+ explode (k->x+fx,k->y+fy,fs);
+ k->ID=10;//BOMBER
+ break;
+ }
- case 5: //SPLAT
- printf("SPLAT ->");
- if(boom){
- explode (k->x+fx,k->y+fy,fs);
- k->ID=10;//BOMBER
- break;
- }
- if(k->data.pl->cptState==0){
- k->data.pl->cptState=gInit->mapI.lemmingDATA[k->ID].state;
- printf("Play Sound SND_SPLAT\n");
- //GameController.sound.play(GameController.SND_SPLAT);
- }
- break;
- /*
- case 13: //DIGGER
- if(boom){
- k->ID=10;//BOMBER
- if(!gInit->mapI.nuke){
- printf("Play Sound SND_EXPLODE\n");
- //GameController.sound.play(GameController.SND_EXPLODE);
- }
- break;
- }
- break;
- case 14: // BASHER
- {
- if(boom){
- k->ID=10;//BOMBER
- if(!gInit->mapI.nuke){
- printf("Play Sound SND_EXPLODE\n");
- //GameController.sound.play(GameController.SND_EXPLODE);
- }
- break;
- }
- err=turnedByStopper(k->x+fx,k->y+fy,fs,k->data.pl->dir);
- if(err==116){return 116;}
- if(err!=2){
- k->data.pl->dir=err;
- k->ID=0;//WALKER
- break;
- }
- free=checkPixelDOWN(FALLER_STEP, ccc_black, k->x+fx,k->y+fy,pStencil);
- if(free==113){return 113;}
- if(free==FALL_DISTANCE_FORCE_FALL)
- {k->y += FALLER_STEP;}
- else
- {k->y += free;} // max: FALLER_STEP
-
- if(free != 0){
- k->data.pl->cptFall += free;
- if (k->data.pl->cptFall >= BASHER_FALL_DISTANCE)
- {
- k->ID=1;//FALLER;
- }
- } else {
- k->data.pl->cptFall = 0;
- }
- //Mask m;
- //int checkMask;
- maxF=gInit->mapI.lemmingDATA[k->ID].state
- idX= maxF - k->data.pl->cptState + 1;
- if (idx >= maxF) {idx=0;}
- switch(idx){
- case 2 :
- case 3 :
- case 4 :
- case 5 : {
- // bash mask should have the same height as the lemming
- sx=k->x;
- sy=k->y;
- checkMask = ccc_s|((k->data.pl->dir==0) ? ccc_oNoDigLeft : ccc_oNoDigRight);
- eraseMask(sx);
- }
- //ETC ...
- */
- case 12: //BUILDER_END
- printf("BUILDER_END ->");
- if(boom){
- k->ID=10;//BOMBER
- if(!gInit->mapI.nuke){
- printf("Play Sound SND_EXPLODE\n");
- //GameController.sound.play(GameController.SND_EXPLODE);
- }
- }
- k->data.pl->cptBrick=0;
- k->data.pl->cptState=0;
- break;
+ if ( (++(k->data.pl->cptFall) & 1) == 1) // only every other step
+ {k->y -= CLIMBER_STEP;}
+ err=checkPixelUP(2,k->x+fx,k->y+fy,fs);
+ if(err==113){return 127;}
+ if (midY(k->y+fy,fs) < 0 || err<2) {
+ k->data.pl->dir = (k->data.pl->dir==1) ? 0 : 1 ;
+ k->ID=1; //FALLER;
+ k->data.pl->cptFall = 0;
+ } else {
+ err=reachedPlateau(k->x+fx,k->y+fy,fs,k->data.pl->dir);
+ if (err==115){return 115;}
+ if(err) {
+ k->data.pl->cptFall = 0;
+ k->ID=3; //CLIMBER_TO_WALKER;
+ }
+ }
+ break;
- case 11: // BUILDER
- {
- printf("BUILDER ->");
- if(boom){
- k->ID=10;//BOMBER
- if(!gInit->mapI.nuke){
+ case 5: //SPLAT
+ printf("SPLAT ->");
+ if(boom){
+ explode (k->x+fx,k->y+fy,fs);
+ k->ID=10;//BOMBER
+ break;
+ }
+ if(k->data.pl->cptState==0){
+ k->data.pl->cptState=gInit->mapI.lemmingDATA[newID].state;
+ printf("Play Sound SND_SPLAT\n");
+ //GameController.sound.play(GameController.SND_SPLAT);
+ }
+ break;
+ /*
+ case 13: //DIGGER
+ if(boom){
+ k->ID=10;//BOMBER
+ if(!gInit->mapI.nuke){
+ printf("Play Sound SND_EXPLODE\n");
+ //GameController.sound.play(GameController.SND_EXPLODE);
+ }
+ break;
+ }
+ break;
+ case 14: // BASHER
+ {
+ if(boom){
+ k->ID=10;//BOMBER
+ if(!gInit->mapI.nuke){
printf("Play Sound SND_EXPLODE\n");
//GameController.sound.play(GameController.SND_EXPLODE);
- }
- break;
- }
- // check collision with stopper
- err=turnedByStopper(k->x+fx,k->y+fy,fs,k->data.pl->dir);
- if(err==116){return 116;}
- if(err!=2){
- k->data.pl->dir=err;
- break;
- }
-
- k->data.pl->cptState++;
- if(k->data.pl->cptState >= lState){
- // step created -> move up
- k->data.pl->cptState=0;
- k->data.pl->cptBrick++;
-
- if (k->data.pl->dir == 1)
- { k->x += 4;} // step forward
- else
- { k->x -= 4;}
- k->y -= 2;// step up
- err = aboveGround(k->x+fx,k->y+fy);// should be 0, if not, we built into a wall -> stop
- if(err==114){return 117;}
- levitation=err;
- // check for conversion to walker
- err=checkPixelUP(8, k->x+fx,k->y+fy,fs); // check if builder is too close to ceiling
- if(err==113){return 113;}
- fa=err;
- if(fa<8|| levitation > 0){
- k->ID=0;//WALKER
- // a lemming can jump through the ceiling like in Mayhem2-Boiler Room
- if (levitation >= WALKER_OBSTACLE_HEIGHT) {
- // avoid getting stuck
- k->x = oldX;
- k->y += 2;
}
- k->data.pl->dir = (k->data.pl->dir==1) ? 0 : 1 ;
break;
- }
- if(k->data.pl->cptState >= STEPS_MAX){
- k->ID=12; //BUILDER_END
+ }
+ err=turnedByStopper(k->x+fx,k->y+fy,fs,k->data.pl->dir);
+ if(err==116){return 116;}
+ if(err!=2){
+ k->data.pl->dir=err;
+ k->ID=0;//WALKER
break;
- }
- } else {
- if (k->data.pl->cptState==9){
- printf("insert mask\n");
- if(k->data.pl->cptBrick >= STEPS_WARNING){
- printf("Play Sound SND_TING\n");
- //GameController.sound.play(GameController.SND_TING);
}
- }
+ free=checkPixelDOWN(FALLER_STEP, ccc_black, k->x+fx,k->y+fy,pStencil);
+ if(free==113){return 113;}
+ if(free==FALL_DISTANCE_FORCE_FALL)
+ {k->y += FALLER_STEP;}
+ else
+ {k->y += free;} // max: FALLER_STEP
+
+ if(free != 0){
+ k->data.pl->cptFall += free;
+ if (k->data.pl->cptFall >= BASHER_FALL_DISTANCE)
+ {
+ k->ID=1;//FALLER;
+ }
+ } else {
+ k->data.pl->cptFall = 0;
+ }
+ //Mask m;
+ //int checkMask;
+ maxF=gInit->mapI.lemmingDATA[newID].state
+ idX= maxF - k->data.pl->cptState + 1;
+ if (idx >= maxF) {idx=0;}
+ switch(idx){
+ case 2 :
+ case 3 :
+ case 4 :
+ case 5 : {
+ // bash mask should have the same height as the lemming
+ sx=k->x;
+ sy=k->y;
+ checkMask = ccc_s|((k->data.pl->dir==0) ? ccc_oNoDigLeft : ccc_oNoDigRight);
+ eraseMask(sx);
+ }
+ }
+ }
+ //ETC ...
+ */
+ case 12: //BUILDER_END
+ printf("BUILDER_END ->");
+ if(boom){
+ k->ID=10;//BOMBER
+ if(!gInit->mapI.nuke){
+ printf("Play Sound SND_EXPLODE\n");
+ //GameController.sound.play(GameController.SND_EXPLODE);
+ }
+ }
+ k->data.pl->cptBrick=0;
+ k->data.pl->cptState=0;
+ break;
+
+ case 11: // BUILDER
+ {
+ printf("BUILDER ->");
+ if(boom){
+ k->ID=10;//BOMBER
+ if(!gInit->mapI.nuke){
+ printf("Play Sound SND_EXPLODE\n");
+ //GameController.sound.play(GameController.SND_EXPLODE);
+ }
+ break;
+ }
+ // check collision with stopper
+ err=turnedByStopper(k->x+fx,k->y+fy,fs,k->data.pl->dir);
+ if(err==116){return 116;}
+ if(err!=2){
+ k->data.pl->dir=err;
+ break;
+ }
+
+ k->data.pl->cptState++;
+ if(k->data.pl->cptState >= lState){
+ // step created -> move up
+ k->data.pl->cptState=0;
+ k->data.pl->cptBrick++;
+
+ if (k->data.pl->dir == 1)
+ { k->x += 4;} // step forward
+ else
+ { k->x -= 4;}
+ k->y -= 2;// step up
+ err = aboveGround(k->x+fx,k->y+fy);// should be 0, if not, we built into a wall -> stop
+ if(err==114){return 117;}
+ levitation=err;
+ // check for conversion to walker
+ err=checkPixelUP(8, k->x+fx,k->y+fy,fs); // check if builder is too close to ceiling
+ if(err==113){return 113;}
+ fa=err;
+ if(fa<8|| levitation > 0){
+ k->ID=0;//WALKER
+ // a lemming can jump through the ceiling like in Mayhem2-Boiler Room
+ if (levitation >= WALKER_OBSTACLE_HEIGHT) {
+ // avoid getting stuck
+ k->x = oldX;
+ k->y += 2;
+ }
+ k->data.pl->dir = (k->data.pl->dir==1) ? 0 : 1 ;
+ break;
+ }
+ if(k->data.pl->cptState >= STEPS_MAX){
+ k->ID=12; //BUILDER_END
+ break;
+ }
+ } else {
+ if (k->data.pl->cptState==9){
+ printf("insert mask\n");
+ if(k->data.pl->cptBrick >= STEPS_WARNING){
+ printf("Play Sound SND_TING\n");
+ //GameController.sound.play(GameController.SND_TING);
+ }
+ }
+ }
+ break;
+ }
+ case 6: // STOPPER
+ { printf("STOPPER ->");
+ if(boom){
+ k->ID=10;//BOMBER
+ if(!gInit->mapI.nuke){
+ printf("Play Sound SND_EXPLODE\n");
+ //GameController.sound.play(GameController.SND_EXPLODE);
+ }
+ break;
+ }
+ //check for conversion to faller
+ free=checkPixelDOWN(FLOATER_STEP, k->x+fx,k->y+fy);
+ if(free==113){return 113;}
+ if(free>0){
+ if(free==FALL_DISTANCE_FORCE_FALL)
+ {k->y += FALLER_STEP;}
+ else
+ {k->y += free;} // max: FALLER_STEP
+ k->data.pl->cptFall+=free;
+ if (k->data.pl->cptFall >= FALL_DISTANCE_FALL)
+ {k->ID=1;}//FALLER;
+ else
+ {k->ID=0;}//WALKER;
+ // conversion to faller or walker -> erase stopper mask
+ // Mask m = lemmings[getOrdinal(Type.STOPPER)].getMask(dir);
+ // m.clearType(maskX,maskY,0,Stencil.MSK_STOPPER);
+ } else {
+ k->data.pl->cptFall=0;
+ }
+ break;
+ }
+ case 21: //BOMBER_STOPPER:
+ printf("BOMBER_STOPPER ->");
+ free=checkPixelDOWN(FLOATER_STEP, k->x+fx,k->y+fy);
+ if(free==113){return 113;}
+ if(free>0){
+ // stopper falls -> erase mask and convert to normal stopper.
+ //Mask m = lemmings[getOrdinal(Type.STOPPER)].getMask(dir);
+ //m.clearType(maskX,maskY,0,Stencil.MSK_STOPPER);
+ k->ID=10;//BOMBER
+ } else {break;}
+
+ case 10: // BOMBER
+ printf("BOMBER ->");
+ free=checkPixelDOWN(FLOATER_STEP, k->x+fx,k->y+fy);
+ if(free==113){return 113;}
+ if(free==FALL_DISTANCE_FORCE_FALL)
+ {k->y += FALLER_STEP;}
+ else
+ {k->y += free;} // max: FALLER_STEP
+ err=outOfLowerMap(k->y+fy);
+ if(err==114){return 114;}
+ if(err==1) {k->ID=17;}
+ break;
+
+ default:
+ printf("default ->");
+ if(boom){
+ explode (k->x+fx,k->y+fy,fs);
+ k->ID=10;//BOMBER
+ break;
+ }
+ break;
+ }//FIN SWITCH
+
+ // trap
+ err=get_pixel32(k->x+fx,k->y,pStencil);
+ if(err==ccc_error){return 12;}
+ printf("k->ID => %d get_pixel32(k->x %d+fx %d => %d,k->y %d,pStencil) == %p \n",k->ID,k->x,fx,k->x+fx,k->y,err);
+ if(err==ccc_oTrapDrown){
+ k->ID=7;
+ k->data.pl->cptState=gInit->mapI.lemmingDATA[k->ID].state;
}
- break;
- }
- case 6: // STOPPER
- { printf("STOPPER ->");
- if(boom){
- k->ID=10;//BOMBER
- if(!gInit->mapI.nuke){
- printf("Play Sound SND_EXPLODE\n");
- //GameController.sound.play(GameController.SND_EXPLODE);
- }
- break;
+ if(err==ccc_oTrapAndLem){
+ k->ID=8;
+ k->data.pl->cptState=gInit->mapI.lemmingDATA[k->ID].state;
}
- //check for conversion to faller
- free=checkPixelDOWN(FLOATER_STEP, k->x+fx,k->y+fy);
- if(free==113){return 113;}
- if(free>0){
- if(free==FALL_DISTANCE_FORCE_FALL)
- {k->y += FALLER_STEP;}
- else
- {k->y += free;} // max: FALLER_STEP
- k->data.pl->cptFall+=free;
- if (k->data.pl->cptFall >= FALL_DISTANCE_FALL)
- {k->ID=1;}//FALLER;
- else
- {k->ID=0;}//WALKER;
- // conversion to faller or walker -> erase stopper mask
- // Mask m = lemmings[getOrdinal(Type.STOPPER)].getMask(dir);
- // m.clearType(maskX,maskY,0,Stencil.MSK_STOPPER);
- } else {
- k->data.pl->cptFall=0;
+ if(err==ccc_oTrapAndNoLem){
+ k->ID=17;
+ o=gInit->o.lo;
+ while(o!=NULL){
+ if((gInit->mapI.map.tabDataSprO[o->ID].type==6)&&
+ (o->x<=(k->x+fx))&&
+ (gInit->mapI.map.tabGif[gInit->mapI.map.tiles*2+o->ID*2+o->data.po->UD+ADD_OBJ]->w>=(k->x+fx))&&
+ (o->y<=(k->y))&&
+ (gInit->mapI.map.tabGif[gInit->mapI.map.tiles*2+k->ID*2+k->data.po->UD+ADD_OBJ]->h>=(k->y))){
+ err=gInit->mapI.map.tabDataSprO[o->ID].state;
+ break;
+ }
+ o=o->next;
+ }
+ o->data.po->cptState=err;
+ }
+ if(err==ccc_oExit){
+ k->ID=9;
+ k->data.pl->cptState=gInit->mapI.lemmingDATA[k->ID].state;
}
- break;
+ printf("\n");
}
- case 21: //BOMBER_STOPPER:
- printf("BOMBER_STOPPER ->");
- free=checkPixelDOWN(FLOATER_STEP, k->x+fx,k->y+fy);
- if(free==113){return 113;}
- if(free>0){
- // stopper falls -> erase mask and convert to normal stopper.
- //Mask m = lemmings[getOrdinal(Type.STOPPER)].getMask(dir);
- //m.clearType(maskX,maskY,0,Stencil.MSK_STOPPER);
- k->ID=10;//BOMBER
- } else {break;}
-
- case 10: // BOMBER
- printf("BOMBER ->");
- free=checkPixelDOWN(FLOATER_STEP, k->x+fx,k->y+fy);
- if(free==113){return 113;}
- if(free==FALL_DISTANCE_FORCE_FALL)
- {k->y += FALLER_STEP;}
- else
- {k->y += free;} // max: FALLER_STEP
- err=outOfLowerMap(k->y+fy);
- if(err==114){return 114;}
- if(err==1) {k->ID=17;}
- break;
+ k=k->next;
+ }// FIN WHILE
- default:
- printf("default ->");
- if(boom){
- explode (k->x+fx,k->y+fy,fs);
- k->ID=10;//BOMBER
- break;
- }
- break;
- }//FIN SWITCH
- printf("\n");
+
+ return 0;
}
- k=k->next;
- }// FIN WHILE
+ int print_num(SDL_Surface *dst, SDL_Surface *src, int x, int y, int value)
+ {
+ char buf[9];
+ int i,r,v,p=0;
+ int max = 1000000000;
+ SDL_Rect from;
+ if(value >= 1000000000){
+ printf("value out of Bound %d\n",value);return(15);
+ }
+ v=value;
- return 0;
- }
+ while(max > 1)
+ {
+ r = v / max;
+ v -= r * max;
+ max /= 10;
+ if(p || r)
+ buf[p++] = r;
+ }
+ buf[p++] = value%10;
- int print_num(SDL_Surface *dst, SDL_Surface *src, int x, int y, int value)
- {
- char buf[9];
- int i,r,v,p=0;
- int max = 1000000000;
- SDL_Rect from;
- if(value >= 10000000000){
- printf("value out of Bound %d\n",value);return(15);
- }
- v=value;
+ /* Render! */
+ from.x = 0;
+ from.w = src->w;
+ from.h = src->h/10;
- while(max > 1)
- {
- r = v / max;
- v -= r * max;
- max /= 10;
- if(p || r)
- buf[p++] = r;
+ for(i = 0; i < p; ++i)
+ {
+ SDL_Rect to;
+ to.x = x + i * (from.w + 2);
+ to.y = y;
+ from.y = buf[i] * (from.h);
+ test_blit(src, &from, dst, &to);
+ }
+ return 0;
}
- buf[p++] = value%10;
- /* Render! */
- from.x = 0;
- from.w = src->w;
- from.h = src->h/10;
- for(i = 0; i < p; ++i)
- {
+ int testAlpha(SDL_Surface *dst, SDL_Surface *src,SDL_Surface *src2, int x, int y){
+ SDL_Rect from;
SDL_Rect to;
- to.x = x + i * (from.w + 2);
- to.y = y;
- from.y = buf[i] * (from.h);
- SDL_BlitSurface(src, &from, dst, &to);
- }
- return 0;
- }
+ int i;
+ from.x = 0;
+ from.w = src->w;
+ from.h = src->h/188;
- int testAlpha(SDL_Surface *dst, SDL_Surface *src,SDL_Surface *src2, int x, int y){
- SDL_Rect from;
- SDL_Rect to;
- int i;
+ for(i = 0; i < 188; ++i)
+ {
+ from.y = i * (from.h ) ;
+ to.x = x + (i%40)*16;
+ to.y = y + from.h * (i/40);
+ test_blit(src, &from, dst, &to);
+ //print_num(screen, src2, to.x + 20, to.y, i);
+ }
- from.x = 0;
- from.w = src->w;
- from.h = src->h/188;
+ return 0;
- for(i = 0; i < 188; ++i)
- {
- from.y = i * (from.h ) ;
- to.x = x + (i%40)*16;
- to.y = y + from.h * (i/40);
- SDL_BlitSurface(src, &from, dst, &to);
- //print_num(screen, src2, to.x + 20, to.y, i);
}
- return 0;
+ int print_alpha(SDL_Surface *dst, SDL_Surface *src, int x, int y, char* msg)
+ {
+ SDL_Rect from;
+ SDL_Rect to;
+ int i;
+ int n;
- }
+ from.x = 0;
+ from.w = src->w;
+ from.h = src->h/188;
- int print_alpha(SDL_Surface *dst, SDL_Surface *src, int x, int y, char* msg)
- {
- SDL_Rect from;
- SDL_Rect to;
- int i;
- int n;
+ for(i = 0; i < strlen(msg); ++i)
+ {
+ n=msg[i];
+ //printf("-> %d ~ %c\n",n,n);
+ from.y = 404;
+ if (n > 32 && n < 127) { from.y = (n - 33) * (from.h) ;}
+ //if (n == 32) {continue;}
+ to.x = x + i * (from.w);
+ to.y = y;
+ if(from.y!=404){
+ test_blit(src, &from, dst, &to);
+ }
+ }
+ return 0;
+ }
- from.x = 0;
- from.w = src->w;
- from.h = src->h/188;
- for(i = 0; i < strlen(msg); ++i)
+ int init()
{
- n=msg[i];
- //printf("-> %d ~ %c\n",n,n);
- from.y = 404;
- if (n > 32 && n < 127) { from.y = (n - 33) * (from.h) ;}
- //if (n == 32) {continue;}
- to.x = x + i * (from.w);
- to.y = y;
- if(from.y!=404){
- SDL_BlitSurface(src, &from, dst, &to);
+
+ //Initialisation de tous les sous-systèmes de SDL
+ if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
+ {
+ return 90;
}
- }
- return 0;
- }
+ //Mise en place de l'écran
+ screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_HWSURFACE | SDL_DOUBLEBUF );
- int init()
- {
+ printf("DEBUG ludo : screen->w==%i, screen->h==%i\n", screen->w, screen->h);
+ //S'il y a une erreur lors de la mise en place de l'écran
+ if( screen == NULL ) {
+ printf("problème\n");
+ return 2;
+ }
- //Initialisation de tous les sous-systèmes de SDL
- if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
- {
- return 90;
- }
+ pTerrain = SDL_CreateRGBSurface(SDL_HWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT,
+ SCREEN_BPP,0,0,0,0);//(ccc_black>> 16) & 0xff, (ccc_black>> 8)&0xff,(ccc_black& 0xff),0);
+ if( pTerrain == NULL ) {
+ return 3;
+ }
- //Mise en place de l'écran
- screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_SRCALPHA );
+ pSpr_Lem = SDL_CreateRGBSurface(SDL_HWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT,
+ SCREEN_BPP,0,0,0,0);
- printf("DEBUG ludo : screen->w==%i, screen->h==%i\n", screen->w, screen->h);
- //S'il y a une erreur lors de la mise en place de l'écran
- if( screen == NULL ) {
- printf("problème\n");
- return 2;
- }
+ if( pSpr_Lem == NULL ) {
+ return 3;
+ }
- pTerrain = SDL_CreateRGBSurface(SDL_HWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT,
- SCREEN_BPP,0,0,0,0);//(ccc_black>> 16) & 0xff, (ccc_black>> 8)&0xff,(ccc_black& 0xff),0);
- if( pTerrain == NULL ) {
- return 3;
- }
+ pStencil = SDL_CreateRGBSurface(SDL_SWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT,
+ SCREEN_BPP,0,0,0,0);
+ if( pStencil == NULL ) {
+ return 3;
+ }
- pSpr_Lem = SDL_CreateRGBSurface(SDL_HWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT,
- SCREEN_BPP,0,0,0,0);
+ pStencilFixe = SDL_CreateRGBSurface(SDL_SWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT,
+ SCREEN_BPP,0,0,0,0);
+ if( pStencil == NULL ) {
+ return 3;
+ }
+ //Mise en place de la barre caption
+ SDL_WM_SetCaption( "Test_LVL", NULL );
+ //No pointer of mouse
+ SDL_ShowCursor(0);
- if( pSpr_Lem == NULL ) {
- return 3;
+ //Si tout s'est bien passé
+ return 0;
}
- pStencil = SDL_CreateRGBSurface(SDL_HWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT,
- SCREEN_BPP,0,0,0,0);
- if( pStencil == NULL ) {
- return 3;
- }
+ SDL_Surface* flipSurfaceUD_LR(SDL_Surface* src, enum sens sensO, Uint32 c) {
+ int i,j;
- pStencilFixe = SDL_CreateRGBSurface(SDL_HWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT,
- SCREEN_BPP,0,0,0,0);
- if( pStencil == NULL ) {
- return 3;
- }
- //Mise en place de la barre caption
- SDL_WM_SetCaption( "Test_LVL", NULL );
- //No pointer of mouse
- SDL_ShowCursor(0);
+ SDL_Surface* copy_surface = NULL;
- //Si tout s'est bien passé
- return 0;
- }
+ // This only works for 32 bit pixel format
+ if( src->format->BitsPerPixel == 32 ) {
+ // This surface must be freed by the caller.
+ copy_surface = SDL_CreateRGBSurface(src->flags, src->w, src->h,
+ src->format->BitsPerPixel,
- SDL_Surface* flipSurfaceUD_LR(SDL_Surface* src, enum sens sensO, Uint32 c) {
- int i,j;
-
- SDL_Surface* copy_surface = NULL;
-
- // This only works for 32 bit pixel format
- if( src->format->BitsPerPixel == 32 ) {
- // This surface must be freed by the caller.
- copy_surface = SDL_CreateRGBSurface(src->flags, src->w, src->h,
- src->format->BitsPerPixel,
-
- src->format->Rmask,
- src->format->Gmask,
- src->format->Bmask,
- src->format->Amask);
-
- SDL_SetColorKey( copy_surface,
- SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA,
- SDL_MapRGBA( copy_surface->format,
- (c >> 16) & 0xff,
- (c >> 8) & 0xff,
- (c & 0xff),
- (c >> 24) & 0xff
- )
- );
-
- //FIXME : lock surface
- Uint32 *source = src->pixels;
- Uint32 *dest = copy_surface->pixels;
-
- for(i = 0; i < src->h; i++) {
- for(j = 0; j < src->w; j++) {
- if (sensO == UD){// Sens UD
- dest[ (src->h-i-1)*src->w + j ] = source[ i*src->w + j];
- }
- if (sensO == LR){// Sens LR
- dest[ i*src->w + (src->w-j-1) ] = source[ i*src->w + j];
+ src->format->Rmask,
+ src->format->Gmask,
+ src->format->Bmask,
+ src->format->Amask);
+
+ SDL_SetColorKey( copy_surface,
+ SDL_RLEACCEL | SDL_SRCCOLORKEY,
+ SDL_MapRGB/*A*/( copy_surface->format,
+ (c >> 16) & 0xff,
+ (c >> 8) & 0xff,
+ (c & 0xff)//,
+ //(c >> 24) & 0xff
+ )
+ );
+
+ //FIXME : lock surface
+ Uint32 *source = src->pixels;
+ Uint32 *dest = copy_surface->pixels;
+
+ for(i = 0; i < src->h; i++) {
+ for(j = 0; j < src->w; j++) {
+ if (sensO == UD){// Sens UD
+ dest[ (src->h-i-1)*src->w + j ] = source[ i*src->w + j];
+ }
+ if (sensO == LR){// Sens LR
+ dest[ i*src->w + (src->w-j-1) ] = source[ i*src->w + j];
+ }
}
}
}
- }
- return copy_surface;
- }
+ return copy_surface;
+ }
- SDL_Surface *load_image( char* filename, Uint32 cbg )
- {
- //L'image qui est chargée
- SDL_Surface* loadedImage = NULL;
+ SDL_Surface *load_image( char* filename, Uint32 cbg )
+ {
+ //L'image qui est chargée
+ SDL_Surface* loadedImage = NULL;
- //L'image optimisée qu'on va utiliser
- SDL_Surface* optimizedImage = NULL;
+ //L'image optimisée qu'on va utiliser
+ SDL_Surface* optimizedImage = NULL;
- //Chargement de l'image
- loadedImage = IMG_Load( filename );
+ //Chargement de l'image
+ loadedImage = IMG_Load( filename );
- //Si l'image est chargée
- if( loadedImage != NULL )
- {
- //Création de l'image optimisée
- optimizedImage = SDL_DisplayFormat( loadedImage );
+ //Si l'image est chargée
+ if( loadedImage != NULL )
+ {
+ //Création de l'image optimisée
+ optimizedImage = SDL_DisplayFormat( loadedImage );
- //Libération de l'ancienne image
- SDL_FreeSurface( loadedImage );
+ //Libération de l'ancienne image
+ SDL_FreeSurface( loadedImage );
- //Si la création de l'image optimisée s'est bien passée
- if( optimizedImage != NULL )
- {
- SDL_SetColorKey( optimizedImage,
- SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA,
- SDL_MapRGBA( optimizedImage->format,
- (cbg >> 16) & 0xff,
- (cbg >> 8) & 0xff,
- (cbg & 0xff),
- (cbg >> 24) & 0xff
- )
- );
+ //Si la création de l'image optimisée s'est bien passée
+ if( optimizedImage != NULL )
+ {
+ SDL_SetColorKey( optimizedImage,
+ SDL_RLEACCEL | SDL_SRCCOLORKEY,
+ SDL_MapRGB( optimizedImage->format,
+ (cbg >> 16) & 0xff,
+ (cbg >> 8) & 0xff,
+ (cbg & 0xff)//,
+ //(cbg >> 24) & 0xff
+ )
+ );
+ }
}
- }
- //On retourne l'image optimisée
- return optimizedImage;
- }
+ //On retourne l'image optimisée
+ return optimizedImage;
+ }
- int load_fields(char *folder, struct gameInit *gInit, int tabNum[255] ) {
- int i, lt,total,cpt=-1,llem;
- char *temp;
- char *filepath;
- char *folderLem;
+ int load_fields(char *folder, struct gameInit *gInit, int tabNum[255] ) {
+ int i, lt,total,cpt=-1,llem;
+ char *temp;
+ char *filepath;
+ char *folderLem;
- temp = tabString_eMapStyle[gInit->mapI.map.style];
- lt = strlen(temp);
+ temp = tabString_eMapStyle[gInit->mapI.map.style];
+ lt = strlen(temp);
- llem= strlen("../../../misc/");
- folderLem=malloc(sizeof(char)*(llem+1));
- sprintf(folderLem,"%s","../../../misc/");
+ llem= strlen("../../../misc/");
+ folderLem=malloc(sizeof(char)*(llem+1));
+ sprintf(folderLem,"%s","../../../misc/");
- total=(LEM_JOB*2) + (gInit->mapI.map.tiles)*2 + gInit->mapI.map.tilesSteel + ((gInit->mapI.map.tilesObjet)*2);
+ total=(LEM_JOB*2) + (gInit->mapI.map.tiles)*2 + gInit->mapI.map.tilesSteel + ((gInit->mapI.map.tilesObjet)*2);
- gInit->mapI.map.tabGif=malloc((total + ADD_OBJ) * sizeof(SDL_Surface *));
+ gInit->mapI.map.tabGif=malloc((total + ADD_OBJ) * sizeof(SDL_Surface *));
- //stored terrains
- cpt=ADD_OBJ;
+ //stored terrains
+ cpt=ADD_OBJ;
- filepath = malloc(sizeof(char)*(strlen(folder)+lt+strlen("/_.gif")+(sizeof(int)*10)));
+ filepath = malloc(sizeof(char)*(strlen(folder)+lt+strlen("/_.gif")+(sizeof(int)*10)));
- for(i=0; i < gInit->mapI.map.tiles*2 ; i+=2) {
- sprintf(filepath, "%s/%s%s%d.gif", folder,temp,"_", i/2);
- gInit->mapI.map.tabGif[i+cpt] = load_image(filepath,ccc_terrain);
- gInit->mapI.map.tabGif[i+1+cpt] = flipSurfaceUD_LR(load_image(filepath,ccc_terrain),UD,ccc_terrain);
- if((gInit->mapI.map.tabGif[i+cpt] == NULL)||(gInit->mapI.map.tabGif[i+1+cpt] == NULL)) {
- printf("ERREUR load_file Objet: %s\n", filepath);
- return(16);
- } else {
- //printf("load_file ok : %i -> '%s' + flip_LR\n", i+cpt, filepath);
- }
- }
- free(filepath);
- //stored objet
- cpt=ADD_OBJ+gInit->mapI.map.tiles*2;
-
- filepath = malloc(sizeof(char)*(strlen(folder)+lt+strlen("/o_.gif")+(sizeof(int)*10)));
-
- for(i=0; i < gInit->mapI.map.tilesObjet*2 ; i+=2) {
- sprintf(filepath, "%s/%s%s%d.gif", folder,temp,"o_", i/2);
- gInit->mapI.map.tabGif[i+cpt] = load_image(filepath,ccc_objet);
- gInit->mapI.map.tabGif[i+1+cpt] = flipSurfaceUD_LR(load_image(filepath,ccc_objet),UD,ccc_objet);
- if((gInit->mapI.map.tabGif[i+cpt] == NULL)||(gInit->mapI.map.tabGif[i+1+cpt] == NULL)) {
- printf("ERREUR load_file Objet: %s\n", filepath);
- return(17);
- } else {
- //printf("load_file ok : %i -> '%s' + flip_LR\n", i+cpt, filepath);
+ for(i=0; i < gInit->mapI.map.tiles*2 ; i+=2) {
+ sprintf(filepath, "%s/%s%s%d.gif", folder,temp,"_", i/2);
+ gInit->mapI.map.tabGif[i+cpt] = load_image(filepath,ccc_terrain);
+ gInit->mapI.map.tabGif[i+1+cpt] = flipSurfaceUD_LR(load_image(filepath,ccc_terrain),UD,ccc_terrain);
+ if((gInit->mapI.map.tabGif[i+cpt] == NULL)||(gInit->mapI.map.tabGif[i+1+cpt] == NULL)) {
+ printf("ERREUR load_file Objet: %s\n", filepath);
+ return(16);
+ } else {
+ //printf("load_file ok : %i -> '%s' + flip_LR\n", i+cpt, filepath);
+ }
+ }
+ free(filepath);
+ //stored objet
+ cpt=ADD_OBJ+gInit->mapI.map.tiles*2;
+
+ filepath = malloc(sizeof(char)*(strlen(folder)+lt+strlen("/o_.gif")+(sizeof(int)*10)));
+
+ for(i=0; i < gInit->mapI.map.tilesObjet*2 ; i+=2) {
+ sprintf(filepath, "%s/%s%s%d.gif", folder,temp,"o_", i/2);
+ gInit->mapI.map.tabGif[i+cpt] = load_image(filepath,ccc_objet);
+ gInit->mapI.map.tabGif[i+1+cpt] = flipSurfaceUD_LR(load_image(filepath,ccc_objet),UD,ccc_objet);
+ if((gInit->mapI.map.tabGif[i+cpt] == NULL)||(gInit->mapI.map.tabGif[i+1+cpt] == NULL)) {
+ printf("ERREUR load_file Objet: %s\n", filepath);
+ return(17);
+ } else {
+ //printf("load_file ok : %i -> '%s' + flip_LR\n", i+cpt, filepath);
+ }
+ }
+ free(filepath);
+ //stored steel
+ cpt=ADD_OBJ+(gInit->mapI.map.tiles*2)+(gInit->mapI.map.tilesObjet*2);
+
+ filepath = malloc(sizeof(char)*(strlen(folder)+lt+strlen("/om_.gif")+(sizeof(int)*10)));
+
+ for(i=0; i < gInit->mapI.map.tilesSteel ; ++i) {
+ sprintf(filepath, "%s/%s%s%d.gif", folder,temp,"om_", tabNum[i]);
+ gInit->mapI.map.tabGif[i+cpt] = load_image(filepath,ccc_steel);
+ if(gInit->mapI.map.tabGif[i+cpt] == NULL) {
+ printf("ERREUR load_file steel: %s\n", filepath);
+ return(18);
+ } else {
+ //printf("load_file ok : %i -> '%s'\n", i+cpt, filepath);
+ }
+ }
+ free(filepath);
+ //stored lemmingsDATA
+ cpt=ADD_OBJ+(gInit->mapI.map.tilesObjet*2)+(gInit->mapI.map.tiles)*2+gInit->mapI.map.tilesSteel;
+
+ filepath = malloc(sizeof(char)*(strlen(folderLem)+strlen("lemm")+strlen("/_.gif")+(sizeof(int)*10)));
+
+ for(i=0; i < LEM_JOB*2 ; i+=2) {
+ sprintf(filepath, "%s/%s%d.gif", folderLem,"lemm_",i/2);
+ gInit->mapI.map.tabGif[i+1+cpt] = load_image(filepath,ccc_lemming);
+ gInit->mapI.map.tabGif[i+cpt] = flipSurfaceUD_LR(load_image(filepath,ccc_lemming),LR,ccc_lemming);
+ if((gInit->mapI.map.tabGif[i+cpt] == NULL)||(gInit->mapI.map.tabGif[i+1+cpt] == NULL)) {
+ printf("ERREUR load_file lemmingsDATA: %s\n", filepath);
+ return(19);
+ } else {
+ //printf("load_file ok : %i -> '%s' + flip_LR\n", i+cpt, filepath);
+ }
}
- }
- free(filepath);
- //stored steel
- cpt=ADD_OBJ+(gInit->mapI.map.tiles*2)+(gInit->mapI.map.tilesObjet*2);
-
- filepath = malloc(sizeof(char)*(strlen(folder)+lt+strlen("/om_.gif")+(sizeof(int)*10)));
-
- for(i=0; i < gInit->mapI.map.tilesSteel ; ++i) {
- sprintf(filepath, "%s/%s%s%d.gif", folder,temp,"om_", tabNum[i]);
- gInit->mapI.map.tabGif[i+cpt] = load_image(filepath,ccc_steel);
- if(gInit->mapI.map.tabGif[i+cpt] == NULL) {
- printf("ERREUR load_file steel: %s\n", filepath);
- return(18);
- } else {
- //printf("load_file ok : %i -> '%s'\n", i+cpt, filepath);
- }
- }
- free(filepath);
- //stored lemmingsDATA
- cpt=ADD_OBJ+(gInit->mapI.map.tilesObjet*2)+(gInit->mapI.map.tiles)*2+gInit->mapI.map.tilesSteel;
-
- filepath = malloc(sizeof(char)*(strlen(folderLem)+strlen("lemm")+strlen("/_.gif")+(sizeof(int)*10)));
-
- for(i=0; i < LEM_JOB*2 ; i+=2) {
- sprintf(filepath, "%s/%s%d.gif", folderLem,"lemm_",i/2);
- gInit->mapI.map.tabGif[i+1+cpt] = load_image(filepath,ccc_lemming);
- gInit->mapI.map.tabGif[i+cpt] = flipSurfaceUD_LR(load_image(filepath,ccc_lemming),LR,ccc_lemming);
- if((gInit->mapI.map.tabGif[i+cpt] == NULL)||(gInit->mapI.map.tabGif[i+1+cpt] == NULL)) {
- printf("ERREUR load_file lemmingsDATA: %s\n", filepath);
- return(19);
- } else {
- //printf("load_file ok : %i -> '%s' + flip_LR\n", i+cpt, filepath);
+ free(filepath);
+ //0: lemmfont.gif
+ gInit->mapI.map.tabGif[0]= load_image("../../../misc/lemmfont.gif",gInit->mapI.map.cmap.bgColor);
+ if ( gInit->mapI.map.tabGif[0] == NULL ) {
+ printf("ERREUR load_file lemmfont.gif: %s\n", "../../../misc/lemmfont.gif");
+ return(20);
}
- }
- free(filepath);
- //0: lemmfont.gif
- gInit->mapI.map.tabGif[0]= load_image("../../../misc/lemmfont.gif",gInit->mapI.map.cmap.bgColor);
- if ( gInit->mapI.map.tabGif[0] == NULL ) {
- printf("ERREUR load_file lemmfont.gif: %s\n", "../../../misc/lemmfont.gif");
- return(20);
- }
- //1: numfont.gif
- gInit->mapI.map.tabGif[1]= load_image("../../../misc/numfont.gif",gInit->mapI.map.cmap.bgColor);
- if ( gInit->mapI.map.tabGif[1] == NULL ) {
- printf("ERREUR load_file numfont.gif: %s\n", "../../../misc/numfont.gif");
- return(21);
- }
- //2: countdown.gif
- gInit->mapI.map.tabGif[2]= load_image("../../../misc/countdown.gif",gInit->mapI.map.cmap.bgColor);
- if ( gInit->mapI.map.tabGif[2] == NULL ) {
- printf("ERREUR load_file countdown.gif: %s\n", "../../../misc/countdown.gif");
- return(22);
- }
- //3: cursor.gif
- gInit->mapI.map.tabGif[3]= load_image("../../../misc/cursor.gif",ccc_cursor);//gInit->mapI.map.cmap.bgColor);
- if ( gInit->mapI.map.tabGif[3] == NULL ) {
- printf("ERREUR load_file cursor.gif: %s\n", "../../../misc/cursor.gif");
- return(23);
- }
- //4: explode.gif
- gInit->mapI.map.tabGif[4]= load_image("../../../misc/explode.gif",gInit->mapI.map.cmap.bgColor);
- if ( gInit->mapI.map.tabGif[4] == NULL ) {
- printf("ERREUR load_file explode.gif: %s\n", "../../../misc/explode.gif");
- return(24);
- }
- //5: border.gif
- gInit->mapI.map.tabGif[5]= load_image("../../../misc/border.gif",gInit->mapI.map.cmap.bgColor);
- if ( gInit->mapI.map.tabGif[5] == NULL ) {
- printf("ERREUR load_file border.gif: %s\n", "../../../misc/border.gif");
- return(25);
- }
- //6: replay.gif
- gInit->mapI.map.tabGif[6]= load_image("../../../misc/replay.gif",gInit->mapI.map.cmap.bgColor);
- if ( gInit->mapI.map.tabGif[6] == NULL ) {
- printf("ERREUR load_file replay.gif: %s\n", "../../../misc/replay.gif");
- return(26);
- }
- //7: select.gif
- gInit->mapI.map.tabGif[7]= load_image("../../../misc/select.gif",gInit->mapI.map.cmap.bgColor);
- if ( gInit->mapI.map.tabGif[7] == NULL ) {
- printf("ERREUR load_file select.gif: %s\n", "../../../misc/select.gif");
- return(27);
- }
- // 8: font7x10.bmp
- gInit->mapI.map.tabGif[8]= load_image("./font7x10.bmp",gInit->mapI.map.cmap.bgColor);
- if ( gInit->mapI.map.tabGif[8] == NULL ) {
- printf("ERREUR load_file font7x10.bmp: %s\n", "./font7x10.bmp");
- return(28);
- }
- // 9: alphabet.gif
- gInit->mapI.map.tabGif[9]= load_image("./alphabet.gif",ccc_cursor);
- if ( gInit->mapI.map.tabGif[9] == NULL ) {
- printf("ERREUR load_file alphabet.gif: %s\n", "./alphabet.gif");
- return(29);
- }
- //icone.gif
- cpt=NBR_ADD_OBJ;
- filepath = malloc(sizeof(char)*(strlen(folderLem)+strlen("icon")+strlen("/__alt.gif")+(sizeof(int)*10)));
-
- for(i=0; i < NBR_BUTTON_LEMMING ; ++i) {
- sprintf(filepath, "%s/%s%d.gif", folderLem,"icon_",i);
- //if(i<7){sprintf(filepath, "%s/%s%d.gif", folderLem,"icon_",i);}
- //if(i==7){sprintf(filepath, "%s/%s.gif", folderLem,"icon_6_alt");}
- //if(i>7){sprintf(filepath, "%s/%s%d.gif", folderLem,"icon_",i-1);}
- gInit->mapI.map.tabGif[i+cpt] = load_image(filepath,ccc_icon);
- if(gInit->mapI.map.tabGif[i+cpt] == NULL) {
- printf("ERREUR load_file icon: %s\n", filepath);
- return(30);
- } else {
- //printf("load_file ok : %i -> '%s' + flip_LR\n", i+cpt, filepath);
+ //1: numfont.gif
+ gInit->mapI.map.tabGif[1]= load_image("../../../misc/numfont.gif",gInit->mapI.map.cmap.bgColor);
+ if ( gInit->mapI.map.tabGif[1] == NULL ) {
+ printf("ERREUR load_file numfont.gif: %s\n", "../../../misc/numfont.gif");
+ return(21);
}
- }
- free(filepath);
- free(folderLem);
+ //2: countdown.gif
+ gInit->mapI.map.tabGif[2]= load_image("../../../misc/countdown.gif",gInit->mapI.map.cmap.bgColor);
+ if ( gInit->mapI.map.tabGif[2] == NULL ) {
+ printf("ERREUR load_file countdown.gif: %s\n", "../../../misc/countdown.gif");
+ return(22);
+ }
+ //3: cursor.gif
+ gInit->mapI.map.tabGif[3]= load_image("../../../misc/cursor.gif",ccc_cursor);//gInit->mapI.map.cmap.bgColor);
+ if ( gInit->mapI.map.tabGif[3] == NULL ) {
+ printf("ERREUR load_file cursor.gif: %s\n", "../../../misc/cursor.gif");
+ return(23);
+ }
+ //4: explode.gif
+ gInit->mapI.map.tabGif[4]= load_image("../../../misc/explode.gif",gInit->mapI.map.cmap.bgColor);
+ if ( gInit->mapI.map.tabGif[4] == NULL ) {
+ printf("ERREUR load_file explode.gif: %s\n", "../../../misc/explode.gif");
+ return(24);
+ }
+ //5: border.gif
+ gInit->mapI.map.tabGif[5]= load_image("../../../misc/border.gif",gInit->mapI.map.cmap.bgColor);
+ if ( gInit->mapI.map.tabGif[5] == NULL ) {
+ printf("ERREUR load_file border.gif: %s\n", "../../../misc/border.gif");
+ return(25);
+ }
+ //6: replay.gif
+ gInit->mapI.map.tabGif[6]= load_image("../../../misc/replay.gif",gInit->mapI.map.cmap.bgColor);
+ if ( gInit->mapI.map.tabGif[6] == NULL ) {
+ printf("ERREUR load_file replay.gif: %s\n", "../../../misc/replay.gif");
+ return(26);
+ }
+ //7: select.gif
+ gInit->mapI.map.tabGif[7]= load_image("../../../misc/select.gif",gInit->mapI.map.cmap.bgColor);
+ if ( gInit->mapI.map.tabGif[7] == NULL ) {
+ printf("ERREUR load_file select.gif: %s\n", "../../../misc/select.gif");
+ return(27);
+ }
+ // 8: font7x10.bmp
+ gInit->mapI.map.tabGif[8]= load_image("./font7x10.bmp",gInit->mapI.map.cmap.bgColor);
+ if ( gInit->mapI.map.tabGif[8] == NULL ) {
+ printf("ERREUR load_file font7x10.bmp: %s\n", "./font7x10.bmp");
+ return(28);
+ }
+ // 9: alphabet.gif
+ gInit->mapI.map.tabGif[9]= load_image("./alphabet.gif",ccc_cursor);
+ if ( gInit->mapI.map.tabGif[9] == NULL ) {
+ printf("ERREUR load_file alphabet.gif: %s\n", "./alphabet.gif");
+ return(29);
+ }
+ //icone.gif
+ cpt=NBR_ADD_OBJ;
+ filepath = malloc(sizeof(char)*(strlen(folderLem)+strlen("icon")+strlen("/__alt.gif")+(sizeof(int)*10)));
+
+ for(i=0; i < NBR_BUTTON_LEMMING ; ++i) {
+ sprintf(filepath, "%s/%s%d.gif", folderLem,"icon_",i);
+ //if(i<7){sprintf(filepath, "%s/%s%d.gif", folderLem,"icon_",i);}
+ //if(i==7){sprintf(filepath, "%s/%s.gif", folderLem,"icon_6_alt");}
+ //if(i>7){sprintf(filepath, "%s/%s%d.gif", folderLem,"icon_",i-1);}
+ gInit->mapI.map.tabGif[i+cpt] = load_image(filepath,ccc_icon);
+ if(gInit->mapI.map.tabGif[i+cpt] == NULL) {
+ printf("ERREUR load_file icon: %s\n", filepath);
+ return(30);
+ } else {
+ //printf("load_file ok : %i -> '%s' + flip_LR\n", i+cpt, filepath);
+ }
+ }
+ free(filepath);
+ free(folderLem);
- return 0;
- }
+ return 0;
+ }
- int load_files(struct gameInit *gInit)
- {
- int lt,ltt,ltlem;
- int err=0;
- int res, lterrain, lobjet, lsteel;
- char *folder;
- char *spriteINI;
- char *lemINI;
- char *terrainGif;
- char *objetGif;
- char *steelGif;
- char *temp;
- int tabNum[255];
- struct dirent *lecture;
- DIR *rep;
-
- yyparse(gInit);
-
- fclose(yyin);
- printf("CLOSE 1\n");
-
-
- lt = (strlen("../../../styles/"));
- ltlem = (strlen("../../../misc/lemming.ini"));
- ltt = (strlen(tabString_eMapStyle[gInit->mapI.map.style]));
-
- folder = malloc(sizeof(char)*(lt+ltt+1));
- spriteINI = malloc(sizeof(char)*(lt+ltt*2+5));// *2:dossier/fichier, +4: .ini, +1: string
- lemINI = malloc(sizeof(char)*ltlem+1);
-
-
- //folder = "/home/jazzblue/Bureau/Projet-Lemmings/trunk/styles/dirt";
- //printf("test segFault\n");
- sprintf(folder,"../../../styles/%s",tabString_eMapStyle[gInit->mapI.map.style]);
- sprintf(spriteINI,"%s/%s.ini",folder,tabString_eMapStyle[gInit->mapI.map.style]);
- sprintf(lemINI,"%s","../../../misc/lemming.ini");
- //printf("test2\n");
-
- temp = tabString_eMapStyle[gInit->mapI.map.style];
- lt = strlen(temp);
- lterrain = lt+1;
- lobjet = lt+2;
- lsteel = lt+3;
- terrainGif=malloc(sizeof(char)*(lterrain+1));
- objetGif=malloc(sizeof(char)*(lobjet+1));
- steelGif=malloc(sizeof(char)*(lsteel+1));
- sprintf(terrainGif,"%s_",temp);
- sprintf(objetGif,"%so_",temp);
- sprintf(steelGif,"%som_",temp);
-
- // Compter les textures de terrain
- rep = opendir(folder);
- if (rep==NULL) {
- printf("Erreur opendir('%s')\n", folder);
- return(31);
- }
+ int load_files(struct gameInit *gInit)
+ {
+ int lt,ltt,ltlem;
+ int err=0;
+ int res, lterrain, lobjet, lsteel;
+ char *folder;
+ char *spriteINI;
+ char *lemINI;
+ char *terrainGif;
+ char *objetGif;
+ char *steelGif;
+ char *temp;
+ int tabNum[255];
+ struct dirent *lecture;
+ DIR *rep;
+
+ yyparse(gInit);
+
+ fclose(yyin);
+ printf("CLOSE 1\n");
+
+
+ lt = (strlen("../../../styles/"));
+ ltlem = (strlen("../../../misc/lemming.ini"));
+ ltt = (strlen(tabString_eMapStyle[gInit->mapI.map.style]));
+
+ folder = malloc(sizeof(char)*(lt+ltt+1));
+ spriteINI = malloc(sizeof(char)*(lt+ltt*2+5));// *2:dossier/fichier, +4: .ini, +1: string
+ lemINI = malloc(sizeof(char)*ltlem+1);
+
+
+ //folder = "/home/jazzblue/Bureau/Projet-Lemmings/trunk/styles/dirt";
+ //printf("test segFault\n");
+ sprintf(folder,"../../../styles/%s",tabString_eMapStyle[gInit->mapI.map.style]);
+ sprintf(spriteINI,"%s/%s.ini",folder,tabString_eMapStyle[gInit->mapI.map.style]);
+ sprintf(lemINI,"%s","../../../misc/lemming.ini");
+ //printf("test2\n");
+
+ temp = tabString_eMapStyle[gInit->mapI.map.style];
+ lt = strlen(temp);
+ lterrain = lt+1;
+ lobjet = lt+2;
+ lsteel = lt+3;
+ terrainGif=malloc(sizeof(char)*(lterrain+1));
+ objetGif=malloc(sizeof(char)*(lobjet+1));
+ steelGif=malloc(sizeof(char)*(lsteel+1));
+ sprintf(terrainGif,"%s_",temp);
+ sprintf(objetGif,"%so_",temp);
+ sprintf(steelGif,"%som_",temp);
+
+ // Compter les textures de terrain
+ rep = opendir(folder);
+ if (rep==NULL) {
+ printf("Erreur opendir('%s')\n", folder);
+ return(31);
+ }
- while ((lecture = readdir(rep))) {
- if( (res=strncmp(terrainGif, lecture->d_name,lterrain)) == 0 ){
- ++(gInit->mapI.map.tiles);
- } else {
- if( (res=strncmp(objetGif, lecture->d_name,lobjet)) == 0 ) {
- ++(gInit->mapI.map.tilesObjet);
+ while ((lecture = readdir(rep))) {
+ if( (res=strncmp(terrainGif, lecture->d_name,lterrain)) == 0 ){
+ ++(gInit->mapI.map.tiles);
} else {
- if ( (res=strncmp(steelGif, lecture->d_name,lsteel)) == 0 ) {
- sscanf(lecture->d_name+lsteel, "%i", &(tabNum[gInit->mapI.map.tilesSteel]));
- ++(gInit->mapI.map.tilesSteel);
-
+ if( (res=strncmp(objetGif, lecture->d_name,lobjet)) == 0 ) {
+ ++(gInit->mapI.map.tilesObjet);
} else {
- printf("BUG : type de fichier non reconnu [%s] \n", lecture->d_name);
+ if ( (res=strncmp(steelGif, lecture->d_name,lsteel)) == 0 ) {
+ sscanf(lecture->d_name+lsteel, "%i", &(tabNum[gInit->mapI.map.tilesSteel]));
+ ++(gInit->mapI.map.tilesSteel);
+
+ } else {
+ printf("BUG : type de fichier non reconnu [%s] \n", lecture->d_name);
+ }
}
}
}
- }
- closedir(rep);
+ closedir(rep);
- yyin=fopen(spriteINI, "r");
- if (yyin==NULL) { fprintf(stderr,"Filename INVALIDE: %s\n",spriteINI);
- perror("Impossible d'ouvrir le fichier de configuration des sprite"); return(32);
- }
- yyparse(gInit);
- fclose(yyin);
- printf("CLOSE 2\n");
+ yyin=fopen(spriteINI, "r");
+ if (yyin==NULL) { fprintf(stderr,"Filename INVALIDE: %s\n",spriteINI);
+ perror("Impossible d'ouvrir le fichier de configuration des sprite"); return(32);
+ }
+ yyparse(gInit);
+ fclose(yyin);
+ printf("CLOSE 2\n");
- yyin=fopen(lemINI, "r");
- if (yyin==NULL) { fprintf(stderr,"Filename INVALIDE: %s\n",lemINI);
- perror("Impossible d'ouvrir le fichier de configuration des lemmings"); return(33);
- }
- yyparse(gInit);
- fclose(yyin);
- printf("CLOSE 3\n");
+ yyin=fopen(lemINI, "r");
+ if (yyin==NULL) { fprintf(stderr,"Filename INVALIDE: %s\n",lemINI);
+ perror("Impossible d'ouvrir le fichier de configuration des lemmings"); return(33);
+ }
+ yyparse(gInit);
+ fclose(yyin);
+ printf("CLOSE 3\n");
- err=load_fields(folder, gInit, tabNum);
- if(err!=0){return err;}
+ err=load_fields(folder, gInit, tabNum);
+ if(err!=0){return err;}
- //printf("REVERSE t.lt\n");
- gInit->t.lt=(struct listeSimplementChainee*)rev_listeO(gInit->t.lt);
- //printf("REVERSE o.lo\n");
- gInit->o.lo=(struct listeSimplementChainee*)rev_listeO(gInit->o.lo);
- //printf("REVERSE s.ls\n");
- gInit->s.ls=(struct listeSimplementChainee*)rev_listeO(gInit->s.ls);
+ //printf("REVERSE t.lt\n");
+ gInit->t.lt=(struct listeSimplementChainee*)rev_listeO(gInit->t.lt);
+ //printf("REVERSE o.lo\n");
+ gInit->o.lo=(struct listeSimplementChainee*)rev_listeO(gInit->o.lo);
+ //printf("REVERSE s.ls\n");
+ gInit->s.ls=(struct listeSimplementChainee*)rev_listeO(gInit->s.ls);
- // AFFICHAGE DES INFOS DE LA MAP
- err=afficher(gInit);
- if(err!=0){return err;}
+ // AFFICHAGE DES INFOS DE LA MAP
+ err=afficher(gInit);
+ if(err!=0){return err;}
- //Si tout s'est bien passé
- free(terrainGif);
- free(objetGif);
- free(steelGif);
- free(folder);
- free(spriteINI);
- free(lemINI);
+ //Si tout s'est bien passé
+ free(terrainGif);
+ free(objetGif);
+ free(steelGif);
+ free(folder);
+ free(spriteINI);
+ free(lemINI);
- return 0;
- }
+ return 0;
+ }
- int afficher(struct gameInit *gInit){
+ int afficher(struct gameInit *gInit){
- int i;
- struct listeSimplementChainee *k;
+ int i;
+ struct listeSimplementChainee *k;
- printf("AFFICHAGE DE GAME INIT\n");
- printf("LES PARAMETRES:\n");
- for(i=0;i<IDENT_COUNT;++i){
- printf("\t%s = %d\n",tabString_eParaMap[i],gInit->mapI.paraMap[i]);
- }
- printf("\txPos = %d\n",gInit->mapI.xPos);
- printf("\tstyle = %s\n",tabString_eMapStyle[gInit->mapI.map.style]);
-
- printf("LE NOM DU NIVEAU:\n");
- printf("name = %s\n",gInit->mapI.name);
- printf("LES COULEURS DU NIVEAU:\n");
- printf("bgColor R = %X G = %X B = %X\n",
- ((gInit->mapI.map.cmap.bgColor>>16) & 0xff),
- ((gInit->mapI.map.cmap.bgColor>>8) & 0xff),
- (gInit->mapI.map.cmap.bgColor & 0xff) );
- printf("debrisColor R = %X G = %X B = %X\n",
- ((gInit->mapI.map.cmap.debrisColor>>16) & 0xff),
- ((gInit->mapI.map.cmap.debrisColor>>8) & 0xff),
- (gInit->mapI.map.cmap.debrisColor & 0xff) );
- printf("debrisColor:\n");
- for(i=0;i<PARTICULE_COUNT;++i){
- printf("\tP%d: R = %X G = %X B = %X\n",i,
- ((gInit->mapI.map.cmap.particleColor[i]>>16) & 0xff),
- ((gInit->mapI.map.cmap.particleColor[i]>>8) & 0xff),
- (gInit->mapI.map.cmap.particleColor[i] & 0xff) );
+ printf("AFFICHAGE DE GAME INIT\n");
+ printf("LES PARAMETRES:\n");
+ for(i=0;i<IDENT_COUNT;++i){
+ printf("\t%s = %d\n",tabString_eParaMap[i],gInit->mapI.paraMap[i]);
+ }
+ printf("\txPos = %d\n",gInit->mapI.xPos);
+ printf("\tstyle = %s\n",tabString_eMapStyle[gInit->mapI.map.style]);
+
+ printf("LE NOM DU NIVEAU:\n");
+ printf("name = %s\n",gInit->mapI.name);
+ printf("LES COULEURS DU NIVEAU:\n");
+ printf("bgColor R = %X G = %X B = %X\n",
+ ((gInit->mapI.map.cmap.bgColor>>16) & 0xff),
+ ((gInit->mapI.map.cmap.bgColor>>8) & 0xff),
+ (gInit->mapI.map.cmap.bgColor & 0xff) );
+ printf("debrisColor R = %X G = %X B = %X\n",
+ ((gInit->mapI.map.cmap.debrisColor>>16) & 0xff),
+ ((gInit->mapI.map.cmap.debrisColor>>8) & 0xff),
+ (gInit->mapI.map.cmap.debrisColor & 0xff) );
+ printf("debrisColor:\n");
+ for(i=0;i<PARTICULE_COUNT;++i){
+ printf("\tP%d: R = %X G = %X B = %X\n",i,
+ ((gInit->mapI.map.cmap.particleColor[i]>>16) & 0xff),
+ ((gInit->mapI.map.cmap.particleColor[i]>>8) & 0xff),
+ (gInit->mapI.map.cmap.particleColor[i] & 0xff) );
- }
+ }
- printf("TERRAINS:\n");
- k=gInit->t.lt;
- i=0;
- while ( k !=NULL ) {
- if(k->data.pt != NULL){//{printf("paraTerrain non initialiser\n");return(34);}
- printf("\tterrain_%d = %d, %d, %d, %d\n",i,k->ID, k->x, k->y,k->data.pt->modif);
+ printf("TERRAINS:\n");
+ k=gInit->t.lt;
+ i=0;
+ while ( k !=NULL ) {
+ if(k->data.pt != NULL){//{printf("paraTerrain non initialiser\n");return(34);}
+ printf("\tterrain_%d = %d, %d, %d, %d\n",i,k->ID, k->x, k->y,k->data.pt->modif);
+ }
+ ++i;
+ k=k->next;
}
- ++i;
- k=k->next;
- }
- printf("OBJETS:\n");
+ printf("OBJETS:\n");
- k=gInit->o.lo;
- i=0;
- while ( k !=NULL ) {
- if(k->data.po != NULL){ //{printf("paraObjet non initialiser\n");return(35);}
- printf("\tobject_%d = %d, %d, %d, %d, %d\n",i,k->ID, k->x, k->y, k->data.po->paintMode,k->data.po->UD);
+ k=gInit->o.lo;
+ i=0;
+ while ( k !=NULL ) {
+ if(k->data.po != NULL){ //{printf("paraObjet non initialiser\n");return(35);}
+ printf("\tobject_%d = %d, %d, %d, %d, %d\n",i,k->ID, k->x, k->y, k->data.po->paintMode,k->data.po->UD);
+ }
+ ++i;
+ k=k->next;
}
- ++i;
- k=k->next;
- }
- printf("STEELS:\n");
- k=gInit->s.ls;
- i=0;
- while ( k !=NULL ) {
- if(k->data.ps != NULL){//{printf("paraSteel non initialiser\n");return(36);}
- printf("\tsteel_%d = %d, %d, %d, %d, %d\n",i,k->ID=i, k->x, k->y, k->data.ps->w,k->data.ps->h); // FIXME big fuck here with "="
+ printf("STEELS:\n");
+ k=gInit->s.ls;
+ i=0;
+ while ( k !=NULL ) {
+ if(k->data.ps != NULL){//{printf("paraSteel non initialiser\n");return(36);}
+ printf("\tsteel_%d = %d, %d, %d, %d, %d\n",i,k->ID=i, k->x, k->y, k->data.ps->w,k->data.ps->h); // FIXME big fuck here with "="
+ }
+ ++i;
+ k=k->next;
}
- ++i;
- k=k->next;
- }
- printf("DATA SPRITES OBJET:\n");
- for(i=0;i<gInit->mapI.map.tilesObjet;++i){
- printf("spr_%d:\n\tframes_%d = %d\n\tanim_%d = %d\n\ttype_%d = %d\n\tsound_%d = %d\n",i,i,gInit->mapI.map.tabDataSprO[i].state,i,gInit->mapI.map.tabDataSprO[i].anim,i,gInit->mapI.map.tabDataSprO[i].type,i,gInit->mapI.map.tabDataSprO[i].sound);
- }
+ printf("DATA SPRITES OBJET:\n");
+ for(i=0;i<gInit->mapI.map.tilesObjet;++i){
+ printf("spr_%d:\n\tframes_%d = %d\n\tanim_%d = %d\n\ttype_%d = %d\n\tsound_%d = %d\n",i,i,gInit->mapI.map.tabDataSprO[i].state,i,gInit->mapI.map.tabDataSprO[i].anim,i,gInit->mapI.map.tabDataSprO[i].type,i,gInit->mapI.map.tabDataSprO[i].sound);
+ }
- printf("DATA JOB LEMMINGS:\n");
- for(i=0;i<LEM_JOB;++i){
- printf("lem_%d:\n\tlemm_%d = %d, %d, %d\n\tpos_%d = %d, %d, %d\n",i,i,gInit->mapI.lemmingDATA[i].state,gInit->mapI.lemmingDATA[i].dir,gInit->mapI.lemmingDATA[i].anim,i,gInit->mapI.lemmingDATA[i].footX,gInit->mapI.lemmingDATA[i].footY,gInit->mapI.lemmingDATA[i].footSize);
+ printf("DATA JOB LEMMINGS:\n");
+ for(i=0;i<LEM_JOB;++i){
+ printf("lem_%d:\n\tlemm_%d = %d, %d, %d\n\tpos_%d = %d, %d, %d\n",i,i,gInit->mapI.lemmingDATA[i].state,gInit->mapI.lemmingDATA[i].dir,gInit->mapI.lemmingDATA[i].anim,i,gInit->mapI.lemmingDATA[i].footX,gInit->mapI.lemmingDATA[i].footY,gInit->mapI.lemmingDATA[i].footSize);
- if (gInit->mapI.lemmingDATA[i].mask != NULL){
- printf("\tmask_%d = %d, %d, %d\n",i,gInit->mapI.lemmingDATA[i].mask->stateM,gInit->mapI.lemmingDATA[i].mask->dirM,gInit->mapI.lemmingDATA[i].mask->cooldown);
- }
+ if (gInit->mapI.lemmingDATA[i].mask != NULL){
+ printf("\tmask_%d = %d, %d, %d\n",i,gInit->mapI.lemmingDATA[i].mask->stateM,gInit->mapI.lemmingDATA[i].mask->dirM,gInit->mapI.lemmingDATA[i].mask->cooldown);
+ }
- if (gInit->mapI.lemmingDATA[i].imask != NULL){
- printf("\timask_%d = %d , %d\n",i,gInit->mapI.lemmingDATA[i].imask->stateI,gInit->mapI.lemmingDATA[i].imask->dirI);
+ if (gInit->mapI.lemmingDATA[i].imask != NULL){
+ printf("\timask_%d = %d , %d\n",i,gInit->mapI.lemmingDATA[i].imask->stateI,gInit->mapI.lemmingDATA[i].imask->dirI);
+ }
}
+ return 0;
}
- return 0;
- }
- int clean_up()
- {
- //On libère la feuille de sprites
- // SDL_FreeSurface( faces );
- SDL_FreeSurface( pTerrain );
- //On quitte SDL
- SDL_Quit();
+ int clean_up()
+ {
+ //On libère la feuille de sprites
+ // SDL_FreeSurface( faces );
+ SDL_FreeSurface( pTerrain );
+ //On quitte SDL
+ SDL_Quit();
- return 0;
- }
+ return 0;
+ }
- int initGame(struct gameInit *gInit){
+ int initGame(struct gameInit *gInit){
- int i;
+ int i;
- // init liste
- gInit->t.nbr=0;
- gInit->o.nbr=0;
- gInit->s.nbr=0;
- gInit->l.nbrInput=0;
- gInit->l.nbr=0;
- gInit->l.nbrDied=0;
- gInit->l.nbrSafe=0;
+ // init liste
+ gInit->t.nbr=0;
+ gInit->o.nbr=0;
+ gInit->s.nbr=0;
+ gInit->l.nbrInput=0;
+ gInit->l.nbr=0;
+ gInit->l.nbrDied=0;
+ gInit->l.nbrSafe=0;
+
+ gInit->t.lt=NULL;
+ gInit->o.lo=NULL;
+ gInit->s.ls=NULL;
+ gInit->l.ll=NULL;
- gInit->t.lt=NULL;
- gInit->o.lo=NULL;
- gInit->s.ls=NULL;
- gInit->l.ll=NULL;
+ // init button state
+ for(i=0;i<NBR_CPT;++i){
+ gInit->cptGame[i]=0;
+ }
+ gInit->cptGame[17]=404;
- // init button state
- for(i=0;i<NBR_CPT;++i){
- gInit->cptGame[i]=0;
- }
- gInit->cptGame[17]=404;
+ // init InfoMap
+ // map name
+ gInit->mapI.name = NULL;
- // init InfoMap
- // map name
- gInit->mapI.name = NULL;
+ // paraMap
+ for(i=0;i<IDENT_COUNT;++i){
+ gInit->mapI.paraMap[i]=0;
+ }
+ // xPos
+ gInit->mapI.xPos=0;
+
+ //MaxFallDistance
+ gInit->mapI.nbrEntry=0;
+ gInit->mapI.MaxFallDistance = 126;
+ gInit->mapI.nuke=0;
+
+ // init MapStyle
+ gInit->mapI.map.style=undefined;
+ gInit->mapI.map.superLemming=0;
+ gInit->mapI.map.tiles=0;
+ gInit->mapI.map.tilesObjet=0;
+ gInit->mapI.map.tilesSteel=0;
+ gInit->mapI.map.tabDataSprO=NULL;
+ gInit->mapI.map.tabGif=NULL;
+
+ // lemmingJobAndSprite
+ gInit->mapI.lemmingDATA=NULL;
- // paraMap
- for(i=0;i<IDENT_COUNT;++i){
- gInit->mapI.paraMap[i]=0;
+ return 0;
}
- // xPos
- gInit->mapI.xPos=0;
-
- //MaxFallDistance
- gInit->mapI.nbrEntry=0;
- gInit->mapI.MaxFallDistance = 126;
- gInit->mapI.nuke=0;
-
- // init MapStyle
- gInit->mapI.map.style=undefined;
- gInit->mapI.map.superLemming=0;
- gInit->mapI.map.tiles=0;
- gInit->mapI.map.tilesObjet=0;
- gInit->mapI.map.tilesSteel=0;
- gInit->mapI.map.tabDataSprO=NULL;
- gInit->mapI.map.tabGif=NULL;
-
- // lemmingJobAndSprite
- gInit->mapI.lemmingDATA=NULL;
- return 0;
- }
+ int test_O_UD(int UD){
- int test_O_UD(int UD){
-
- switch(UD){
- case 4 : return 1;break;
- case 6 : return 1;break;
- case 12 : return 1;break;
- case 14 : return 1;break;
- default: return 0;break;
+ switch(UD){
+ case 4 : return 1;break;
+ case 6 : return 1;break;
+ case 12 : return 1;break;
+ case 14 : return 1;break;
+ default: return 0;break;
+ }
+ return 0;
}
- return 0;
- }
- int creationLemming(struct gameInit *gInit){
- int nbLem;
- struct listeSimplementChainee *k=NULL;
- struct listeSimplementChainee *kTemp=NULL;
- SDL_Surface *sf=NULL;
-
- int coorE[10][2];
- int i=0;
- //DEBUT TEST CREATION UN LEMMING
+ int creationLemming(struct gameInit *gInit){
+ int nbLem;
+ struct listeSimplementChainee *k=NULL;
+ struct listeSimplementChainee *kTemp=NULL;
+ SDL_Surface *sf=NULL;
- // DEBUT DEBUG: LEMMING COLLISION
- //gInit->mapI.paraMap[1]=1;
- // FIN DEBUG: LEMMING COLLISION
+ int coorE[10][2];
+ int i=0;
+ //DEBUT TEST CREATION UN LEMMING
- nbLem=gInit->mapI.paraMap[1];
- //nbLem=1;
- //printf("nbLem %d\n",nbLem);
+ // DEBUT DEBUG: LEMMING COLLISION
+ //gInit->mapI.paraMap[1]=1;
+ // FIN DEBUG: LEMMING COLLISION
- if(gInit->mapI.nbrEntry==0){
- printf("ERREUR ALGO: nbrEntry == 0\n");
- return(37);
- }
-
-
- // PREMIER CAS
- gInit->l.nbrInput=1;
- gInit->l.ll = malloc(sizeof(struct listeSimplementChainee));
- gInit->l.ll->ID=18;
+ nbLem=gInit->mapI.paraMap[1];
+ //nbLem=1;
+ //printf("nbLem %d\n",nbLem);
- k=gInit->o.lo;
- while ( k !=NULL ) {
- if( k->ID == 1 ){// Entry detecte
- sf = gInit->mapI.map.tabGif[gInit->mapI.map.tiles*2+k->ID*2+k->data.po->UD+ADD_OBJ];
- coorE[i][0]=k->x+(sf->w/2)-16;
- coorE[i][1]=k->y;
- ++i;
- if(i>=gInit->mapI.nbrEntry){break;}
- if(i>9){printf("ERREUR: too many entry\n");return(38);}
+ if(gInit->mapI.nbrEntry==0){
+ printf("ERREUR ALGO: nbrEntry == 0\n");
+ return(37);
}
- k=k->next;
- }
- if(k == NULL){
- printf("BUG: NO ENTRY IN THIS LEVEL ...\n");
- return(39);
- }
- gInit->l.ll->x=coorE[0][0];
- gInit->l.ll->y=coorE[0][1];
-
- gInit->l.ll->data.pt=NULL;
- gInit->l.ll->data.po=NULL;
- gInit->l.ll->data.ps=NULL;
- gInit->l.ll->data.pl=malloc(sizeof(struct paraLemming));
-
- gInit->l.ll->data.pl->dir=1;
- gInit->l.ll->data.pl->climber=0;
- gInit->l.ll->data.pl->blocker=0;
- gInit->l.ll->data.pl->bomber=404;
- gInit->l.ll->data.pl->floater=0;
- gInit->l.ll->data.pl->cptFall=0;
- gInit->l.ll->data.pl->cptJump=0;
- gInit->l.ll->data.pl->nuke=0;
- gInit->l.ll->data.pl->cptState=0;
- gInit->l.ll->data.pl->CptBoom=404;
- gInit->l.ll->data.pl->cptFall2=0;
- gInit->l.ll->data.pl->cptBrick=0;
-
- gInit->l.ll->next=NULL;
- if(gInit->mapI.nbrEntry==1){i=0;}
- else {i=1;}
- while(--nbLem > 0){
- // TOUS LES AUTRES CAS
-
- kTemp=malloc(sizeof(struct listeSimplementChainee));
- kTemp=gInit->l.ll;
-
- gInit->l.ll=NULL;
- gInit->l.ll=malloc(sizeof(struct listeSimplementChainee));
-
- gInit->l.ll->next=NULL;
- gInit->l.ll->next=malloc(sizeof(struct listeSimplementChainee));
- gInit->l.ll->next=kTemp;
- gInit->l.nbrInput += 1;
+ // PREMIER CAS
+ gInit->l.nbrInput=1;
+ gInit->l.ll = malloc(sizeof(struct listeSimplementChainee));
gInit->l.ll->ID=18;
- gInit->l.ll->x=coorE[i%gInit->mapI.nbrEntry][0];
- gInit->l.ll->y=coorE[i%gInit->mapI.nbrEntry][1];
+ k=gInit->o.lo;
+ while ( k !=NULL ) {
+ if( k->ID == 1 ){// Entry detecte
+ sf = gInit->mapI.map.tabGif[gInit->mapI.map.tiles*2+k->ID*2+k->data.po->UD+ADD_OBJ];
+ coorE[i][0]=k->x+(sf->w/2)-16;
+ coorE[i][1]=k->y;
+ ++i;
+ if(i>=gInit->mapI.nbrEntry){break;}
+ if(i>9){printf("ERREUR: too many entry\n");return(38);}
+ }
+ k=k->next;
+ }
+ if(k == NULL){
+ printf("BUG: NO ENTRY IN THIS LEVEL ...\n");
+ return(39);
+ }
+ gInit->l.ll->x=coorE[0][0];
+ gInit->l.ll->y=coorE[0][1];
+ gInit->l.ll->data.pt=NULL;
+ gInit->l.ll->data.po=NULL;
+ gInit->l.ll->data.ps=NULL;
gInit->l.ll->data.pl=malloc(sizeof(struct paraLemming));
+
gInit->l.ll->data.pl->dir=1;
gInit->l.ll->data.pl->climber=0;
gInit->l.ll->data.pl->blocker=0;
@@ -2560,324 +2577,503 @@ int stateLemming(struct gameInit *gInit){
gInit->l.ll->data.pl->CptBoom=404;
gInit->l.ll->data.pl->cptFall2=0;
gInit->l.ll->data.pl->cptBrick=0;
+
+ gInit->l.ll->next=NULL;
if(gInit->mapI.nbrEntry==1){i=0;}
- else {++i;}
- }
- //FIN TEST CREATION UN LEMMING
+ else {i=1;}
+ while(--nbLem > 0){
+ // TOUS LES AUTRES CAS
+
+ kTemp=malloc(sizeof(struct listeSimplementChainee));
+ kTemp=gInit->l.ll;
+
+ gInit->l.ll=NULL;
+ gInit->l.ll=malloc(sizeof(struct listeSimplementChainee));
+
+ gInit->l.ll->next=NULL;
+ gInit->l.ll->next=malloc(sizeof(struct listeSimplementChainee));
+
+ gInit->l.ll->next=kTemp;
+
+ gInit->l.nbrInput += 1;
+ gInit->l.ll->ID=18;
+
+ gInit->l.ll->x=coorE[i%gInit->mapI.nbrEntry][0];
+ gInit->l.ll->y=coorE[i%gInit->mapI.nbrEntry][1];
+
+ gInit->l.ll->data.pl=malloc(sizeof(struct paraLemming));
+ gInit->l.ll->data.pl->dir=1;
+ gInit->l.ll->data.pl->climber=0;
+ gInit->l.ll->data.pl->blocker=0;
+ gInit->l.ll->data.pl->bomber=404;
+ gInit->l.ll->data.pl->floater=0;
+ gInit->l.ll->data.pl->cptFall=0;
+ gInit->l.ll->data.pl->cptJump=0;
+ gInit->l.ll->data.pl->nuke=0;
+ gInit->l.ll->data.pl->cptState=0;
+ gInit->l.ll->data.pl->CptBoom=404;
+ gInit->l.ll->data.pl->cptFall2=0;
+ gInit->l.ll->data.pl->cptBrick=0;
+ if(gInit->mapI.nbrEntry==1){i=0;}
+ else {++i;}
+ }
+ //FIN TEST CREATION UN LEMMING
- //printf("REVERSE l.ll\n");
- gInit->l.ll=(struct listeSimplementChainee*)rev_listeO(gInit->l.ll);
+ //printf("REVERSE l.ll\n");
+ gInit->l.ll=(struct listeSimplementChainee*)rev_listeO(gInit->l.ll);
- return 0;
- }
+ return 0;
+ }
- int paint_terrain (struct gameInit *gInit, int choix){
- struct listeSimplementChainee *k=NULL;
- SDL_Rect offset;
- SDL_Surface *sf;
- int err=0;
- int overwrite=0;
- int remove=0;
- int paint=0;
- int tx,ty=0;
- int cpt=0;
- int ok=0;
- Uint32 color;
+ int paint_terrain (struct gameInit *gInit, int choix){
+ struct listeSimplementChainee *k=NULL;
+ SDL_Rect offset;
+ SDL_Surface *sf;
+ int err=0;
+ int overwrite=0;
+ int remove=0;
+ int paint=0;
+ int tx,ty=0;
+ int cpt=0;
+ int ok=0;
+ Uint32 color;
+
+ // printf("LES TERRAINS : ");
+ k=gInit->t.lt;
+ while ( k !=NULL ) {
+ offset.x = k->x;
+ offset.y = k->y;
- // printf("LES TERRAINS : ");
- k=gInit->t.lt;
- while ( k !=NULL ) {
- offset.x = k->x;
- offset.y = k->y;
-
- sf = gInit->mapI.map.tabGif[test_O_UD(k->data.pt->modif)+k->ID*2+ADD_OBJ];
-
- if((k->data.pt->modif != 0)&&
- (k->data.pt->modif != 2)&&
- (k->data.pt->modif != 4)&&
- (k->data.pt->modif != 6)&&
- (k->data.pt->modif != 8)&&
- (k->data.pt->modif != 10)&&
- (k->data.pt->modif != 12)&&
- (k->data.pt->modif != 14)&&
- (k->data.pt->modif != 15)
- ) {
- printf("WTF ... k->data.pt->modif == %d\n",k->data.pt->modif);
- return(40);
- }
- for(ty=k->y;ty<sf->h+k->y;++ty){
- if(ty<0) {continue;}
- if(ty>=pTerrain->h){continue;}
- for(tx=k->x;tx<sf->w+k->x;++tx){
- if(tx<0) {continue;}
- if(tx>=pTerrain->w){continue;}
-
- if(ty>=LEVEL_HEIGHT) {continue;}
- if(tx>=LEVEL_WIDTH) {continue;}
-
- overwrite = ((k->data.pt->modif & 8) == 8)? 0 : 1;
- remove = ((k->data.pt->modif & 2) == 2)? 1 : 0;
- if(k->data.pt->modif == 15){
- overwrite=0;
- remove=0;
- }
+ sf = gInit->mapI.map.tabGif[test_O_UD(k->data.pt->modif)+k->ID*2+ADD_OBJ];
+
+ if((k->data.pt->modif != 0)&&
+ (k->data.pt->modif != 2)&&
+ (k->data.pt->modif != 4)&&
+ (k->data.pt->modif != 6)&&
+ (k->data.pt->modif != 8)&&
+ (k->data.pt->modif != 10)&&
+ (k->data.pt->modif != 12)&&
+ (k->data.pt->modif != 14)&&
+ (k->data.pt->modif != 15)
+ ) {
+ printf("WTF ... k->data.pt->modif == %d\n",k->data.pt->modif);
+ return(40);
+ }
+ for(ty=k->y;ty<sf->h+k->y;++ty){
+ if(ty<0) {continue;}
+ if(ty>=pTerrain->h){continue;}
+ for(tx=k->x;tx<sf->w+k->x;++tx){
+ if(tx<0) {continue;}
+ if(tx>=pTerrain->w){continue;}
+ if(ty>=LEVEL_HEIGHT) {continue;}
+ if(tx>=LEVEL_WIDTH) {continue;}
- color = get_pixel32(tx-k->x,ty-k->y,sf);
- if(color==ccc_error){return 250;}
- if (color == ccc_black)
- { //putPixel(pStencil,tx,ty , ccc_tEmpty );
- continue;
- }
- paint=0;
- if(!overwrite){
- if((get_pixel32(tx,ty,pStencil)==ccc_error)){return 667;}
- // don't overwrite -> only paint if background is transparent
- if(((get_pixel32(tx,ty,pStencil)>>24) & 0xff ) == 0)
- {// ccc_tEmpty){
- paint=1;
+ overwrite = ((k->data.pt->modif & 8) == 8)? 0 : 1;
+ remove = ((k->data.pt->modif & 2) == 2)? 1 : 0;
+ if(k->data.pt->modif == 15){
+ overwrite=0;
+ remove=0;
}
- } else if(remove){
- // if(((get_pixel32(tx,ty,pStencil)) & ccc_tFull) != 0){
- err=putPixel(pTerrain,tx,ty , gInit->mapI.map.cmap.bgColor);
- if(err!=0){return err;}
- err=putPixel(pStencil,tx,ty , ccc_tRemove );//ccc_tEmpty);
- if(err!=0){return err;}
- // }
- } else {
- paint=1;
+
+ color = get_pixel32(tx-k->x,ty-k->y,sf);
+ if(color==ccc_error){return 250;}
+ if (color == ccc_black)
+ { //putPixel(pStencil,tx,ty , ccc_tEmpty );
+ continue;
}
+ paint=0;
+ if(!overwrite){
+ if((get_pixel32(tx,ty,pStencil)==ccc_error)){return 667;}
+ // don't overwrite -> only paint if background is transparent
+ if(((get_pixel32(tx,ty,pStencil)>>24) & 0xff ) == 0)
+ {// ccc_tEmpty){
+ paint=1;
+ }
+ } else if(remove){
+ // if(((get_pixel32(tx,ty,pStencil)) & ccc_tFull) != 0){
+ err=putPixel(pTerrain,tx,ty , gInit->mapI.map.cmap.bgColor);
+ if(err!=0){return err;}
+ err=putPixel(pStencil,tx,ty , ccc_tRemove );//ccc_tEmpty);
+ if(err!=0){return err;}
+ // }
- if(paint==1){
- if(!overwrite){
- if(!remove){
- err=putPixel(pTerrain,tx,ty ,color);
- if(err!=0){return err;}
- if(k->data.pt->modif==15){
- err=putPixel(pStencil,tx,ty , ccc_tHidden );//ccc_tBrick);
+ } else {
+ paint=1;
+ }
+
+ if(paint==1){
+ if(!overwrite){
+ if(!remove){
+ err=putPixel(pTerrain,tx,ty ,color);
if(err!=0){return err;}
+ if(k->data.pt->modif==15){
+ err=putPixel(pStencil,tx,ty , ccc_tHidden );//ccc_tBrick);
+ if(err!=0){return err;}
+ } else {
+ err=putPixel(pStencil,tx,ty , ccc_tNoOverwrite );//ccc_tBrick);
+ if(err!=0){return err;}
+ }
} else {
- err=putPixel(pStencil,tx,ty , ccc_tNoOverwrite );//ccc_tBrick);
+ err=putPixel(pTerrain,tx,ty ,color);
+ if(err!=0){return err;}
+ err=putPixel(pStencil,tx,ty , ccc_tRemoveNoOverwrite );//ccc_tBrick);
if(err!=0){return err;}
}
} else {
err=putPixel(pTerrain,tx,ty ,color);
if(err!=0){return err;}
- err=putPixel(pStencil,tx,ty , ccc_tRemoveNoOverwrite );//ccc_tBrick);
+ err=putPixel(pStencil,tx,ty , ccc_tFull );//ccc_tBrick);
if(err!=0){return err;}
}
- } else {
- err=putPixel(pTerrain,tx,ty ,color);
- if(err!=0){return err;}
- err=putPixel(pStencil,tx,ty , ccc_tFull );//ccc_tBrick);
- if(err!=0){return err;}
}
- }
- }//fin tx
- }//fin ty
- k=k->next;
- cpt++;
- ok=0;
- //SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0x0, 0x0, 0x0 ) ); SDL_BlitSurface(pTerrain, &camera, screen, NULL); if( SDL_Flip( screen ) == -1 ) { return 1;} //scanf("%d",&pas);
- }
- // elimination des pixel remove
- for(ty=0;ty<LEVEL_HEIGHT;++ty){
- for(tx=0;tx<LEVEL_WIDTH;++tx){
- color = get_pixel32(tx,ty,pStencil);
- if(color==ccc_tRemove){
- err=putPixel(pStencil,tx,ty , ccc_Empty );
- if(err!=0){return err;}
- } else {
- if(color!=ccc_Empty){
- err=putPixel(pStencil,tx,ty , ccc_tBrick );
+ }//fin tx
+ }//fin ty
+ k=k->next;
+ cpt++;
+ ok=0;
+ //SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0x0, 0x0, 0x0 ) ); test_blit(pTerrain, &camera, screen, NULL); if( SDL_Flip( screen ) == -1 ) { return 1;} //scanf("%d",&pas);
+ }
+ // elimination des pixel remove
+ for(ty=0;ty<LEVEL_HEIGHT;++ty){
+ for(tx=0;tx<LEVEL_WIDTH;++tx){
+ color = get_pixel32(tx,ty,pStencil);
+ if(color==ccc_tRemove){
+ err=putPixel(pStencil,tx,ty , ccc_bgStencil );
if(err!=0){return err;}
+ } else {
+ if(color!=ccc_bgStencil){
+ err=putPixel(pStencil,tx,ty , ccc_tBrick );
+ if(err!=0){return err;}
+ }
}
}
}
- }
- // printf("LES STEEL : ");
- k=gInit->s.ls;
- while ( k !=NULL ) {
- offset.x = k->x;
- offset.y = k->y;
+ // printf("LES STEEL : ");
+ k=gInit->s.ls;
+ while ( k !=NULL ) {
+ offset.x = k->x;
+ offset.y = k->y;
- sf = gInit->mapI.map.tabGif[ADD_OBJ+(gInit->mapI.map.tiles*2)+(gInit->mapI.map.tilesObjet*2)+k->ID];
+ sf = gInit->mapI.map.tabGif[ADD_OBJ+(gInit->mapI.map.tiles*2)+(gInit->mapI.map.tilesObjet*2)+k->ID];
- offset.w = k->data.ps->w;
- offset.h = k->data.ps->h;
- //printf("H=)> %d\n",offset.h);
+ offset.w = k->data.ps->w;
+ offset.h = k->data.ps->h;
+ //printf("H=)> %d\n",offset.h);
- for(ty=k->y;ty<offset.h+k->y;++ty){
- if(ty<0) {continue;}
- if(ty>pTerrain->h){continue;}
- for(tx=k->x;tx<offset.w+k->x;++tx){
- if(tx<0) {continue;}
- if(tx>pTerrain->w){continue;}
+ for(ty=k->y;ty<offset.h+k->y;++ty){
+ if(ty<0) {continue;}
+ if(ty>pTerrain->h){continue;}
+ for(tx=k->x;tx<offset.w+k->x;++tx){
+ if(tx<0) {continue;}
+ if(tx>pTerrain->w){continue;}
- if(ty>=LEVEL_HEIGHT) {continue;}
- if(tx>=LEVEL_WIDTH) {continue;}
+ if(ty>=LEVEL_HEIGHT) {continue;}
+ if(tx>=LEVEL_WIDTH) {continue;}
- color = get_pixel32(tx,ty,pStencil);
- if(color==ccc_error){return 219;}
- if (color == ccc_black){
- continue;
- } else {
- err=putPixel(pStencil,tx,ty , ccc_s );
- if(err!=0){return err;}
+ color = get_pixel32(tx,ty,pStencil);
+ if(color==ccc_error){return 219;}
+ if (color == ccc_black){
+ continue;
+ } else {
+ err=putPixel(pStencil,tx,ty , ccc_s );
+ if(err!=0){return err;}
+ }
}
}
+ // SDL_FillRect(pStencil, &offset, ccc_s);
+ k=k->next;
}
- // SDL_FillRect(pStencil, &offset, ccc_s);
- k=k->next;
- }
- //}
+ //}
- return 0;
- }
+ return 0;
+ }
- int paint_objet (struct gameInit *gInit, int cptFps){
- SDL_Rect offset,objetAnim,rStencil;
- SDL_Surface *sf;
- struct listeSimplementChainee *k=NULL;
- int res;
- int err=0;
- int type=0;
- int ox,oy;
- int mode=0;
- Uint32 color,color2,color3;
- int size;
- void *temp_pixels = NULL;
- //DEBUT TEST: SPR
- k=gInit->o.lo;
- while ( k !=NULL ) {
+int test_blit(SDL_Surface *spr,SDL_Rect *from,SDL_Surface *t,SDL_Rect *to){
- sf = gInit->mapI.map.tabGif[gInit->mapI.map.tiles*2+k->ID*2+k->data.po->UD+ADD_OBJ];
+ return SDL_BlitSurface(spr,from, t,to);
- size=sf->h*sf->pitch;
- temp_pixels=malloc(size);
- //memcpy(temp_pixels,sf->pixels,size);
-
- type=gInit->mapI.map.tabDataSprO[k->ID].type;
+}
+ int paint_manip(SDL_Surface *spr,SDL_Rect from,SDL_Surface *t,SDL_Rect to,Uint32 ccc_t, Uint32 ccc_spr, int mode){
- offset.x = k->x;
- offset.y = k->y;
+ int size,i,j,err;
+ void *temp_pixels = NULL;
+ Uint32 ccc_temp=0x00000000;
- objetAnim.x = 0;
- objetAnim.h = sf->h/gInit->mapI.map.tabDataSprO[k->ID].state;
- objetAnim.y = (anim_objet(
- gInit->mapI.map.tabDataSprO[k->ID].anim,
- type,
- cptFps,
- gInit->mapI.map.tabDataSprO[k->ID].state,
- &k->data.po->cptState,
- gInit)
- )*(objetAnim.h);
- objetAnim.w = sf->w;
+ //FULL
+ if(mode==0){
+ err=test_blit(spr,&from, t,&to);
+ return err;
+ }
- rStencil.x=k->x ;
- rStencil.y=k->y ;
- rStencil.h=objetAnim.h;
- rStencil.w=objetAnim.w;
+ //printf("paint_manip(), from.x==%4i, from.y==%4i, from.h==%4i, from.w==%4i, from to.x==%4i, to.y==%4i\n", from.x, from.y, from.h, from.w, to.x, to.y);
- mode=k->data.po->paintMode;
+ if(from.y<0 || from.y > spr->h) {
+ printf("simple y\n");
+ return 345;
+ }
- // check combi impossible
- if((mode!=8)&&((type==3)||(type==4))){
- printf("Construction impossible: mode!=%d(8) && type=%d(3 ou 4)\n",mode,type);
- return 56;
+ if(from.x<0 || from.x > spr->w) {
+ printf("simple x\n");
+ return 346;
}
- if((mode==8)&&(type==5)){
- printf("Construction impossible: mode==%d(8) && type=%d(5)\n",mode,type);
- return 57;
+
+ if(to.y<0 || to.y > t->h) {
+ printf("simple y2\n");
+ return 91;
}
- // fin check
- if(type!=4&&type!=3){
+ if(to.x<0 || to.x > t->w) {
+ printf("simple x2\n");
+ return 92;
+ }
- if((res=SDL_BlitSurface(sf, &objetAnim, pSpr_Lem, &offset)) != 0)
- {
- printf("ERREUR [%d] SDL_BlitSurface : ",res);
- }
+ if(from.y+from.h > spr->h) {
+ from.h=spr->h - from.y;
+ }
+ if(from.x+from.w > spr->w) {
+ from.w=spr->w - from.x;
+ }
- if(type==5){
- rStencil.y=k->y+rStencil.h/3;
- rStencil.h=(rStencil.h/3 + (rStencil.h/3)%3)*2;
- }
+ if(to.y+from.h > t->h) {
+ from.h=t->h - to.y;
+ }
+
+ if(to.x + from.w > t->w) {
+ from.w=t->w - to.x;
+ }
+
+ size=spr->h*spr->pitch;
+ temp_pixels=malloc(size);
- switch(type){
- case 0://passive
- SDL_FillRect(pStencil, &rStencil, ccc_oPassive);break;
- /* case 3://no digging to the left
- SDL_FillRect(pStencil, &rStencil, ccc_oNoDigLeft);break;
- case 4://no digging to the right
- SDL_FillRect(pStencil, &rStencil, ccc_oNoDigRight);break;*/
- case 5://trap which makes lemmings drown (water/quick sand/mud)
- SDL_FillRect(pStencil, &rStencil, ccc_oTrapDrown);break;
- case 6://trap which replaces lemming with death animation
- SDL_FillRect(pStencil, &rStencil, ccc_oTrapAndNoLem);break;
- case 7://trap which triggers lemming death animation
- SDL_FillRect(pStencil, &rStencil, ccc_oTrapAndLem);break;
- case 8://exit
- SDL_FillRect(pStencil, &rStencil, ccc_oExit);break;
- case 32://entry
- SDL_FillRect(pStencil, &rStencil, ccc_oEntry);
- break;
- default:SDL_FillRect(pStencil, &rStencil, ccc_oUnknow);break;
+ SDL_LockSurface(spr);
+ SDL_LockSurface(t);
+ memcpy(temp_pixels,spr->pixels,size);
+
+ // NO OVERWRITE
+ if(mode==4){
+
+ for(j=0;j<from.h;j++) {
+ for(i=0;i<from.w;i++) {
+ /* if((to.y+j)*t->w+(to.x+i)>=(t->w*t->h)){
+ printf("out of bound1 x=%d + i=%d, y=%d + j=%d * t->w %d == %d >= %d (t->h %d, from.h %d) \n",to.x,i,to.y,j,t->w,(to.y+j)*t->w+(to.x+i),(t->w*t->h),t->h,from.h);
+ return 56;
+ //continue;
+ }*/
+ ccc_temp=((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
+ //printf("ccc_temp1 = %p == %p t->format->colorkey\n",ccc_temp,t->format->colorkey);
+ if (ccc_temp!=ccc_t) {
+ ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_temp;//spr->format->colorkey;
+ }
+ }
}
+ }
+ // VIS ON TERRAIN
+ if(mode==8){
+ for(j=0;j<from.h;j++) {
+ for(i=0;i<from.w;i++) {
+ /* if((to.y+j)*t->w+(to.x+i)>=(t->w*t->h)){
+ printf("out of bound2 x=%d + i=%d, y=%d + j=%d * t->w %d == %d >= %d (t->h %d, from.h %d) \n",to.x,i,to.y,j,t->w,(to.y+j)*t->w+(to.x+i),(t->w*t->h),t->h,from.h);
+ return 57;
+ //continue;
+ }*/
+ ccc_temp=((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
+ //printf("ccc_temp1 = %p == %p ccc_t\n",ccc_temp,ccc_t);
+ if (ccc_temp==ccc_t) {
+ ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_t;//spr->format->colorkey;
- switch(mode){
- case 0:break;// FULL
- case 4: {//No Overwrite
- SDL_BlitSurface(pStencilFixe, &rStencil, pStencil, &rStencil);
- SDL_BlitSurface(pTerrain, &rStencil, pSpr_Lem, &rStencil);
- break;
- }
- case 8: break;//Vis On Terrain
- default:{printf("BUG: value is not 8 4 or 0 : %d \n",mode);return(36);}
+ }
+ }
}
}
+ SDL_UnlockSurface(t);
+ SDL_UnlockSurface(spr);
+ test_blit(spr,&from, t,&to);
- if((type==5&&mode!=8)||(mode==8&&(type==3||type==4))){
- if(type==5){
- rStencil.h=rStencil.y-k->y;
- rStencil.y=k->y;
+ SDL_LockSurface(spr);
+ memcpy(spr->pixels,temp_pixels,size);
+ SDL_UnlockSurface(spr);
+
+ free(temp_pixels);
+
+ return 0;
+
+ }
+
+ int paint_objet (struct gameInit *gInit, int cptFps){
+ SDL_Rect offset,objetAnim,rStencil;
+ SDL_Surface *sf;
+ struct listeSimplementChainee *k=NULL;
+ int res;
+ int err=0;
+ int type=0;
+ int ox,oy;
+ int mode=0;
+ Uint32 color,color2,color3;
+ int size;
+ void *temp_pixels = NULL;
+ //DEBUT TEST: SPR
+ k=gInit->o.lo;
+ while ( k !=NULL ) {
+
+ sf = gInit->mapI.map.tabGif[gInit->mapI.map.tiles*2+k->ID*2+k->data.po->UD+ADD_OBJ];
+
+ type=gInit->mapI.map.tabDataSprO[k->ID].type;
+
+ offset.x = k->x;
+ offset.y = k->y;
+
+ objetAnim.x = 0;
+ objetAnim.h = sf->h/gInit->mapI.map.tabDataSprO[k->ID].state;
+ objetAnim.y = (anim_objet(
+ gInit->mapI.map.tabDataSprO[k->ID].anim,
+ type,
+ cptFps,
+ gInit->mapI.map.tabDataSprO[k->ID].state,
+ &k->data.po->cptState,
+ gInit)
+ )*(objetAnim.h);
+ objetAnim.w = sf->w;
+
+ rStencil.x=k->x ;
+ rStencil.y=k->y ;
+ rStencil.h=objetAnim.h;
+ rStencil.w=objetAnim.w;
+
+ mode=k->data.po->paintMode;
+
+ // check combi impossible
+ if((mode!=8)&&((type==3)||(type==4))){
+ printf("Construction impossible: mode!=%d(8) && type=%d(3 ou 4)\n",mode,type);
+ return 56;
}
- for(oy=k->y;oy<rStencil.h+k->y;oy+=2){
- if(oy<0) {continue;}
- if(oy>pSpr_Lem->h){continue;}
- for(ox=k->x;ox<rStencil.w+k->x;ox+=2){
- if(ox<0) {continue;}
- if(ox>pSpr_Lem->w){continue;}
-
- if(oy>=LEVEL_HEIGHT) {continue;}
- if(ox>=LEVEL_WIDTH) {continue;}
-
- //if(temp_pixels==NULL){continue;}
- if(sf->pixels==NULL){continue;}
- //memcpy(sf->pixels,temp_pixels,size);
- color2 = get_pixel32(objetAnim.x+ox-k->x,objetAnim.y+oy-k->y,sf);
- if(color2==ccc_error){return 253;}
-
- if(type==5&&mode!=8){
-
- if(color2==ccc_vide){continue;}
+ if((mode==8)&&(type==5)){
+ printf("Construction impossible: mode==%d(8) && type=%d(5)\n",mode,type);
+ return 57;
+ }
+ // fin check
+ rStencil.x=0 ;
+ rStencil.y=objetAnim.y ;
+ if((err=paint_manip(sf,rStencil,pSpr_Lem,offset,gInit->mapI.map.cmap.bgColor,ccc_objet,mode))!=0){
+ return err;
+ }
+ k=k->next;
+ }
+ ///FIN TEST: SPR
+ return 0;
+ }
- } else {
+ int paint_objet_stencil (struct gameInit *gInit, int cptFps){
+ SDL_Rect offset,objetAnim,rStencil;
+ SDL_Surface *sf;
+ struct listeSimplementChainee *k=NULL;
+ int res;
+ int err=0;
+ int type=0;
+ int ox,oy;
+ int mode=0;
+ Uint32 color,color2,color3;
+ int size;
+ void *temp_pixels = NULL;
+ //DEBUT TEST: SPR
+ k=gInit->o.lo;
+ while ( k !=NULL ) {
+
+ sf = gInit->mapI.map.tabGif[gInit->mapI.map.tiles*2+k->ID*2+k->data.po->UD+ADD_OBJ];
+
+ type=gInit->mapI.map.tabDataSprO[k->ID].type;
+
+
+ offset.x = k->x;
+ offset.y = k->y;
+
+ objetAnim.x = 0;
+ objetAnim.h = sf->h/gInit->mapI.map.tabDataSprO[k->ID].state;
+ objetAnim.y = (anim_objet(
+ gInit->mapI.map.tabDataSprO[k->ID].anim,
+ type,
+ cptFps,
+ gInit->mapI.map.tabDataSprO[k->ID].state,
+ &k->data.po->cptState,
+ gInit)
+ )*(objetAnim.h);
+ objetAnim.w = sf->w;
+
+ rStencil.x=k->x ;
+ rStencil.y=k->y ;
+ rStencil.h=objetAnim.h;
+ rStencil.w=objetAnim.w;
+
+ mode=k->data.po->paintMode;
+
+ // check combi impossible
+ if((mode!=8)&&((type==3)||(type==4))){
+ printf("Construction impossible: mode!=%d(8) && type=%d(3 ou 4)\n",mode,type);
+ return 56;
+ }
+ if((mode==8)&&(type==5)){
+ printf("Construction impossible: mode==%d(8) && type=%d(5)\n",mode,type);
+ return 57;
+ }
+ // fin check
+ if(type!=4&&type!=3){
+ if(type==5){
+ rStencil.y=k->y+rStencil.h/3;
+ rStencil.h=(rStencil.h/3 + (rStencil.h/3)%3)*2;
+ }
+ switch(type){
+ case 0://passive
+ SDL_FillRect(pStencil, &rStencil, ccc_oPassive);break;
+ case 5://trap which makes lemmings drown (water/quick sand/mud)
+ SDL_FillRect(pStencil, &rStencil, ccc_oTrapDrown);break;
+ case 6://trap which replaces lemming with death animation
+ SDL_FillRect(pStencil, &rStencil, ccc_oTrapAndNoLem);break;
+ case 7://trap which triggers lemming death animation
+ SDL_FillRect(pStencil, &rStencil, ccc_oTrapAndLem);break;
+ case 8://exit
+ SDL_FillRect(pStencil, &rStencil, ccc_oExit);break;
+ case 32://entry
+ SDL_FillRect(pStencil, &rStencil, ccc_oEntry);
+ break;
+ default:SDL_FillRect(pStencil, &rStencil, ccc_oUnknow);break;
+ }
+ switch(mode){
+ case 0:break;// FULL
+ case 4: {//No Overwrite
+ test_blit(pStencilFixe, &rStencil, pStencil, &rStencil);
+ break;
+ }
+ case 8: break;//Vis On Terrain
+ default:{printf("BUG: value is not 8 4 or 0 : %d \n",mode);return(36);}
+ }
+ }
+ if(mode==8&&(type==3||type==4)){
+ for(oy=k->y;oy<rStencil.h+k->y;oy+=1){
+ if(oy<0) {continue;}
+ if(oy>pSpr_Lem->h){continue;}
+ for(ox=k->x;ox<rStencil.w+k->x;ox+=1){
+ if(ox<0) {continue;}
+ if(ox>pSpr_Lem->w){continue;}
+
+ if(oy>=LEVEL_HEIGHT) {continue;}
+ if(ox>=LEVEL_WIDTH) {continue;}
+
+ //if(temp_pixels==NULL){continue;}
+ if(sf->pixels==NULL){continue;}
+ //memcpy(sf->pixels,temp_pixels,size);
+ color2 = get_pixel32(objetAnim.x+ox-k->x,objetAnim.y+oy-k->y,sf);
+ if(color2==ccc_error){return 253;}
// NO DIG
color = get_pixel32(ox,oy,pStencil);
if(color==ccc_error){return 254;}
- if(color==ccc_Empty){continue;}
- }
- // pixel transparency in object.gif
- if(type==5&&mode!=8){
- err=putPixel(pStencil,ox,oy,ccc_oTrapDrown);
- if(err!=0){return err;}
- } else {
+ if(color==ccc_bgStencil){continue;}
+
+ // pixel transparency in object.gif
if(type==3){
err=putPixel(pStencil,ox,oy,ccc_oNoDigLeft);
if(err!=0){return err;}
@@ -2885,825 +3081,828 @@ int stateLemming(struct gameInit *gInit){
err=putPixel(pStencil,ox,oy,ccc_oNoDigRight);
if(err!=0){return err;}
}
- if(color2==ccc_vide){continue;}
- err=putPixel(pSpr_Lem,ox,oy,color2);
- if(err!=0){return err;}
}
-
}
- }
-
- if(type==5&&mode==4){
- SDL_BlitSurface(pStencilFixe, &rStencil, pStencil, &rStencil);
- SDL_BlitSurface(pTerrain, &rStencil, pSpr_Lem, &rStencil);
- }
-
-
- //}
- }//FIN ELSE MODE
-
- k=k->next;
+ //}
+ }//FIN ELSE MODE
+ k=k->next;
+ }
+ ///FIN TEST: SPR
+ return 0;
}
- ///FIN TEST: SPR
- return 0;
- }
-
- int paint_lemming (struct gameInit *gInit, int cptFps){
- //DEBUT TEST: LEM
- SDL_Rect offset,objetAnim;
- SDL_Surface *sf;
- struct listeSimplementChainee *k=NULL;
- int res;
- int err=0;
- int cpt=0;
+ int paint_lemming (struct gameInit *gInit, int cptFps){
- k=gInit->l.ll;
- while ( k !=NULL ) {
+ //DEBUT TEST: LEM
+ SDL_Rect offset,objetAnim;
+ SDL_Surface *sf;
+ struct listeSimplementChainee *k=NULL;
+ int res;
+ int err=0;
+ int cpt=0;
+ int newID;
- // DIED
- if((k->data.pl->cptState == 0 ) && ((k->ID == 8) || (k->ID == 5) ))
- {
- k->ID=17; // decret de décès
- }
- // SAFE
- if((k->data.pl->cptState == 0 ) && (k->ID == 9))
- {
- k->ID=19; // decret de survivant
- }
- //8 + (99 - releaseRate)
- if((gInit->cptGame[15]==0)&&(gInit->cptGame[16]==gInit->mapI.nbrEntry)){
- gInit->cptGame[15]=cptFps;
- }
+ k=gInit->l.ll;
- if( (k->ID==18)&&
- (gInit->cptGame[16]==gInit->mapI.nbrEntry)&&
- ((gInit->l.nbrInput-(gInit->l.nbr + gInit->l.nbrDied + gInit->l.nbrSafe))>0)&&
- (cptFps==(gInit->cptGame[15]+(8 + 99 - gInit->mapI.paraMap[0])))
- ){
- k->ID=1;
- ++(gInit->l.nbr);
- gInit->cptGame[15]=cptFps;
- }
+ while ( k !=NULL ) {
- // lemmings => spr de sa mort ou vivant
- if((k->data.pl->cptState != 0 ) || (k->ID < LEM_JOB) || (k->ID>19) ){//FIXME il y a une faille dans la condition
- printf("num = %d id=%d\n",cpt++,k->ID);
-
- offset.x = k->x;
- offset.y = k->y;
- sf = gInit->mapI.map.tabGif[gInit->mapI.map.tiles*2+(gInit->mapI.map.tilesObjet*2)+gInit->mapI.map.tilesSteel+(k->ID)*2+k->data.pl->dir+ADD_OBJ];
- objetAnim.x = 0;
- objetAnim.h = sf->h/(gInit->mapI.lemmingDATA[k->ID].state);
- objetAnim.y = (anim_objet((gInit->mapI.lemmingDATA[k->ID].anim+90),0,cptFps,gInit->mapI.lemmingDATA[k->ID].state,&k->data.pl->cptState,gInit))*(objetAnim.h); // +3 : 0 == loop et dans anim_objet c'est 3 pas 0 (fichier de conf) FIXME
- objetAnim.w = sf->w;
- offset.w = objetAnim.w;
- offset.h = objetAnim.h;
- switch(k->ID){
- case 0: SDL_FillRect(pStencil, &offset, ccc_lWalk_on);break;
- case 6: SDL_FillRect(pStencil, &offset, ccc_lStopper);break;
- default:break;
+ // DIED
+ if((k->data.pl->cptState == 0 ) && ((k->ID == 8) || (k->ID == 5) ))
+ {
+ k->ID=17; // decret de décès
}
- if ((res=SDL_BlitSurface(sf, &objetAnim, pSpr_Lem, &offset)) != 0){
- printf("ERREUR [%d] SDL_BlitSurface : ",res);
+ // SAFE
+ if((k->data.pl->cptState == 0 ) && (k->ID == 9))
+ {
+ k->ID=19; // decret de survivant
+ }
+ //8 + (99 - releaseRate)
+ if((gInit->cptGame[15]==0)&&(gInit->cptGame[16]==gInit->mapI.nbrEntry)){
+ gInit->cptGame[15]=cptFps;
}
- }
- k=k->next;
- }
- ///FIN TEST: LEM
- err=stateLemming(gInit);
- if(err!=0){return err;}
+ if( (k->ID==18)&&
+ (gInit->cptGame[16]==gInit->mapI.nbrEntry)&&
+ ((gInit->l.nbrInput-(gInit->l.nbr + gInit->l.nbrDied + gInit->l.nbrSafe))>0)&&
+ (cptFps==(gInit->cptGame[15]+(8 + 99 - gInit->mapI.paraMap[0])))
+ ){
+ k->ID=1;
+ ++(gInit->l.nbr);
+ gInit->cptGame[15]=cptFps;
+ }
- return 0;
- }
+ // lemmings => spr de sa mort ou vivant
+ switch(k->ID){
+ case 20: newID=10;break;
+ case 21: newID=6;break;
+ case 22: newID=4;break;
+ default: newID=k->ID;break;
+ }
+ if((k->data.pl->cptState != 0 ) || (newID < LEM_JOB)){//FIXME il y a une faille dans la condition
+ printf("num = %d id=%d(%d)\n",cpt++,newID,k->ID);
- int giveSkill (struct gameInit *gInit, struct listeSimplementChainee* k, int skill ){
+ offset.x = k->x;
+ offset.y = k->y;
+ sf = gInit->mapI.map.tabGif[gInit->mapI.map.tiles*2+(gInit->mapI.map.tilesObjet*2)+gInit->mapI.map.tilesSteel+(newID)*2+k->data.pl->dir+ADD_OBJ];
+ objetAnim.x = 0;
+ objetAnim.h = sf->h/(gInit->mapI.lemmingDATA[newID].state);
+ objetAnim.y = (anim_objet((gInit->mapI.lemmingDATA[newID].anim+90),0,cptFps,gInit->mapI.lemmingDATA[newID].state,&k->data.pl->cptState,gInit))*(objetAnim.h); // +3 : 0 == loop et dans anim_objet c'est 3 pas 0 (fichier de conf) FIXME
+ objetAnim.w = sf->w;
+ offset.w = objetAnim.w;
+ offset.h = objetAnim.h;
+ switch(newID){
+ case 0: SDL_FillRect(pStencil, &offset, ccc_lWalk_on);break;
+ case 6: SDL_FillRect(pStencil, &offset, ccc_lStopper);break;
+ default:break;
+ }
+ if ((res=test_blit(sf, &objetAnim, pSpr_Lem, &offset)) != 0){
+ printf("ERREUR [%d] test_blit : ",res);
+ }
+ }
+ k=k->next;
- switch(skill){
- //climber
- case 2 : if((gInit->mapI.paraMap[4]>0)&&
- (k->data.pl->climber==0)){
- --gInit->mapI.paraMap[4];
- k->data.pl->climber=1;
- }
- break;
- //floater
- case 4 : if((gInit->mapI.paraMap[5]>0)&&
- (k->data.pl->floater==0)){
- --gInit->mapI.paraMap[5];
- k->data.pl->floater=1;
- }
- break;
- //bomber
- case 10 : if((gInit->mapI.paraMap[6]>0)&&
- (k->data.pl->bomber==404)){
- --gInit->mapI.paraMap[6];
- k->data.pl->bomber=5;
- }
- break;
- //blocker
- case 6 : if((gInit->mapI.paraMap[7]>0)&&
- (k->data.pl->blocker==0)){
- --gInit->mapI.paraMap[7];
- k->data.pl->blocker=1;
- }
- break;
- case 11 : ;break;//builder
- case 14 : ;break;//basher
- case 15 : ;break;//miner
- case 13 : ;break;//digger
+ }
+ ///FIN TEST: LEM
+ err=stateLemming(gInit);
+ if(err!=0){return err;}
- default: break;
+ return 0;
}
- return 0;
- }
+ int giveSkill (struct gameInit *gInit, struct listeSimplementChainee* k, int skill ){
- int findTerrain( struct gameInit *gInit,int x, int y, int x0){
- SDL_Rect to;
- int i=0;
- int cpt=0;
- int err=0;
- SDL_Surface *sf;
- struct listeSimplementChainee *k=NULL;
- k=gInit->t.lt;
- to.x=5;
- to.y=screen->h-10;
- to.w=600;
- to.h=10;
- SDL_FillRect(screen, &to, ccc_black);
- while(k != NULL){
- sf=gInit->mapI.map.tabGif[test_O_UD(k->data.pt->modif)+k->ID*2+ADD_OBJ];
- if( (x+15 <= k->x + sf->w)&&
- (x+15 >= k->x)&&
- (y+15 <= k->y + sf->h)&&
- (y+15 > k->y)){//on the terrain
- ++cpt;
- print_num(screen, gInit->mapI.map.tabGif[1], 5 , screen->h-10, cpt);
- print_num(screen, gInit->mapI.map.tabGif[1], 5 + cpt*40, screen->h-10, i);
- to.x=k->x;
- to.y=k->y;
- to.w=sf->w;
- to.h=1;
- SDL_FillRect(pStencil, &to, ccc_red);
- to.x=k->x;
- to.y=k->y;
- to.w=1;
- to.h=sf->h;
- SDL_FillRect(pStencil, &to, ccc_red);
- to.x=k->x + sf->w;
- to.y=k->y;
- to.w=1;
- to.h=sf->h;
- SDL_FillRect(pStencil, &to, ccc_red);
- to.x=k->x ;
- to.y=k->y + sf->h;
- to.w=sf->w;
- to.h=1;
- SDL_FillRect(pStencil, &to, ccc_red);
- err=print_num(pStencil, gInit->mapI.map.tabGif[1], k->x + 2, k->y + 2, i);
- if(err!=0){return err;}
+ switch(skill){
+ //climber
+ case 2 : if((gInit->mapI.paraMap[4]>0)&&
+ (k->data.pl->climber==0)){
+ --gInit->mapI.paraMap[4];
+ k->data.pl->climber=1;
+ }
+ break;
+ //floater
+ case 4 : if((gInit->mapI.paraMap[5]>0)&&
+ (k->data.pl->floater==0)){
+ --gInit->mapI.paraMap[5];
+ k->data.pl->floater=1;
+ }
+ break;
+ //bomber
+ case 10 : if((gInit->mapI.paraMap[6]>0)&&
+ (k->data.pl->bomber==404)){
+ --gInit->mapI.paraMap[6];
+ k->data.pl->bomber=5;
+ }
+ break;
+ //blocker
+ case 6 : if((gInit->mapI.paraMap[7]>0)&&
+ (k->data.pl->blocker==0)){
+ --gInit->mapI.paraMap[7];
+ k->data.pl->blocker=1;
+ }
+ break;
+ case 11 : ;break;//builder
+ case 14 : ;break;//basher
+ case 15 : ;break;//miner
+ case 13 : ;break;//digger
+ default: break;
}
- ++i;
- k=k->next;
+
+
+ return 0;
}
- return 0;
- }
- int paint_cursor(SDL_Surface *dst1,SDL_Surface *dst2, SDL_Surface *src, int x, int y, int x0, struct gameInit *gInit)
- {
- SDL_Rect from, to;
- int f=0;
- int err=0;
- struct listeSimplementChainee *k=NULL;
-
- /* Render! */
- from.x = 0;
- from.h = src->h/8;
- from.y = gInit->cptGame[NBR_BUTTON_LEMMING] * (from.h);
- from.w = src->w;
-
- to.x = (y>LEVEL_HEIGHT)? x0 : x;
- to.y = y;
- if (y>LEVEL_HEIGHT){// cursor in pSpr_Lem
- SDL_BlitSurface(src, &from, dst2, &to);
- } else {
- k=gInit->l.ll;
+ int findTerrain( struct gameInit *gInit,int x, int y, int x0){
+ SDL_Rect to;
+ int i=0;
+ int cpt=0;
+ int err=0;
+ SDL_Surface *sf;
+ struct listeSimplementChainee *k=NULL;
+ k=gInit->t.lt;
+ to.x=5;
+ to.y=screen->h-10;
+ to.w=600;
+ to.h=10;
+ SDL_FillRect(screen, &to, ccc_black);
while(k != NULL){
- if( (x+15 <= k->x + 32)&&
+ sf=gInit->mapI.map.tabGif[test_O_UD(k->data.pt->modif)+k->ID*2+ADD_OBJ];
+ if( (x+15 <= k->x + sf->w)&&
(x+15 >= k->x)&&
- (y+15 <= k->y + 20)&&
- (y+15 > k->y)){//on the lemming
+ (y+15 <= k->y + sf->h)&&
+ (y+15 > k->y)){//on the terrain
+ ++cpt;
+ print_num(screen, gInit->mapI.map.tabGif[1], 5 , screen->h-10, cpt);
+ print_num(screen, gInit->mapI.map.tabGif[1], 5 + cpt*40, screen->h-10, i);
+ to.x=k->x;
+ to.y=k->y;
+ to.w=sf->w;
+ to.h=1;
+ SDL_FillRect(pStencil, &to, ccc_red);
to.x=k->x;
to.y=k->y;
- from.y = 4 * (from.h);
- f=1;
- //begin giveSkill
- if((gInit->cptGame[18]==1)&&(gInit->cptGame[17]!=404)){
- switch(gInit->cptGame[17]){
+ to.w=1;
+ to.h=sf->h;
+ SDL_FillRect(pStencil, &to, ccc_red);
+ to.x=k->x + sf->w;
+ to.y=k->y;
+ to.w=1;
+ to.h=sf->h;
+ SDL_FillRect(pStencil, &to, ccc_red);
+ to.x=k->x ;
+ to.y=k->y + sf->h;
+ to.w=sf->w;
+ to.h=1;
+ SDL_FillRect(pStencil, &to, ccc_red);
+ err=print_num(pStencil, gInit->mapI.map.tabGif[1], k->x + 2, k->y + 2, i);
+ if(err!=0){return err;}
- case 2 : err=giveSkill(gInit,k,2);break;//climber
- case 3 : err=giveSkill(gInit,k,4);break;//floater
- case 4 : err=giveSkill(gInit,k,10);break;//bomber
+ }
+ ++i;
+ k=k->next;
- case 5 : err=giveSkill(gInit,k,6);break;//stopper
+ }
+ return 0;
+ }
+
+ int paint_cursor(SDL_Surface *dst1,SDL_Surface *dst2, SDL_Surface *src, int x, int y, int x0, struct gameInit *gInit)
+ {
+ SDL_Rect from, to;
+ int f=0;
+ int err=0;
+ struct listeSimplementChainee *k=NULL;
- case 6 : err=giveSkill(gInit,k,11);break;//builder
- case 7 : err=giveSkill(gInit,k,14);break;//basher
- case 8 : err=giveSkill(gInit,k,15);break;//miner
- case 9 : err=giveSkill(gInit,k,13);break;//digger
+ /* Render! */
+ from.x = 0;
+ from.h = src->h/8;
+ from.y = gInit->cptGame[NBR_BUTTON_LEMMING] * (from.h);
+ from.w = src->w;
- default: break;
+ to.x = (y>LEVEL_HEIGHT)? x0 : x;
+ to.y = y;
+ if (y>LEVEL_HEIGHT){// cursor in pSpr_Lem
+ test_blit(src, &from, dst2, &to);
+ } else {
+ k=gInit->l.ll;
+ while(k != NULL){
+ if( (x+15 <= k->x + 32)&&
+ (x+15 >= k->x)&&
+ (y+15 <= k->y + 20)&&
+ (y+15 > k->y)){//on the lemming
+ to.x=k->x;
+ to.y=k->y;
+ from.y = 4 * (from.h);
+ f=1;
+ //begin giveSkill
+ if((gInit->cptGame[18]==1)&&(gInit->cptGame[17]!=404)){
+ switch(gInit->cptGame[17]){
+
+ case 2 : err=giveSkill(gInit,k,2);break;//climber
+ case 3 : err=giveSkill(gInit,k,4);break;//floater
+ case 4 : err=giveSkill(gInit,k,10);break;//bomber
+
+ case 5 : err=giveSkill(gInit,k,6);break;//stopper
+
+ case 6 : err=giveSkill(gInit,k,11);break;//builder
+ case 7 : err=giveSkill(gInit,k,14);break;//basher
+ case 8 : err=giveSkill(gInit,k,15);break;//miner
+ case 9 : err=giveSkill(gInit,k,13);break;//digger
+
+ default: break;
+ }
+ if(err!=0){return err;}
+ gInit->cptGame[18]=0;
}
- if(err!=0){return err;}
- gInit->cptGame[18]=0;
+ //end giveSkill
+ break;
}
- //end giveSkill
- break;
+ k=k->next;
}
- k=k->next;
- }
- to.y -= 4;
- SDL_BlitSurface(src, &from, dst1, &to);
- if(y+from.h>LEVEL_HEIGHT){
- to.x = (f==1)? k->x-x + x0:x0;
- to.y = (f==1)? k->y -4 :y -4;
- SDL_BlitSurface(src, &from, dst2, &to);
- } else {
- if(f==1){
- to.x = k->x-x + x0;
- to.y = k->y -4 ;
- SDL_BlitSurface(src, &from, dst2, &to);
+ to.y -= 4;
+ test_blit(src, &from, dst1, &to);
+ if(y+from.h>LEVEL_HEIGHT){
+ to.x = (f==1)? k->x-x + x0:x0;
+ to.y = (f==1)? k->y -4 :y -4;
+ test_blit(src, &from, dst2, &to);
+ } else {
+ if(f==1){
+ to.x = k->x-x + x0;
+ to.y = k->y -4 ;
+ test_blit(src, &from, dst2, &to);
+ }
}
}
+ return 0;
}
- return 0;
- }
- int legende (struct gameInit *gInit){
-
- SDL_Rect rStencil;
- int decalY = 11;
- int err=0;
- //char* msg=NULL;
-
- rStencil.x= 400;
- rStencil.y= LEVEL_HEIGHT + 1;
- rStencil.w= 10;
- rStencil.h= 10;
-
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Terrain:");
- if(err!=0){return err;}
- rStencil.y += decalY;
- SDL_FillRect(screen, &rStencil, ccc_tRemove);
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y ,"Remove");
- if(err!=0){return err;}
- rStencil.y += decalY;
- SDL_FillRect(screen, &rStencil, ccc_tRemoveNoOverwrite);
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"No Overwrite Remove");
- if(err!=0){return err;}
- rStencil.y += decalY;
-
- SDL_FillRect(screen, &rStencil, ccc_tFull);
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Full");
- if(err!=0){return err;}
- rStencil.y += decalY;
-
- SDL_FillRect(screen, &rStencil, ccc_tNoOverwrite);
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"No Overwrite");
- if(err!=0){return err;}
- rStencil.y += decalY;
-
- SDL_FillRect(screen, &rStencil, ccc_tHidden);
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Hidden");
- if(err!=0){return err;}
- rStencil.y += decalY;
-
- // object
- rStencil.x = 30;
- rStencil.y = LEVEL_HEIGHT + 1;
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Objet:");
- if(err!=0){return err;}
- rStencil.y += decalY;
- SDL_FillRect(screen, &rStencil, ccc_oPassive);
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Passive");
- if(err!=0){return err;}
- rStencil.y += decalY;
-
- SDL_FillRect(screen, &rStencil, ccc_oNoDigLeft);
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"No digging to the left");
- if(err!=0){return err;}
- rStencil.y += decalY;
-
- SDL_FillRect(screen, &rStencil, ccc_oNoDigRight);
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"No digging to the right");
- if(err!=0){return err;}
- rStencil.y += decalY;
-
- SDL_FillRect(screen, &rStencil, ccc_oExit);
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Exit");
- if(err!=0){return err;}
- rStencil.y += decalY;
-
- SDL_FillRect(screen, &rStencil, ccc_oEntry);
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Entry");
- if(err!=0){return err;}
- rStencil.y += decalY;
-
- SDL_FillRect(screen, &rStencil, ccc_oUnknow);
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Unknow");
- if(err!=0){return err;}
- rStencil.y += decalY;
-
- SDL_FillRect(screen, &rStencil, ccc_oTrapDrown);
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Trap which makes lemmings drown (water/quick sand/mud)");
- if(err!=0){return err;}
- rStencil.y += decalY;
-
- SDL_FillRect(screen, &rStencil, ccc_oTrapAndNoLem);
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Trap which replaces lemming with death animation");
- if(err!=0){return err;}
- rStencil.y += decalY;
-
- SDL_FillRect(screen, &rStencil, ccc_oTrapAndLem);
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Trap which triggers lemming death animation");
- if(err!=0){return err;}
-
- rStencil.y += decalY + 2;
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x +15 ,rStencil.y,"Steel:");
- if(err!=0){return err;}
- rStencil.y += decalY;
- SDL_FillRect(screen, &rStencil, ccc_s);
- err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Indestructible terrain");
- if(err!=0){return err;}
+ int legende (struct gameInit *gInit){
- return 0;
- }
+ SDL_Rect rStencil;
+ int decalY = 11;
+ int err=0;
+ //char* msg=NULL;
- int paint_interface (struct gameInit *gInit){
- int i,n;
- int err=0;
- SDL_Rect to,from;
- SDL_Surface *sf;
+ rStencil.x= 400;
+ rStencil.y= LEVEL_HEIGHT + 1;
+ rStencil.w= 10;
+ rStencil.h= 10;
- from.x = 0;
- to.y = LEVEL_HEIGHT + INTER_BUTTON_Y;
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Terrain:");
+ if(err!=0){return err;}
+ rStencil.y += decalY;
+ SDL_FillRect(screen, &rStencil, ccc_tRemove);
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y ,"Remove");
+ if(err!=0){return err;}
+ rStencil.y += decalY;
+ SDL_FillRect(screen, &rStencil, ccc_tRemoveNoOverwrite);
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"No Overwrite Remove");
+ if(err!=0){return err;}
+ rStencil.y += decalY;
+
+ SDL_FillRect(screen, &rStencil, ccc_tFull);
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Full");
+ if(err!=0){return err;}
+ rStencil.y += decalY;
+
+ SDL_FillRect(screen, &rStencil, ccc_tNoOverwrite);
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"No Overwrite");
+ if(err!=0){return err;}
+ rStencil.y += decalY;
- for(i=0;i<NBR_BUTTON_LEMMING;++i){
+ SDL_FillRect(screen, &rStencil, ccc_tHidden);
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Hidden");
+ if(err!=0){return err;}
+ rStencil.y += decalY;
- sf=gInit->mapI.map.tabGif[i+NBR_ADD_OBJ];
+ // object
+ rStencil.x = 30;
+ rStencil.y = LEVEL_HEIGHT + 1;
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Objet:");
+ if(err!=0){return err;}
+ rStencil.y += decalY;
+ SDL_FillRect(screen, &rStencil, ccc_oPassive);
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Passive");
+ if(err!=0){return err;}
+ rStencil.y += decalY;
- to.x = (i*(sf->w)) + INTER_BUTTON_X;
- to.w = sf->w;
- to.h = sf->h/2;
+ SDL_FillRect(screen, &rStencil, ccc_oNoDigLeft);
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"No digging to the left");
+ if(err!=0){return err;}
+ rStencil.y += decalY;
- from.y = (to.h)*(gInit->cptGame[i]);
- from.w = sf->w;
- from.h = to.h;
+ SDL_FillRect(screen, &rStencil, ccc_oNoDigRight);
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"No digging to the right");
+ if(err!=0){return err;}
+ rStencil.y += decalY;
- if(i+4 < 12){
- n=gInit->mapI.paraMap[i+4];
- err=print_num(screen, gInit->mapI.map.tabGif[1], (to.x+7+(((n/10)>0)?0:5))+(sf->w*(2)), to.y-12,
- n);
- if(err!=0){return err;}
+ SDL_FillRect(screen, &rStencil, ccc_oExit);
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Exit");
+ if(err!=0){return err;}
+ rStencil.y += decalY;
+
+ SDL_FillRect(screen, &rStencil, ccc_oEntry);
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Entry");
+ if(err!=0){return err;}
+ rStencil.y += decalY;
+
+ SDL_FillRect(screen, &rStencil, ccc_oUnknow);
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Unknow");
+ if(err!=0){return err;}
+ rStencil.y += decalY;
+
+ SDL_FillRect(screen, &rStencil, ccc_oTrapDrown);
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Trap which makes lemmings drown (water/quick sand/mud)");
+ if(err!=0){return err;}
+ rStencil.y += decalY;
+
+ SDL_FillRect(screen, &rStencil, ccc_oTrapAndNoLem);
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Trap which replaces lemming with death animation");
+ if(err!=0){return err;}
+ rStencil.y += decalY;
+
+ SDL_FillRect(screen, &rStencil, ccc_oTrapAndLem);
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Trap which triggers lemming death animation");
+ if(err!=0){return err;}
+
+ rStencil.y += decalY + 2;
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x +15 ,rStencil.y,"Steel:");
+ if(err!=0){return err;}
+ rStencil.y += decalY;
+ SDL_FillRect(screen, &rStencil, ccc_s);
+ err=print_alpha(screen, gInit->mapI.map.tabGif[9], rStencil.x + 15,rStencil.y,"Indestructible terrain");
+ if(err!=0){return err;}
+
+ return 0;
+ }
+
+ int paint_interface (struct gameInit *gInit){
+ int i,n;
+ int err=0;
+ SDL_Rect to,from;
+ SDL_Surface *sf;
+
+ from.x = 0;
+ to.y = LEVEL_HEIGHT + INTER_BUTTON_Y;
+
+ for(i=0;i<NBR_BUTTON_LEMMING;++i){
+
+ sf=gInit->mapI.map.tabGif[i+NBR_ADD_OBJ];
+
+ to.x = (i*(sf->w)) + INTER_BUTTON_X;
+ to.w = sf->w;
+ to.h = sf->h/2;
+
+ from.y = (to.h)*(gInit->cptGame[i]);
+ from.w = sf->w;
+ from.h = to.h;
+
+ if(i+4 < 12){
+ n=gInit->mapI.paraMap[i+4];
+ err=print_num(screen, gInit->mapI.map.tabGif[1], (to.x+7+(((n/10)>0)?0:5))+(sf->w*(2)), to.y-12,
+ n);
+ if(err!=0){return err;}
+ }
+ test_blit(sf, &from, screen, &to);
}
- SDL_BlitSurface(sf, &from, screen, &to);
+ n=gInit->mapI.paraMap[0];
+ err=print_num(screen, gInit->mapI.map.tabGif[1],INTER_BUTTON_X + 20 + (((n/10)>0)?0:5), to.y-12, n);
+ if(err!=0){return err;}
+ return 0;
}
- n=gInit->mapI.paraMap[0];
- err=print_num(screen, gInit->mapI.map.tabGif[1],INTER_BUTTON_X + 20 + (((n/10)>0)?0:5), to.y-12, n);
- if(err!=0){return err;}
- return 0;
- }
- int mouse_action (struct gameInit *gInit, int x, int y, int camX, int camY ){
-
- int i,numB;
- SDL_Surface *sf;
- // size cursor
- sf=gInit->mapI.map.tabGif[3];
- x+=sf->w/2;
- y+=sf->h/16;// (sf->h/8)/2;
- sf=gInit->mapI.map.tabGif[NBR_ADD_OBJ];
- printf("action mouse ?\n");
- // test mouse on interface button
- if( (x >= INTER_BUTTON_X)&&
- (x <= sf->w*NBR_BUTTON_LEMMING)&&
- (y >= INTER_BUTTON_Y + LEVEL_HEIGHT)&&
- (y < INTER_BUTTON_Y + LEVEL_HEIGHT + (sf->h/2)))
- {// mouse is on interface button
- numB=((x-INTER_BUTTON_X)/sf->w);
- if((gInit->cptGame[numB]==1)&&((numB==0)||(numB==1))){
- // incr or decr lemmingRate
- if((numB==0)&&(gInit->mapI.paraMap[0]>13)){
- gInit->cptGame[15]-=5;
- gInit->mapI.paraMap[0]-=5;
- } else{
- if((numB==0)&&(gInit->mapI.paraMap[0]>8)){
- gInit->cptGame[15]-=1;
- gInit->mapI.paraMap[0]-=1;
- } }
- if((numB==1)&&(gInit->mapI.paraMap[0]<91)){
- gInit->cptGame[15]+=5;
- gInit->mapI.paraMap[0]+=5;
- } else {
- if((numB==1)&&(gInit->mapI.paraMap[0]<99)){
- gInit->cptGame[15]+=1;
- gInit->mapI.paraMap[0]+=1;
- } }
- gInit->cptGame[numB]=0;
- } else {
- for(i=0;i<NBR_BUTTON_LEMMING;++i){
- if(i != numB){
- gInit->cptGame[i]=0;
+ int mouse_action (struct gameInit *gInit, int x, int y, int camX, int camY ){
+
+ int i,numB;
+ SDL_Surface *sf;
+ // size cursor
+ sf=gInit->mapI.map.tabGif[3];
+ x+=sf->w/2;
+ y+=sf->h/16;// (sf->h/8)/2;
+ sf=gInit->mapI.map.tabGif[NBR_ADD_OBJ];
+ printf("action mouse ?\n");
+ // test mouse on interface button
+ if( (x >= INTER_BUTTON_X)&&
+ (x <= sf->w*NBR_BUTTON_LEMMING)&&
+ (y >= INTER_BUTTON_Y + LEVEL_HEIGHT)&&
+ (y < INTER_BUTTON_Y + LEVEL_HEIGHT + (sf->h/2)))
+ {// mouse is on interface button
+ numB=((x-INTER_BUTTON_X)/sf->w);
+ if((gInit->cptGame[numB]==1)&&((numB==0)||(numB==1))){
+ // incr or decr lemmingRate
+ if((numB==0)&&(gInit->mapI.paraMap[0]>13)){
+ gInit->cptGame[15]-=5;
+ gInit->mapI.paraMap[0]-=5;
+ } else{
+ if((numB==0)&&(gInit->mapI.paraMap[0]>8)){
+ gInit->cptGame[15]-=1;
+ gInit->mapI.paraMap[0]-=1;
+ } }
+ if((numB==1)&&(gInit->mapI.paraMap[0]<91)){
+ gInit->cptGame[15]+=5;
+ gInit->mapI.paraMap[0]+=5;
} else {
- if(gInit->cptGame[i] == 1){
- gInit->cptGame[i] = 0;
- gInit->cptGame[17]=404;
+ if((numB==1)&&(gInit->mapI.paraMap[0]<99)){
+ gInit->cptGame[15]+=1;
+ gInit->mapI.paraMap[0]+=1;
+ } }
+ gInit->cptGame[numB]=0;
+ } else {
+ for(i=0;i<NBR_BUTTON_LEMMING;++i){
+ if(i != numB){
+ gInit->cptGame[i]=0;
} else {
- gInit->cptGame[i] = 1;
- gInit->cptGame[17]=i;
+ if(gInit->cptGame[i] == 1){
+ gInit->cptGame[i] = 0;
+ gInit->cptGame[17]=404;
+ } else {
+ gInit->cptGame[i] = 1;
+ gInit->cptGame[17]=i;
+ }
}
}
}
+ gInit->cptGame[18]=0;
+ } else {
+ // mouse is on pSpr_Lem
+ //if ..
+ //gInit.cptGame[NBR_BUTTON_LEMMING]
+ gInit->cptGame[18]=1;
}
- gInit->cptGame[18]=0;
- } else {
- // mouse is on pSpr_Lem
- //if ..
- //gInit.cptGame[NBR_BUTTON_LEMMING]
- gInit->cptGame[18]=1;
+ return 0;
}
- return 0;
- }
- int supprLem (struct gameInit *gInit, int cptFps){
- struct listeSimplementChainee *k=NULL;
- // refresh liste all of 100 tick
- if(cptFps % 100 == 0)
- {
- k=gInit->l.ll;
- if((k != NULL)&&(gInit->l.nbr == 1)){
- if(k->ID == 17){++gInit->l.nbrDied; --gInit->l.nbr;}
- if(k->ID == 19){++gInit->l.nbrSafe; --gInit->l.nbr;}
- if((k->ID == 17)||(k->ID == 19)) {k=NULL;}
- } else {
- while(k != NULL){
- if(k->next != NULL){
- switch(k->next->ID){
- // DIED
- case 17 : {
- k->next=k->next->next;
- ++gInit->l.nbrDied;
- --gInit->l.nbr;
- break;
- }
- // SAFE
- case 19 : {
- k->next=k->next->next;
- ++gInit->l.nbrSafe;
- --gInit->l.nbr;
- break;
- }
- default: k=k->next; break;
- }
- } else {
- k=k->next;
- }
+ int supprLem (struct gameInit *gInit, int cptFps){
+ struct listeSimplementChainee *k=NULL;
+ // refresh liste all of 100 tick
+ if(cptFps % 100 == 0)
+ {
+ k=gInit->l.ll;
+ if((k != NULL)&&(gInit->l.nbr == 1)){
+ if(k->ID == 17){++gInit->l.nbrDied; --gInit->l.nbr;}
+ if(k->ID == 19){++gInit->l.nbrSafe; --gInit->l.nbr;}
+ if((k->ID == 17)||(k->ID == 19)) {k=NULL;}
+ } else {
+ while(k != NULL){
+ if(k->next != NULL){
+ switch(k->next->ID){
+ // DIED
+ case 17 : {
+ k->next=k->next->next;
+ ++gInit->l.nbrDied;
+ --gInit->l.nbr;
+ break;
+ }
+ // SAFE
+ case 19 : {
+ k->next=k->next->next;
+ ++gInit->l.nbrSafe;
+ --gInit->l.nbr;
+ break;
+ }
+ default: k=k->next; break;
+ }
+ } else {
+ k=k->next;
+ }
+ }
}
+ printf("nbrInput = %d\nnbrInGame = %d\nnbrDied = %d\nnbrSafe = %d\n",gInit->l.nbrInput,gInit->l.nbr,gInit->l.nbrDied,gInit->l.nbrSafe);
}
- printf("nbrInput = %d\nnbrInGame = %d\nnbrDied = %d\nnbrSafe = %d\n",gInit->l.nbrInput,gInit->l.nbr,gInit->l.nbrDied,gInit->l.nbrSafe);
+ return 0;
}
- return 0;
- }
- // Par défaut, c'est l'analyse LEXICALE qui est lancée !
- int lancement (){
+ // Par défaut, c'est l'analyse LEXICALE qui est lancée !
+ int lancement (){
- int res,cptFps/*,i*/;
- int err=0;
- //Ce qui va nous permettre de quitter
- int quit = 0;
- SDL_Rect camera,inter;
- int mouseX,mouseY=0;
- long tick,temps=0;
- float fps = 0.0;
- int fps_count = 0;
- int fps_start = 0;
- int decalFps = 0;
-
- //La structure d'evenement
- SDL_Event event;
- event.type=0;
+ int res,cptFps/*,i*/;
+ int err=0;
+ //Ce qui va nous permettre de quitter
+ int quit = 0;
+ SDL_Rect camera,inter;
+ int mouseX,mouseY=0;
+ long tick,temps=0;
+ float fps = 0.0;
+ int fps_count = 0;
+ int fps_start = 0;
+ int decalFps = 0;
- //paint_stencil=1;
+ //La structure d'evenement
+ SDL_Event event;
+ event.type=0;
+ //paint_stencil=1;
- /* camera.x=160;
- camera.y=120;
- */
- camera.x=0;
- camera.y=0;
- struct gameInit gInit;
+ /* camera.x=160;
+ camera.y=120;
+ */
+ camera.x=0;
+ camera.y=0;
- // constructor ...
- err=initGame(&gInit);
- if(err!=0){return err;}
+ struct gameInit gInit;
- //Initialisation
- err=init();
- if(err!=0){return err;}
- //printf("DONE\n");
+ // constructor ...
+ err=initGame(&gInit);
+ if(err!=0){return err;}
- //printf("DEBUG3: load_file ... \n");
- //Chargement des fichiers
- err=load_files(&gInit);
- if(err!=0){return err;}
+ //Initialisation
+ err=init();
+ if(err!=0){return err;}
+ //printf("DONE\n");
- // paraMap
- for(res=4;res<IDENT_COUNT;++res){
- gInit.mapI.paraMap[res]=99;
- }
+ //printf("DEBUG3: load_file ... \n");
+ //Chargement des fichiers
+ err=load_files(&gInit);
+ if(err!=0){return err;}
- // CREATION OF SOME LEMMING
- err=creationLemming(&gInit);
- if(err!=0){return err;}
+ // paraMap
+ for(res=4;res<IDENT_COUNT;++res){
+ gInit.mapI.paraMap[res]=99;
+ }
- mouseX = gInit.mapI.xPos;
- camera.x=gInit.mapI.xPos;
- camera.w=screen->w;
- camera.h=screen->h;
- inter.x=0;
- inter.y=LEVEL_HEIGHT;
- inter.w=SCREEN_WIDTH;
- inter.h=INTERFACE_HEIGHT;
+ // CREATION OF SOME LEMMING
+ err=creationLemming(&gInit);
+ if(err!=0){return err;}
- //printf("DEBUG ludo : camera.w==%i, camera.h==%i\n", camera.w, camera.h);
+ mouseX = gInit.mapI.xPos;
+ camera.x=gInit.mapI.xPos;
+ camera.w=screen->w;
+ camera.h=screen->h;
+ inter.x=0;
+ inter.y=LEVEL_HEIGHT;
+ inter.w=SCREEN_WIDTH;
+ inter.h=INTERFACE_HEIGHT;
- // init level map (upper part of screen)
- SDL_FillRect( pTerrain, &pTerrain->clip_rect,
- gInit.mapI.map.cmap.bgColor );
+ //printf("DEBUG ludo : camera.w==%i, camera.h==%i\n", camera.w, camera.h);
+ // init level map (upper part of screen)
+ SDL_FillRect( pTerrain, &pTerrain->clip_rect,
+ gInit.mapI.map.cmap.bgColor );
- // init interface (downner part of screen)
- SDL_FillRect( screen, &inter, ccc_black);
- cptFps=0;
- gInit.cptGame[15]=0;
- SDL_FillRect( pStencil, NULL, ccc_Empty);
- //paint_terrain => pTerrain
- err=paint_terrain(&gInit,0);
- if(err!=0){return err;}
+ // init interface (downner part of screen)
+ SDL_FillRect( screen, &inter, ccc_black);
+ cptFps=0;
+ gInit.cptGame[15]=0;
- SDL_SetColorKey(pTerrain, SDL_SRCCOLORKEY|SDL_RLEACCEL, gInit.mapI.map.cmap.bgColor);
+ SDL_FillRect( pStencil, NULL, ccc_bgStencil);
+ //paint_terrain => pTerrain
+ err=paint_terrain(&gInit,0);
+ if(err!=0){return err;}
- SDL_BlitSurface(pStencil, NULL, pStencilFixe, NULL);
- SDL_SetColorKey(pStencilFixe, SDL_SRCCOLORKEY|SDL_RLEACCEL, ccc_Empty);
+ SDL_SetColorKey(pTerrain, SDL_SRCCOLORKEY|SDL_RLEACCEL, gInit.mapI.map.cmap.bgColor);
+
+ err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-37, screen->h-10, FPS);
+ if(err!=0){return err;}
- //Tant que l'utilisateur n'a pas quitter
+ test_blit(pStencil, NULL, pStencilFixe, NULL);
+ SDL_SetColorKey(pStencilFixe, SDL_SRCCOLORKEY, ccc_bgStencil);
+ err=paint_objet_stencil (&gInit,cptFps);
+ if(err!=0){return err;}
+ test_blit(pStencil, NULL, pStencilFixe, NULL);
- while( quit == 0 )
- {
- /* Timing */
- tick = SDL_GetTicks();
+ //Tant que l'utilisateur n'a pas quitter
- //Tant qu'il y a un événement
- while( SDL_PollEvent( &event ) )
+ while( quit == 0 )
{
- switch(event.key.keysym.sym){
- case SDLK_HOME : decalFps = 0; break;
- case SDLK_END : decalFps = FPS-11; break;
- case SDLK_PAGEUP : if(decalFps>0){decalFps -=1;}break;
- case SDLK_PAGEDOWN : if(decalFps<(FPS-1)){decalFps +=1;}break;
- case SDLK_w : paint_stencil = (paint_stencil==0)? 1 : 0 ; break;
- case SDLK_ESCAPE : quit = 1; break;
- default:break;
- }
- // SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
-
- switch (event.type) {
- case SDL_MOUSEMOTION: { mouseX = event.motion.x;
- mouseY = event.motion.y;break; }
- case SDL_MOUSEBUTTONDOWN: { err=mouse_action (&gInit, mouseX, mouseY,camera.x,camera.y );
- if(err!=0){return err;}
- break;}
- case SDL_QUIT : {
- //On quitte le programme
- quit = 1;
- }
- default:break;
- }
- }
+ /* Timing */
+ tick = SDL_GetTicks();
- if(mouseY <= LEVEL_HEIGHT){
- if (mouseX > (SCREEN_WIDTH - BOUND_SENSIBILITE)){
- if (camera.x < (LEVEL_WIDTH - SCREEN_WIDTH ) )
- {camera.x += CAM_VITESSE;}
- }
- if (mouseX < BOUND_SENSIBILITE){
- if (camera.x >= CAM_VITESSE )
- {camera.x -= CAM_VITESSE;}
+ //Tant qu'il y a un événement
+ while( SDL_PollEvent( &event ) )
+ {
+ switch(event.key.keysym.sym){
+ case SDLK_HOME : decalFps = 0; break;
+ case SDLK_END : decalFps = FPS-11; break;
+ case SDLK_PAGEUP : if(decalFps>0){decalFps -=1;}break;
+ case SDLK_PAGEDOWN : if(decalFps<(FPS-1)){decalFps +=1;}break;
+ case SDLK_w : paint_stencil = (paint_stencil==0)? 1 : 0 ; break;
+ case SDLK_ESCAPE : quit = 1; break;
+ default:break;
+ }
+ // SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
+
+ switch (event.type) {
+ case SDL_MOUSEMOTION: { mouseX = event.motion.x;
+ mouseY = event.motion.y;break; }
+ case SDL_MOUSEBUTTONDOWN: { err=mouse_action (&gInit, mouseX, mouseY,camera.x,camera.y );
+ if(err!=0){return err;}
+ break;}
+ case SDL_QUIT : {
+ //On quitte le programme
+ quit = 1;
+ }
+ default:break;
+ }
}
- }
-
- SDL_FillRect( pSpr_Lem, NULL, gInit.mapI.map.cmap.bgColor);
- SDL_BlitSurface(pTerrain, NULL, pSpr_Lem, NULL);
- SDL_FillRect( screen, &inter, ccc_black);
+ if(mouseY <= LEVEL_HEIGHT){
+ if (mouseX > (SCREEN_WIDTH - BOUND_SENSIBILITE)){
+ if (camera.x < (LEVEL_WIDTH - SCREEN_WIDTH ) )
+ {camera.x += CAM_VITESSE;}
+ }
+ if (mouseX < BOUND_SENSIBILITE){
+ if (camera.x >= CAM_VITESSE )
+ {camera.x -= CAM_VITESSE;}
+ }
+ }
+ SDL_FillRect( pSpr_Lem, NULL, gInit.mapI.map.cmap.bgColor);
+ test_blit(pTerrain, NULL, pSpr_Lem, NULL);
- //if(paint_stencil==1){
- SDL_FillRect( pStencil, NULL, ccc_Empty);
- SDL_BlitSurface(pStencilFixe, NULL, pStencil, NULL);
- //}
+ SDL_FillRect( screen, &inter, ccc_black);
- // SPR => pSpr_Lem
- err=paint_objet (&gInit,cptFps);
- if(err!=0){return err;}
- // SUPPR LEM => gInit
- err=supprLem(&gInit,cptFps);
- if(err!=0){return err;}
-
- // LEM => pSpr_Lem
- //if(paint_stencil==0){
- err=paint_lemming (&gInit,cptFps);
- if(err!=0){return err;}
- //}
+ //if(paint_stencil==1){
+ SDL_FillRect( pStencil, NULL, ccc_bgStencil);
+ test_blit(pStencilFixe, NULL, pStencil, NULL);
+ //}
- // INTERFACE => screen
- if(paint_stencil==0){
- err=paint_interface (&gInit);
+ // SPR => pSpr_Lem
+ err=paint_objet (&gInit,cptFps);
if(err!=0){return err;}
- } else {
- //testAlpha(screen, gInit.mapI.map.tabGif[9],gInit.mapI.map.tabGif[1],2,330);
- err=legende (&gInit);
+
+ // SUPPR LEM => gInit
+ err=supprLem(&gInit,cptFps);
if(err!=0){return err;}
- }
- // CURSOR => pSpr_Lem, screen
- if(paint_stencil==0){
- err=paint_cursor (pSpr_Lem,screen, gInit.mapI.map.tabGif[3], mouseX+camera.x, mouseY+camera.y, mouseX, &gInit);
- if(err!=0){return err;}
- } else {
- err=findTerrain(&gInit,mouseX+camera.x, mouseY+camera.y, mouseX);
+ // LEM => pSpr_Lem
+ //if(paint_stencil==0){
+ err=paint_lemming (&gInit,cptFps);
if(err!=0){return err;}
- err=paint_cursor (pStencil,screen, gInit.mapI.map.tabGif[3], mouseX+camera.x, mouseY+camera.y, mouseX, &gInit);
- if(err!=0){return err;}
- printf("x=%d y=%d\n",mouseX+camera.x,mouseY+camera.y);
- }
+ //}
- //get_pixel32( event.motion.x + camera.x, event.motion.y, pTerrain );
- //get_pixel32( event.motion.x + camera.x, event.motion.y, pSpr_Lem );
- //get_pixel32( event.motion.x + camera.x , event.motion.y, screen );
+ // INTERFACE => screen
+ if(paint_stencil==0){
+ err=paint_interface (&gInit);
+ if(err!=0){return err;}
+ } else {
+ //testAlpha(screen, gInit.mapI.map.tabGif[9],gInit.mapI.map.tabGif[1],2,330);
+ err=legende (&gInit);
+ if(err!=0){return err;}
+ }
- if(paint_stencil==0){
- SDL_BlitSurface(pSpr_Lem, &camera, screen, NULL);
- } else {
- SDL_BlitSurface(pStencil, &camera, screen, NULL);
- }
+ // CURSOR => pSpr_Lem, screen
+ if(paint_stencil==0){
+ err=paint_cursor (pSpr_Lem,screen, gInit.mapI.map.tabGif[3], mouseX+camera.x, mouseY+camera.y, mouseX, &gInit);
+ if(err!=0){return err;}
+ } else {
+ err=findTerrain(&gInit,mouseX+camera.x, mouseY+camera.y, mouseX);
+ if(err!=0){return err;}
+ err=paint_cursor (pStencil,screen, gInit.mapI.map.tabGif[3], mouseX+camera.x, mouseY+camera.y, mouseX, &gInit);
+ if(err!=0){return err;}
+ printf("x=%d y=%d\n",mouseX+camera.x,mouseY+camera.y);
+ }
- /* FPS counter */
- //printf("(tick %ld > fps_start %d +500)\n",tick,fps_start);
- // refresh fps all 500 ms
- if(tick > fps_start + 500)
- {
- fps = (float)fps_count * 1000.0 / (tick - fps_start);
- fps_count = 0;
- fps_start = tick;
- }
+ //get_pixel32( event.motion.x + camera.x, event.motion.y, pTerrain );
+ //get_pixel32( event.motion.x + camera.x, event.motion.y, pSpr_Lem );
+ //get_pixel32( event.motion.x + camera.x , event.motion.y, screen );
- ++fps_count;
+ if(paint_stencil==0){
+ test_blit(pSpr_Lem, &camera, screen, NULL);
+ } else {
+ test_blit(pStencil, &camera, screen, NULL);
+ }
- if (cptFps == 9999) {
- //if(SDL_GetTicks()==240000){
- //decalFps = 99;
- quit=1;
- }
+ /* FPS counter */
+ //printf("(tick %ld > fps_start %d +500)\n",tick,fps_start);
+ // refresh fps all 500 ms
+ if(tick > fps_start + 500)
+ {
+ fps = (float)fps_count * 1000.0 / (tick - fps_start);
+ fps_count = 0;
+ fps_start = tick;
+ }
- // limte fps
+ ++fps_count;
- if(FPS<=decalFps){printf("BUG: FPS < 0 : (FPS %d - decalFps %d) < 0",FPS,decalFps);return(42);} else {
- while((FPS>decalFps)&&(((float)fps_count * 1000.0 / (SDL_GetTicks()-fps_start)) > FPS-decalFps) ){
- if((FPS-decalFps)<=120){// useless ?
- SDL_Delay(3);
- }
- }}
+ if (cptFps == 99999) {
+ //if(SDL_GetTicks()==240000){
+ //decalFps = 99;
+ quit=1;
+ }
- temps = SDL_GetTicks();
- //heure
- err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-160, screen->h-40, temps/(1000*3600));
- if(err!=0){return err;}
- //minute
- err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-130, screen->h-40, (temps/(1000*60))%60);
- if(err!=0){return err;}
- //seconde
- err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-100, screen->h-40, (temps/1000)%60);
- if(err!=0){return err;}
+ // limte fps
- err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-100, screen->h-12, cptFps);
- if(err!=0){return err;}
- err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-37, screen->h-12, fps);
- if(err!=0){return err;}
+ if(FPS<=decalFps){printf("BUG: FPS < 0 : (FPS %d - decalFps %d) < 0",FPS,decalFps);return(42);} else {
+ while((FPS>decalFps)&&(((float)fps_count * 1000.0 / (SDL_GetTicks()-fps_start)) > FPS-decalFps) ){
+ if((FPS-decalFps)<=120){// useless ?
+ SDL_Delay(3);
+ }
+ }}
- //Mise à jour de l'écran
- if( SDL_Flip( screen ) == -1 ) {
- return 4;
- }
+ temps = SDL_GetTicks();
+ //heure
+ err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-160, screen->h-40, temps/(1000*3600));
+ if(err!=0){return err;}
+ //minute
+ err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-130, screen->h-40, (temps/(1000*60))%60);
+ if(err!=0){return err;}
+ //seconde
+ err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-100, screen->h-40, (temps/1000)%60);
+ if(err!=0){return err;}
- //SDL_Delay(1);
+ err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-150, screen->h-10, cptFps);
+ if(err!=0){return err;}
+ err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-87, screen->h-10, fps);
+ if(err!=0){return err;}
- if(FPS<=decalFps){printf("BUG: FPS < 0 : (FPS %d - decalFps %d) < 0",FPS,decalFps);return(43);} else {
- temps = SDL_GetTicks();
- //printf("cptFps = %d, time: %ld:%ld:%ld \n",cptFps,temps/(1000*3600),(temps/(1000*60))%60,(temps/1000)%60);
- }
- cptFps++;
+ //Mise à jour de l'écran
+ if( SDL_Flip( screen ) == -1 ) {
+ return 4;
+ }
- //quit = 1;
+ //SDL_Delay(1);
- }
+ if(FPS<=decalFps){printf("BUG: FPS < 0 : (FPS %d - decalFps %d) < 0",FPS,decalFps);return(43);} else {
+ temps = SDL_GetTicks();
+ //printf("cptFps = %d, time: %ld:%ld:%ld \n",cptFps,temps/(1000*3600),(temps/(1000*60))%60,(temps/1000)%60);
+ }
+ cptFps++;
- //On libère les images et on quitte SDL
- err=clean_up();
- if(err!=0){return err;}
+ //quit = 1;
- return 0;
- }
+ }
+ //On libère les images et on quitte SDL
+ err=clean_up();
+ if(err!=0){return err;}
- int main (int argc, char **argv)
- {
- int res,i,num,lt;
- char *temp,*temp0;
- //Uint32 ctest;
- //int j,k;
- //argc=3;
- //argv[1]="1";
- //argv[2]="72";
- if (argc<2 || argc>3) {
- fprintf(stderr, "Usage %s [Option] <Filename>\n",argv[0]);
- fprintf(stderr,"\nOption:\n\t- 1: on se place dans le dossier 1_orig\n");
- fprintf(stderr,"\t- 2: on se place dans le dossier 2_ohno\n");
- fprintf(stderr,"Filename:\n\t- numero du lvl (ex: 1, 4, 13, 65b )\n");
- return(44);
+ return 0;
}
- if (argc==3) {
- i=1;
- num=atoi(argv[2]);
- if (num >= 10) ++i;
- if (num >= 100) ++i;
- if (num >= 1000){
- fprintf(stderr,"Too many lvl (%d > 999)\n",num);
- return(45);
- }
- temp0=malloc(sizeof(char)*(3-i));// => [00] [0] []
- switch(i){
- case 1 : temp0 = "00";break;
- case 2 : temp0 = "0";break;
- case 3 : temp0 = "";break;
- default:fprintf(stderr,"BUG: i[=%d] > 3 ERREUR\n",i);return(46);
- }
-
- lt = (strlen("../../../../trunk/level/1_orig/lvl.ini")+5);// + 4 : 4 chiffres lvl.ini, +1 : string
- temp=malloc(sizeof(char)*lt);
- switch(atoi(argv[1])){
- case 1 : sprintf(temp,"../../../../trunk/level/1_orig/lvl0%s%d.ini",temp0,num);break;
- case 2 : sprintf(temp,"../../../../trunk/level/2_ohno/lvl1%s%d.ini",temp0,num);break;
- default:fprintf(stderr,"ERREUR: dossier [%d] inconnu\n",atoi(argv[1]));return(47);
+
+
+ int main (int argc, char **argv)
+ {
+ int res,i,num,lt;
+ char *temp,*temp0;
+ //Uint32 ctest;
+ //int j,k;
+ //argc=3;
+ //argv[1]="1";
+ //argv[2]="72";
+ if (argc<2 || argc>3) {
+ fprintf(stderr, "Usage %s [Option] <Filename>\n",argv[0]);
+ fprintf(stderr,"\nOption:\n\t- 1: on se place dans le dossier 1_orig\n");
+ fprintf(stderr,"\t- 2: on se place dans le dossier 2_ohno\n");
+ fprintf(stderr,"Filename:\n\t- numero du lvl (ex: 1, 4, 13, 65b )\n");
+ return(44);
}
- } else {
- temp=malloc(sizeof(char)*(strlen(argv[1])+1));
- sprintf(temp,"%s",argv[1]);
- }
- yyin=fopen(temp, "r");
- //yyin=fopen("./lvlTest01.ini", "r");
- if (yyin==NULL) {
- fprintf(stderr,"Filename INVALIDE: %s\n",temp);
- perror("Impossible d'ouvrir le niveau"); return(48); }
-
- /*
- for(i=0;i<256;++i){
- for(j=0;j<256;++j){
- for(k=0;k<256;++k){
- ctest = ((i<<16 | j<<8 | k) & 0xffffff);
- printf("[i]=%d, R = %X G = %X B = %X\n",
- i, ((ctest>>16) & 0xff),
- ((ctest>>8) & 0xff),
- (ctest & 0xff) );
- }}}*/
-
- res=lancement();
- //fclose(yyin); fait dans lancement
+ if (argc==3) {
+ i=1;
+ num=atoi(argv[2]);
+ if (num >= 10) ++i;
+ if (num >= 100) ++i;
+ if (num >= 1000){
+ fprintf(stderr,"Too many lvl (%d > 999)\n",num);
+ return(45);
+ }
+ temp0=malloc(sizeof(char)*(3-i));// => [00] [0] []
+ switch(i){
+ case 1 : temp0 = "00";break;
+ case 2 : temp0 = "0";break;
+ case 3 : temp0 = "";break;
+ default:fprintf(stderr,"BUG: i[=%d] > 3 ERREUR\n",i);return(46);
+ }
- return res;
+ lt = (strlen("../../../../trunk/level/1_orig/lvl.ini")+5);// + 4 : 4 chiffres lvl.ini, +1 : string
+ temp=malloc(sizeof(char)*lt);
+ switch(atoi(argv[1])){
+ case 1 : sprintf(temp,"../../../../trunk/level/1_orig/lvl0%s%d.ini",temp0,num);break;
+ case 2 : sprintf(temp,"../../../../trunk/level/2_ohno/lvl1%s%d.ini",temp0,num);break;
+ default:fprintf(stderr,"ERREUR: dossier [%d] inconnu\n",atoi(argv[1]));return(47);
+ }
+ } else {
+ temp=malloc(sizeof(char)*(strlen(argv[1])+1));
+ sprintf(temp,"%s",argv[1]);
+ }
+ yyin=fopen(temp, "r");
+ //yyin=fopen("./lvlTest01.ini", "r");
+ if (yyin==NULL) {
+ fprintf(stderr,"Filename INVALIDE: %s\n",temp);
+ perror("Impossible d'ouvrir le niveau"); return(48); }
- }
+ /*
+ for(i=0;i<256;++i){
+ for(j=0;j<256;++j){
+ for(k=0;k<256;++k){
+ ctest = ((i<<16 | j<<8 | k) & 0xffffff);
+ printf("[i]=%d, R = %X G = %X B = %X\n",
+ i, ((ctest>>16) & 0xff),
+ ((ctest>>8) & 0xff),
+ (ctest & 0xff) );
+ }}}*/
+
+ res=lancement();
+ //fclose(yyin); fait dans lancement
+
+ return res;
+
+ }