Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

/home/rdbrown/doxygen/cse125g1/src/game/client/hudOLD.cpp

00001 #include <stdlib.h>
00002 #include "hud.h"
00003 
00004 #include "opengl.h"
00005 #include "input/Input.h"
00006 #include "menu/menu.h"
00007 #include "resources/resources.h"
00008 
00009 
00010 Hud::Hud(MMNet::Player *player) {
00011         this->player = player;
00012 
00013         init();
00014         //menuInit(); //can't use this because the input stuff
00015         menuClear();
00016         healthMeter = menuAddMeter(HEALTH_X, HEALTH_Y, HEALTH_WIDTH, HEALTH_HEIGHT,   1, 0, 0, .7,  0, 0,1,100);
00017         healthMeter->update(100);
00018         health_textfield = menuAddTextfield(HEALTH_X, HEALTH_Y+30, 60, 14, 0,0,0,0, 0,1,0);
00019         health_textfield->writeText("MORALE");
00020 
00021         player_textfield = menuAddTextfield(TEAM_X, TEAM_Y, TEAM_WIDTH, TEAM_HEIGHT,    0,0,0,0,    0,1,0);
00022         player_textfield->writeText(player->getName());
00023     
00024         team_textfield = menuAddTextfield(TEAM_X, TEAM_Y+20, TEAM_WIDTH, TEAM_HEIGHT,    0,0,0,0,    0,1,0);
00025         char buffer[10];
00026         sprintf(buffer, "Team %d", player->getTeam());
00027         team_textfield->writeText(buffer);
00028 
00029         status_textfield = menuAddTextfield(STATUS_X, STATUS_Y, STATUS_WIDTH, STATUS_HEIGHT,    0,0,0,0,    0,1,0);
00030 
00031         kills = menuAddTextfield(KILLS_X, KILLS_Y, KILLS_WIDTH, KILLS_HEIGHT,     0,0,0,0,    0,1,0);
00032         deaths = menuAddTextfield(KILLS_X, KILLS_Y+20, KILLS_WIDTH, KILLS_HEIGHT,     0,0,0,0,    0,1,0);
00033 
00034         valid = true;
00035 }
00036 bool Hud::isValid() {
00037         return valid;
00038 }
00039 void Hud::update() {
00040         int stuff[8];
00041         init();
00042         setPositions();
00043 
00044         healthMeter->update(player->getHealth());
00045         
00046         sprintf(buffer,"Kills: %d",player->getKills());
00047         kills->writeText(buffer);
00048         sprintf(buffer,"Deaths: %d",player->getDeaths());
00049         deaths->writeText(buffer);
00050 
00051         //the rest of the things
00052         player->getEverything(stuff);
00053         sprintf(buffer, "fblr=%d%d%d%d, animState=%d, weaState=%d, score=%d, fired=%d, hit=%d, charging=%d, ready=$d, charge=%d", 
00054         stuff[0],stuff[1],stuff[2],stuff[3],
00055         stuff[4], stuff[5], player->getScore(),stuff[6],stuff[7],player->isCharging(),player->isReady(), player->getCharging());
00056         status_textfield->writeText(buffer);
00057 }
00058 void Hud::draw() {
00059         glColor3f(0.0f,0,0);
00060 
00061         // switch to projection mode
00062         glMatrixMode(GL_PROJECTION);
00063         // save previous matrix which contains the 
00064         //settings for the perspective projection
00065         glPushMatrix();
00066         // reset matrix
00067         glLoadIdentity();
00068         // set a 2D orthographic projection
00069         GLint vPort[4];
00070         glGetIntegerv(GL_VIEWPORT, vPort);
00071 
00072         gluOrtho2D(0, vPort[2], 0, vPort[3]);
00073         // invert the y axis, down is positive
00074         glScalef(1, -1, 1);
00075         // mover the origin from the bottom left corner
00076         // to the upper left corner
00077         glTranslatef(0, -vPort[3], 0);
00078         glMatrixMode(GL_MODELVIEW);
00079         glPushMatrix();
00080         glLoadIdentity();
00081 
00082         glEnable(GL_BLEND);             // Turn Blending On
00083         glDisable(GL_DEPTH_TEST);
00084         glBlendFunc(GL_SRC_ALPHA,GL_ONE);
00085 
00086         glColor4f(.5,.5,.5,.5);
00087         glPushMatrix();
00088         glBegin(GL_QUADS);
00089         glVertex3f(MIN_PANEL_X, MIN_PANEL_Y, 0.0);
00090         glVertex3f(MIN_PANEL_X, MAX_PANEL_Y, 0.0);
00091         glVertex3f(MAX_PANEL_X, MAX_PANEL_Y, 0.0);
00092         glVertex3f(MAX_PANEL_X, MIN_PANEL_Y, 0.0);
00093         glEnd();
00094         glPopMatrix();
00095 
00096         //okay, now that that crap is over, lets add a health meter okay okay okay . i think i will stop drinking so much water and getting high off of prrrrrrrrrrrrrrrrrrrrrrrr
00097         menuRender();
00098 
00099 
00100         glDisable(GL_BLEND);            // Turn Blending Off
00101         glEnable(GL_DEPTH_TEST);        // Turn Depth Testing On
00102 
00103 
00104         // set the current matrix to GL_PROJECTION
00105         glMatrixMode(GL_PROJECTION);
00106         // restore previous settings
00107         glPopMatrix();
00108         // get back to GL_MODELVIEW matrix
00109         glMatrixMode(GL_MODELVIEW);
00110 }
00111 
00112 void Hud::init() {
00113                 GLint vPort[4];
00114                 glGetIntegerv(GL_VIEWPORT, vPort);
00115 
00116                 gluOrtho2D(0, vPort[2], 0, vPort[3]);
00117                 //lowest right corner
00118                  MAX_PANEL_X =800;
00119                  MAX_PANEL_Y =vPort[3];
00120                 //upper left corner
00121                  MIN_PANEL_X = 0;
00122                  MIN_PANEL_Y = vPort[3]-100;
00123 
00124                  HEALTH_X = MAX_SCREEN_X/2;
00125                  HEALTH_Y = MIN_PANEL_Y+1;
00126                  HEALTH_HEIGHT =99;
00127                  HEALTH_WIDTH =50;
00128 
00129                 TEAM_X =MAX_SCREEN_X/4;
00130                 TEAM_Y =MIN_PANEL_Y;
00131                  TEAM_HEIGHT =20;
00132                  TEAM_WIDTH =120;
00133 
00134                  STATUS_X =MAX_SCREEN_X/4*3;
00135                  STATUS_Y =MIN_PANEL_Y;
00136                  STATUS_HEIGHT = HEALTH_HEIGHT;
00137                  STATUS_WIDTH =200;
00138 
00139                  KILLS_X =STATUS_X-KILLS_WIDTH;
00140                  KILLS_Y =MIN_PANEL_Y;
00141                  KILLS_HEIGHT =20;
00142                  KILLS_WIDTH =120;
00143 
00144 }
00145 
00146 void Hud::setPositions() {
00147                 healthMeter->updatePosition(HEALTH_X, HEALTH_Y);
00148                 health_textfield->updatePosition(HEALTH_X, HEALTH_Y+30);
00149                 kills->updatePosition(KILLS_X, KILLS_Y);
00150                 deaths->updatePosition(KILLS_X, KILLS_Y+20);
00151                 status_textfield->updatePosition(STATUS_X, STATUS_Y);
00152                 player_textfield->updatePosition(TEAM_X, TEAM_Y);
00153                 team_textfield->updatePosition(TEAM_X, TEAM_Y+20);
00154 
00155 }

Generated on Thu Aug 18 16:03:08 2005 for Robin Hood: Thieves & Knights by doxygen1.2.18