From 57ee47105cd1c88471d92e9ba8d66ac35eef0151 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Tue, 25 Apr 2023 19:10:34 -0500 Subject: [PATCH] Implement powerup timers and HUD. Plus some additive blending. --- Faceball2030/main.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++- Faceball2030/main.h | 7 ++++-- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/Faceball2030/main.cpp b/Faceball2030/main.cpp index 9d9fa8c..3ecc7ea 100644 --- a/Faceball2030/main.cpp +++ b/Faceball2030/main.cpp @@ -1757,7 +1757,6 @@ void FaceBall::RenderHud(float fElapsedTime) { hudOffsetAcc--; } } - SetDecalMode(DecalMode::NORMAL); if (hp <= 0) { FillRectDecal({ 0,0 }, { float(ScreenWidth()),float(ScreenHeight()) }); std::string topText = enemyData[lastHitBy].name + " SAYS"; @@ -1775,10 +1774,14 @@ void FaceBall::RenderHud(float fElapsedTime) { hudAdjustment.y += hudShakeAmt * 4; } vf2d hudLoc = { hudAdjustment.x + (hp>0?hudOffset:0),hudAdjustment.y}; + if (hp > 0) { + SetDecalMode(DecalMode::ADDITIVE); + } DrawWarpedDecal(hudmeter, { meter_ARMOR[0] + hudLoc + vf2d{float(hudmeter->sprite->width),float(hudmeter->sprite->height)} / 2,meter_ARMOR[1] + hudLoc + vf2d{float(hudmeter->sprite->width),float(hudmeter->sprite->height)} / 2,meter_ARMOR[2].lerp(meter_ARMOR[1],1 - float(armorUpgrades)/maxArmorUpgrades) + hudLoc + vf2d{float(hudmeter->sprite->width),float(hudmeter->sprite->height)} / 2, meter_ARMOR[3].lerp(meter_ARMOR[0],1- float(armorUpgrades)/maxArmorUpgrades) + hudLoc + vf2d{float(hudmeter->sprite->width),float(hudmeter->sprite->height)} / 2}); DrawWarpedDecal(hudmeter, { meter_SPEED[0] + hudLoc + vf2d{float(hudmeter->sprite->width),float(hudmeter->sprite->height)}/2, meter_SPEED[1] + hudLoc + vf2d{float(hudmeter->sprite->width),float(hudmeter->sprite->height)} / 2,meter_SPEED[2].lerp(meter_SPEED[1],1 - float(speedUpgrades) / maxSpeedUpgrades) + hudLoc + vf2d{float(hudmeter->sprite->width),float(hudmeter->sprite->height)}/2, meter_SPEED[3].lerp(meter_SPEED[0],1-float(speedUpgrades) / maxSpeedUpgrades) + hudLoc + vf2d{float(hudmeter->sprite->width),float(hudmeter->sprite->height)} / 2 }); DrawWarpedDecal(hudmeter, { meter_SHOTS[0] + hudLoc + vf2d{float(hudmeter->sprite->width),float(hudmeter->sprite->height)} / 2,meter_SHOTS[1] + hudLoc + vf2d{float(hudmeter->sprite->width),float(hudmeter->sprite->height)} / 2,meter_SHOTS[2].lerp(meter_SHOTS[1],1 - float(shotsUpgrades) / maxShotsUpgrades) + hudLoc + vf2d{float(hudmeter->sprite->width),float(hudmeter->sprite->height)} / 2, meter_SHOTS[3].lerp(meter_SHOTS[0],1-float(shotsUpgrades) / maxShotsUpgrades) + hudLoc + vf2d{float(hudmeter->sprite->width),float(hudmeter->sprite->height)} / 2}); DrawDecal(hudLoc, hud, { 1.05,1.05 }); + SetDecalMode(DecalMode::NORMAL); DrawDecal(hudLoc + vf2d{ 704+32,56+18 }, life4, { 1,1 }, float(hp) / maxHP > 0.75f ? WHITE : VERY_DARK_GREEN); DrawDecal(hudLoc + vf2d{ 704 - 64+32,56+18 }, life3, { 1,1 }, float(hp) / maxHP > 0.34f && float(hp) / maxHP <= 0.75f ? WHITE : VERY_DARK_GREEN); DrawDecal(hudLoc + vf2d{ 704 - 128+32,56+18 }, life2, { 1,1 }, hp > 0 && float(hp) / maxHP <= 0.34f ? WHITE : VERY_DARK_GREEN); @@ -1795,7 +1798,18 @@ void FaceBall::RenderHud(float fElapsedTime) { } } DrawStringDecal(vf2d{ hudOffset + float(ScreenWidth() / 2 - GetTextSize(hudDisplayText).x / 2 * 4) + 32,float(ScreenHeight() - 128 - GetTextSize(hudDisplayText).y * 4) + 18 }, hudDisplayText, { 192,192,255 }, { 4,4 }); + SetDecalMode(DecalMode::ADDITIVE); DrawDecal({ float(ScreenWidth() / 2 - crosshair->sprite->width / 2),float(ScreenHeight() / 2 - crosshair->sprite->height / 2) }, crosshair, { 1,1 }, {255,255,255,128}); + if (stopDuration > 0) { + DrawPartialDecal({ hudOffset + float(ScreenWidth() / 10 - 16), float(ScreenHeight() / 4 - 16 * 4) }, vf2d{ 32,32 }*4, powerups_tex, { 3 * 32,0 }, { 32,32 },stopDuration>7?WHITE:stopDuration>2?std::abs(std::sin(10*stopDuration))>0.65?WHITE:BLACK: std::abs(std::sin(30 * stopDuration)) > 0.75 ? WHITE : BLACK); + } + if (shieldDuration > 0) { + DrawPartialDecal({ hudOffset + float(ScreenWidth() / 10 - 16), float(ScreenHeight() / 4 + ScreenHeight() / 4 * 1 - 16 * 4) }, vf2d{ 32,32 }*4, powerups_tex, { 4 * 32,0 }, { 32,32 }, shieldDuration > 7 ? WHITE : shieldDuration > 2 ? std::abs(std::sin(10 * shieldDuration)) > 0.65 ? WHITE : BLACK : std::abs(std::sin(30 * shieldDuration)) > 0.75 ? WHITE : BLACK); + } + if (camoDuration > 0) { + DrawPartialDecal({ hudOffset + float(ScreenWidth() / 10 - 16), float(ScreenHeight() / 4 + ScreenHeight() / 4 * 2 - 16 * 4) }, vf2d{ 32,32 }*4, powerups_tex, { 5 * 32,0 }, { 32,32 },camoDuration>7?WHITE:camoDuration>2?std::abs(std::sin(10*camoDuration))>0.65?WHITE:BLACK: std::abs(std::sin(30 * camoDuration)) > 0.75 ? WHITE : BLACK); + } + SetDecalMode(DecalMode::NORMAL); } GradientFillRectDecal({ 0,0 }, vf2d{ (float)ScreenWidth()/2,(float)ScreenHeight()/2 }, { (uint8_t)screenCol.r,(uint8_t)screenCol.g,(uint8_t)screenCol.b,(uint8_t)(hudShakeTime>0.2f?120:hudShakeTime>0?64:0) }, { (uint8_t)screenCol.r,(uint8_t)screenCol.g,(uint8_t)screenCol.b,(uint8_t)(hudShakeTime>0.2f?120:hudShakeTime>0?64:0) }, { (uint8_t)screenCol.r,(uint8_t)screenCol.g,(uint8_t)screenCol.b,(uint8_t)(hudShakeTime > 0.2f ? 64 : 0) }, { (uint8_t)screenCol.r,(uint8_t)screenCol.g,(uint8_t)screenCol.b,(uint8_t)(hudShakeTime>0.2f?120:hudShakeTime>0?64:0) }); GradientFillRectDecal({ float(ScreenWidth()/2),0}, vf2d{(float)ScreenWidth() / 2,(float)ScreenHeight() / 2}, {(uint8_t)screenCol.r,(uint8_t)screenCol.g,(uint8_t)screenCol.b,(uint8_t)(hudShakeTime>0.2f?120:hudShakeTime>0?64:0)}, { (uint8_t)screenCol.r,(uint8_t)screenCol.g,(uint8_t)screenCol.b,(uint8_t)(hudShakeTime > 0.2f ? 64 : 0) }, {(uint8_t)screenCol.r,(uint8_t)screenCol.g,(uint8_t)screenCol.b,(uint8_t)(hudShakeTime>0.2f?120:hudShakeTime>0?64:0)}, {(uint8_t)screenCol.r,(uint8_t)screenCol.g,(uint8_t)screenCol.b,(uint8_t)(hudShakeTime>0.2f?120:hudShakeTime>0?64:0)}); @@ -2060,6 +2074,15 @@ bool FaceBall::OnUserUpdate(float fElapsedTime) switch (mode) { case GAME: { hudDisplayText = ""; + if (stopDuration > 0) { + stopDuration -= fElapsedTime; + } + if (shieldDuration > 0) { + shieldDuration -= fElapsedTime; + } + if (camoDuration > 0) { + camoDuration -= fElapsedTime; + } for (std::vector::iterator it = bullets.begin(); it != bullets.end();) { Bullet& b = *it; if (!b.Update(fElapsedTime)) { @@ -2092,6 +2115,33 @@ bool FaceBall::OnUserUpdate(float fElapsedTime) powerups[lastPowerupCollidedWith].opened = true; hudDisplayText = powerupData[powerups[lastPowerupCollidedWith].type].name; if (GetKey(F).bPressed) { + Powerup& power = powerups[lastPowerupCollidedWith]; + switch (power.type) { + case PowerupType::ARMOR: { + armorUpgrades++; + }break; + case PowerupType::SPEED: { + speedUpgrades++; + }break; + case PowerupType::SHOTS: { + shotsUpgrades++; + }break; + case PowerupType::STOP: { + stopDuration = 20; + }break; + case PowerupType::SHIELD: { + shieldDuration = 20; + }break; + case PowerupType::CAMO: { + camoDuration = 20; + }break; + case PowerupType::MAP: { + hasMapUpgrade = true; + }break; + case PowerupType::COIN: { + score += 1000; + }break; + } powerups.erase(powerups.begin() + lastPowerupCollidedWith); lastPowerupCollidedWith = -1; } @@ -2105,6 +2155,7 @@ bool FaceBall::OnUserUpdate(float fElapsedTime) respawnTimer -= fElapsedTime; if (respawnTimer <= 0.0f) { lives--; + hasMapUpgrade = false; if (lives > 0) { hp = maxHP; player.UpdatePos(spawnLoc); diff --git a/Faceball2030/main.h b/Faceball2030/main.h index 544f880..f1f9fc0 100644 --- a/Faceball2030/main.h +++ b/Faceball2030/main.h @@ -287,6 +287,8 @@ class FaceBall : public PixelGameEngine double gameTimer = 0; int lastPowerupCollidedWith = -1; std::string hudDisplayText = ""; + float stopDuration = 0,shieldDuration=0,camoDuration=0; + bool hasMapUpgrade = false; mat4x4 matProj; @@ -299,8 +301,8 @@ class FaceBall : public PixelGameEngine float pitch = -PI / 6; std::array meter_ARMOR = { - vf2d{1034,218}, - vf2d{1039,260}, + vf2d{1039,218}, + vf2d{1040,260}, vf2d{1166,244}, vf2d{1164,195} }, @@ -320,6 +322,7 @@ class FaceBall : public PixelGameEngine Player player = { {3.7,0.3,0.7}, {{0.5,0.5},0.2} }; int hp = 3; int maxHP=hp; + int score = 0; Object walls; Object exit; vec3d freeRoamCamera = { 1,0.5,1 };