Commit 0a4e8759 authored by Dario Seyb's avatar Dario Seyb

extended intro a bit

parent 19567fd9
This diff is collapsed.
......@@ -41,6 +41,11 @@ private:
Entity soundSource;
Entity planet;
Drawable::Handle planetDrawable;
Transform::Handle planetTransform;
Drawable::Handle textDrawable;
Drawable::Handle letterADrawable;
Drawable::Handle backgroundDrawable;
......@@ -76,6 +81,11 @@ private:
void spawnEnemy(glm::dvec3 pos, glm::dvec3 vel);
void updateEnemies(double dt);
void updateFFT();
double planetRotation;
void updatePlanet(double dt);
float timeSinceLastShot = 0;
float nextEnemySpawnTime = 2;
......
......@@ -109,6 +109,18 @@ void Console::startup() {
enemyMaterial = Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4(3, .4, .2, 1),
textTexture, nullptr, nullptr, nullptr, textShader,
false, RenderQueue::OPAQUE, GL_BACK };
auto planetGeom = Geometry{ VertexArrayObjectCreator("planet_wireframe.obj").create() };
auto planetMaterial = Material{ glm::vec4{ 1, 1, 1, 1 }, glm::vec4(0.2, 1.0, 0.3, 1) * 2,
textTexture, nullptr, nullptr, nullptr, textShader,
false, RenderQueue::OPAQUE, GL_BACK };
planet = m_sceneGraph->create();
planetDrawable = planet.assign<Drawable>(planetGeom, planetMaterial, 0, consolePassId);
planetTransform = planet.assign<Transform>();
planetTransform->position = { 8, 0.2, -5 };
planetTransform->scale = { 0.7, 0.7, 0.7 };
}
void Console::spawnShot(glm::dvec3 pos, glm::dvec3 vel, bool friendly) {
......@@ -129,6 +141,13 @@ void Console::spawnShot(glm::dvec3 pos, glm::dvec3 vel, bool friendly) {
shots.push_back(newShot);
}
void Console::updatePlanet(double dt) {
planetTransform->position.x -= dt * (planetTransform->position.x - 1);
planetRotation += dt * 0.3;
planetTransform->rotation = glm::yawPitchRoll(planetRotation, 0.0, 0.0);
}
void Console::updateShots(double dt) {
Transform::Handle trans;
Shot::Handle shot;
......@@ -179,9 +198,9 @@ void Console::updateShots(double dt) {
void Console::spawnEnemy(glm::dvec3 pos, glm::dvec3 vel) {
auto newEnemy = m_sceneGraph->create();
auto enemyGeom = enemyGeometries[std::string(1, enemyOrder.at(currentEnemy))];
auto enemyGeom = enemyGeometries[std::string(1, enemyOrder.at(currentEnemy % enemyOrder.length()))];
currentEnemy = (currentEnemy + 1) % enemyOrder.length();
currentEnemy++;
newEnemy.assign<Drawable>(enemyGeom, enemyMaterial, 0, consolePassId);
auto trans = newEnemy.assign<Transform>();
......@@ -217,14 +236,7 @@ void Console::updateEnemies(double dt) {
}
}
bool Console::update(const SimulateEvent &e, const bool* keyTable) {
double dt = e.dt;
updateShots(dt);
updateEnemies(dt);
void Console::updateFFT() {
float* data = nullptr;
unsigned int length = 0;
m_audio->getSpectrum(&data, &length);
......@@ -236,7 +248,7 @@ bool Console::update(const SimulateEvent &e, const bool* keyTable) {
GLubyte* byteData = new GLubyte[length];
for (int i = 0; i < length; i++) {
byteData[i] = (GLubyte)(data[i]/max * 255);
byteData[i] = (GLubyte)(data[i] / max * 255);
}
SharedTextureData fftData = std::make_shared<TextureData>();
......@@ -253,9 +265,17 @@ bool Console::update(const SimulateEvent &e, const bool* keyTable) {
backgroundDrawable->material.mainTexture = fftTex;
float posPercentage = (letterATransform->position.x + 3.2) / 4.5;
m_audio->setLowPassCutoff(500 + posPercentage * 3000);
}
bool Console::update(const SimulateEvent &e, const bool* keyTable) {
double dt = e.dt;
updateShots(dt);
updateEnemies(dt);
updateFFT();
switch (state) {
case State::FadingIn:
......@@ -323,11 +343,17 @@ bool Console::update(const SimulateEvent &e, const bool* keyTable) {
timeSinceLastShot += dt;
nextEnemySpawnTime -= dt;
if (nextEnemySpawnTime <= 0) {
if (nextEnemySpawnTime <= 0 && currentEnemy < enemyOrder.length()) {
spawnEnemy({ 5, -1.4 + ((float)std::rand() / RAND_MAX) * (2 + 1.4), -5 }, { -2, 0 ,0 });
nextEnemySpawnTime = ((float)std::rand() / RAND_MAX) * 1 + 0.5;
}
if (currentEnemy == enemyOrder.length() && nextEnemySpawnTime <= 0) {
updatePlanet(dt);
if (glm::length(letterATransform->position - planetTransform->position) < 1) return true;
}
playerSpeed += moveDir * 20 * dt;
auto newPos = letterATransform->position + playerSpeed * dt;
......@@ -367,8 +393,6 @@ bool Console::update(const SimulateEvent &e, const bool* keyTable) {
letterATransform->position += playerSpeed * dt;
playerSpeed -= playerSpeed * 5 * dt;
if (newPos.x > 4.5) return true;
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment