0

So im trying to write some code that displays 5 sprites randomly on an lcd screen on a microprocessor (teensy). I've already taken care of simulating randomness with seeding on a button press;

void seedwithButtonPress() {
DDRB |= 0b00001100;
unsigned int seed = 0;
while (!((PINB >> PB0) & 1)) {
    seed++;
}
srand(seed);
}

As far as initilizing and drawing the sprites to the screen, my current attempt has failed.

void create_sprites(Sprite sprites[]) {

byte bitmap [] = {
BYTE( 11100000 ),
BYTE( 01000000 ),
BYTE( 11100000 )
};

for (int i = 0; i < 8; i++) {
    Sprite * sprites = &sprites[i];
    init_sprite(sprites, rand()%76, rand()%42, 3, 3, bitmap);
    }

setup_sprites();
}


void setup_sprites(Sprite * sprites) {
for ( int i = 0; i < 10; i++) {
    draw_sprite( sprites + i );
    refresh();
}
}

How could I go about this?

  • 1
    I'm worried about your use of pointers to the local array `bitmap`, because once the function `create_sprites` returns that array will go out of scope and those pointers will become invalid. – Some programmer dude May 11 '15 at 15:19
  • 1
    I trust you have not skipped the earlier steps: a) display one sprite at a fixed position, b) add second sprite, c) introduce random position. – Weather Vane May 11 '15 at 15:36

0 Answers0