//////////////////////////////////////////////////////////////////////////////// //! //\file Input.cpp //\author Bryce Mercado //\par email: bmercado\@digipen.edu //\par DigiPen login: bmercad //\par Course: GAM250 //\date 02/21/2006 //\brief // Implementation file for the HUD functions // 02/24/06 3:30pm bmercado - Created HUD all nicey nice. Take that! // 02/24/06 4:20pm bmercado - Implemented second player info. // 03/03/06 1:15pm mbetts - Renamed SINGLETON_Player1.h to PlayerObject.h. // 03/03/06 3:15pm bmercado - Fixed negative health bar. //////////////////////////////////////////////////////////////////////////////// #include "..\Header\Graphics.h" // for Render #include "..\Header\Texture.h" #include "..\Header\PlayerObject.h" using namespace TMII; extern std::vector Textures; // In Texture.h extern std::vector HudTextures; extern Player_Object PlayerOne; extern Player_Object PlayerTwo; extern Graphics GraphicsEngine; //////////////////////////////////////////////////////////////////////////////// //! // RenderHUD // Renders all the HUD elements. // //////////////////////////////////////////////////////////////////////////////// void RenderHUD(void) { // A magic number. Icons are 64 pixels wide, plus 16 for a little space int AfterIcon = 80; // Another one. The HUD is 64 pixels tall. int HalfwayDown = 32; // Yet another. Each number is 32 pixels wide. Max of 10. // Putting it under last one. int EndOfScore = 288; // This one is for Robomopho's junk. Screen is 1024 pixels wide, // TMB's stuff takes up 80 + 320. 1023 - 400 = 623 int RBMPStart = 623; // Single player can switch between robots. unsigned P1Icon = HUD_TMB; if( PlayerOne.GetAvatar()->GetType() == robomopho ) { P1Icon = HUD_RBMP; } // A double to hold how much of the power bar to display based on the // percentage given by currHealth / maxHealth. double P1Power = PlayerOne.GetAvatar()->GetHealth() / (PlayerOne.GetAvatar()->GetMaxHealth() * 1.0); if( P1Power < 0 ) P1Power = 0; Vector P1PowerSize = HudTextures[HUD_POWER].GetSize(); P1PowerSize.SetX( static_cast(P1PowerSize.GetX()*P1Power) ); // Holds the current weapon of player one. Add HUD_WEAPONS, so the // value corresponds to the correct texture in HudTextures. unsigned P1Weapon = PlayerOne.GetAvatar()->GetWeapon() + HUD_WEAPONS; // Draw Treasuremobot Info // Draw robot Icon GraphicsEngine.Render(HudTextures[P1Icon].GetTextureMap()[0].frame[0], HudTextures[P1Icon].GetSize(), 2, 0, 0, 0); // Draw Treasuremobot's score GraphicsEngine.RenderNum(PlayerOne.GetAvatar()->GetMoney(),Vector(AfterIcon,0),10,true); // Draw Battery GraphicsEngine.Render(HudTextures[HUD_BATTERY].GetTextureMap()[0].frame[0], HudTextures[HUD_BATTERY].GetSize(), 2, AfterIcon, HalfwayDown, 0); // Draw Power GraphicsEngine.Render(HudTextures[HUD_POWER].GetTextureMap()[0].frame[0], P1PowerSize, 2, AfterIcon, HalfwayDown, 0,0.0f, Color(1.0f, 1.0f, 1.0f, 1.0f)); // Draw PlayerOne current weapon icon GraphicsEngine.Render(HudTextures[P1Weapon].GetTextureMap()[0].frame[0], HudTextures[P1Weapon].GetSize(), 2, AfterIcon+EndOfScore, HalfwayDown, 0); //Only draw energy bar when weapon with energy is selected if(PlayerOne.GetAvatar()->GetWeapon()) { // A double to hold how much of the energy to display based on the // percentage given by curEnergy / maxEnergy. double P1Energy = PlayerOne.GetAvatar()->Energy(PlayerOne.GetAvatar()->GetWeapon()-1) / (PlayerOne.GetAvatar()->MaxEnergy(PlayerOne.GetAvatar()->GetWeapon()-1) * 1.0); Vector P1EnergySize = HudTextures[HUD_POWER].GetSize(); P1EnergySize.SetX( static_cast(P1EnergySize.GetX()*P1Energy) ); //Draw Energy Bar GraphicsEngine.Render(HudTextures[HUD_POWER].GetTextureMap()[0].frame[0], P1EnergySize, 2, AfterIcon, HalfwayDown+16, 0, 0.0f, Color(1.0f, 0.5f, .3f, 1.0f)); } // Draw Robomopho Info only if second player is playing if( PlayerTwo.GetAvatar() != NULL ) { // A double to hold how much of the power bar to display based on the // percentage given by currHealth / maxHealth. double P2Power = PlayerTwo.GetAvatar()->GetHealth() / (PlayerTwo.GetAvatar()->GetMaxHealth() * 1.0); Vector P2PowerSize = HudTextures[HUD_POWER].GetSize(); P2PowerSize.SetX( static_cast(P2PowerSize.GetX()*P2Power) ); // Holds the current weapon of player two. Add HUD_WEAPONS, so the // value corresponds to the correct texture in HudTextures. unsigned P2Weapon = PlayerTwo.GetAvatar()->GetWeapon() + HUD_WEAPONS; // Draw robot Icon GraphicsEngine.Render(HudTextures[HUD_RBMP].GetTextureMap()[0].frame[0], HudTextures[HUD_RBMP].GetSize(), 2, RBMPStart, 0, 0); // Draw Robomopho's score GraphicsEngine.RenderNum(PlayerTwo.GetAvatar()->GetMoney(), Vector(RBMPStart+AfterIcon,0),10,true); // Draw Battery GraphicsEngine.Render(HudTextures[HUD_BATTERY].GetTextureMap()[0].frame[0], HudTextures[HUD_BATTERY].GetSize(), 2, RBMPStart+AfterIcon, HalfwayDown, 0); // Draw Power GraphicsEngine.Render(HudTextures[HUD_POWER].GetTextureMap()[0].frame[0], P2PowerSize, 2, RBMPStart+AfterIcon, HalfwayDown, 0); // Draw PlayerOne current weapon icon GraphicsEngine.Render(HudTextures[P2Weapon].GetTextureMap()[0].frame[0], HudTextures[P2Weapon].GetSize(), 2, RBMPStart+AfterIcon+EndOfScore, HalfwayDown, 0); } }