Good afternoon! I have to finish a work of a game for the university and I have the typical problem of "sometimes it works". I tell you above: it's a game where you take a character, if the enemies touch you, the game ends and you take points that appear randomly.
struct EstrellasRep{
Estrella * s;
int maximo, n;
};
Estrellas EstrellasCrea (int maximo){
Estrellas e = malloc (sizeof(struct EstrellasRep));
e->n=0;
e->maximo=maximo;
return e;
}
void EstrellasLibera (Estrellas e){
for (int i=0; i<e->n; i++) EstrellaLibera(e->s[i]);
free(e->s);
free(e);
}
void EstrellasDibuja (Estrellas e){
for (int i=0; i<e->n; i++) EstrellaDibuja(e->s[i]);
}
int EstrellasColisiona (Estrellas e, int x, int y, int w, int h){
int i=0;
int colisiona=0;
while(i<e->n){
if (colision(EstrellaGetX(e->s[i]),EstrellaGetY(e->s[i]),EstrellaGetW(e->s[i]), EstrellaGetH(e->s[i]),x,y,w,h))
{
EstrellaLibera(e->s[i]);
e->s[i]=e->s[e->n-1];
e->n--;
colisiona++;
}
else i++;
}
return colisiona;
}
void EstrellasInserta (Estrellas e, Imagen i, int x, int y, int w, int h)
{
if (e->n<e->maximo) {
e->s[e->n] = EstrellaCrea(i,x,y,w,h);
e->n++;
}
}
the sigsev comes to me on the line e-> s [e-> n] = EstrellaCrea (i, x, y, w, h);
And I say, sometimes it goes xD Greetings
Edit:
Stars is a structure that leads to the set of Star, which are the points that must be collected. struct EstrellaRep { Image i; int x, y, w, h, r, cx, cy; };
Estrella EstrellaCrea(Imagen i, int x, int y, int w, int h) {
Estrella e = malloc(sizeof(struct EstrellaRep));
e->i=i;
e->x=x;
e->y=y;
e->w=w;
e->h=h;
return e;
}
And Estrella is a class with its drawing and coordinates.