www.pudn.com > RCApp-src.zip > Status.cpp
/* RedEye Project (http://members.ozemail.com.au/~ndmcevoy/) Copyright (C) 2003 Nick McEvoy This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ----------------------------------------------------------------- Commented for use with Doxygen (http://www.doxygen.org) ----------------------------------------------------------------- */ /*! \file Status.cpp * \brief Game status. * * This file contains the game status. */ // GLUT includes #include// RedEye includes #include "Status.h" #define HELP_TEXT "---------- CONTROLS ----------\n" \ "up arrow : forward\n" \ "down arrow : reverse\n" \ "left arrow : steer left\n" \ "right arrow : steer right\n" \ "\n------------ VIEW ------------\n" \ "f1 : player view\n" \ "f2 : external view attached\n" \ "f3 : external view detached\n" \ "f4 : tracking view\n" \ "shift+arrows : rotate external camera\n" \ "page-up/down : zoom in/out external camera\n" \ "home : reset external camera\n" \ "t : toggle tracking (closest) target\n" \ "n : select next target\n" \ "\n------------ GAME ------------\n" \ "1 : start jet ski game\n" \ "2 : start tux billy kart game\n" \ "r : restart\n" \ "h : help\n" \ "p : pause\n" \ "q : quit\n" \ "\nPress any key to continue..." #define START_TEXT "Press <1> to start jet ski game\n" \ "Press <2> to tux billy kart game\n" \ "Press for help\n" \ "Press to quit" #define LOADING_TEXT "Please wait game is loading..." #define PAUSE_TEXT "Press any key to continue..." //! The one and only instance reGameStatus* reGameStatus::mpInstance = NULL; reGameStatus::reGameStatus() { // Initialise data strcpy(msPlayerText, ""); strcpy(msStatusText, ""); strcpy(msDebugText, ""); mbHelpTextOn = false; mbStartTextOn = false; mbLoadingTextOn = false; mbPauseTextOn = false; mbPlayerTextOn = false; mbStatusTextOn = false; mbDebugTextOn = false; // Load default font mTexFont.load("fonts/courier-bold.txf"); mText.setFont(&mTexFont); } reGameStatus::~reGameStatus() { mpInstance = NULL; } reGameStatus* reGameStatus::GetInstance() { if (mpInstance == NULL) { mpInstance = new reGameStatus; } return mpInstance; } void reGameStatus::Display() { int w = glutGet(GLUT_WINDOW_WIDTH); int h = glutGet(GLUT_WINDOW_HEIGHT); int cx = w/2; int cy = h/2; // Set opengl state glPushAttrib(GL_ENABLE_BIT | GL_VIEWPORT_BIT | GL_TRANSFORM_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT | GL_FOG_BIT); glDisable(GL_LIGHTING); glDisable(GL_FOG); glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glEnable(GL_ALPHA_TEST); glEnable(GL_BLEND); glAlphaFunc(GL_GREATER, 0.1); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0, w, 0, h); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); // Draw text if (mbHelpTextOn) { DrawDropShadowText(HELP_TEXT, 14, cx-180, cy+200); } else // Display other text { if (mbStartTextOn) DrawDropShadowText(START_TEXT, 14, cx-140, cy+50); if (mbLoadingTextOn) DrawDropShadowText(LOADING_TEXT, 14, cx-140, cy); if (mbPauseTextOn) DrawDropShadowText(PAUSE_TEXT, 14, cx-140, cy); if (mbPlayerTextOn) DrawPlainText(msPlayerText, 12, 5, h-15); if (mbStatusTextOn) DrawDropShadowText(msStatusText, 14, 5, 5); if (mbDebugTextOn) DrawPlainText(msDebugText, 10, 5, h-150); } // Restore opengl state glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glPopAttrib(); } void reGameStatus::SetStatusOff() { mbHelpTextOn = false; mbStartTextOn = false; mbLoadingTextOn = false; mbPauseTextOn = false; mbPlayerTextOn = false; mbStatusTextOn = false; mbDebugTextOn = false; } void reGameStatus::SetPlayerText(const char* sText, bool bOn) { mbPlayerTextOn = bOn; strcpy(msPlayerText, sText); } void reGameStatus::SetStatusText(const char* sText, bool bOn) { mbStatusTextOn = bOn; strcpy(msStatusText, sText); } void reGameStatus::SetDebugText(const char* sText, bool bOn) { mbDebugTextOn = bOn; strcpy(msDebugText, sText); } void reGameStatus::DrawText(const char* sText, int iSize, int x, int y) { mText.setPointSize(iSize); mText.begin(); mText.start2f(x, y); mText.puts(sText); mText.end(); } void reGameStatus::DrawInverseDropShadowText(const char* sText, int iSize, int x, int y) { glColor4f(1.0f, 1.0f, 1.0f, 1.0f); DrawText(sText, iSize, x, y); glColor4f(0.0f, 0.0f, 0.0f, 1.0f); DrawText(sText, iSize, x+1, y+1); } void reGameStatus::DrawDropShadowText(const char* sText, int iSize, int x, int y) { glColor4f(0.0f, 0.0f, 0.0f, 1.0f); DrawText(sText, iSize, x, y); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); DrawText(sText, iSize, x+1, y+1); } void reGameStatus::DrawPlainText(const char* sText, int iSize, int x, int y) { glColor4f(1.0f, 1.0f, 1.0f, 1.0f); DrawText(sText, iSize, x, y); }