Mais je suis pas sur !! !
ERREURS :
expected constructor, destructor, or type conversion at end of input
`,´ or `;´ at end of input
SDL_Surface* screen;
SDL_Event event;
char key[400];
int xsouris=0,ysouris=0,xrelsouris=0,yrelsouris=0;
int Bmouse(int b);
char boutons[3]={0,0,0};
//toutes les structures des objets
struct joueur
{
int armed;
int score;
int vies;
};
struct balle
{
int x;
int y;
int v;
double angle;
bool in;
};
struct vaisseau_spatial
{
int x;
int y;
int anim;
bool in;
};
struct briques
{
int x;
int y;
bool in;
};
struct missiles
{
int x;
int y;
bool in;
int dirx;
};
struct explosions
{
int x;
int y;
bool in;
int anim;
};
//initialisation de sdl + updates events ect (merci JYY ^^)
void init_SDL()
{
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(800, 600, 32,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
SDL_ShowCursor(0);
}
int Bmouse(int b)
{
int res;
if (b<0 ||b>2)
return 0;
res=boutons[b+1];
return res;
}
SDL_Rect Rect(int x,int y,int w,int h) // pour faire un rectangle plus vite
{
SDL_Rect r;
r.x=(short)x;
r.y=(short)y;
r.w=(short)w;
r.h=(short)h;
return r;
}
SDL_Surface* LoadBMP(char* fichier,int vram)
{
SDL_Surface* f = SDL_LoadBMP(fichier);
SDL_Surface* r = NULL;
if (vram)
r=SDL_CreateRGBSurface(SDL_HWSURFACE, f->w, f->h, 32, 0, 0, 0, 0);
if (r==NULL) vram=0;
if (!vram)
r=SDL_CreateRGBSurface(SDL_SWSURFACE, f->w, f->h, 32, 0, 0, 0, 0);
SDL_Rect R=Rect(0,0,f->w,f->h);
SDL_BlitSurface(f,NULL,r,&R);
SDL_FreeSurface(f);
return r;
}
void Blit(SDL_Surface* source,int x1,int y1,int x2,int y2,SDL_Surface* dest,int x3,int y3)
{
SDL_Rect S=Rect(x1,y1,x2-x1+1,y2-y1+1);
SDL_Rect D=Rect(x3,y3,0,0);
SDL_Rect* pS=&S;
if (x1<0)
pS=NULL;
SDL_BlitSurface(source,pS,dest,&D);
}
void PrintSDL(SDL_Surface* font,SDL_Surface* dest,int x,int y,char* text,...)
{
char buf[500];
int i;
int inx,iny;
int w,h;
va_list args;
va_start(args,text);
vsprintf(buf,text,args);
va_end(args);
w = font->w/16;
h = font->h/14;
for(i=0;i<(int)strlen(buf);i++)
{
inx=w*((unsigned char)(buf[i])%16);
iny=h*((unsigned char)(buf[i])/16-2); // on saute les 31 premiers codes ASCII
if (iny-h>font->h)
return;
Blit(font,inx,iny,inx+w,iny+h,dest,x,y);
x+=w;
}
}
void UpdateEvents()
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
key[event.key.keysym.sym]=1;
break;
case SDL_KEYUP:
key[event.key.keysym.sym]=0;
break;
case SDL_MOUSEMOTION:
xsouris=event.motion.x;
ysouris=event.motion.y;
xrelsouris=event.motion.xrel;
yrelsouris=event.motion.yrel;
break;
case SDL_MOUSEBUTTONDOWN:
boutons[event.button.button-1]=1;
break;
case SDL_MOUSEBUTTONUP:
boutons[event.button.button-1]=0;
break;
}
}
}
int main(int argc,char** argv)
{
SDL_Joystick *joy;
int s=1, pos_x=20, pos_y=0, i=0,j, start=0;
int sx4=0,sy4=0;
init_SDL();
struct joueur p;
p.armed = 1;
p.score = 0;
p.vies = 3;
struct balle ball;
ball.x = 0;
ball.y = 0;
ball.v = 9;
ball.angle = (rand() % 40) + 80;
ball.in = true;
struct vaisseau_spatial vaisseau;
vaisseau.x = 0;
vaisseau.y = 580;
vaisseau.anim = 0;
vaisseau.in = true;
struct briques briks[297];
for (i=0; i<296; i++)
{
briks[i].x = pos_x;
briks[i].y = pos_y;
briks[i].in = true;
pos_x = pos_x + 20;
if (pos_x >= 760) {pos_y += 10;pos_x = 20;}
}
struct explosions explos[10];
for (i=0; i<9; i++)
{
explos[i].x = pos_x;
explos[i].y = pos_y;
explos[i].in = true;
explos[i].anim = 0;
}
struct missiles missile;
missile.x = 0;
missile.y = 0;
missile.in = false;
missile.dirx = 0;
SDL_Surface* font;
SDL_Surface* firstscreen;
SDL_Surface* img_balle;
SDL_Surface* img_vaisseau;
SDL_Surface* img_vaisseaug;
SDL_Surface* img_vaisseaud;
SDL_Surface* img_vaisseaug2;
SDL_Surface* img_vaisseaud2;
SDL_Surface* img_brique;
SDL_Surface* img_missile;
SDL_Surface* img_explosion1;
SDL_Surface* img_explosion2;
SDL_Surface* img_explosion3;
int fini=0;
font = LoadBMP("font.bmp",1);
SDL_SetColorKey(font,SDL_SRCCOLORKEY ,SDL_MapRGBA(font->format,0,0,0,0));
firstscreen=LoadBMP("images/backgrounds/font_etoil
es.bmp",1);
if (firstscreen == NULL) return(0);
img_balle=LoadBMP("images/objects/balle.bmp",1);
if (img_balle == NULL) return(0);
img_vaisseau=LoadBMP("images/objects/vaisseau.bmp"
,1);
if (img_vaisseau == NULL) return(0);
img_vaisseaug=LoadBMP("images/objects/vaisseau-g.b
mp",1);
if (img_vaisseaug == NULL) return(0);
img_vaisseaud=LoadBMP("images/objects/vaisseau-d.b
mp",1);
if (img_vaisseaud == NULL) return(0);
img_vaisseaug2=LoadBMP("images/objects/vaisseau-g2
.bmp",1);
if (img_vaisseaug2 == NULL) return(0);
img_vaisseaud2=LoadBMP("images/objects/vaisseau-d2
.bmp",1);
if (img_vaisseaud2 == NULL) return(0);
img_brique=LoadBMP("images/objects/brique_bleu.bmp
",1);
if (img_brique == NULL) return(0);
img_missile=LoadBMP("images/objects/missile.bmp",1
);
if (img_missile == NULL) return(0);
img_explosion1=LoadBMP("images/objects/explosion1.
bmp",1);
if (img_missile == NULL) return(0);
img_explosion2=LoadBMP("images/objects/explosion2.
bmp",1);
if (img_missile == NULL) return(0);
img_explosion3=LoadBMP("images/objects/explosion3.
bmp",1);
if (img_missile == NULL) return(0);
SDL_SetColorKey(img_balle,SDL_SRCCOLORKEY ,SDL_MapRGBA(img_balle->format,255,0,255,0));
SDL_SetColorKey(img_vaisseau,SDL_SRCCOLORKEY ,SDL_MapRGBA(img_vaisseau->format,255,0,255,0));
SDL_SetColorKey(img_vaisseaug,SDL_SRCCOLORKEY,SDL_
MapRGBA(img_vaisseaug->format,255,0,255,0));
SDL_SetColorKey(img_vaisseaud,SDL_SRCCOLORKEY,SDL_
MapRGBA(img_vaisseaud->format,255,0,255,0));
SDL_SetColorKey(img_vaisseaug2,SDL_SRCCOLORKEY,SDL
_MapRGBA(img_vaisseaug2->format,255,0,255,0));
SDL_SetColorKey(img_vaisseaud2,SDL_SRCCOLORKEY,SDL
_MapRGBA(img_vaisseaud2->format,255,0,255,0));
SDL_SetColorKey(img_brique,SDL_SRCCOLORKEY ,SDL_MapRGBA(img_brique->format,255,0,255,0));
SDL_SetColorKey(img_missile,SDL_SRCCOLORKEY ,SDL_MapRGBA(img_missile->format,255,0,255,0));
SDL_SetColorKey(img_explosion1,SDL_SRCCOLORKEY
,SDL_MapRGBA(img_explosion1->format,255,0,255,0));
SDL_SetColorKey(img_explosion2,SDL_SRCCOLORKEY
,SDL_MapRGBA(img_explosion2->format,255,0,255,0));
SDL_SetColorKey(img_explosion3,SDL_SRCCOLORKEY
,SDL_MapRGBA(img_explosion3->format,255,0,255,0));
while(1) //boucle principale
{
UpdateEvents(); //recherche d´events, et quitte si echap ou lance la balle si return
if (key[SDLK_RETURN] && start == 0) {sy4 = -1; sx4 = 1; start = 1; ball.v = 9;}
if (key[SDLK_ESCAPE]) break;
if (boutons[0] == 1)
{
PrintSDL(font,screen,650,10,"clic droit");
if (p.armed > 0)
{
if (p.armed == 1)
{
if (missile.in != true)
{
missile.dirx = xsouris;
missile.y = 580;
missile.in = true;
}
}
}
}
if (boutons[1] == 1)
{
PrintSDL(font,screen,650,10,"clic milieu");
}
if (boutons[2] == 1)
{
PrintSDL(font,screen,650,10,"clic gauche");
}
if (xrelsouris > 0) vaisseau.anim = 0;
if (xrelsouris == 0) vaisseau.anim = 1;
if(xrelsouris < 0) vaisseau.anim = 2;
//mouvements de la balle
double rad = (3.1416 * ball.angle) / 180;
ball.x+=(int)(cos(rad)*ball.v);
ball.y+=(int)(sin(rad)*ball.v);
// mouvements du vaisseau
vaisseau.x = xsouris - 100;
if (vaisseau.x < 0) vaisseau.x = 0;
if (vaisseau.x > 700) vaisseau.x = 700;
//mouvements des missiles
if (missile.in == true && missile.y > 0)
{
missile.x = missile.dirx;
missile.y -= 12;
if (missile.y <= 0) missile.in = false;
}
//balle sur la barre
if (start == 0){ball.x = vaisseau.x + 45; ball.y = vaisseau.y - 15;}
//restart si la balle meurt
if (ball.in == false)
{
ball.in = true;
ball.y = -20;
start = 0;
}
//vitesse de la balle
if (ball.v < 7)ball.v = 8;
if (ball.v > 11)ball.v = 11;
//rebonds de la balle
if (ball.x<1) {ball.angle = -((2 * 270) - ball.angle);
ball.angle += ((rand() % 10)+5); }
if (ball.y<1) {ball.angle = (2 * 180) - ball.angle;
ball.angle += ((rand() % 10)+5);}
if (ball.x>784) {ball.angle = (2 * 90) - ball.angle;
ball.angle += ((rand() % 10)+5);}
if (start == 1 && ball.y + 17 >= vaisseau.y && ball.x >= vaisseau.x && ball.x <= vaisseau.x + 100 )
{
ball.angle = 0-ball.angle;
ball.y -= 2;
if (ball.angle > 180 && xrelsouris < 0) ball.v--;
if (ball.angle > 180 && xrelsouris > 0) ball.v++;
if (ball.angle < 180 && xrelsouris < 0) ball.v++;
if (ball.angle < 180 && xrelsouris > 0) ball.v--;
if (ball.y > 590) {ball.in=false ;p .vies --;}
}
if (p.vies == -1)break;
//destruction des briks
for (i=0; i < 296; i++)
{
if (ball.y >= briks[i].y && ball.y <= briks[i].y + 14 && ball.x >= briks[i].x && ball.x <= briks[i].x + 20 )
{
briks[i].in = false;
ball.angle = -(ball.angle);
briks[i].x = 1024;
briks[i].y = 1024;
p.score++;
} //rebond bas
if (ball.y + 16 >= briks[i].y && ball.y + 16 <= briks[i].y + 14 && ball.x >= briks[i].x && ball.x <= briks[i].x + 35 )
{
briks[i].in = false;
ball.angle = -(ball.angle);
briks[i].x = 1024;
briks[i].y = 1024;
p.score++;
} //rebond haut
if (ball.x >= briks[i].x && ball.x <= briks[i].x + 33 && ball.y >= briks[i].y && ball.y <= briks[i].y + 10 )
{
briks[i].in = false;
ball.angle = -(ball.angle);
briks[i].x = 1024;
briks[i].y = 1024;
p.score++;
} //rebond gauche
if (ball.x + 15 >= briks[i].x && ball.x + 15 <= briks[i].x + 20 && ball.y >= briks[i].y && ball.y <= briks[i].y + 10 )
{
briks[i].in = false;
ball.angle = -(ball.angle);
briks[i].x = 1024;
briks[i].y = 1024;
p.score++;
} //rebond droite
if (missile.y <= briks[i].y && missile.x >= briks[i].x && missile.x + 8 <= briks[i].x + 33)
{
briks[i].in = false;
missile.in = false;
for (i=0;i<9;i++)
{
if (explos[i].in != true)
{
explos[i].in = true;
explos[i].x = missile.x;
explos[i].y = missile.y;
explos[i].anim = 1;
}
}
briks[i].y = 1024;
missile.y = 0;
missile.x = 0;
p.score++;
} //missile
}
// génération a l´écran
SDL_BlitSurface(firstscreen,NULL,screen,NULL);
if (ball.in == true)Blit(img_balle,0,0,15,16,screen,ball.x, ball.y);
if (vaisseau.in == true)
{
Blit(img_vaisseau,0,0,30,10,screen,vaisseau.x + 30, vaisseau.y);
if (vaisseau.anim == 2)Blit(img_vaisseaud2,0,0,30,10,screen,vaisseau.x + 60, vaisseau.y);
else Blit(img_vaisseaud,0,0,30,10,screen,vaisseau.x + 60, vaisseau.y);
if (vaisseau.anim ==
0)Blit(img_vaisseaug2,0,0,30,10,screen,vaisseau.x,
vaisseau.y);
else Blit(img_vaisseaug,0,0,30,10,screen,vaisseau.x , vaisseau.y);
}
for (i=0;i<296;i++)
{
if(briks[i].in ==
true)Blit(img_brique,0,0,20,10,screen,briks[i].x,b
riks[i].y);
}
if (missile.in == true)
{
Blit(img_missile,0,0,8,20,screen,missile.x,missile
.y);
}
for (i=0; i<10; i++)
{
if (explos[i].in = true)
{
if (explos[i].anim =
1){Blit(img_explosion1,0,0,10,10,screen,explos[i].
x,explos[i].y); explos[i].anim++;}
if (explos[i].anim =
2){Blit(img_explosion2,0,0,20,30,screen,explos[i].
x,explos[i].y); explos[i].anim++;}
if (explos[i].anim =
3){Blit(img_explosion3,0,0,30,30,screen,explos[i].
x,explos[i].y); explos[i].anim++;}
if (explos[i].anim = 4){explos[i].in = false; explos[i].anim = 0;}
}
}
PrintSDL(font,screen,650,10,"score : %d", p.score);
PrintSDL(font,screen,650,20,"vies : %d", p.vies);
SDL_Flip(screen);
}
SDL_Quit();
SDL_ShowCursor(1);
return 0;
}
J´ai qu´un mot à dire : arf !
LOL
Non, si jamais vous trouvez l´erreur, ça m´arrangerai, mais dites moi au moins d´ou ça peut venir.
C´est pas l´erreur dont parle ton compilo mais tout tes if seront toujours vrais puisque tu utilises = au lieu de ==
Oui, tiens, c´est vrai...
Je corrige ça tout de suite.
Une fois que tu auras corrigé ça poste ton code là http://rafb.net/paste/ et donne nous le lien. Ca sera déjà mieux que de poster direct sur le forum. Et au passage ton compilo précise pas un numéro de ligne ?
Si, il présice la toute derniere ligne.
http://rafb.net/paste/results/BEsQDX12.html
SDL_Flip(screen);
}
SDL_Quit();
SDL_ShowCursor(1);
return 0;
}
La voila ton erreur....
SDL_Flip(screen);
{
SDL_Quit();
SDL_ShowCursor(1);
return 0;
}
´indente´ ton code stp ...
çad tu fais :
if( ... )
{
// tu mets une tabulation
for( ;; )
{
// une autre tabulation ...
}
}
bon , ça va surement etre craque sur jv.com , mais c´est vraiment important de faire ça .
Le message d´erreur de GCC etait suffisemment clair pour que tu le corrige toi meme...
Quand il te parle de ´end of input´ c´est quasiment sur que ca parle d´un bloc mal refermé...
Je ne connaissai pas at the end of input, je croyais que c´était la fin du prog.
Mais en plus ce n´est pas ça l´erreur...
Ben ca m´étonne même pas lol...
On se lance pas dans un truc pareil quand on est pas capable de gérer après...
Refais en plus petit.
Ou tente de localiser ton erreur par élimination...
Non mais la, je ne comprend pas trop d´ou ça peut venir...
J´ai regardé sous notepad, ce n´est pas un problème de { et de }...
Alors soit c´est un point virgule manquant... Soit c´est... Aucune idée.
Si tu prossédais comme l´a dit Jejej ton code serait plus aéré et donc plus lisible. Essaye d´aérer et relis ensuite ton code la faute apparaitra certainement mieux.
J´ai aéré mon code du mieux que je pouvais...
http://rafb.net/paste/results/YJkkwu27.html
Désolé d´avoir poster sans mettre le lien...
J´appelle pas ca aérer...
Je voudrais préciser que tout ce qui est en rapport en la struct explos, je l´ai rajouter, et avant, ça ne buggait pas.