summaryrefslogtreecommitdiff
path: root/engine/bulletpattern.cpp
blob: f73ced564015fc2e385ed37823b23ab732ee5b3c (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
#ifndef __APPLE__
#include <GL/gl.h>
#else
#include <OpenGL/gl.h>
#endif
#include <cmath>
#include "bulletpattern.h"

void BulletPattern::draw() {
	glEnableClientState(GL_VERTEX_ARRAY);
	
	glVertexPointer(4, GL_FLOAT, 4 * sizeof(float) + stride, bullets);
	
	glDrawArrays(GL_POINTS, 0, num_bullets);
	
	glDisableClientState(GL_VERTEX_ARRAY);
	
}

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

void BulletPattern1::update() {
	steps++;
	while(num_bullets < 256 && (unsigned int)(bullets[num_bullets*5 + 4]) < steps) {
		num_bullets++;
	}
	for(int i = 0; i < num_bullets; i++) {
		bullets[i*5] += bullets[i*5 + 2];
		bullets[i*5 + 1] += bullets[i*5 + 3];
	}
}

BulletPattern2::BulletPattern2(const Vector2& initpos) {
	num_bullets = steps = 0;
	color_r = 0.3;
	color_g = 0.3;
	color_b = 1.0;
	stride = sizeof(float)*2;
	bullets = new float[24*16*6];
	
	int k = 0;
	for(int j = 0; j < 24; j++) {
		for(float i = 0; i < 2 * M_PI; i += 0.4, k++) {
			bullets[k*6] = initpos.x;
			bullets[k*6+1] = initpos.y;
			bullets[k*6+2] = cosf(i) / 40;
			bullets[k*6+3] = sinf(i) / 40;
			bullets[k*6+4] = j * 10;
			bullets[k*6+5] = i;
		}
	}
};

void BulletPattern2::update() {
	steps++;
	while(num_bullets < 384 && (unsigned int)(bullets[num_bullets*6 + 4]) < steps) {
		num_bullets++;
	}
	for(int i = 0; i < num_bullets; i++) {
		float l = bullets[i*6 + 5] - log1pf((steps - bullets[i*6+4]));
		bullets[i*6+2] = cosf(l) / 500;
		bullets[i*6+3] = sinf(l) / 500;
		bullets[i*6] += bullets[i*6 + 2];
		bullets[i*6+1] += bullets[i*6 + 3];
	}
}

BulletPattern3::BulletPattern3(const Vector2& initpos) {
	num_bullets = stride = steps = color_g = color_b = 0;
	color_r = 1;
	bullets = new float[2048];
	
	int k = 0;
	
	for(float i = 0; i < M_PI * 16; i += 0.1) {
		bullets[k++] = initpos.x + cosf(i) * 0.05;
		bullets[k++] = initpos.y + sinf(i) * 0.05;
		bullets[k++] = cosf(i) / 1000.0;
		bullets[k++] = 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*4] += bullets[i*4 + 2];
		bullets[i*4 + 1] += bullets[i*4 + 3];
	}
}