glooence Voir le profil de glooence
Posté le 6 octobre 2012 à 12:30:26 Avertir un administrateur
int main()
{
printf("Hello worlds!");
return 0;
}
Tu vois?
HEIN ?
C'est pas simple, c'est Terraria avec l’œil de Cthulu !
bon alors :
ça c'est simple:
int main()
{
printf("Hello worlds!");
return 0;
}
quelque chose de compliqué c'est plutôt ça:
int main ( int argc, char** argv )
{
// initialisation des variables
FMOD_SYSTEM *system;
FMOD_SOUND *musique;
FMOD_SOUND *boom;
FMOD_RESULT resultat;
FMOD_RESULT result2;
FMOD_System_Create(&system);
FMOD_System_Init(system, 1, FMOD_INIT_NORMAL, NULL);
/* On ouvre la musique */
resultat = FMOD_System_CreateSound(system, "sound/fond.mp3", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_LOOP_NORMAL, 0, &musique);
result2 = FMOD_System_CreateSound(system,"sound/boom.mp3",FM
OD_SOFTWARE
| FMOD_2D ,0,&boom);
/* On vérifie si elle a bien été ouverte (IMPORTANT) */
if (resultat != FMOD_OK||result2!=FMOD_OK)
{
fprintf(stderr, "Impossible de lire le fichier mp3\n");
exit(EXIT_FAILURE);
}
/* On active la répétition de la musique à l'infini */
FMOD_Sound_SetLoopCount(musique, -1);
/* On joue la musique */
FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, musique, 0, NULL);
int continuer = 1;// booléen pour la boucle event
int i = 0;
int t = 0;
int j = 0;
int l = 0;
int v = 0;
int resetbase = 0;
int Bool=0;
int tempsprecedent = 0, tempsactuelle = 0;
int afficher=0;
int eteindre = 1;
SDL_Surface *ecran = NULL, *skinbase = NULL, *cursor=NULL,*explosion=NULL;
SDL_Surface *navrescue = NULL;
SDL_Surface *tableaugauche[3];
SDL_Surface *tableaudroit[3];
SDL_Surface *tableauxbas[3];
SDL_Surface *tableauhaut[3];
SDL_Surface *tableauback[3];
SDL_Surface *back = NULL;
SDL_Surface *debris = NULL;
SDL_Surface *brule = NULL;
SDL_Event event;
SDL_Event move;
SDL_Surface **pointeurBack = &back;
// initialisation de la SDL
SDL_Init(SDL_INIT_VIDEO);
// utilisation de la SDL
ecran = SDL_SetVideoMode(1240,720,32,SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF);
// chargement des images
brule = SDL_LoadBMP("picture/BRULE.bmp");
back = SDL_LoadBMP("picture/fontstart.bmp");
debris = SDL_LoadBMP("picture/deagatcolateral.bmp");
skinbase = SDL_LoadBMP("picture/skinbase.bmp");
SDL_Surface *tableauExplosion[49];
int uc = 0;
for(uc;uc<50;uc++){tableauExplosion[uc] = SDL_LoadBMP("picture/deagatcolateral.bmp");}
tableaugauche[0] = SDL_LoadBMP("picture/skingun.bmp");
tableaugauche[1] = SDL_LoadBMP("picture/skingdeux.bmp");
tableaugauche[2] = SDL_LoadBMP("picture/skingtrois.bmp");
tableaudroit[0] = SDL_LoadBMP("picture/skinddeux.bmp");
tableaudroit[1] = SDL_LoadBMP("picture/skinddtrois.bmp");
tableaudroit[2] = SDL_LoadBMP("picture/skinddquatre.bmp");
tableauxbas[0] = SDL_LoadBMP("picture/skinbase.bmp");
tableauxbas[1] = SDL_LoadBMP("picture/skinbasedeux.bmp");
tableauxbas[2] = SDL_LoadBMP("picture/skinbasetrois.bmp");
tableauhaut[0] = SDL_LoadBMP("picture/skindedosun.bmp");
tableauhaut[1] = SDL_LoadBMP("picture/skindedosdeux.bmp");
tableauhaut[2] = SDL_LoadBMP("picture/skindedostrois.bmp");
tableauback[0] = SDL_LoadBMP("picture/fontstart.bmp");
navrescue = SDL_LoadBMP("picture/navrescue.bmp");
SDL_Rect positionnav;
positionnav.x = 130;
positionnav.y = 82;
cursor = SDL_LoadBMP("picture/cursor.bmp");
SDL_Rect positionCursor;
positionCursor.x = 1240/2;
positionCursor.y = 720/2;
explosion = SDL_LoadBMP("picture/explosion.bmp");
SDL_Rect positionExplosion;
positionExplosion.x = 0;
positionExplosion.y = 0;
SDL_Rect positionskin;
positionskin.x = 150;
positionskin.y = 150;
SDL_Rect positionback;
positionback.x = 0;
positionback.y = 0;
// gestion de la transparence
SDL_SetColorKey(cursor,SDL_SRCCOLORKEY,SDL_MapRGB(
cursor->format,255,255,255));
SDL_SetColorKey(skinbase,SDL_SRCCOLORKEY,SDL_MapRG
B(skinbase->format,0,0,0));
SDL_SetColorKey(explosion,SDL_SRCCOLORKEY,SDL_MapR
GB(explosion->format,0,0,0));
SDL_SetColorKey(brule,SDL_SRCCOLORKEY,SDL_MapRGB(b
rule->format,6,251,0));
SDL_SetColorKey(navrescue,SDL_SRCCOLORKEY, SDL_MapRGB(navrescue->format, 0, 0, 0));
SDL_BlitSurface(skinbase,NULL,ecran,&positionskin)
;
SDL_BlitSurface(back,NULL,ecran,&positionback);
SDL_BlitSurface(navrescue,NULL,ecran,&positionnav)
;
SDL_Flip(ecran);
SDL_EnableKeyRepeat(50,50); //répetition des touches activés
SDL_ShowCursor(SDL_DISABLE);
// boucle event
while(eteindre)
{
while(continuer)
{
SDL_PollEvent(&event);
switch(event.type)
{
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE:
eteindre = 0;
continuer = 0;
break;
case SDLK_d:
if(positionskin.x+64<1240)
{
//SDL_Delay(50);
positionskin.x++;
}
skinbase = tableaudroit[t];
SDL_SetColorKey(skinbase,SDL_SRCCOLORKEY,SDL_MapRG
B(skinbase->format,0,0,0));
t++;
if(t > 2)
{
t = 0;
}
break;
case SDLK_w:
positionskin.y--;
skinbase = tableauhaut[l];
SDL_SetColorKey(skinbase,SDL_SRCCOLORKEY,SDL_MapRG
B(skinbase->format,0,0,0));
l++;
if(l > 2)
{
l = 0;
}
break;
case SDLK_a:
positionskin.x--;
skinbase = tableaugauche[i];
SDL_SetColorKey(skinbase,SDL_SRCCOLORKEY,SDL_MapRG
B(skinbase->format,0,0,0));
i++;
if(i > 2)
{
i = 0;
}
break;
case SDLK_s:
if(positionskin.y+64<720){
positionskin.y++;
skinbase = tableauxbas[j];
if(positionskin.y+64>650){afficher=1;}
}
SDL_SetColorKey(skinbase,SDL_SRCCOLORKEY,SDL_MapRG
B(skinbase->format,0,0,0));
j++;
if(j > 2)
{
j = 0;
}
break;
}
case SDL_MOUSEMOTION:
positionCursor.x=event.motion.x-29;
positionCursor.y=event.motion.y-33;
break;
case SDL_MOUSEBUTTONDOWN:
if(event.button.button==SDL_BUTTON_LEFT||event.but
ton.button==SDL_BUTTON_RIGHT){
FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, boom, 0, NULL);
positionExplosion.x=event.motion.x-32;
positionExplosion.y=event.motion.y-32;
Bool=1;
}
break;
// remise du personnage après arrêt de mouvement
case SDL_KEYUP:
switch(event.key.keysym.sym)
{
case SDLK_d:
skinbase = tableaudroit[resetbase];
SDL_SetColorKey(skinbase,SDL_SRCCOLORKEY,SDL_MapRG
B(skinbase->format,0,0,0));
t = 1;
break;
case SDLK_w:
skinbase = tableauhaut[resetbase];
SDL_SetColorKey(skinbase,SDL_SRCCOLORKEY,SDL_MapRG
B(skinbase->format,0,0,0));
l = 1;
break;
case SDLK_a:
skinbase = tableaugauche[resetbase];
SDL_SetColorKey(skinbase,SDL_SRCCOLORKEY,SDL_MapRG
B(skinbase->format,0,0,0));
i = 1;
break;
case SDLK_s:
skinbase = tableauxbas[resetbase];
SDL_SetColorKey(skinbase,SDL_SRCCOLORKEY,SDL_MapRG
B(skinbase->format,0,0,0));
j = 1;
break;
}
break;
}
if(positionskin.y == 0)
{
positionskin.y = 720 - 64;
continuer = 0;
}
//SDL_BlitSurface(tableauExplosion[],NULL,ecran,**
SDL_BlitSurface(tableauback[0],NULL,ecran,&positio
nback);
SDL_BlitSurface(skinbase,NULL,ecran,&positionskin)
;
SDL_BlitSurface(navrescue,NULL,ecran,&positionnav)
;
if(positionskin.x+32>1195){afficher = 1; }
if(afficher==1){SDL_BlitSurface(brule,NULL,ecran,&
positionskin);}
if(Bool==1){SDL_BlitSurface(explosion,NULL,ecran,&
positionExplosion);}
SDL_BlitSurface(cursor,NULL,ecran,&positionCursor)
;
SDL_Flip(ecran);
}
continuer = 1;
tableauback[0] = SDL_LoadBMP("picture/fondnext.bmp");
back = SDL_LoadBMP("picture/fondnext.bmp");
SDL_BlitSurface(back,NULL,ecran,&positionback);
//seconde boucle, second ecran
while(continuer && eteindre)
{
SDL_PollEvent(&move);
switch(move.type)
{
case SDL_KEYDOWN:
switch(move.key.keysym.sym)
{
case SDLK_ESCAPE:
eteindre = 0;
continuer = 0;
break;
case SDLK_d:
if(positionskin.x+64<1240)
{
//SDL_Delay(50);
positionskin.x++;
}
skinbase = tableaudroit[t];
SDL_SetColorKey(skinbase,SDL_SRCCOLORKEY,SDL_MapRG
B(skinbase->format,0,0,0));
t++;
if(t > 2)
{
t = 0;
}
break;
case SDLK_w:
positionskin.y--;
skinbase = tableauhaut[l];
SDL_SetColorKey(skinbase,SDL_SRCCOLORKEY,SDL_MapRG
B(skinbase->format,0,0,0));
l++;
if(l > 2)
{
l = 0;
}
break;
case SDLK_a:
positionskin.x--;
skinbase = tableaugauche[i];
SDL_SetColorKey(skinbase,SDL_SRCCOLORKEY,SDL_MapRG
B(skinbase->format,0,0,0));
i++;
if(i > 2)
{
i = 0;
}
break;
case SDLK_s:
if(positionskin.y+64<720){
positionskin.y++;
skinbase = tableauxbas[j];
if(positionskin.y+64>650){afficher=1;}
}
SDL_SetColorKey(skinbase,SDL_SRCCOLORKEY,SDL_MapRG
B(skinbase->format,0,0,0));
j++;
if(j > 2)
{
j = 0;
}
break;
}
case SDL_MOUSEMOTION:
positionCursor.x=move.motion.x-29;
positionCursor.y=move.motion.y-33;
break;
case SDL_MOUSEBUTTONDOWN:
if(move.button.button==SDL_BUTTON_LEFT||move.butto
n.button==SDL_BUTTON_RIGHT){
FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, boom, 0, NULL);
positionExplosion.x=move.motion.x-32;
positionExplosion.y=move.motion.y-32;
Bool=1;
}
break;
// remise du personnage après arrêt de mouvement
case SDL_KEYUP:
switch(move.key.keysym.sym)
{
case SDLK_d:
skinbase = tableaudroit[resetbase];
SDL_SetColorKey(skinbase,SDL_SRCCOLORKEY,SDL_MapRG
B(skinbase->format,0,0,0));
t = 1;
break;
case SDLK_w:
skinbase = tableauhaut[resetbase];
SDL_SetColorKey(skinbase,SDL_SRCCOLORKEY,SDL_MapRG
B(skinbase->format,0,0,0));
l = 1;
break;
case SDLK_a:
skinbase = tableaugauche[resetbase];
SDL_SetColorKey(skinbase,SDL_SRCCOLORKEY,SDL_MapRG
B(skinbase->format,0,0,0));
i = 1;
break;
case SDLK_s:
skinbase = tableauxbas[resetbase];
SDL_SetColorKey(skinbase,SDL_SRCCOLORKEY,SDL_MapRG
B(skinbase->format,0,0,0));
j = 1;
break;
}
break;
}
//SDL_BlitSurface(tableauExplosion[],NULL,ecran,**
SDL_BlitSurface(tableauback[0],NULL,ecran,&positio
nback);
SDL_BlitSurface(skinbase,NULL,ecran,&positionskin)
;
if(afficher==1){SDL_BlitSurface(brule,NULL,ecran,&
positionskin);}
if(Bool==1){SDL_BlitSurface(explosion,NULL,ecran,&
positionExplosion);}
SDL_BlitSurface(cursor,NULL,ecran,&positionCursor)
;
SDL_Flip(ecran);
}
}
// fermeture de la SDL
FMOD_Sound_Release(boom);
FMOD_Sound_Release(musique);
FMOD_System_Close(system);
FMOD_System_Release(system);
int b=0;
for(b;b<4;b++){
SDL_FreeSurface(tableaudroit[b]);
SDL_FreeSurface(tableaugauche[b]);
SDL_FreeSurface(tableauxbas[b]);
SDL_FreeSurface(tableauhaut[b]);
SDL_FreeSurface(tableauback[b]);
}
b=0;
for(b;b<50;b++){SDL_FreeSurface(tableauExplosion[b
]);}
SDL_FreeSurface(explosion);
SDL_FreeSurface(cursor);
SDL_FreeSurface(skinbase);
SDL_FreeSurface(back);
SDL_FreeSurface(navrescue);
SDL_Quit;
return EXIT_SUCCESS;
}
tu vois? ^^