diff options
| -rw-r--r-- | bulletpattern.h | 2 | ||||
| -rw-r--r-- | main.cpp | 48 | 
2 files changed, 43 insertions, 7 deletions
| diff --git a/bulletpattern.h b/bulletpattern.h index 50d5844..dffb928 100644 --- a/bulletpattern.h +++ b/bulletpattern.h @@ -7,7 +7,7 @@ class BulletPattern {  		int num_bullets;  	public:  		BulletPattern(); -		void update(unsigned int time, unsigned int step); +		virtual void update(unsigned int time, unsigned int step);  		void draw();  }; @@ -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); | 
