0

I'm working on a microprocessor with an LCD screen, and i'm writing code which randomly displays some sprites.

void setup_sprite() {

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, rand()%82, rand()%43, 3, 3, sprite_bitmap);//83/43 is the LCD screen dimensions
    draw_sprite(&sprite);
    refresh();
    }
return 0;
}

How would I go about placing boundaries on where it can be drawn? it should only be drawn within a specific area on the screen. I was thinking an if statement where if the sprite is drawn outside the boundary it redraws until it's correct.

Specifically the problem is I have about 10 pixels in from the left side of the screen left for a menu, the sprites shouldn't be drawn in that area.

Craig S. Anderson
  • 6,966
  • 4
  • 33
  • 46
James
  • 57
  • 1
  • 1
  • 4

1 Answers1

0

Since

rand() % 82

generates a random value between 0 and 81, you could modify that to

10 + rand() % 72

to generate a random value between 10 and 81 instead, which I believe is what you want for your x coordinate.

Matti Virkkunen
  • 63,558
  • 9
  • 127
  • 159