summaryrefslogtreecommitdiff
path: root/engine/bulletpattern.cpp
blob: eabf55424ed67c09de7186736fe868339fa33c53 (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <cmath>
#include "bulletpattern.h"
#include <wriggle/matrix.h>

BulletPattern1::BulletPattern1(const Vector2& initpos) {
	num_bullets = steps = 0;
	color_r = 0;
	color_g = 1;
	color_b = 0;
	bullets = new Bullet[8*32];
	
	int k = 0;
	for(int j = 0; j < 8; j++) {
		for(float i = 0; i < M_PI; i += 0.1, k++) {
			bullets[k].pos.x = initpos.x + sinf(j % 2 ? M_PI_2 + i : M_PI - i + M_PI_2) * 0.09;
			bullets[k].pos.y = initpos.y + cosf(M_PI_2 + i) * 0.1;
			bullets[k].dir.x = sinf(j % 2 ? M_PI_2 + i : M_PI - i + M_PI_2) / 1000;
			bullets[k].dir.y = -0.002;
			bullets[k].data = j * 24 + i * 6;
		}
	}
};

void BulletPattern1::update() {
	steps++;
	while(num_bullets < 256 && (unsigned int)(bullets[num_bullets].data) < steps) {
		num_bullets++;
	}
	for(int i = 0; i < num_bullets; i++) {
		bullets[i].pos += bullets[i].dir;
	}
}

BulletPattern2::BulletPattern2(const Vector2& initpos) {
	num_bullets = steps = 0;
	color_r = 0.3;
	color_g = 0.3;
	color_b = 1.0;
	bullets = new Bullet[24*16];
	
	int k = 0;
	for(int j = 0; j < 24; j++) {
		for(float i = 0; i < 2 * M_PI; i += 0.4, k++) {
			bullets[k].pos = initpos;
			bullets[k].dir.x = cosf(i) / 40;
			bullets[k].dir.y = sinf(i) / 40;
			bullets[k].data.a = j * 10;
			bullets[k].data.b = i;
		}
	}
};

void BulletPattern2::update() {
	steps++;
	while(num_bullets < 384 && (unsigned int)(bullets[num_bullets].data.a) < steps) {
		num_bullets++;
	}
	for(int i = 0; i < num_bullets; i++) {
		float l = bullets[i].data.b - log1pf((steps - bullets[i].data.a));
		bullets[i].dir.x = cosf(l) / 500;
		bullets[i].dir.y = sinf(l) / 500;
		bullets[i].pos += bullets[i].dir;
	}
}

BulletPattern3::BulletPattern3(const Vector2& initpos) {
	num_bullets = steps = color_g = color_b = 0;
	color_r = 1;
	bullets = new Bullet[512];
	
	int k = 0;
	
	for(float i = 0; i < M_PI * 16; i += 0.1) {
		bullets[k].pos.x = initpos.x + cosf(i) * 0.05;
		bullets[k].pos.y = initpos.y + sinf(i) * 0.05;
		bullets[k].dir.x = cosf(i) / 1000.0;
		bullets[k++].dir.y = sinf(i) / 1000.0;
	}
}

void BulletPattern3::update() {
	steps++;
	while(num_bullets < 503 && num_bullets / 2 < steps) {
		num_bullets++;
	}
	for(int i = 0; i < num_bullets; i++) {
		bullets[i].pos += bullets[i].dir;
	}
}

BulletPattern4::BulletPattern4(const Vector2& initpos) {
	num_bullets = steps = 0;
	color_r = 1.0;
	color_g = 1.0;
	color_b = 0.0;
	bullets = new Bullet[24*16];
	
	int k = 0;
	for(int j = 0; j < 24; j++) {
		for(float i = 0; i < 2 * M_PI; i += 0.4, k++) {
			bullets[k].pos = initpos;
			bullets[k].dir.x = cosf(i) * 0.002;
			bullets[k].dir.y = sinf(i) * 0.002;
			bullets[k].data.a = j * 10;
			bullets[k].data.b = i;
		}
	}
};

void BulletPattern4::update() {
	steps++;
	while(num_bullets < 384 && (unsigned int)(bullets[num_bullets].data.a) < steps) {
		num_bullets++;
	}
	
	Matrix2 m = rotation_matrix(cos(steps * 0.010) * 0.005);
	
	for(int i = 0; i < num_bullets; i++) {
		bullets[i].dir = m * bullets[i].dir;
		bullets[i].pos += bullets[i].dir;
	}
}