I have another problem with the Sprite list.
I have a player sprite in sprites[0].
Code: Select all
s8 Nb_Spr = 0; //global
VDP_setPalette(PAL3, shmup_sprite.palette->data);
SPR_initSprite(&sprites[0], &shmup_sprite, posx, posy, TILE_ATTR(PAL3, FALSE, FALSE, FALSE));
Nb_Spr++;
SPR_update(sprites, Nb_Spr); //in Main Code
After I add 4 enemies.
Code: Select all
for (i=1; i<=4; i++)
{
ennx = random() % 300;
enny = random() % 200;
SPR_initSprite(&sprites[i], &enn01_sprite, ennx, enny, TILE_ATTR(PAL2, FALSE, FALSE, FALSE));
Nb_Spr++;
SPR_setAnim(&sprites[i], ANIM_STAND);
}
No problem, I see my player sprite and 4 sprites drawing in game view.
So now, I try to destroy enemy on collision.
Code: Select all
int posx1 = posx + 30; //Collide point of player
int posy1 = posy + 8; //Collide point of player in y
int nb = 0;
for (i=1; i<Nb_Spr; i++)
{
ennx = sprites[i].x - 128; //position of the sprite to test
enny = sprites[i].y - 128;
//test if collision : working
if ( (posx1 < ennx + ennwidth ) && (posx1 > ennx) && (posy1 < enny + ennheight) && (posy1 > enny) )
{
SPR_setNeverVisible(&sprites[i], TRUE); //hide sprite wihen collide
//Nb_Spr--;
nb++;
}
}
Nb_Spr -= nb;
I try with Nb_Spr--; Inside without success.
The problem is : the spritelist change the number of the sprite. I think if I colliding with the sprite[2], the sprite[3] become sprite[2] and disapear too.
If I collide with sprites[1] I lost sprites[1] till sprites[4]
If I collide with sprites[3] I lost sprites[3] till sprites[4]
I try to do the test backward like the function in spr_eng without success
Code: Select all
for (i=Nb_Spr; i>=1; i--)
{
//test collision
}
Edit :: Edit
I read again (many times) your previous post. And I understand :
Code: Select all
for (i=1; i<=Nb_Spr; i++)
{
ennx = sprites[i].x - 128;
enny = sprites[i].y - 128;
if ( (posx1 < ennx + ennwidth ) && (posx1 > ennx) && (posy1 < enny + ennheight) && (posy1 > enny) )
{
SPR_setNeverVisible(&sprites[i], TRUE);
}
}
And I doesn't decrement the number of sprite. The variable Nb_Spr.
So I always do "SPR_update(sprites, Nb_Spr);" Nb_Spr always has 5 as value. 1 player sprite + 4 enemy Sprites. The invisible flag let the update doing the work even if Sprite doesn't show anymore.
I think that's work like that. But now I don't have the good Nb_Spr (nomber of sprite)
If I kill two enemy sprites (2 and 3 number sprites). I have an array like that before : SpriteListe(0,1,2,3,4) and after SpriteList(0,1,4,X,X) and (0,1,2,X,X) after sorting frame
I need to use variable who insert the number of sprite Destroy for using SPR_initSprite with the good value : SPR_initSprite(&sprites[newvalue = 3]
i try with the function you post :
Code: Select all
for (i=0; i<=Nb_Spr; i++)
{
if (sprites[i].visibility != 1) nb++;
// do collision test VISIBILITY_ALWAYS_OFF
}
I don't have the define VISIBILITY_ALWAYS_OFF so I use 1
nb show the good number of sprite hiding. So I can use SPR_initSprite(&sprites[Nb_Spr - nb] ...
I show my solution if it can help other users