diff --git a/Faceball2030/main.cpp b/Faceball2030/main.cpp index f719a8c..e16aeee 100644 --- a/Faceball2030/main.cpp +++ b/Faceball2030/main.cpp @@ -140,8 +140,10 @@ void FaceBall::LoadLevel(int level) exitCoords = { x,y }; } if (id == START) { - player.UpdatePos({ x+0.5f,0.3,y+0.5f }); - fYaw = (int(mapData[y][x].facingDir) - 1) * PI / 2; + spawnLoc = { x + 0.5f,0.3,y + 0.5f }; + player.UpdatePos(spawnLoc); + spawnFacingDir = mapData[y][x].facingDir; + fYaw = (int(spawnFacingDir) - 1) * PI / 2; } } map.push_back(row); @@ -1181,7 +1183,7 @@ bool Bullet::Update(float fElapsedTime) { } else { if (FaceBall::CheckPlayerCollision(adjustedSpd,{pos.x,pos.z},0.1)) { - game->HurtPlayer(shooterID,shooterBlinking); + game->HurtPlayer(shooterID,1,shooterBlinking); return false; } else { @@ -1203,8 +1205,11 @@ bool Bullet::Update(float fElapsedTime) { return true; } -void FaceBall::HurtPlayer(EnemyID id,bool blinking) { - hp = std::max(0, hp - 1); +void FaceBall::HurtPlayer(EnemyID id,int damage,bool blinking) { + hp = std::max(0, hp - damage); + if (hp <= 0) { + respawnTimer = 3.0f; + } lastHitBy = id; lastHitByBlinking = blinking; } @@ -1246,9 +1251,6 @@ void FaceBall::RenderHud(float fElapsedTime) { RenderMeshDeathScreen(matView, vecTrianglesToRaster, o); //std::sort(vecTrianglesToRaster.begin(),vecTrianglesToRaster.end(),[](triangle&t1,triangle&t2){return (t1.p[0].z+t1.p[1].z+t1.p[2].z)/3.0f>(t2.p[0].z+t2.p[1].z+t2.p[2].z)/3.0f;}); - if (vecTrianglesToRaster.size() > 0) { - std::cout << vecTrianglesToRaster[0].p[0] << std::endl; - } triRenderCount = 0; for (auto& triToRaster : vecTrianglesToRaster) { Triangle clipped[2]; @@ -1509,6 +1511,20 @@ bool FaceBall::OnUserUpdate(float fElapsedTime) case GAME: { HandleKeys(fElapsedTime); if (hp > 0) { RenderWorld(); } + else { + respawnTimer -= fElapsedTime; + if (respawnTimer <= 0.0f) { + lives--; + if (lives > 0) { + hp = maxHP; + player.UpdatePos(spawnLoc); + fYaw = (int(spawnFacingDir) - 1) * PI / 2; + } + else { + //TODO Game over. + } + } + } RenderHud(fElapsedTime); }break; case EDITOR: { diff --git a/Faceball2030/main.h b/Faceball2030/main.h index c0ff13b..e246174 100644 --- a/Faceball2030/main.h +++ b/Faceball2030/main.h @@ -266,6 +266,9 @@ class FaceBall : public PixelGameEngine float hudOffset = 0; float hudOffsetAcc = 0; float screenAlpha = 0; + float respawnTimer = 0; + vec3d spawnLoc = { 0,0.3,0 }; + FacingDirection spawnFacingDir = FacingDirection::NORTH; EnemyID lastHitBy=EnemyID::NONE; bool lastHitByBlinking = false; @@ -315,5 +318,5 @@ class FaceBall : public PixelGameEngine static int CheckEnemyCollision(vec3d movementVector, vf2d pos, float radius, int ignoreIndex = -1); static bool CheckPlayerCollision(vec3d movementVector, vf2d pos, float radius); void SubtractTag(); - void HurtPlayer(EnemyID id, bool blinking = false); + void HurtPlayer(EnemyID id, int damage=1,bool blinking = false); }; \ No newline at end of file