Skip to content

Commit

Permalink
end sequence stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Kade-github committed May 19, 2024
1 parent 9b043ba commit 08bffa1
Show file tree
Hide file tree
Showing 20 changed files with 356 additions and 25 deletions.
Binary file added Assets/Sfx/rocket_lift.ogg
Binary file not shown.
2 changes: 1 addition & 1 deletion Assets/Shaders/frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ void main()
FragColor = mix(FragColor, vec4(1.0, 0.0, 0.0, FragColor.a), redness);

if (FogFar < 1000)
FragColor = mix(FragColor, vec4(FogColor, 1.0), fogFactor);
FragColor = mix(FragColor, vec4(FogColor, FragColor.a), fogFactor);

}
Binary file added Assets/Textures/rocket_burn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Textures/star_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/Engine/Audio/AudioManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ class Channel {
CheckError();
}

float GetPosition()
{
if (!IsLoaded())
return 0;

return BASS_ChannelBytes2Seconds(id, BASS_ChannelGetPosition(id, BASS_POS_BYTE));
}

void Set3DDistanceFactor(float dist)
{
if (!IsLoaded())
Expand Down
20 changes: 20 additions & 0 deletions src/Engine/Objects/3DSprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ void Sprite3D::Draw()
Game::instance->shader->Unbind();
}

void Sprite3D::LookAt(glm::vec3 target)
{
glm::vec3 direction = glm::normalize(target - position);
glm::vec3 up = glm::vec3(0, 1, 0);
glm::vec3 right = glm::cross(direction, up);
up = glm::cross(right, direction);

glm::mat4 rotation = glm::mat4(1.0f);
rotation[0] = glm::vec4(right, 0);
rotation[1] = glm::vec4(up, 0);
rotation[2] = glm::vec4(-direction, 0);

glm::quat q = glm::quat_cast(rotation);
glm::vec3 euler = glm::eulerAngles(q);

angle = glm::degrees(euler.x);
angleY = glm::degrees(euler.y);
angleZ = glm::degrees(euler.z);
}

void Sprite3D::UpdateSprite()
{
vertices.clear();
Expand Down
2 changes: 2 additions & 0 deletions src/Engine/Objects/3DSprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Sprite3D : public GameObject

void Draw() override;

void LookAt(glm::vec3 target);

void UpdateSprite();

void Destroy() override;
Expand Down
12 changes: 12 additions & 0 deletions src/Engine/Objects/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,25 @@ void Camera::DrawDebugCube(glm::vec3 pos, glm::vec3 scale)

}

void Camera::SetDirectionSmooth(float amount)
{
glm::vec3 direction;
direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
direction.y = sin(glm::radians(pitch));
direction.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
cameraFront = glm::mix(smoothFront, glm::normalize(direction), amount);

SetViewMatrix();
}

void Camera::SetDirection()
{
glm::vec3 direction;
direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
direction.y = sin(glm::radians(pitch));
direction.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
cameraFront = glm::normalize(direction);
smoothFront = cameraFront;

SetViewMatrix();
}
Expand Down
7 changes: 5 additions & 2 deletions src/Engine/Objects/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Camera

float cameraFar = 100.0f;

glm::vec3 smoothFront = glm::vec3(0.0f, 0.0f, -1.0f);

glm::vec3 scale = glm::vec3(1, 1, 1);

Camera();
Expand All @@ -49,10 +51,9 @@ class Camera

void LookAt(glm::vec3 target)
{
glm::vec3 direction = glm::normalize(position - target);
glm::vec3 direction = -glm::normalize(position - target);
pitch = glm::degrees(asin(direction.y));
yaw = glm::degrees(atan2(direction.z, direction.x));
SetDirection();
}

float YawAngleTo(glm::vec3 pos)
Expand All @@ -69,6 +70,8 @@ class Camera
return angle;
}

void SetDirectionSmooth(float amount);

void SetDirection();
void SetViewMatrix();

Expand Down
7 changes: 7 additions & 0 deletions src/Game/LightingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void LightingManager::SunColor()

Gameplay* gp = (Gameplay*)Game::instance->currentScene;

Camera* cam = Game::instance->GetCamera();

int playerY = gp->player->position.y;
Chunk* c = WorldManager::instance->GetChunk(gp->player->position.x, gp->player->position.z);
int highestBlock = 0;
Expand Down Expand Up @@ -113,6 +115,11 @@ void LightingManager::SunColor()

float distance = (float)highestBlock - (float)playerY;

if (cam->position.y > 170.0f)
{
distance = 5.0f;
}

float mixProgress = distance / 5.0f;

