summaryrefslogtreecommitdiff
path: root/engine/bulletpattern.cpp
blob: 195caf96ba4be0fd44a478ae99e49e4d26f5cb8f (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
#include <cmath>
#include "bulletpattern.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;
	}
}