-
Notifications
You must be signed in to change notification settings - Fork 0
/
bg.c
71 lines (68 loc) · 1.7 KB
/
bg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdint.h>
#include "game.h"
// Arrays and textures for background particles
#define ss 16
Unit small_stars[ss];
uint8_t t_ss[1][1] = {{1}};
#define st 10
Unit stars[st];
uint8_t t_s[2][2] = {{1,1},{1,1}};
#define rd 40
Unit drops[rd];
uint8_t t_rd[3][1] = {{1},{1},{1}};
// Randomly places stars and raindrops on background (can be outside of screen).
void init_bg(){
int i;
Unit s;
for(i = 0; i < ss; i++){
init_Unit(&s, random()*(SCREEN_HEIGHT-2)+1, random()*ss*16,0,-0.3F+random()*-0.1F,0,0,1,1,&t_ss[0][0],1);
small_stars[i] = s;
}
for(i = 0; i < st; i++){
init_Unit(&s, random()*(SCREEN_HEIGHT-2)+1, random()*st*28,0,-0.5F+random()*-0.1F,0,0,2,2,&t_s[0][0],1);
stars[i] = s;
}
for(i = 0; i < rd; i++){
init_Unit(&s, random()*rd*4, random()*SCREEN_WIDTH-1,0.8F+random()*0.3F,0,0,0,3,1,&t_rd[0][0],1);
drops[i] = s;
}
}
// Moves all stars horizontally.
void update_star_bg(){
int i;
Unit *s;
for(i = 0; i < ss; i++){
s = &small_stars[i];
if(s->x < -1) s->x += ss*16;
move_Unit(s);
}
for(i = 0; i < st; i++){
s = &stars[i];
if(s->x < -1) s->x += st*28;
move_Unit(s);
}
}
// Draws all stars.
void draw_star_bg(){
int i;
for(i = 0; i < ss; i++)
draw_Unit(&small_stars[i]);
for(i = 0; i < st; i++)
draw_Unit(&stars[i]);
}
// Moves all raindrops vertically.
void update_rain_bg(){
int i;
Unit *s;
for(i = 0; i < rd; i++){
s = &drops[i];
if(s->y > SCREEN_HEIGHT) s->y -= rd*4;
move_Unit(s);
}
}
// Draws all raindrops.
void draw_rain_bg(){
int i;
for(i = 0; i < rd; i++)
draw_Unit(&drops[i]);
}