summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-05-23 19:15:11 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-05-23 19:15:11 +0200
commitf696350881eeeaf319c29e615cabaa351c55eb12 (patch)
tree87d3d401834b7c3deb4fd04b870aa167a07d28ff /engine
parent57bf396ed52510fee5a34e479ca1f671faba2773 (diff)
Changed BulletPattern::update to not take time and step arguments.
Also updated patterns.
Diffstat (limited to 'engine')
-rw-r--r--engine/bulletpattern.cpp15
-rw-r--r--engine/bulletpattern.h7
-rw-r--r--engine/stage.cpp101
3 files changed, 65 insertions, 58 deletions
diff --git a/engine/bulletpattern.cpp b/engine/bulletpattern.cpp
index b4b5a31..b9a0bbd 100644
--- a/engine/bulletpattern.cpp
+++ b/engine/bulletpattern.cpp
@@ -7,7 +7,7 @@
#include "bulletpattern.h"
BulletPattern::BulletPattern() {
- num_bullets = stride = color_g = color_b = 0;
+ num_bullets = stride = steps = color_g = color_b = 0;
color_r = 1;
bullets = new float[2048];
@@ -16,18 +16,19 @@ BulletPattern::BulletPattern() {
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) / 10000.0;
- bullets[k++] = sinf(i) / 10000.0;
+ bullets[k++] = cosf(i) / 1000.0;
+ bullets[k++] = sinf(i) / 1000.0;
}
}
-void BulletPattern::update(unsigned int time, unsigned int step) {
- while(num_bullets < 503 && num_bullets * 4 < time) {
+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] * step;
- bullets[i*4 + 1] += bullets[i*4 + 3] * step;
+ 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 092713e..9acda5f 100644
--- a/engine/bulletpattern.h
+++ b/engine/bulletpattern.h
@@ -4,13 +4,14 @@
class BulletPattern {
protected:
float* bullets;
- int num_bullets;
- int stride;
+ unsigned int num_bullets;
+ unsigned int stride;
+ unsigned int steps;
public:
float color_r, color_g, color_b;
BulletPattern();
- virtual void update(unsigned int time, unsigned int step);
+ virtual void update();
void draw();
};
diff --git a/engine/stage.cpp b/engine/stage.cpp
index 59377da..cb306df 100644
--- a/engine/stage.cpp
+++ b/engine/stage.cpp
@@ -6,40 +6,9 @@
#include <cmath>
class BulletPattern1 : public BulletPattern {
- unsigned int base;
public:
- BulletPattern1(bool reverse, unsigned int base) {
- num_bullets = 0;
- color_r = 1;
- color_g = 0;
- color_b = 1;
- bullets = new float[128];
- this->base = base;
-
- int j = 0;
- for(float i = 0; i < M_PI; i += 0.1, j++) {
- bullets[j*4] = 0.5 + sinf(!reverse ? M_PI_2 + i : M_PI - i + M_PI_2) * 0.09;
- bullets[j*4 + 1] = 0.8 + cosf(M_PI_2 + i) * 0.1;
- bullets[j*4 + 2] = sinf(!reverse ? M_PI_2 + i : M_PI - i + M_PI_2) / 15000.0;
- bullets[j*4 + 3] = -0.0001;
- }
- };
- 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;
- if(num_bullets > 32) num_bullets = 32;
- }
- 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;
- }
- }
-};
-
-class BulletPattern2 : public BulletPattern {
- public:
- BulletPattern2(unsigned int base) {
- num_bullets = 0;
+ BulletPattern1() {
+ num_bullets = steps = 0;
color_r = 0;
color_g = 1;
color_b = 0;
@@ -51,20 +20,58 @@ class BulletPattern2 : public BulletPattern {
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 + 2] = sinf(j % 2 ? M_PI_2 + i : M_PI - i + M_PI_2) / 15000;
- bullets[k*5 + 3] = -0.0001;
- bullets[k*5 + 4] = base + j * 400 + i * 100;
+ 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 update(unsigned int time, unsigned int step) {
- while(num_bullets < 256 && (unsigned int)(bullets[num_bullets*5 + 4]) < time) {
+ void 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];
+ }
+ }
+};
+
+class BulletPattern2 : public BulletPattern {
+ public:
+ BulletPattern2(float xpos, float ypos) {
+ num_bullets = 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] = xpos;
+ bullets[k*6+1] = ypos;
+ 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 update() {
+ steps++;
+ while(num_bullets < 384 && (unsigned int)(bullets[num_bullets*6 + 4]) < steps) {
num_bullets++;
}
for(int i = 0; i < num_bullets; i++) {
- bullets[i*5] += bullets[i*5 + 2] * step;
- bullets[i*5 + 1] += bullets[i*5 + 3] * step;
+ 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];
}
}
};
@@ -76,10 +83,10 @@ Stage::Stage() {
shader = new GLShaderProgram();
patterns.push_back(new BulletPattern());
- for(int i = 0; i < 8; i++) {
- patterns.push_back(new BulletPattern1(i % 2 == 1, 5000 + i * 400));
- }
- patterns.push_back(new BulletPattern2(9000));
+ 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));
GLFragmentShader shader1("shaders/bullet_fragment.glsl");
GLVertexShader shader2("shaders/bullet_vertex.glsl");
@@ -91,10 +98,8 @@ Stage::Stage() {
void Stage::update() {
player->update();
- static int i;
-
for(std::vector<BulletPattern*>::iterator it = patterns.begin(); it < patterns.end(); it++) {
- (*it)->update(i++, 1);
+ (*it)->update();
}
}
@@ -113,4 +118,4 @@ void Stage::draw() {
}
glUseProgram(0);
-} \ No newline at end of file
+}