From 19649941d59ad43aca2068f15249fd64fb0abff2 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 17 May 2010 14:38:17 +0200 Subject: Implemented pattern 1 using BulletPattern inheritance. --- main.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) (limited to 'main.cpp') 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 bullets; std::priority_queue, 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 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::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::iterator it = patterns.begin(); it < patterns.end(); it++) { + (*it)->draw(); + } glColor4f(0, 1, 0, 1); -- cgit v1.2.3