summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-05-17 14:38:17 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-05-17 14:38:17 +0200
commit19649941d59ad43aca2068f15249fd64fb0abff2 (patch)
tree8cad368c0c4310f119139ad2fbc4afc8c34070e6 /main.cpp
parentad7de669ca9c3f4c5b428fdbeb05245fc8758657 (diff)
Implemented pattern 1 using BulletPattern inheritance.
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp48
1 files changed, 42 insertions, 6 deletions
diff --git a/main.cpp b/main.cpp
index eb1cd92..95ab127 100644
--- a/main.cpp
+++ b/main.cpp
@@ -45,6 +45,33 @@ class BulletAdderComparison {
std::list<Bullet> bullets;
std::priority_queue<BulletAdder, std::vector<BulletAdder>, BulletAdderComparison> bullets_queue;
+class BulletPattern1 : public BulletPattern {
+ unsigned int base;
+ public:
+ BulletPattern1(bool reverse, unsigned int base) {
+ num_bullets = 0;
+ bullets = new float[128];
+ this->base = base;
+
+ int j = 0;
+ for(float i = 0; i < M_PI; i += 0.1, j++) {
+ bullets[j*4] = 50.0 + sinf(!reverse ? M_PI_2 + i : M_PI - i + M_PI_2) * 9;
+ bullets[j*4 + 1] = 80 + cosf(M_PI_2 + i) * 10;
+ bullets[j*4 + 2] = sinf(!reverse ? M_PI_2 + i : M_PI - i + M_PI_2) / 150.0;
+ bullets[j*4 + 3] = -0.01;
+ }
+ };
+ void update(unsigned int time, unsigned int step) {
+ if(num_bullets < 32 && base + num_bullets * 10 < time) {
+ num_bullets += time / 10 - num_bullets - base / 10;
+ }
+ for(int i = 0; i < num_bullets; i++) {
+ bullets[i*4] += bullets[i*4 + 2] * step;
+ bullets[i*4 + 1] += bullets[i*4 + 3] * step;
+ }
+ }
+};
+
void create_pattern1(unsigned int base) {
for(int j = 0; j < 8; j++) {
for(float i = 0; i < M_PI; i += 0.1) {
@@ -83,9 +110,9 @@ void create_pattern3(unsigned int base) {
}
void create_bullets() {
- create_pattern1(50);
- create_pattern2(9000);
- create_pattern3(12000);
+ //create_pattern1(50);
+ //create_pattern2(9000);
+ //create_pattern3(12000);
//create_pattern2_2(100);
}
@@ -131,8 +158,13 @@ int main(int, char**) {
glShadeModel(GL_SMOOTH);
create_bullets();
+
+ std::vector<BulletPattern*> patterns;
- BulletPattern* pattern = new BulletPattern();
+ patterns.push_back(new BulletPattern());
+ for(int i = 0; i < 8; i++) {
+ patterns.push_back(new BulletPattern1(i % 2 == 1, i * 400));
+ }
TextureSDL texture1("foo.png");
TextureSDL texture2("foo4.png");
@@ -200,7 +232,9 @@ int main(int, char**) {
bullets_queue.pop();
bullets.push_back(bullet);
}
- pattern->update(elapsed, step);
+ for(std::vector<BulletPattern*>::iterator it = patterns.begin(); it < patterns.end(); it++) {
+ (*it)->update(elapsed, step);
+ }
}
gluLookAt(
@@ -238,7 +272,9 @@ int main(int, char**) {
glColor4f(1, 0, 0, 1);
- pattern->draw();
+ for(std::vector<BulletPattern*>::iterator it = patterns.begin(); it < patterns.end(); it++) {
+ (*it)->draw();
+ }
glColor4f(0, 1, 0, 1);