vendredi 15 mai 2015

What to use to make sure sprites do not display on top of each other

You know when you first discovered how to use rand()? whatever you wanted printed printed randomly and it was great, but the problem was sometimes things would print on top of each other. That's my problem.

I have this function which randomly prints a 3x3 pixel sprite (declared as an array) randomly 8 times, the problem is I get sprites printing on top of each other.

void setup_sprites() {

Sprite sprite[8];
Sprite * sprite_pointer = &sprite;
byte sprite_bitmap [] = {
BYTE( 10100000 ),
BYTE( 01000000 ),
BYTE( 10100000 )
};
const int width = 3;
const int height = 3;

for (int i = 0; i < 8; i++) {
    init_sprite(&sprite, 20 + rand()%62, rand()%43, 3, 3, sprite_bitmap);
    draw_sprite(&sprite);
    refresh();
    }
return 0;
}

Now what I was thinking of doing was putting in an if statement along the lines of "if &sprite->x == &sprite->x then redraw it until it gets it right" but the way i've set my code up makes it difficult to know where to put it. How would I go about this?




Aucun commentaire:

Enregistrer un commentaire