if (mixProgress > 1.0f)
Expand Down
8 changes: 4 additions & 4 deletions src/Game/MobManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void MobManager::Update()
Camera* cam = Game::instance->GetCamera();

// spawn mobs around player
if (glfwGetTime() - lastWave > 30 && mobs.size() < 45)
if (glfwGetTime() - lastWave > 30 && mobs.size() < 45 && !Hud::endSequence)
{
lastWave = glfwGetTime();

Expand Down Expand Up @@ -148,12 +148,12 @@ void MobManager::Update()
{
float angle = cam->YawAngleTo(mob->position);

if (angle > 100 && glfwGetTime() - mob->lastSeen > 140) // not visible
if (angle > 260 && glfwGetTime() - mob->lastSeen > 140) // not visible
{
RemoveMob(mob);
break;
}
else if (angle > 100)
else if (angle > 260)
mob->lastSeen = glfwGetTime();

if (mob->dead)
Expand Down Expand Up @@ -192,7 +192,7 @@ void MobManager::Update()

float r = rand() % 35 + 20;

if (mob->lastNoise + r < glfwGetTime())
if (mob->lastNoise + r < glfwGetTime() && !Hud::endSequence)
mob->Noise();
}
}
15 changes: 14 additions & 1 deletion src/Game/MusicManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ void MusicManager::PlayMusic(std::string path)
c->CreateFX();

c->Play();
_isPlaying = true;

_fadeTime = 0;
_fadeDuration = 0;
Expand Down Expand Up @@ -169,6 +170,7 @@ void MusicManager::PlayMusic(std::string path, float fadeDuration)

c->SetVolume(0);
c->Play();
_isPlaying = true;

_fadeTime = glfwGetTime();
_fadeDuration = fadeDuration;
Expand Down Expand Up @@ -275,6 +277,16 @@ void MusicManager::PlaySFX(std::string path, glm::vec3 from, float pitch, std::s
c->Play();
}

float MusicManager::GetTime()
{
Channel* c = Game::instance->audioManager->GetChannel(currentSong);

if (c == nullptr)
return 0;

return c->GetPosition();
}

void MusicManager::FadeOut(float duration)
{
if (currentSong == "")
Expand Down Expand Up @@ -333,7 +345,7 @@ void MusicManager::PlayNext()

bool MusicManager::IsPlaying()
{
return _isPlaying;
return ChannelIsPlaying(currentSong);
}

void MusicManager::Update()
Expand All @@ -356,6 +368,7 @@ void MusicManager::Update()
if (Game::instance->audioManager->channels.size() == 0)
return;


if (glfwGetTime() > lastCheck)
{
lastCheck = glfwGetTime() + 0.15f;
Expand Down
2 changes: 2 additions & 0 deletions src/Game/MusicManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class MusicManager
void PlaySFX(std::string path, std::string customName = "sfx");
void PlaySFX(std::string path, glm::vec3 from, float pitch, std::string customName = "sfx");

float GetTime();

void FadeOut(float duration);

void FadeTo(float volume, float duration);
Expand Down
22 changes: 21 additions & 1 deletion src/Game/Objects/Base/Blocks/Rocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../../../LightingManager.h"
#include "../../../Scenes/Gameplay.h"
#include <Game.h>
#include "../RocketEnd.h"

Rocket::Rocket(glm::vec3 _position) : Block(_position, BlockType::ROCKET)
{
Expand Down Expand Up @@ -43,15 +44,34 @@ bool Rocket::Update(int tick)
return true;

int highest = currentChunk->GetHighestBlock(position.x, position.z);
Gameplay* gp = (Gameplay*)Game::instance->currentScene;

if (position.y < highest)
{
Gameplay* gp = (Gameplay*)Game::instance->currentScene;

gp->hud->ShowHint("Route blocked, unable to launch.");
Hud::endSequence = false;
gp->hud->playEnd = false;
return true;
}

if (LightingManager::GetInstance()->sun.angle < 200 || LightingManager::GetInstance()->sun.angle > 290)
{
gp->hud->ShowHint("Route unclear, the sky must be shrouded in darkness.");
Hud::endSequence = false;
gp->hud->playEnd = false;
return true;
}

if (!destroyed)
{
RocketEnd* end = new RocketEnd(position);

gp->AddObject(end);

destroyed = true;
currentChunk->ModifyBlock(position.x, position.y, position.z, 0);
}

return true;
}
2 changes: 2 additions & 0 deletions src/Game/Objects/Base/Blocks/Rocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Rocket : public Block
public:
Chunk* currentChunk;

bool destroyed = false;

Rocket(glm::vec3 _position);

void LoadModel() override;
Expand Down
Loading

0 comments on commit 08bffa1

Please sign in to comment.