%{ #include "y.tab.h" #include "SDL/SDL.h" #include "SDL/SDL_image.h" #include #include #include #include /** time per frame in microseconds - this is the timing everything else is based on */ #define FPS 30 /** redraw animated level obejcts every 3rd frame (about 100ms) */ #define ANIM_STEP_FPS 3 // the original formula is: release lemming every 4+(99-speed)/2 time steps // where one step is 60ms (3s/50) or 66ms (4s/60). // Lemmini runs at 30ms/33ms, so the term has to be multiplied by 2 // 8+(99-releaseRate) should be correct //releaseBase = 8 + (99 - releaseRate); extern FILE *yyin; const int TIME_WAIT_TRAP_START = 15000; // milliseconde const int INTERFACE_HEIGHT = 150;//200; //Les attributs de l'écran (640 * 480) const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; //SCREEN_HEIGHT = LEVEL_HEIGHT + INTERFACE_HEIGHT + 10; const int SCREEN_BPP = 32; const int INTER_BUTTON_X = 0; const int INTER_BUTTON_Y = 50; //Les dimensions du niveau const int LEVEL_WIDTH = 1664*2; const int LEVEL_HEIGHT = 160*2; // Decale le tableau d'objet //0: lemmfont.gif //1: numfont.gif //2: countdown.gif //3: cursor.gif //4: explode.gif //5: border.gif //6: replay.gif //7: select.gif //8: font7x10.bmp //9: alphabet.gif #define NBR_ADD_OBJ 10 //9-21 : icone_XX.gif #define NBR_BUTTON_LEMMING 13 const int ADD_OBJ = NBR_ADD_OBJ + NBR_BUTTON_LEMMING; //vide == black Uint32 ccc_vide = 0x000000; //cyan pixel color Uint32 ccc_cyan= 0x00ffff; //yellow pixel color Uint32 ccc_yellow = 0xffff00; //Red pixel color Uint32 ccc_red= 0xff0000; //green pixel color Uint32 ccc_green= 0x00ff00; // erase surface; Uint32 ccc_black= 0x000000; //Blanc cursor Uint32 ccc_cursor = 0xffffff; //Noir Objet Uint32 ccc_objet = 0xff000000; //Noir Terrain Uint32 ccc_terrain = 0xff000000; // Noir Steel Uint32 ccc_steel = 0xff000000; // lemming color Uint32 ccc_lemming = 0x001a82; // icon_color Uint32 ccc_icon = 0x000000; // object color // terrain Uint32 ccc_tRemove = 0x007f00ff; // Violet Uint32 ccc_tRemoveNoOverwrite = 0x009932cd; // Lilas Uint32 ccc_tFull = 0xff38b0de; // Ciel d'été Uint32 ccc_tNoOverwrite = 0xff0000ff; // bleu // new formule Uint32 ccc_tEmpty = 0xcccccc; // gris Uint32 ccc_tBrick = 0x00ed4f; // vert // object Uint32 ccc_oPassive = 0x6b8e23; // Vert olive clair Uint32 ccc_oNoDigLeft = 0xff7f00; // Thé Uint32 ccc_oNoDigRight = 0xd98719; // Ocre Uint32 ccc_oTrapDrown = 0x7fff00;// Vert de Hooker Uint32 ccc_oTrapAndNoLem = 0x8c1717; // Ecarlate Uint32 ccc_oTrapAndLem = 0xa62a2a; // Brun Uint32 ccc_oExit = 0xd9d919; // Blond Uint32 ccc_oEntry = 0x855e42; // Bronze Uint32 ccc_oUnknow = 0xffffff; // Blanc // steel Uint32 ccc_s = 0xff00ff; // error Uint32 ccc_error = 0x6666669; // Config Cam const int CAM_VITESSE = 8; const int BOUND_SENSIBILITE = 50; //Les surfaces SDL_Surface *pTerrain = NULL; //Fond avec juste la map SDL_Surface *pSpr_Lem = NULL; // Fond + lemmings + animations SDL_Surface *screen = NULL; // Ecran via la caméra SDL_Surface *pStencil= NULL; // Ecran Stencil struct list_int { int val; struct list_int *next; }; struct val { int type; union ptr_u { char * str; struct list_int *ints;} ptr; }; //DEBUT NEW CONCEPTION // DEBUT: MAP_STRUCTURE #define NBR_STYLE_MAP 11 #define PARTICULE_COUNT 16 enum eMapStyle { brick , bubble , crystal , dirt , fire , marble , pillar , rock , snow , special, undefined }; char tabString_eMapStyle[NBR_STYLE_MAP][10] = { "brick" , "bubble" , "crystal" , "dirt" , "fire" , "marble" , "pillar" , "rock" , "snow" , "special", "undefined" }; struct colorMap { Uint32 bgColor;// background color present in "style".ini Uint32 debrisColor;// debris color present in "style".ini Uint32* particleColor; //particle color present in "style".ini }; struct spriteObjet { // ID == Objet.ID int state; // number of state in terraino_XX.gif; // animation types // 0 - don't animate // 1 - animate continously // 2 - trap - animate on trigger - else show first pic // 3 - entry animation: animate once at level start int anim; // object types // 0 - passive // 3 - no digging to the left // 4 - no digging to the right // 5 - trap which makes lemmings drown (water/quick sand/mud) // 6 - trap which replaces lemming with death animation // 7 - trap which triggers lemming death animation // 8 - exit // 32 - entry int type; int sound; // numero of sound }; struct mapStyle { enum eMapStyle style; // map' style int superLemming; // off = 0; on = 1; int tiles; // number of terrain_XX.gif present in "style".ini int tilesObjet; //number of terraino_XX.gif int tilesSteel; // number of terrainom_XX.gif struct colorMap cmap; // level's info's color struct spriteObjet* tabDataSprO; // sprite'data ; default=NULL; SDL_Surface **tabGif; // all gif are stored in; default=NULL; }; // FIN: MAP_STRUCTURE // DEBUT: LEMMINGS_STRUCTURE // LEM_JOB - OTHER_LEM_JOB == lemm_XX.gif #define OTHER_LEM_JOB 3 #define LEM_JOB 20 #define MAX_LEM_FALL 3 #define MAX_LEM_FALL_FLOATER 2 #define FALLER_MAX 126 #define FLOATER_TO_FALLER 32 #define MAX_LEM_FLOATER 2 #define WALKER_OBSTACLE_HEIGHT 14 /** a jumper moves up two pixels per frame */ #define MAX_JUMPER_STEP 2 /** if a walker jumps up 6 pixels, it becomes a jumper */ #define MAX_JUMPER_JUMP 4 #define MAX_BUILD_BRICK 9 #define MAX_BUILD_END 3 enum eLemmingJob { walker , faller , climber , climber_to_faller , floater , splat , stopper , drowning , trap_death , exIt , bomber, builder , builder_end , digger , basher , miner , jumper , died , enter , safe }; char tabString_eLemmingJob[LEM_JOB][20] = { "walker" , "faller" , "climber" , "climber_to_faller" , "floater" , "splat" , "stopper" , "drowning" , "trap_death" , "exIt" , "bomber", "builder" , "builder_end , digger" , "basher" , "miner" , "jumper", "died" , "enter" , "safe" }; struct lemmingMask { // ID == lemming.ID; int stateM; // number of state in mask_XX.gif; int dirM; // number of direction int cooldown; // after animations of lemming animation, do mask action and increase mask frame idx }; struct lemmingImask { // ID == lemming.ID; int stateI; // number of state in imask_XX.gif; int dirI; // number of direction }; struct lemmingJobAndSprite { // ID == lemming.ID; int state; // number of state in lemm_XX.gif; int dir; // direction of lemming: 0=left(do FlipLR); 1=right; default=1; int anim; // animation type: 0=loop, 1=once (state change if finished); // foot: director 's foot for collision 's test // calcul the X' symetry if lemming.dir==0(left) int footX; // position X of right's lemming's foot; int footY; // position Y of right's lemming's foot; int footSize; // size of lemming's foot; // mask for screen ... struct lemmingMask* mask; // mask of this job; default=NULL; struct lemmingImask* imask; // imask of this job; default=NULL; }; // FIN: LEMMINGS_STRUCTURE // DEBUT: INFOMAP #define IDENT_COUNT 12 enum eParaMap { releaseRate,numLemmings,numToRescue,timeLimit, numClimbers,numFloaters,numBombers,numBlockers,numBuilders, numBashers,numMiners,numDiggers }; char tabString_eParaMap[IDENT_COUNT][32] = { "releaseRate","numLemmings","numToRescue","timeLimit", "numClimbers","numFloaters","numBombers","numBlockers", "numBuilders","numBashers","numMiners","numDiggers" }; struct infoMap { char* name; // map name; default=NULL; int paraMap[IDENT_COUNT]; // some parameter of this map int xPos; // camera started position int maxFall; // max pixel lemming fall before died;default=0; int nbrEntry; // number of entry in this map; default=0; struct mapStyle map; // map struct lemmingJobAndSprite *lemmingDATA; // DATA of lemmingJob; default=NULL; }; // FIN: INFOMAP // DEBUT: GAMEINIT struct paraTerrain { int modif; //modifier: 8=NO_OVERWRITE, 4=UPSIDE_DOWN, 2=REMOVE (combining allowed, 0=FULL); }; struct paraObjet { int UD; // upside down (0,1); int paintMode;// paint modes: 8=VIS_ON_TERRAIN, 4=NO_OVERWRITE, 0=FULL (only one value possible) int cptState; // count number of frame for an animation at once, default=0; }; struct paraSteel { int w;// weight int h;// height }; struct paraLemming { int dir; // direction of lemming; default=1; int climber; // skill climber; default = 0; int blocker; // skill blocker; default = 0; int bomber; // skill bomber; default = 404; int floater; // skill floater; default = 0; int nuke; // nuked or not; default=0; int cptFall; // count number of pixel when lemming falling;default = 0; int cptJump; // count number of pixel when lemming jumping;default = 0; int cptState; // count number of frame for an animation at once, default=0; }; struct listeSimplementChainee { int ID; // ID for tabGif; int x; // x position; int y; // y position; union listeDataType { struct paraTerrain *pt; // other para about terrain; default=NULL; struct paraObjet *po; // other para about objet; default=NULL; struct paraSteel *ps; // other para about steel; default=NULL; struct paraLemming *pl; // other para about lemming; default=NULL; } data; struct listeSimplementChainee *next;// default=NULL; }; struct terrain { int nbr; // number of terrain on this map; default=0; struct listeSimplementChainee *lt; // list of terrain; default=NULL; }; struct objet { int nbr; // number of objet on this map; default=0; struct listeSimplementChainee *lo; // list of objet; default=NULL; }; struct steel { int nbr; // number of steel on this map; default=0; struct listeSimplementChainee *ls; // list of steel; default=NULL; }; struct lemming { int nbrInput; // number of lemming will be create; default=0; int nbr; // number of lemming on this map; default=0; int nbrDied; // number of lemming Died on this map; default=0; int nbrSafe; // number of lemming Saved on this map; default=0; struct listeSimplementChainee *ll; // list of lemming; default=NULL; }; // game use some cpt #define NBR_CPT 20 struct gameInit { struct infoMap mapI; // all DATA of the map; struct terrain t; // all DATA of terrain on this map; struct objet o; // all DATA of objet on this map; struct steel s; // all DATA of steel on this map; struct lemming l; // all DATA of lemming on this map; // 0-13 : BUTTON_LEMMING state button 0: off; 1: on; // 14 : CURSOR STATE // 15 : FREE CPT: for all need it ...; default=0; // 16 : NBR_ENTRY OPEN; default=0; // 17 : clic on mouse on lemning skill; default=404; // 18 : clic on mouse on lemning;default=0; int cptGame[NBR_CPT]; // default=0; }; // FIN: GAMEINIT //FIN NEW CONCEPTION enum sens { UD , LR }; extern int yylineno; // Bidouille pour avoir le numero de ligne du lexer ^^ int yylex(); void yyerror(struct gameInit *gInit, char *s); SDL_Surface *load_image( char* filename, Uint32 cbg ); // void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip ); int init(); SDL_Surface* flipSurfaceUD_LR(SDL_Surface* src, enum sens sensO, Uint32 c); int load_fields(char *folder, struct gameInit *gInit, int tabnum[255] ); int afficher(struct gameInit *gInit); int load_files(struct gameInit *gInit); int clean_up(); int anim_objet(int typeS, int typeO, int cptFps, int frames, int *cpt, struct gameInit *gInit);// returne le state de l'oblet a afficher Uint32 get_pixel32( int x, int y, SDL_Surface *surface ); int putPixel(SDL_Surface *surface,Uint16 x,Uint16 y,Uint32 color); int stateLemming(struct gameInit *gInit, SDL_Surface *s); struct listeSimplementChainee* rev_listeO (struct listeSimplementChainee* liste); int initGame(struct gameInit *gInit); int creationLemming(struct gameInit *gInit); int paint_terrain (struct gameInit *gInit, int choix); int paint_objet (struct gameInit *gInit, int cptFps); int supprLem (struct gameInit *gInit, int cptFps); int paint_lemming (struct gameInit *gInit, int cptFps); int test_O_UD(int UD); Uint32 string_to_Uint32 (char* c, int taille); Uint32* tab_of_string_to_Uint32 (char* c, int taille); int paint_letters (char* text); int findTerrain( struct gameInit *gInit,int x, int y, int x0); int paint_cursor(SDL_Surface *dst1,SDL_Surface *dst2, SDL_Surface *src, int x, int y, int x0, struct gameInit *gInit); int print_num(SDL_Surface *dst, SDL_Surface *font, int x, int y, int value); int print_alpha(SDL_Surface *dst, SDL_Surface *src, int x, int y, char* msg); int testAlpha(SDL_Surface *dst, SDL_Surface *src,SDL_Surface *src2, int x, int y); int legende (struct gameInit *gInit); int paint_interface(struct gameInit *gInit); int giveSkill (struct gameInit *gInit, struct listeSimplementChainee* k, int skill ); int mouse_action (struct gameInit *gInit, int x, int y, int camX , int camY); int lancement(); int paint_stencil=0; %} %parse-param { struct gameInit *gInit } %union {char* str; int num; struct list_int *ints; struct val *val;} %token LEXERROR %token STYLE %token NAME %token SLEM %token BGCOLOR %token DEBRISCOLOR %token PARTICLECOLOR %token AFF %token XC %token EOL %token VIR %token IDENT %token STR %token INT %type extra_vals %type val %start ini %% ini: | ini decl | ini EOL decl: STYLE AFF val { int ok=0; enum eMapStyle s; // STYLE //printf("Le style\n"); if ( $3->type != 0 ) { printf("ERREUR: Fichier .ini corrompu (style n'est pas de style int)\n"); } else { s=0; while(sptr.str,"undefined")!=0)&& (strcmp($3->ptr.str,tabString_eMapStyle[s]) == 0 ) ){ ok=2; gInit->mapI.map.style=s; break; } ++s; } if (ok!=2) { // BUG ... printf("Style [%s] invalide (undefined) !!\n",$3->ptr.str); exit(2); } } } | NAME AFF val { //printf("Le name \n"); gInit->mapI.name=$3->ptr.str; //FIXME } | SLEM AFF val { int res=99; //printf("Le superlemming \n"); if(strcmp($3->ptr.str,"true")==0){ res = 1; } if(strcmp($3->ptr.str,"false")==0){ res = 0; } if(res!=99){ gInit->mapI.map.superLemming=res; } else { printf("superlemming value invalid: %d %s\n",res,$3->ptr.str);return(3); } } | BGCOLOR AFF val { printf("BGCOLOR XC\n"); gInit->mapI.map.cmap.bgColor = string_to_Uint32($3->ptr.str,6); } | DEBRISCOLOR AFF val { printf("DEBRISCOLOR XC\n"); gInit->mapI.map.cmap.debrisColor = string_to_Uint32($3->ptr.str,6); } | PARTICLECOLOR AFF val { gInit->mapI.map.cmap.particleColor=tab_of_string_to_Uint32($3->ptr.str,6); } | IDENT AFF val EOL { enum eParaMap t; // parameter of this map int i=0,state=0; // cette variable sert a derteminer dans quel cas on se trouve // lvl*.ini => fichier de conf des d'une map de lemming // state==0: aucun token detecter // state==1: token para de la map detecter // state==2: token xPos detecter // state==3: token terrain_ detecter // state==4: token object_ detecter // state==5: token steel_ detecter // style.ini => fichire de conf des objets animes // state==6: token frames_ detecter // state==7: token anim_ detecter // state==8: token type_ detecter // state==9: token sound_ detecter // state==10: token title detecter FIXME // lemming.ini => fichier de conf des lemmings // state==11: token lemm_ detecter // state==12: token pos_ detecter // state==13: token mask_ detecter // state==14: token imask_ detecter // liste terrain || objet || steel struct listeSimplementChainee **listeItem=NULL; //printf("'%s' ^\n ", $1); // donne les parametres de la map t=0; while(tmapI.paraMap[t]=$3->ptr.ints->val; break; } ++t; } if (state!=1){ if (strcmp($1,"xPos") == 0){ state=2; gInit->mapI.xPos=$3->ptr.ints->val; } if(strncmp($1,"terrain_",8) == 0){ state=3; // init terrain if(gInit->t.lt==NULL){ gInit->t.nbr=0; } else { gInit->t.nbr+=1; } listeItem=&gInit->t.lt; } if(strncmp($1,"object_",7) == 0){ state=4; // init objet if(gInit->o.lo==NULL){ gInit->o.nbr=0; } else { gInit->o.nbr+=1; } listeItem=&gInit->o.lo; } if(strncmp($1,"steel_",6) == 0){ state=5; // init steel if(gInit->s.ls==NULL){ gInit->s.nbr=0; } else { gInit->o.nbr+=1; } listeItem=&gInit->s.ls; } // Sprite Objet if(strncmp($1,"frames_",7) == 0){ state=6; // 1ER CAS if(gInit->mapI.map.tilesObjet == 0){printf("ERREUR: tilesObjet == 0 => exit to prevent a segFault\n");exit(4);}; if(gInit->mapI.map.tabDataSprO == NULL){ gInit->mapI.map.tabDataSprO= malloc((sizeof(struct spriteObjet))*(gInit->mapI.map.tilesObjet)); gInit->cptGame[15] = -1; } gInit->cptGame[15] +=1; gInit->mapI.map.tabDataSprO[gInit->cptGame[15]].state=$3->ptr.ints->val; } if(strncmp($1,"anim_",5) == 0){ state=7; gInit->mapI.map.tabDataSprO[gInit->cptGame[15]].anim=$3->ptr.ints->val; } if(strncmp($1,"type_",5) == 0){ state=8; gInit->mapI.map.tabDataSprO[gInit->cptGame[15]].type=$3->ptr.ints->val; } if(strncmp($1,"sound_",6) == 0){ state=9; gInit->mapI.map.tabDataSprO[gInit->cptGame[15]].sound=$3->ptr.ints->val; } // "style".ini if(strncmp($1,"tiles",5) == 0){ state=10; if($3->ptr.ints->val!=gInit->mapI.map.tiles){ printf("BUG: variable parse && nbrFichier are different\n"); return(5); } //gInit->mapI.map.tiles=$3->ptr.ints->val; } // lemming .ini if(strncmp($1,"lemm_",5)==0){ state=11; // PREMIER CAS if(gInit->mapI.lemmingDATA == NULL){ // 1ER CAS gInit->mapI.lemmingDATA=malloc((sizeof(struct lemmingJobAndSprite))*(LEM_JOB - OTHER_LEM_JOB)); gInit->cptGame[15] = -1; } gInit->cptGame[15] +=1; gInit->mapI.lemmingDATA[gInit->cptGame[15]].mask=NULL; gInit->mapI.lemmingDATA[gInit->cptGame[15]].imask=NULL; } if(strncmp($1,"pos_",4)==0){ state=12; } if(strncmp($1,"mask_",5)==0){ state=13; gInit->mapI.lemmingDATA[gInit->cptGame[15]].mask=malloc(sizeof(struct lemmingMask)); } if(strncmp($1,"imask_",6)==0){ state=14; gInit->mapI.lemmingDATA[gInit->cptGame[15]].imask=malloc(sizeof(struct lemmingImask)); } if((state>2 && state<6)||(state>10 && state<15)){ struct list_int *curr=$3->ptr.ints; struct listeSimplementChainee *k = malloc(sizeof(struct listeSimplementChainee)); //k->data.pt=NULL; //i=0; switch(state){ // 3: terrain case 3 : {i=0;k->data.pt=malloc(sizeof(struct paraTerrain));break;} // 4: objet case 4 : { i=4; k->data.po=malloc(sizeof(struct paraObjet)); k->data.po->cptState=0; break; } // 5 : steel case 5 : {i=9;k->ID=0;k->data.ps=malloc(sizeof(struct paraSteel));break;} case 11 : {i=13;break;} case 12 : {i=16;break;} case 13 : {i=19;break;} case 14 : {i=22;break;} // en cas de BUG default: printf("BUG parser: state = %d\n",state);exit(6); } while (curr!=NULL) { // printf("%i ", curr->val); switch(i) { // pour les terrains case 0: k->ID=curr->val; break; case 3: k->x=curr->val; break; case 2: k->y=curr->val; break; case 1: k->data.pt->modif=curr->val; break; // pour les objets case 4: k->ID=curr->val; if(k->ID==1){++gInit->mapI.nbrEntry;} break; case 8: k->x=curr->val; break; case 7: k->y=curr->val; break; case 6: k->data.po->paintMode=curr->val; break; case 5: k->data.po->UD = curr->val; break; // pour les steels case 9: k->x=curr->val; break; case 10: k->y=curr->val; break; case 11: k->data.ps->w=curr->val; break; case 12: k->data.ps->h = curr->val; break; // pour les lemmings // lemm_ case 13: gInit->mapI.lemmingDATA[gInit->cptGame[15]].state=curr->val;break; case 15: gInit->mapI.lemmingDATA[gInit->cptGame[15]].dir=curr->val;break; case 14: gInit->mapI.lemmingDATA[gInit->cptGame[15]].anim=curr->val;break; // pos_ case 16: gInit->mapI.lemmingDATA[gInit->cptGame[15]].footX=curr->val;break; case 18: gInit->mapI.lemmingDATA[gInit->cptGame[15]].footY=curr->val;break; case 17: gInit->mapI.lemmingDATA[gInit->cptGame[15]].footSize=curr->val;break; // mask_ case 19: gInit->mapI.lemmingDATA[gInit->cptGame[15]].mask->stateM=curr->val;break; case 21: gInit->mapI.lemmingDATA[gInit->cptGame[15]].mask->dirM=curr->val;break; case 20: gInit->mapI.lemmingDATA[gInit->cptGame[15]].mask->cooldown=curr->val;break; // imask_ case 22: gInit->mapI.lemmingDATA[gInit->cptGame[15]].imask->stateI=curr->val;break; case 23: gInit->mapI.lemmingDATA[gInit->cptGame[15]].imask->dirI=curr->val;break; // en cas de BUG default: printf("BUG parser i = %d\n",i);exit(7); } curr=curr->next; ++i; } // fichier lvl*.ini if(state>2 && state<6){ k->next=*listeItem; *listeItem=k; } //free(curr); } else { if(state == 0) { printf("BUG: no parse for this token : %s \n",$1); exit(8); } } } // FIN ok==0 } val: INT extra_vals { // printf("creation de liste int ... \n"); $$=malloc(sizeof(struct val)); $$->type=1; $$->ptr.ints=malloc(sizeof(struct list_int)); $$->ptr.ints->val=$1; $$->ptr.ints->next=$2; // printf("liste int %d\n",$1); } | STR { // printf("creation de liste STR ...\n"); $$=malloc(sizeof(struct val)); $$->type=0; $$->ptr.str=malloc(sizeof(char)*strlen($1)+1); strcpy($$->ptr.str, $1); // printf("liste STR %s\n",$1); } extra_vals: { $$=NULL; } | extra_vals VIR INT { //FIXME : => VIR INT extra_vals $$=malloc(sizeof(struct list_int)); $$->val=$3; $$->next=$1; } %% void yyerror(struct gameInit *gInit, char *s) { //fprintf(stderr, "Syntax Error : '%s' at l%d,c%d-l%d,c%d\n", s, @$.first_column, @$.last_line, @$.last_column); // Nécessite l'option %locations et un lexer qui va bien fprintf(stderr, "(stdin):%i: error: %s\n", yylineno, s); exit(9); } Uint32 string_to_Uint32 (char* c,int taille){ Uint32 u32c; int i,n,lc = strlen(c); int t[taille]; if(lc-3 != taille){ printf("ERREUR: wrong format .. expect (strlen[%s] - 3)==%d but it's = %d\n",c,taille,lc-3);return(10); } u32c = 0; for(i=0;i 47 && n < 58 ) { t[i]=(n - 48) ;} if (n > 64 && n < 71 ) { t[i]=(n - 55) ;} if (n > 96 && n < 103 ){ t[i]=(n - 87) ;} } n=0; for(i=0;inext; /* on libère l'élélement de la liste et on le place en début de la liste à renvoyer*/ travail->next=retour; /* l'élément qu'on vient de mettre en début de liste devient le début de la liste de à renvoyer */ retour=travail; } /* YAPUKA renvoyer la liste inversée */ return retour; } // returne le state de l'oblet a afficher int anim_objet(int typeS, int typeO, int cptFps, int frames, int *cpt, struct gameInit *gInit){ int f=0; if(typeS == 90){typeS=4;}//Lemming anim continue if(typeS == 91){typeS=5;}//Lemming anim at once switch(typeS){ // not animed case 0 : break;//f=0 // Object animation continue case 1 : f=(cptFps/ANIM_STEP_FPS)%(frames);break; // Object animation at once case 2 : if((*cpt) > 0){ f=(cptFps/ANIM_STEP_FPS)%(frames);--(*cpt); } break; //animation at start level case 3 : if((SDL_GetTicks()-TIME_WAIT_TRAP_START)>0){ if(cptFpscptGame[16] < gInit->mapI.nbrEntry){++(gInit->cptGame[16]);} } } } break; // Lemming animation continue case 4 : f=(cptFps)%(frames);break; // Lemming animation at once case 5 : if((*cpt) > 0){ f=(cptFps)%(frames);--(*cpt); } else {//on s'arrête à last frame f=(frames-1); } break; default : printf("BUG typeSprite : %d\n",typeS); exit(11); } /* switch(typeO){ case 0 : f=cptFps%(frames);break; case 3 : f=cptFps%(frames);break;//FIXME case 4 : f=cptFps%(frames);break;//FIXME case 5 : f=cptFps%(frames);break;//FIXME case 6 : f=cptFps%(frames);break;//FIXME case 7 : f=cptFps%(frames);break;//FIXME case 8 : f=cptFps%(frames);break;//FIXME case 32 : f=cptFps%(frames);break;//FIXME default : printf("BUG typeObjet : %d\n",type0); return(12); } }*/ /* # animation types # 0 - don't animate # 1 - animate continously # 2 - trap - animate on trigger - else show first pic # 3 - entry animation: animate once at level start # object types # 0 - passive # 3 - no digging to the left # 4 - no digging to the right # 5 - trap which makes lemmings drown (water/quick sand/mud) # 6 - trap which replaces lemming with death animation # 7 - trap which triggers lemming death animation # 8 - exit # 32 - entry*/ return f; } Uint32 get_pixel32( int x, int y, SDL_Surface *surface ) { //Convertie les pixels en 32 bit Uint32 *pixels = (Uint32 *)surface->pixels; //printf("4) x=%d,y=%d,p =%X\n",x,y,pixels[ ( y * surface->w ) + x ]); //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"); exit(42); } if ( pixels==NULL ) { printf("ludo2\n"); exit(42); } 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 ]; } int putPixel(SDL_Surface *surface,Uint16 x,Uint16 y,Uint32 colori) { /* bpp de la surface ecran */ Uint8 bpp = surface->format->BytesPerPixel; /* pointeur vers le pixel a remplacer */ if((((y * surface->w ) + x) >= surface->h*surface->w)|| (((y * surface->w ) + x) < 0)){ if(y==surface->h){printf("put C'EST PAS ASSEZ GROS POUR TOI !!!! y=surface->h\n"); return (ccc_error);} 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 (14); } Uint8 *p = ((Uint8 *)surface->pixels) + y * surface->pitch + x * bpp; /*printf("pixel R = %X G = %X B = %X A=%X bpp = %d, ccc=%X \n", ((colori>>16) & 0xff), ((colori>>8) & 0xff), (colori & 0xff), ((colori>>24) & 0xff), bpp, colori );*/ switch(bpp) { case 1: *p = (Uint8) colori; break; case 2: *(Uint16 *)p = (Uint16) colori; break; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { *(Uint16 *)p = ((colori >> 8) & 0xff00) | ((colori >> 8) & 0xff); *(p + 2) = colori & 0xffff; } else { *(Uint16 *)p = colori & 0xffff; *(p + 2) = ((colori >> 16) & 0xffff) ; } break; case 4:{ *(Uint32 *)p = colori; } break; } return 0; } int stateLemming(struct gameInit *gInit, SDL_Surface *surf ){ struct listeSimplementChainee *unl; struct listeSimplementChainee *k; SDL_Surface *sfT; int coor[4][7]; // [4] : 0:left, 1:right, 2:up, 3:down // [7] : x0,weightGif,y0,henghtGif,id,anim,type int pixCtrlLem[2][5]; // line 0 : x, 1 : y // pt 0-3 : 3 //[lemmingFoot] 2 // 0 1 // pt 4 : pt G lemming int i=0,j,d,step=0; int heightGif,weightGif,x0,y0,beginO,endO; int heightLem,weightLem; int min_up =-200; int min_down = LEVEL_HEIGHT; int min_left =-200; int min_right = LEVEL_WIDTH; unl=gInit->l.ll; for(i=0;i<4;++i){ for(j=0;j<7;++j){ coor[i][j]=404; } } while (unl != NULL){ if(unl->ID < (LEM_JOB - OTHER_LEM_JOB)){ sfT = gInit->mapI.map.tabGif[gInit->mapI.map.tiles*2 + gInit->mapI.map.tilesObjet*2 +gInit->mapI.map.tilesSteel +(unl->ID)*2+(unl->data.pl->dir) + ADD_OBJ]; // foot of lemming d = unl->y + gInit->mapI.lemmingDATA[unl->ID].footY; if(unl->data.pl->dir==1){//right i= unl->x + gInit->mapI.lemmingDATA[unl->ID].footX + gInit->mapI.lemmingDATA[unl->ID].footSize - 1; pixCtrlLem[0][0]= i; pixCtrlLem[1][0]= d + 1 ; pixCtrlLem[0][1]= i + 1 ; pixCtrlLem[1][1]= d + 1 ; pixCtrlLem[0][2]= i + 1 ; pixCtrlLem[1][2]= d ; pixCtrlLem[0][3]= i + 1 ; pixCtrlLem[1][3]= d - 1 ; } else {//left i = unl->x+(sfT->w-gInit->mapI.lemmingDATA[unl->ID].footX - gInit->mapI.lemmingDATA[unl->ID].footSize) + 1 ; pixCtrlLem[0][0]= i ; pixCtrlLem[1][0]= d + 1 ; pixCtrlLem[0][1]= i - 1 ; pixCtrlLem[1][1]= d + 1 ; pixCtrlLem[0][2]= i - 1 ; pixCtrlLem[1][2]= d ; pixCtrlLem[0][3]= i - 1 ; pixCtrlLem[1][3]= d - 1 ; } weightLem=sfT->w; heightLem=sfT->h/(gInit->mapI.lemmingDATA[unl->ID].state); pixCtrlLem[0][4]= unl->x + sfT->w/2; pixCtrlLem[1][4]= unl->x + heightLem/2; //for(i=0;i<4;++i){ // putPixel(pSpr_Lem,pixCtrlLem[0][0],pixCtrlLem[1][0] ,ccc_cyan); // putPixel(pSpr_Lem,pixCtrlLem[0][1],pixCtrlLem[1][1] ,ccc_red); // putPixel(pSpr_Lem,pixCtrlLem[0][2],pixCtrlLem[1][2] ,ccc_green); // putPixel(pSpr_Lem,pixCtrlLem[0][3],pixCtrlLem[1][3] ,ccc_yellow); //} /* // if(unl->data.pl->dir==1){ for(i=0;imapI.lemmingDATA[unl->ID].footSize;++i){ putPixel(pSpr_Lem,gInit->mapI.lemmingDATA[unl->ID].footX+unl->x+i,unl->y+gInit->mapI.lemmingDATA[unl->ID].footY,ccc_green); }//} else { for(i=gInit->mapI.lemmingDATA[unl->ID].footSize;i>0;--i){ putPixel(pSpr_Lem,unl->x+(sfT->w-gInit->mapI.lemmingDATA[unl->ID].footX - gInit->mapI.lemmingDATA[unl->ID].footSize)+i,unl->y+gInit->mapI.lemmingDATA[unl->ID].footY,ccc_red); }//}*/ k=gInit->o.lo; while(k != NULL){ sfT=gInit->mapI.map.tabGif[gInit->mapI.map.tiles*2+k->ID*2+k->data.po->UD+ADD_OBJ]; x0 = k->x; weightGif = sfT->w; y0 = k->y; heightGif = sfT->h/(gInit->mapI.map.tabDataSprO[k->ID].state); if(k->data.po->UD==0){// Up==0 or Down==1 ? beginO=y0; endO=y0+heightGif; } else { beginO=y0-heightGif; endO=y0; } // verif objet autour du lemming // verif left and right if ((pixCtrlLem[1][2] >= beginO )&&(pixCtrlLem[1][2] <= endO )){ // verif left if ((pixCtrlLem[0][2]) >= (x0 + weightGif)){ if (min_left <= (x0 + weightGif)){ min_left = (x0 + weightGif); // printf("\t--> verif left\n"); coor[0][0]=x0; coor[0][1]=weightGif; coor[0][2]=y0; coor[0][3]=endO-y0; coor[0][4]=k->ID; coor[0][5]=gInit->mapI.map.tabDataSprO[k->ID].anim; coor[0][6]=gInit->mapI.map.tabDataSprO[k->ID].type; } } // verif right if (pixCtrlLem[0][2] <= x0) { if (min_right >= x0){ min_right = x0; // printf("\t--> verif right\n"); coor[1][0]=x0; coor[1][1]=weightGif; coor[1][2]=y0; coor[1][3]=endO-y0; coor[1][4]=k->ID; coor[1][5]=gInit->mapI.map.tabDataSprO[k->ID].anim; coor[1][6]=gInit->mapI.map.tabDataSprO[k->ID].type; } } } // verif up and down if ((pixCtrlLem[0][2] >= x0)&&((pixCtrlLem[0][2] ) <= (x0 + weightGif))){ // verif up if ( pixCtrlLem[1][2] >= endO){ if (min_up <= endO){ min_up = endO; // printf("\t--> verif up\n"); coor[2][0]=x0; coor[2][1]=weightGif; coor[2][2]=y0; coor[2][3]=endO-y0; coor[2][4]=k->ID; coor[2][5]=gInit->mapI.map.tabDataSprO[k->ID].anim; coor[2][6]=gInit->mapI.map.tabDataSprO[k->ID].type; } } // verif down if (pixCtrlLem[1][2] <= beginO) { if (min_down >= beginO){ min_down = beginO; //printf("\t--> verif down\n"); coor[3][0]=x0; coor[3][1]=weightGif; coor[3][2]=y0; coor[3][3]=endO-y0; coor[3][4]=k->ID; coor[3][5]=gInit->mapI.map.tabDataSprO[k->ID].anim; coor[3][6]=gInit->mapI.map.tabDataSprO[k->ID].type; } } } k=k->next; } for(i=0;i<4;++i){ printf("Objet %d : ID=%d, anim=%d, type=%d, (x0=%d,w=%d,y0=%d,h=%d)\n",i,coor[i][4],coor[i][5],coor[i][6],coor[i][0],coor[i][1],coor[i][2],coor[i][3]); } //test object collision for(i=0;i<4;++i){//foot lemming is on the half of trap if( (pixCtrlLem[0][2] == ( coor[i][0] + (coor[i][1])/2 ))&& (pixCtrlLem[1][2] <= ( coor[i][2] + (coor[i][3]) )) ){ // collision trap objet detecter // died: // 5 - trap which makes lemmings drown (water/quick sand/mud) if((unl->ID != 8) &&(coor[i][6]==5)){ unl->ID=7; unl->data.pl->cptState=gInit->mapI.lemmingDATA[unl->ID].state; j=100; } // 6 - trap which replaces lemming with death animation // 7 - trap which triggers lemming death animation if((unl->ID != 8) &&(coor[i][6]==6 ||coor[i][6]==7)){ unl->ID=8; //7 - trap which triggers lemming death animation if(coor[i][6]==7){ // activation de la mort du lemming unl->data.pl->cptState=gInit->mapI.lemmingDATA[unl->ID].state; } //6 - trap which replaces lemming with death animation k=gInit->o.lo; while(k != NULL ){// activation du sprite ^^ if (k->ID == coor[i][4]) { k->data.po->cptState=gInit->mapI.map.tabDataSprO[k->ID].state;break; } k=k->next; } j=100; } // 8 - exit if((unl->ID != 8) &&(coor[i][6]==8)){ unl->ID=9; unl->data.pl->cptState=gInit->mapI.lemmingDATA[unl->ID].state; j=100; } } } // changement state + test collision avec le terrain // not saving and not dying if((unl->ID != 5)&&(unl->ID != 9)&&(unl->ID != 8)){ // test de test faller : // test pixel under lemming foot // floater ? if(get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] , surf ) == ccc_error ) {return (101);} if ((step==0)&& (unl->data.pl->cptFall >= FLOATER_TO_FALLER )&& (unl->data.pl->floater == 1) && (get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] , surf ) == gInit->mapI.map.cmap.bgColor )){ // floater: if(unl->ID != 4){ // activation du sprite du lemming unl->data.pl->cptState=gInit->mapI.lemmingDATA[unl->ID].state; } unl->ID=4; unl->y += 1; for(i=1;imapI.map.cmap.bgColor ) { unl->y += 1; } else {break;} } step=1; } // splat ? if(get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] , surf ) == ccc_error ) {return (103);} if ((step==0)&& (unl->data.pl->cptFall >= FALLER_MAX )&& (get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] , surf ) != gInit->mapI.map.cmap.bgColor )){ // splat: unl->ID=5; unl->y += 1; unl->data.pl->cptFall =0; // activation de la mort du lemming unl->data.pl->cptState=gInit->mapI.lemmingDATA[unl->ID].state; step=1; } // faller ? if(get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] , surf ) == ccc_error ) {return (104);} if ((unl->ID!=4)&&(step==0)&&(get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] , surf ) == gInit->mapI.map.cmap.bgColor )){ // tombe: unl->ID=1; unl->y += 1; unl->data.pl->cptFall +=1; for(i=1;imapI.map.cmap.bgColor ) { unl->y += 1; unl->data.pl->cptFall +=1; } else {break;} } step=1; } // walker collision if(get_pixel32( pixCtrlLem[0][2] , pixCtrlLem[1][2] , surf ) == ccc_error ) {return (106);} if ((step==0)&&(get_pixel32( pixCtrlLem[0][2] , pixCtrlLem[1][2] , surf ) != gInit->mapI.map.cmap.bgColor )){ if(unl->data.pl->cptJump > MAX_JUMPER_STEP){ unl->y -= MAX_JUMPER_STEP; } if(unl->data.pl->cptJump >= MAX_JUMPER_JUMP){ unl->y -= MAX_JUMPER_STEP; } if(unl->data.pl->climber == 1){ unl->ID=2; unl->y -= 1; unl->data.pl->cptFall=0; step=1; } else { unl->data.pl->dir = (unl->data.pl->dir==1) ? 0 : 1; } } // walker //printf("val pix test IN %d x=%d, y=%d\n",get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] , surf ),pixCtrlLem[0][0],pixCtrlLem[1][0]); if(get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] , surf ) == ccc_error ) {return (107);} if ((step==0)&&(get_pixel32( pixCtrlLem[0][0] , pixCtrlLem[1][0] , surf ) != gInit->mapI.map.cmap.bgColor )){ // marche: if(unl->ID==1){unl->y-=2;}//FIXME unl->ID=0; if(unl->data.pl->dir == 1){ unl->x += 1; } else { unl->x -= 1; } unl->data.pl->cptFall=0; step=1; } // dans la map if(pixCtrlLem[1][0] >= LEVEL_HEIGHT ){ // hors de la map => mort du lemming unl->ID=17; unl->data.pl->cptState = 0; } } } step=0; unl=unl->next; } return 0; } 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; while(max > 1) { r = v / max; v -= r * max; max /= 10; if(p || r) buf[p++] = r; } buf[p++] = value%10; /* Render! */ from.x = 0; from.w = src->w; from.h = src->h/10; 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); SDL_BlitSurface(src, &from, dst, &to); } return 0; } int testAlpha(SDL_Surface *dst, SDL_Surface *src,SDL_Surface *src2, int x, int y){ SDL_Rect from; SDL_Rect to; int i; from.x = 0; from.w = src->w; from.h = src->h/188; 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; 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){ SDL_BlitSurface(src, &from, dst, &to); } } return 0; } int init() { //Initialisation de tous les sous-systèmes de SDL if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) { return 90; } //Mise en place de l'écran screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_SRCALPHA ); 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; } 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; } pSpr_Lem = SDL_CreateRGBSurface(SDL_HWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0); if( pSpr_Lem == NULL ) { return 3; } pStencil = 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); //Si tout s'est bien passé return 0; } 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]; } } } } return copy_surface; } 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; //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 ); //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 ) ); } } //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; temp = tabString_eMapStyle[gInit->mapI.map.style]; lt = strlen(temp); llem= strlen("../../../misc/"); folderLem=malloc(sizeof(char)*(llem+1)); sprintf(folderLem,"%s","../../../misc/"); total=((LEM_JOB - OTHER_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 *)); //stored terrains cpt=ADD_OBJ; 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); } } 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 - OTHER_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); } //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); } } free(filepath); free(folderLem); 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); } 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); } 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); } else { printf("BUG : type de fichier non reconnu [%s] \n", lecture->d_name); } } } } 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(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;} //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;} //Si tout s'est bien passé free(terrainGif); free(objetGif); free(steelGif); free(folder); free(spriteINI); free(lemINI); return 0; } int afficher(struct gameInit *gInit){ int i; struct listeSimplementChainee *k; printf("AFFICHAGE DE GAME INIT\n"); printf("LES PARAMETRES:\n"); for(i=0;imapI.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;imapI.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); } ++i; k=k->next; } 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); } ++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 "=" } ++i; k=k->next; } printf("DATA SPRITES OBJET:\n"); for(i=0;imapI.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 - OTHER_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].imask != NULL){ printf("\timask_%d = %d , %d\n",i,gInit->mapI.lemmingDATA[i].imask->stateI,gInit->mapI.lemmingDATA[i].imask->dirI); } } return 0; } int clean_up() { //On libère la feuille de sprites // SDL_FreeSurface( faces ); SDL_FreeSurface( pTerrain ); //On quitte SDL SDL_Quit(); return 0; } int initGame(struct gameInit *gInit){ 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; gInit->t.lt=NULL; gInit->o.lo=NULL; gInit->s.ls=NULL; gInit->l.ll=NULL; // init button state for(i=0;icptGame[i]=0; } gInit->cptGame[17]=404; // init InfoMap // map name gInit->mapI.name = NULL; gInit->mapI.nbrEntry=0; // paraMap for(i=0;imapI.paraMap[i]=0; } // xPos gInit->mapI.xPos=0; //maxFall gInit->mapI.maxFall=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){ 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; } 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 // DEBUT DEBUG: LEMMING COLLISION gInit->mapI.paraMap[1]=1; // FIN DEBUG: LEMMING COLLISION nbLem=gInit->mapI.paraMap[1]; //nbLem=1; //printf("nbLem %d\n",nbLem); 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; 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; 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->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; 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; 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); 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; // 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) ) { printf("WTF ... k->data.pt->modif == %d\n",k->data.pt->modif); return(40); } for(ty=k->y;tyh+k->y;++ty){ if(ty<0) {continue;} if(ty>=pTerrain->h){continue;} for(tx=k->x;txw+k->x;++tx){ if(tx<0) {continue;} if(tx>=pTerrain->w){continue;} overwrite = ((k->data.pt->modif & 8) == 8)? 0 : 1; remove = ((k->data.pt->modif & 2) == 2)? 1 : 0; color = get_pixel32(tx-k->x,ty-k->y,sf); if(color==ccc_error){return 666;} 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;} // } } else { paint=1; } if(paint==1){ if(!overwrite){ if(!remove){ err=putPixel(pTerrain,tx,ty ,color); if(err!=0){return err;} err=putPixel(pStencil,tx,ty , ccc_tNoOverwrite );//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); 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); } // 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]; offset.w = k->data.ps->w; offset.h = k->data.ps->h; for(ty=k->y;tyy;++ty){ if(ty<0) {continue;} if(ty>pTerrain->h){continue;} for(tx=k->x;txx;++tx){ if(tx<0) {continue;} if(tx>pTerrain->w){continue;} color = get_pixel32(tx,ty,pStencil); if(color==ccc_error){return 668;} 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; } //} 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; //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; if(mode==0){ 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; } //if(k->data.po->paintMode==8){ if ((res=SDL_BlitSurface(sf, &objetAnim, pSpr_Lem, &offset)) != 0) { printf("ERREUR [%d] SDL_BlitSurface : ",res); } } else { for(oy=k->y;oyy;++oy){ if(oy<0) {continue;} if(oy>pSpr_Lem->h){continue;} for(ox=k->x;oxx;++ox){ if(ox<0) {continue;} if(ox>pSpr_Lem->w){continue;} // printf("pixel R = %X G = %X B = %X ->", // ((color>>16) & 0xff), // ((color>>8) & 0xff), // (color & 0xff) ); color = get_pixel32(ox,oy,pStencil); color2 = get_pixel32(objetAnim.x+ox-k->x,objetAnim.y+oy-k->y,sf); color3 = get_pixel32(ox,oy,pTerrain); if(color==ccc_error){return 669;} if(color2==ccc_error){return 670;} if(color3==ccc_error){return 671;} // pixel transparency in object.gif if(color2!=ccc_vide){ if(mode==8){ // VIS_ON_TERRAIN if(color3==gInit->mapI.map.cmap.bgColor){ continue; } err=putPixel(pSpr_Lem,ox,oy,color2); if(err!=0){return err;} } if(mode==4){ // NO_OVERWRITE if(color3!=gInit->mapI.map.cmap.bgColor){ continue; } err=putPixel(pSpr_Lem,ox,oy,color2); if(err!=0){return err;} } } else {// utile pour affiner les formes sur le pStencil if((k->ID!=3)&&(k->ID!=4)){continue;} } if(((k->ID==3)||(k->ID==4))&& (color==ccc_vide)){ continue; } switch(type){ case 0://passive err=putPixel(pStencil, ox,oy, ccc_oPassive); if(err!=0){return err;} break; case 3://no digging to the left err=putPixel(pStencil, ox,oy, ccc_oNoDigLeft); if(err!=0){return err;} break; case 4://no digging to the right err=putPixel(pStencil, ox,oy, ccc_oNoDigRight); if(err!=0){return err;}break; case 5://trap which makes lemmings drown (water/quick sand/mud) err=putPixel(pStencil, ox,oy, ccc_oTrapDrown); if(err!=0){return err;} break; case 6://trap which replaces lemming with death animation err=putPixel(pStencil, ox,oy, ccc_oTrapAndNoLem); if(err!=0){return err;} break; case 7://trap which triggers lemming death animation err=putPixel(pStencil, ox,oy, ccc_oTrapAndLem); if(err!=0){return err;} break; case 8://exit err=putPixel(pStencil, ox,oy, ccc_oExit); if(err!=0){return err;} break; case 32://entry err=putPixel(pStencil, ox,oy, ccc_oEntry); if(err!=0){return err;} break; default:err=putPixel(pStencil, ox,oy, ccc_oUnknow); if(err!=0){return err;} break; } // if ((res=SDL_BlitSurface(sf, &objetAnim, pSpr_Lem, &offset)) != 0) // { // printf("ERREUR [%d] SDL_BlitSurface : ",res); // } } } } k=k->next; } ///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; k=gInit->l.ll; while ( k !=NULL ) { // 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; } /* 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]))) ){ printf("ERREUR cptFps %d > gInit->cptGame[15] %d + (8 + 99 - gInit->mapI.paraMap[0] %d) => res = %d\n",cptFps,gInit->cptGame[15],gInit->mapI.paraMap[0],cptFps-(gInit->cptGame[15]+(8 + 99 - gInit->mapI.paraMap[0]))); return(41); }*/ 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; } // lemmings => spr de sa mort ou vivant if((k->data.pl->cptState != 0 ) || (k->ID < (LEM_JOB - OTHER_LEM_JOB))){//FIXME il y a une faille dans la condition 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; if ((res=SDL_BlitSurface(sf, &objetAnim, pSpr_Lem, &offset)) != 0){ printf("ERREUR [%d] SDL_BlitSurface : ",res); } } k=k->next; } ///FIN TEST: LEM err=stateLemming(gInit,pTerrain); if(err==156){printf("here\n");return 3453;} if(err!=0){return err;} return 0; } int giveSkill (struct gameInit *gInit, struct listeSimplementChainee* k, int skill ){ 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; } return 0; } 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;} } ++i; k=k->next; } 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; 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; } //end giveSkill break; } k=k->next; } 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:y; SDL_BlitSurface(src, &from, dst2, &to); } else { if(f==1){ to.x = k->x-x + x0; to.y = k->y; SDL_BlitSurface(src, &from, dst2, &to); } } } 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; // 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_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; 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 + 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;imapI.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;} } 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; } 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;icptGame[i]=0; } else { 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; } 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; } } } printf("nbrInput = %d\nnbrInGame = %d\nnbrDied = %d\nnbrSafe = %d\n",gInit->l.nbrInput,gInit->l.nbr,gInit->l.nbrDied,gInit->l.nbrSafe); } return 0; } // 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; /* camera.x=160; camera.y=120; */ camera.x=0; camera.y=0; struct gameInit gInit; // constructor ... err=initGame(&gInit); if(err!=0){return err;} //Initialisation err=init(); if(err!=0){return err;} //printf("DONE\n"); //printf("DEBUG3: load_file ... \n"); //Chargement des fichiers err=load_files(&gInit); if(err!=0){return err;} // paraMap for(res=4;resw; camera.h=screen->h; inter.x=0; inter.y=LEVEL_HEIGHT; inter.w=SCREEN_WIDTH; inter.h=INTERFACE_HEIGHT; //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 ); SDL_FillRect( pStencil, NULL, ccc_black); // init interface (downner part of screen) SDL_FillRect( screen, &inter, ccc_black); cptFps=0; gInit.cptGame[15]=0; //paint_terrain => pTerrain err=paint_terrain(&gInit,0); if(err!=0){return err;} //Tant que l'utilisateur n'a pas quitter while( quit == 0 ) { /* Timing */ tick = SDL_GetTicks(); //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; } } 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_BlitSurface(pTerrain, NULL, pSpr_Lem, NULL); SDL_FillRect( screen, &inter, ccc_black); if(paint_stencil==1){ SDL_FillRect( pStencil, NULL, ccc_black); err=paint_terrain(&gInit,1); if(err!=0){return err;} } // 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;} } // 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;} } // 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); } //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 ); if(paint_stencil==0){ SDL_BlitSurface(pSpr_Lem, &camera, screen, NULL); } else { SDL_BlitSurface(pStencil, &camera, screen, NULL); } /* 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; } ++fps_count; //if (cptFps == 250) {decalFps = 99; } // limte fps 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); } }} 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;} 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;} //Mise à jour de l'écran if( SDL_Flip( screen ) == -1 ) { return 4; } //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++; //quit = 1; } //On libère les images et on quitte SDL err=clean_up(); if(err!=0){return err;} return 0; } int main (int argc, char **argv) { int res,i,num,lt; char *temp,*temp0; //Uint32 ctest; //int j,k; if (argc<2 || argc>3) { fprintf(stderr, "Usage %s [Option] \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); } 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); } } 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; }