From c0508d0b705d79cb3359cd15971b477172b7eb4b Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Fri, 14 Apr 2023 17:45:25 -0500 Subject: [PATCH] Level complete transition and screen. --- Faceball2030/main.cpp | 43 +++++++++++++++++++++++++++++++------------ Faceball2030/main.h | 5 ++++- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/Faceball2030/main.cpp b/Faceball2030/main.cpp index 55325b0..d78792d 100644 --- a/Faceball2030/main.cpp +++ b/Faceball2030/main.cpp @@ -849,6 +849,10 @@ void FaceBall::HandleKeys(float fElapsedTime) { vec3d zMovement{ 0,0,vForward.z }; player.UpdatePos(Vector_Add(player.GetPos(), zMovement)); } + float distanceToExit = std::sqrtf(std::powf(player.GetPos().x - exit.pos.x, 2) + std::powf(player.GetPos().z - exit.pos.z, 2)); + if (distanceToExit < player.GetRadius() + exit.radius) { + mode = LEVELCOMPLETE; + } } } if (GetKey(S).bHeld) { @@ -990,6 +994,22 @@ bool Bullet::Update(float fElapsedTime) { return true; } +void FaceBall::RenderHud(float fElapsedTime) { + if (!GetKey(olc::D).bHeld && !GetKey(olc::A).bHeld) { + hudOffsetAcc += 20 * fElapsedTime; + while (hudOffsetAcc >= 1) { + hudOffset /= 2; + hudOffsetAcc--; + } + } + SetDecalMode(DecalMode::NORMAL); + DrawDecal({ -32 + hudOffset,-18 }, hud, { 1.05,1.05 }); + DrawStringDecal({ 112 + hudOffset,4 }, "Triangles: " + std::to_string(triRenderCount), BLACK, { 2,4 }); + std::string hudText = "Tags Left: " + std::to_string(tagsRemaining) + " Lives: " + std::to_string(lives); + DrawStringPropDecal(vf2d{ hudOffset + (float)(ScreenWidth() / 2 - GetTextSizeProp(hudText).x * 3 / 2),(float)(ScreenHeight() - 64 - GetTextSizeProp(hudText).y * 6) }, hudText, WHITE, { 3,6 }); + FillRectDecal({ 0,0 }, vf2d{ (float)ScreenWidth(),(float)ScreenHeight() }, { (uint8_t)0,(uint8_t)0,(uint8_t)0,(uint8_t)screenAlpha }); +} + void FaceBall::SubtractTag() { tagsRemaining = std::max(0, tagsRemaining - 1); if (!exitWallsCleared&&tagsRemaining <= 0) { @@ -1132,22 +1152,21 @@ bool FaceBall::OnUserUpdate(float fElapsedTime) case GAME: { HandleKeys(fElapsedTime); RenderWorld(); - if (!GetKey(olc::D).bHeld && !GetKey(olc::A).bHeld) { - hudOffsetAcc += 20 * fElapsedTime; - while (hudOffsetAcc >= 1) { - hudOffset /= 2; - hudOffsetAcc--; - } - } - SetDecalMode(DecalMode::NORMAL); - DrawDecal({ -32+hudOffset,-18 }, hud, {1.05,1.05}); - DrawStringDecal({ 112+hudOffset,4 }, "Triangles: " + std::to_string(triRenderCount), BLACK, { 2,4 }); - std::string hudText = "Tags Left: " + std::to_string(tagsRemaining) + " Lives: " + std::to_string(lives); - DrawStringPropDecal(vf2d{ hudOffset+(float)(ScreenWidth() / 2 - GetTextSizeProp(hudText).x * 3 / 2),(float)(ScreenHeight() - 64 - GetTextSizeProp(hudText).y*6) }, hudText, WHITE, {3,6}); + RenderHud(fElapsedTime); }break; case EDITOR: { editor.Update(fElapsedTime); }break; + case LEVELCOMPLETE: { + RenderWorld(); + RenderHud(fElapsedTime); + if (screenAlpha < 255) { + screenAlpha = std::min(255.f,screenAlpha+200 * fElapsedTime); + } + else { + DrawStringDecal({ 16,16 }, "Level " + std::to_string(level) + " complete!", WHITE, { 4,8 }); + } + }break; } if (GetKey(olc::F5).bPressed) { mode = (GAMEMODE)!(mode&1); diff --git a/Faceball2030/main.h b/Faceball2030/main.h index 9504949..1581070 100644 --- a/Faceball2030/main.h +++ b/Faceball2030/main.h @@ -9,7 +9,8 @@ const float PI = 3.14159f; enum GAMEMODE { GAME, - EDITOR + EDITOR, + LEVELCOMPLETE }; enum Direction { @@ -243,6 +244,7 @@ class FaceBall : public PixelGameEngine float moveSpd = 2.0f; float hudOffset = 0; float hudOffsetAcc = 0; + float screenAlpha = 0; int triRenderCount = 0; @@ -277,6 +279,7 @@ class FaceBall : public PixelGameEngine void LoadLevel(int level); void RenderMesh(mat4x4&matView, std::vector&vecTrianglesToRaster,Object&o); void RunEnemyAI(Enemy& e,float fElapsedTime); + void RenderHud(float fElapsedTime); public: static bool CheckCollision(vec3d movementVector,vf2d pos,float radius); static int CheckEnemyCollision(vec3d movementVector, vf2d pos, float radius);