summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/bulletpattern.cpp68
-rw-r--r--engine/bulletpattern.h17
-rw-r--r--engine/stage.cpp10
3 files changed, 51 insertions, 44 deletions
diff --git a/engine/bulletpattern.cpp b/engine/bulletpattern.cpp
index fa43f59..f73ced5 100644
--- a/engine/bulletpattern.cpp
+++ b/engine/bulletpattern.cpp
@@ -6,32 +6,6 @@
#include <cmath>
#include "bulletpattern.h"
-BulletPattern::BulletPattern() {
- 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++] = 0.5 + cosf(i) * 0.05;
- bullets[k++] = 0.5 + sinf(i) * 0.05;
- bullets[k++] = cosf(i) / 1000.0;
- bullets[k++] = sinf(i) / 1000.0;
- }
-}
-
-void BulletPattern::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];
- }
-}
-
void BulletPattern::draw() {
glEnableClientState(GL_VERTEX_ARRAY);
@@ -43,7 +17,7 @@ void BulletPattern::draw() {
}
-BulletPattern1::BulletPattern1() {
+BulletPattern1::BulletPattern1(const Vector2& initpos) {
num_bullets = steps = 0;
color_r = 0;
color_g = 1;
@@ -54,8 +28,8 @@ BulletPattern1::BulletPattern1() {
int k = 0;
for(int j = 0; j < 8; j++) {
for(float i = 0; i < M_PI; i += 0.1, k++) {
- bullets[k*5] = 0.5 + sinf(j % 2 ? M_PI_2 + i : M_PI - i + M_PI_2) * 0.09;
- bullets[k*5 + 1] = 0.8 + cosf(M_PI_2 + i) * 0.1;
+ 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;
@@ -74,8 +48,8 @@ void BulletPattern1::update() {
}
}
-BulletPattern2::BulletPattern2(float xpos, float ypos) {
- num_bullets = 0;
+BulletPattern2::BulletPattern2(const Vector2& initpos) {
+ num_bullets = steps = 0;
color_r = 0.3;
color_g = 0.3;
color_b = 1.0;
@@ -85,8 +59,8 @@ BulletPattern2::BulletPattern2(float xpos, float ypos) {
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] = xpos;
- bullets[k*6+1] = ypos;
+ 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;
@@ -107,4 +81,30 @@ void BulletPattern2::update() {
bullets[i*6] += bullets[i*6 + 2];
bullets[i*6+1] += bullets[i*6 + 3];
}
-} \ No newline at end of file
+}
+
+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];
+ }
+}
diff --git a/engine/bulletpattern.h b/engine/bulletpattern.h
index e1dd3a2..8df7945 100644
--- a/engine/bulletpattern.h
+++ b/engine/bulletpattern.h
@@ -1,6 +1,8 @@
#ifndef BULLETPATTERN_H
#define BULLETPATTERN_H
+#include "vector.h"
+
class BulletPattern {
protected:
float* bullets;
@@ -9,21 +11,26 @@ class BulletPattern {
unsigned int steps;
public:
float color_r, color_g, color_b;
-
- BulletPattern();
- virtual void update();
+
+ virtual void update() = 0;
void draw();
};
class BulletPattern1 : public BulletPattern {
public:
- BulletPattern1();
+ BulletPattern1(const Vector2& initpos);
void update();
};
class BulletPattern2 : public BulletPattern {
public:
- BulletPattern2(float xpos, float ypos);
+ BulletPattern2(const Vector2& initpos);
+ void update();
+};
+
+class BulletPattern3 : public BulletPattern {
+ public:
+ BulletPattern3(const Vector2& initpos);
void update();
};
diff --git a/engine/stage.cpp b/engine/stage.cpp
index b9995ed..06ae1ef 100644
--- a/engine/stage.cpp
+++ b/engine/stage.cpp
@@ -11,11 +11,11 @@ Stage::Stage() {
texture = new TextureSDL("textures/shot1.png");
shader = new GLShaderProgram();
- patterns.push_back(new BulletPattern());
- patterns.push_back(new BulletPattern1());
- patterns.push_back(new BulletPattern2(0.2, 0.5));
- patterns.push_back(new BulletPattern2(0.5, 0.5));
- patterns.push_back(new BulletPattern2(0.8, 0.5));
+ patterns.push_back(new BulletPattern3(Vector2(0.5, 0.5)));
+ patterns.push_back(new BulletPattern1(Vector2(0.5, 0.8)));
+ patterns.push_back(new BulletPattern2(Vector2(0.2, 0.5)));
+ patterns.push_back(new BulletPattern2(Vector2(0.5, 0.5)));
+ patterns.push_back(new BulletPattern2(Vector2(0.8, 0.5)));
GLFragmentShader shader1("shaders/bullet_fragment.glsl");
GLVertexShader shader2("shaders/bullet_vertex.glsl");