45 lines
1.1 KiB
C
45 lines
1.1 KiB
C
#include"starfield.h"
|
|
|
|
struct Star Stars[MAX_STARS];
|
|
|
|
void starfield_Init(void) {
|
|
unsigned char theStar = 0;
|
|
memset(Stars, 0, sizeof(Stars));
|
|
|
|
for(theStar = 0; theStar < MAX_STARS; theStar++) {
|
|
Stars[theStar].x = rand() % SSD1306_WIDTH;
|
|
Stars[theStar].y = rand() % SSD1306_HEIGHT;
|
|
Stars[theStar].type = rand() % 3;
|
|
}
|
|
}
|
|
|
|
void starfield_Update(void) {
|
|
unsigned char theStar = 0;
|
|
|
|
for(theStar = 0; theStar < MAX_STARS; theStar++) {
|
|
|
|
switch(Stars[theStar].type) {
|
|
case 0:
|
|
Stars[theStar].x += 2;
|
|
break;
|
|
case 1:
|
|
Stars[theStar].x += 3;
|
|
break;
|
|
case 2:
|
|
Stars[theStar].x += 4;
|
|
break;
|
|
}
|
|
|
|
if (Stars[theStar].x >= SSD1306_WIDTH) {
|
|
//HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_6);
|
|
Stars[theStar].x = 0;
|
|
Stars[theStar].y = rand() % SSD1306_HEIGHT;
|
|
Stars[theStar].type = rand() % 3;
|
|
continue;
|
|
}
|
|
|
|
// Draw star
|
|
ssd1306_DrawPixel(Stars[theStar].x, Stars[theStar].y, White);
|
|
}
|
|
}
|