ShotCountDown.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <graph/ShotCountDown.h>
00022 #include <client/ScorchedClient.h>
00023 #include <client/ClientState.h>
00024 #include <common/OptionsScorched.h>
00025 #include <common/DefinesString.h>
00026 #include <GLEXT/GLViewPort.h>
00027 #include <GLW/GLWFont.h>
00028 #include <GLW/GLWidget.h>
00029 
00030 ShotCountDown *ShotCountDown::instance_ = 0;
00031 
00032 ShotCountDown *ShotCountDown::instance()
00033 {
00034         if (!instance_)
00035         {
00036                 instance_ = new ShotCountDown;
00037         }
00038         return instance_;
00039 }
00040 
00041 ShotCountDown::ShotCountDown() : 
00042         GameStateI("ShotCountDown"),
00043         counter_(0.0f), blinkTimer_(0.0f), 
00044         showTime_(true), timerOff_(true)
00045 {
00046 }
00047 
00048 ShotCountDown::~ShotCountDown()
00049 {
00050 }
00051 
00052 void ShotCountDown::reset(float time)
00053 {
00054         timerOff_ = (time == 0.0f);
00055         counter_ = time;
00056         blinkTimer_ = 0.0f;
00057         showTime_ = true;
00058 }
00059 
00060 void ShotCountDown::simulate(const unsigned state, float simTime)
00061 {
00062         counter_ -= simTime;
00063         blinkTimer_ += simTime;
00064 
00065         if (blinkTimer_ > 0.25f)
00066         {
00067                 if (counter_ < 5.0f)
00068                 {
00069                         showTime_ = !showTime_;
00070                 }
00071                 blinkTimer_ = 0.0f;
00072         }
00073 }
00074 
00075 void ShotCountDown::draw(const unsigned currentstate)
00076 {
00077         if (timerOff_) return;
00078 
00079         // The remaining time for this shot
00080         int timeLeft = (int) counter_;
00081 
00082         // Split into seconds and minutes
00083         div_t split = div(timeLeft, 60);
00084 
00085         GLState state(GLState::BLEND_ON | GLState::TEXTURE_OFF | GLState::DEPTH_OFF); 
00086 
00087         static Vector fontColor;
00088         fontColor = Vector(0.7f, 0.7f, 0.2f);
00089         if (timeLeft <= 5)
00090         {
00091                 fontColor = Vector(0.7f, 0.0f, 0.0f);
00092         }
00093 
00094         const char *format = "%02i:%02i";
00095         if (timeLeft < 0) format = "--:--";
00096 
00097         float width = 0.0f;
00098         if (currentstate == ClientState::StateWait)
00099         {
00100                 width = GLWFont::instance()->getGameFont()->getWidth(10,
00101                         S3D::formatStringBuffer(format, 
00102                         split.quot,
00103                         split.rem));    
00104         }
00105         else 
00106         {
00107                 width = GLWFont::instance()->getGameFont()->getWidth(20,
00108                         S3D::formatStringBuffer(format, 
00109                         split.quot,
00110                         split.rem));    
00111         }
00112 
00113         float wHeight = (float) GLViewPort::getHeight();
00114         float wWidth = (float) GLViewPort::getWidth();
00115         if (currentstate == ClientState::StateWait)
00116         {
00117                 static Vector green(0.2f, 0.7f, 0.2f);
00118                 GLWFont::instance()->getGameFont()->draw(
00119                         green, 10, (wWidth/2.0f) - (width / 2), 
00120                         wHeight - 50.0f, 0.0f, 
00121                         S3D::formatStringBuffer(format, 
00122                         split.quot,
00123                         split.rem));    
00124         }
00125         else if (showTime_)
00126         {
00127                 GLWFont::instance()->getGameFont()->draw(
00128                         fontColor, 20, (wWidth/2.0f) - (width / 2),
00129                         wHeight - 50.0f, 0.0f, 
00130                         S3D::formatStringBuffer(format, 
00131                         split.quot,
00132                         split.rem));
00133         }
00134 }

Generated on Mon Feb 16 15:14:46 2009 for Scorched3D by  doxygen 1.5.3