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

/home/rdbrown/doxygen/cse125g1/src/game/client/hud.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 #include "textures.h"
00009 
00010 using namespace JMenu;
00011 
00012 Hud::Hud(MMNet::Player *player) {
00013         this->player = player;
00014 
00015         init();
00016         //menuInit(); //can't use this because the input stuff
00017         menuClear();
00018         healthMeter = menuAddHMeter(HEALTH_X, HEALTH_Y, HEALTH_WIDTH, HEALTH_HEIGHT,   1, 0, 0, .7,  0, 0,1,100);
00019         healthMeter->update(100);
00020 
00021         /*    
00022         team_textfield = menuAddTextfield(TEAM_X, TEAM_Y+20, TEAM_WIDTH, TEAM_HEIGHT,    0,0,0,0,    0,1,0);
00023         char buffer[50];
00024         if (player->getTeam() == MMNet::TeamThieves) {
00025                 sprintf(buffer, "Thief %s", player->getName());
00026         } else if (player->getTeam() == MMNet::TeamKnights) {
00027                 sprintf(buffer, "Knight %s", player->getName());
00028         } else {
00029                 sprintf(buffer, "Alien %s", player->getName());
00030         }
00031         team_textfield->writeText(buffer);
00032         */
00033 
00034         //status_textfield = menuAddTextfield(STATUS_X, STATUS_Y, STATUS_WIDTH, STATUS_HEIGHT,    1,0,0,.11,    0,1,0);
00035 
00036         //kills = menuAddTextfield(KILLS_X, KILLS_Y, KILLS_WIDTH, KILLS_HEIGHT,     0,0,0,0,    0,1,0);
00037         //deaths = menuAddTextfield(KILLS_X, KILLS_Y+20, KILLS_WIDTH, KILLS_HEIGHT,     0,0,0,0,    0,1,0);
00038 
00039         meleeWeapon = menuAddLabel(WEAPON_X, WEAPON_Y, WEAPON_WIDTH, WEAPON_HEIGHT, TEXTURE_MELEE_UP, TEXTURE_MELEE_DOWN, TEXTURE_MELEE_DOWN);
00040         rangeWeapon = menuAddLabel(WEAPON_X+WEAPON_WIDTH, WEAPON_Y, WEAPON_WIDTH, WEAPON_HEIGHT, TEXTURE_RANGE_UP, TEXTURE_RANGE_DOWN, TEXTURE_RANGE_DOWN);
00041         valid = true;
00042         
00043 }
00044 bool Hud::isValid() {
00045         return valid;
00046 }
00047 void Hud::update() {
00048         if (init()) {
00049                 setPositions();
00050         }
00051 
00052 
00053         healthMeter->update(player->getHealth());
00054         
00055         //sprintf(buffer,"Kills: %d",player->getKills());
00056         //kills->writeText(buffer);
00057         //sprintf(buffer,"Deaths: %d",player->getDeaths());
00058         //deaths->writeText(buffer);
00059 
00060         //the rest of the things
00061         player->getEverything(stuff);
00062         //sprintf(buffer, "fblr=%d%d%d%d, animState=%d, weaState=%d, score=%d, fired=%d, hit=%d, charging=%d, ready=$d, charge=%d", 
00063         //stuff[0],stuff[1],stuff[2],stuff[3],
00064         //stuff[4], stuff[5], player->getScore(),stuff[6],stuff[7],player->isCharging(),player->isReady(), player->getCharging());
00065         //status_textfield->writeText(buffer);
00066 
00067         //weapons
00068         if (stuff[5] == MMNet::WeaponMelee) {
00069                 meleeWeapon->changeState(ButtonDown);
00070                 rangeWeapon->changeState(ButtonUp);
00071         } else {
00072                 meleeWeapon->changeState(ButtonUp);
00073                 rangeWeapon->changeState(ButtonDown);
00074         }
00075         //ButtonUp,
00076     //ButtonDown,
00077     //ButtonRollover        
00078 
00079 }
00080 void Hud::draw() {
00081         glColor3f(0.0f,0,0);
00082 
00083         // switch to projection mode
00084         glMatrixMode(GL_PROJECTION);
00085         // save previous matrix which contains the 
00086         //settings for the perspective projection
00087         glPushMatrix();
00088         // reset matrix
00089         glLoadIdentity();
00090         // set a 2D orthographic projection
00091         GLint vPort[4];
00092         glGetIntegerv(GL_VIEWPORT, vPort);
00093 
00094         gluOrtho2D(0, vPort[2], 0, vPort[3]);
00095         // invert the y axis, down is positive
00096         glScalef(1, -1, 1);
00097         // mover the origin from the bottom left corner
00098         // to the upper left corner
00099         glTranslatef(0, -vPort[3], 0);
00100         glMatrixMode(GL_MODELVIEW);
00101         glPushMatrix();
00102         glLoadIdentity();
00103 
00104         glEnable(GL_BLEND);             // Turn Blending On
00105         glDisable(GL_DEPTH_TEST);
00106         glBlendFunc(GL_SRC_ALPHA,GL_ONE);
00107 
00108 
00109         menuRender();
00110 
00111 
00112         glDisable(GL_BLEND);            // Turn Blending Off
00113         glEnable(GL_DEPTH_TEST);        // Turn Depth Testing On
00114 
00115 
00116         // set the current matrix to GL_PROJECTION
00117         glMatrixMode(GL_PROJECTION);
00118         // restore previous settings
00119         glPopMatrix();
00120         // get back to GL_MODELVIEW matrix
00121         glMatrixMode(GL_MODELVIEW);
00122 }
00123 
00124 bool Hud::init() {
00125                 GLint vPort[4];
00126                 glGetIntegerv(GL_VIEWPORT, vPort);
00127 
00128                 gluOrtho2D(0, vPort[2], 0, vPort[3]);
00129 
00130                 if (MAX_PANEL_X == vPort[2] && MAX_PANEL_Y == vPort[3]) {
00131                         return false;
00132                 }
00133 
00134                 //lowest right corner
00135                  MAX_PANEL_X = vPort[2];
00136                  MAX_PANEL_Y = vPort[3];
00137                 //upper left corner
00138                  MIN_PANEL_X = 0;
00139                  MIN_PANEL_Y = vPort[3]-20;
00140 
00141                  HEALTH_X = 0;
00142                  HEALTH_Y = MIN_PANEL_Y+1;
00143                  HEALTH_HEIGHT = 20;
00144                  HEALTH_WIDTH = MAX_PANEL_X-1;
00145 
00146                 WEAPON_HEIGHT = 20;
00147                 WEAPON_WIDTH = 30;
00148                 WEAPON_X=MAX_PANEL_X-WEAPON_WIDTH-WEAPON_WIDTH-1;
00149                 WEAPON_Y=MIN_PANEL_Y+1;
00150 
00151                  TEAM_HEIGHT =20;
00152                  TEAM_WIDTH =300;
00153                  TEAM_X = WEAPON_X-TEAM_WIDTH-100;
00154                  TEAM_Y = MIN_PANEL_Y-TEAM_HEIGHT;
00155 
00156                  STATUS_X =0;
00157                  STATUS_Y =MIN_PANEL_Y;
00158                  STATUS_HEIGHT = 300;
00159                  STATUS_WIDTH =300;
00160 
00161                  KILLS_X =STATUS_X-KILLS_WIDTH;
00162                  KILLS_Y =MIN_PANEL_Y;
00163                  KILLS_HEIGHT =20;
00164                  KILLS_WIDTH =120;
00165 
00166                 return true;
00167 }
00168 
00169 void Hud::setPositions() {
00170                 healthMeter->updatePosition(HEALTH_X, HEALTH_Y);
00171                 healthMeter->resize(HEALTH_WIDTH, HEALTH_HEIGHT);
00172 //              kills->updatePosition(KILLS_X, KILLS_Y);
00173 //              deaths->updatePosition(KILLS_X, KILLS_Y+20);
00174 //              status_textfield->updatePosition(STATUS_X, STATUS_Y);
00175 //              team_textfield->updatePosition(TEAM_X, TEAM_Y+20);
00176                 meleeWeapon->updatePosition(WEAPON_X, WEAPON_Y);
00177                 rangeWeapon->updatePosition(WEAPON_X+WEAPON_WIDTH, WEAPON_Y);
00178 
00179 }

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