Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

Join.cpp

Go to the documentation of this file.
00001 
00007 #include "Join.h"
00008 
00009 /********************************************************************
00010  * Constructor
00011  */
00012 Join::Join() {
00013 
00014 }
00015 
00016 /********************************************************************
00017  * Constructor
00018  */
00019 Join::~Join() {
00020         unload();
00021 }
00022 
00023 /********************************************************************
00024  * Load
00025  */
00026 bool Join::load(Application *parent) {
00027         if (parent != NULL)
00028                 m_parent = parent;
00029 
00030         unsigned int i;
00031 
00032         if (!gne || !gne->isRunning())
00033                 return false;
00034 
00035         g_music.play(50);
00036 
00037         //---------------------------------------------------------
00038         // Reset my player states
00039         //---------------------------------------------------------
00040         g_players[g_myPlayerID].life = 100.0f;
00041         g_players[g_myPlayerID].frags = 0;
00042         g_players[g_myPlayerID].kills = 0;
00043         g_players[g_myPlayerID].deaths = 0;
00044         g_players[g_myPlayerID].state = PLAYER_STATE_LOADING;
00045         g_players[g_myPlayerID].ownsParticleSystem = -1;
00046         g_players[g_myPlayerID].chatClr = getPlayerChatColor(g_myPlayerID);
00047 
00048 //LOG_MISC(("x:%f, y:%f, z:%f, w:%f",g_players[g_myPlayerID].chatClr.x, g_players[g_myPlayerID].chatClr.y, g_players[g_myPlayerID].chatClr.z, g_players[g_myPlayerID].chatClr.w));
00049 
00050         for (i=0; i<SPLAYER_MAX_PLAYERS; i++) {
00051                 if (i != g_myPlayerID) {
00052                         g_players[i].state = PLAYER_STATE_OFFLINE;
00053                         g_players[i].model = 0;
00054                 }
00055         }
00056 
00057         for (i=0; i<JOIN_GALAXY_MAX_LVLS; i++) {
00058                 g_gameInfo.lvlList[i][0] = 0;
00059         }
00060 
00061         g_gameInfo.nLvls = 0;
00062         g_gameInfo.thisLevel = 0;
00063 
00064         //---------------------------------------------------------
00065         // Textures
00066         //---------------------------------------------------------
00067         if ((m_textures[JOIN_TEX_CUBEMAP] = m_parent->renderer->addCubemap(
00068                                                                                 "data\\textures\\cubemaps\\stars\\test.bmp",
00069                                                                                 "data\\textures\\cubemaps\\stars\\test.bmp",
00070                                                                                 "data\\textures\\cubemaps\\stars\\test.bmp",
00071                                                                                 "data\\textures\\cubemaps\\stars\\test.bmp",
00072                                                                                 "data\\textures\\cubemaps\\stars\\test.bmp",
00073                                                                                 "data\\textures\\cubemaps\\stars\\test.bmp")) == TEXTURE_NONE) return false;
00074 
00075         if ((m_textures[JOIN_TEX_SELECTION] = m_parent->renderer->addTexture("data\\textures\\menu\\selection.bmp")) == TEXTURE_NONE) return false;
00076         if ((m_textures[JOIN_TEX_LVL_LIST] = m_parent->renderer->addTexture("data\\textures\\join\\levellist.bmp")) == TEXTURE_NONE) return false;
00077         //if ((m_textures[JOIN_TEX_AVATAR] = m_parent->renderer->addTexture("data\\textures\\models\\0.bmp")) == TEXTURE_NONE) return false;
00078 
00079         if ((m_textures[JOIN_TEX_PLANET_0] = m_parent->renderer->addTexture("data\\textures\\planets\\planet1.bmp")) == TEXTURE_NONE) return false;
00080         if ((m_textures[JOIN_TEX_PLANET_1] = m_parent->renderer->addTexture("data\\textures\\planets\\planet2.bmp")) == TEXTURE_NONE) return false;
00081         if ((m_textures[JOIN_TEX_PLANET_2] = m_parent->renderer->addTexture("data\\textures\\planets\\planet3.bmp")) == TEXTURE_NONE) return false;
00082         if ((m_textures[JOIN_TEX_PLANET_3] = m_parent->renderer->addTexture("data\\textures\\planets\\planet4.bmp")) == TEXTURE_NONE) return false;
00083         if ((m_textures[JOIN_TEX_PLANET_4] = m_parent->renderer->addTexture("data\\textures\\planets\\planet5.bmp")) == TEXTURE_NONE) return false;
00084 
00085         for (i=0; i<MODELS; i++) {
00086                 LOG_MISC(("laddar bild:%d",i));
00087                 if ((m_texModels[i] = m_parent->renderer->addTexture(g_allModels[i].avatar)) == TEXTURE_NONE) return false;
00088         }
00089 
00090         //---------------------------------------------------------
00091         // Objects
00092         //---------------------------------------------------------
00093         m_objects[JOIN_OBJ_CUBEMAP] = new Cubemap(1.0f);
00094         m_objects[JOIN_OBJ_SPHERE] = new Sphere(0.0f, 0.0f, 0.0f, 1.0f, 26);
00095         m_objects[JOIN_OBJ_BOX] = new Box(1.05f);
00096 
00097 
00098         //---------------------------------------------------------
00099         // Sounds
00100         //---------------------------------------------------------
00101         m_sounds[JOIN_SOUND_SELECT].load("data\\sounds\\menu\\select.wav");
00102         m_sounds[JOIN_SOUND_ONLINE].load("data\\sounds\\join\\online.wav");
00103         m_sounds[JOIN_SOUND_ADD].load("data\\sounds\\menu\\select.wav");
00104         m_sounds[JOIN_SOUND_REMOVE].load("data\\sounds\\join\\remove.wav");
00105 
00106 
00107         //---------------------------------------------------------
00108         // Galaxies
00109         //---------------------------------------------------------
00110         if (!loadGalaxies()) return false;
00111 
00112         // Disable all old lights
00113         for (i=0; i<GL_MAX_LIGHTS; i++) {
00114                 glDisable(GL_LIGHT0+i);
00115         }
00116 
00117         m_lights[0].pos = Vec3(0.0f, 0.0f, 0.0f);
00118         m_lights[0].clr = Vec3(1.0f, 1.0f, 1.0f);
00119 
00120         //m_lights[1].pos = Vec3(3.0f, 5.0f, 8.0f);
00121         //m_lights[1].clr = Vec3(0.7f, 0.7f, 0.8f);
00122 
00123         m_parent->camera.setPosition(Vec3(0.0f, 30.0f, -150.0f));
00124         m_parent->camera.setHeading(90.0f);
00125         m_parent->camera.setPitch(0.0f);
00126 
00127         m_selectedGalaxy = 0;
00128         m_selectedLevel = 0;
00129 
00130         g_drawConsole = true;
00131         g_showFPS = false;
00132 
00133         // Notify network my color
00134         gne->setPlayerExtras(g_myPlayerID, g_players[g_myPlayerID].model, 0);
00135 
00136         // Notify network I'm ready
00137         g_players[g_myPlayerID].state = PLAYER_STATE_INVISIBLE;
00138         gne->setPlayerState(g_myPlayerID, PLAYER_STATE_INVISIBLE);
00139 
00140         LOG_SUCCESS(("Join game loaded"));
00141         m_loaded = true;
00142         return true;
00143 }
00144 
00145 /********************************************************************
00146  * Unload
00147  */
00148 bool Join::unload() {
00149         if (!m_loaded)
00150                 return false;
00151 
00152         unsigned int i;
00153 
00154         //---------------------------------------------------------
00155         // Textures
00156         //---------------------------------------------------------
00157         for (i=0; i<JOIN_TEXTURES; i++) {
00158                 m_parent->renderer->deleteTexture(m_textures[i]);
00159         }
00160 
00161         for (i=0; i<MODELS; i++) {
00162                 m_parent->renderer->deleteTexture(m_texModels[i]);
00163         }
00164 
00165         //---------------------------------------------------------
00166         // Objects
00167         //---------------------------------------------------------
00168         for (i=0; i<JOIN_OBJECTS; i++) {
00169                 if (m_objects[i]) {
00170                         m_objects[i]->clearVertexBuffer();
00171                         delete m_objects[i];
00172                 }
00173                 m_objects[i] = NULL;
00174         }
00175 
00176         //---------------------------------------------------------
00177         // Sounds
00178         //---------------------------------------------------------
00179         for (i=0; i<JOIN_SOUNDS; i++) {
00180                 m_sounds[i].unload();
00181         }
00182 
00183         unloadGalaxies();
00184 
00185         LOG_SUCCESS(("Join game unloaded"));
00186         m_loaded = false;
00187         return true;
00188 }
00189 
00190 /********************************************************************
00191  * Update
00192  */
00193 bool Join::update() {
00194         if (!m_loaded)
00195                 return false;
00196 
00197         this->networkLoop();
00198         this->serverLoop();
00199 
00200         if (gne->isServer()) {
00201                 bool changed = false;
00202 
00203                 //------------------------------------------------------------
00204                 // Select galaxy
00205                 //------------------------------------------------------------
00206                 if (m_parent->keys[VK_LEFT]) {
00207                         m_selectedGalaxy--;
00208                         if (m_selectedGalaxy < 0) m_selectedGalaxy = JOIN_GALAXIES-1;
00209                         //m_sounds[MENU_SOUND_SELECT].play();
00210                         m_parent->keys[VK_LEFT] = false;
00211 
00212                         m_selectedLevel = 0;
00213                         changed = true;
00214                 }
00215 
00216                 if (m_parent->keys[VK_RIGHT]) {
00217                         m_selectedGalaxy++;
00218                         if (m_selectedGalaxy > JOIN_GALAXIES-1) m_selectedGalaxy = 0;
00219                         //m_sounds[MENU_SOUND_SELECT].play();
00220                         m_parent->keys[VK_RIGHT] = false;
00221 
00222                         m_selectedLevel = 0;
00223                         changed = true;
00224                 }
00225 
00226                 //------------------------------------------------------------
00227                 // Select levels
00228                 //------------------------------------------------------------
00229                 if (m_parent->keys[VK_UP]) {
00230                         m_selectedLevel--;
00231                         if (m_selectedLevel < 0) m_selectedLevel = g_galaxies[m_selectedGalaxy].nLvls-1;
00232                         //m_sounds[MENU_SOUND_SELECT].play();
00233                         m_parent->keys[VK_UP] = false;
00234 
00235                         changed = true;
00236                 }
00237 
00238                 if (m_parent->keys[VK_DOWN]) {
00239                         m_selectedLevel++;
00240                         if (m_selectedLevel > g_galaxies[m_selectedGalaxy].nLvls-1) m_selectedLevel = 0;
00241                         //m_sounds[MENU_SOUND_SELECT].play();
00242                         m_parent->keys[VK_DOWN] = false;
00243 
00244                         changed = true;
00245                 }
00246 
00247 
00248                 if (changed) {
00249                         gne->setPlayerExtras(JOIN_NET_SELECT, m_selectedGalaxy, m_selectedLevel);
00250                 }
00251 
00252                 //------------------------------------------------------------
00253                 // Add/remove level
00254                 //------------------------------------------------------------
00255                 if (m_parent->keys[VK_SPACE]) {
00256                         addLevel(m_selectedGalaxy, m_selectedLevel);
00257                         m_parent->keys[VK_SPACE] = false;
00258                 }
00259 
00260                 if (m_parent->keys[VK_BACK]) {
00261                         removeLevel();
00262                         m_parent->keys[VK_BACK] = false;
00263                 }
00264 
00265                 //------------------------------------------------------------
00266                 // Start game
00267                 //------------------------------------------------------------
00268                 if (m_parent->keys['S']) {
00269                         g_gameInfo.thisLevel = 0;
00270                         g_gameInfo.currLvl[0] = g_gameInfo.lvlList[0][1];
00271                         g_gameInfo.currLvl[1] = g_gameInfo.lvlList[0][2];
00272                         if (g_gameInfo.lvlList[0][0] == 1) {
00273                                 gne->setPlayerExtras(JOIN_NET_START,g_gameInfo.currLvl[0],g_gameInfo.currLvl[1]);
00274                                 m_parent->keys['S'] = false;
00275                         }
00276                 }
00277 
00278         }
00279 
00280         if (m_parent->keys[VK_ESCAPE]) {
00281                 LOG_MISC(("1"));
00282                 gne->disconnect();
00283                 LOG_MISC(("2"));
00284                 Sleep(500);
00285                 LOG_MISC(("3"));
00286                 //gne->stopServer();
00287                 if (gne) delete gne;
00288                 LOG_MISC(("4"));
00289                 gne = NULL;
00290                 LOG_MISC(("5"));
00291                 g_selectedScene = SCENE_MENU;
00292                 LOG_MISC(("6"));
00293                 m_parent->keys[VK_ESCAPE] = false;
00294                 LOG_MISC(("7"));
00295 
00296         }
00297 
00306         Vec3 pos = g_galaxies[m_selectedGalaxy].pos; // + Vec3( 0.0f, -10.0f, 30.0f);
00307         float pitch = -10.0f;
00308         float heading = 0.0f;
00309 
00310         heading = -atanf(pos.x/pos.z)*180.0f/PI + (pos.z >= 0.0f ? 0.0f : -180.0f);
00311 
00312         pos += Vec3(0.0f, -3.0f, 0.0f);
00313 
00314         pos += Vec3(pos.x*0.2f, 0.0f, pos.z*0.2f);
00315 
00316         setCamera(pos, pitch, heading);
00317 
00318         return true;
00319 }
00320 
00321 /********************************************************************
00322  * Draw frame
00323  */
00324 bool Join::drawFrame() {
00325         if (!m_loaded)
00326                 return false;
00327 
00328         if (!gne) return false;
00329 
00330         float camHeading;
00331         float camPitch;
00332 
00333         camHeading = m_parent->camera.getHeading();
00334         camPitch = m_parent->camera.getPitch();
00335 
00336         m_parent->camera.setHeading(camHeading+sinf(g_time*0.0005f)*1.0f);
00337         m_parent->camera.setPitch(camPitch+sinf(g_time*0.00075f)*cosf(g_time*0.0005f)*1.0f);
00338 
00339         unsigned int i;
00340         int n;
00341 
00342         for (i=0; i<JOIN_LIGHTS; i++) {
00343                 glLightfv(GL_LIGHT0+i, GL_AMBIENT, m_lights[i].clr*0.2f);
00344                 glLightfv(GL_LIGHT0+i, GL_DIFFUSE, m_lights[i].clr);
00345                 glLightfv(GL_LIGHT0+i, GL_POSITION, Vec4(m_lights[i].pos, 0.5f));
00346                 glLightf(GL_LIGHT0+i, GL_CONSTANT_ATTENUATION, 1.0f);
00347                 glLightf(GL_LIGHT0+i, GL_LINEAR_ATTENUATION, 0.0f);
00348                 glLightf(GL_LIGHT0+i, GL_QUADRATIC_ATTENUATION, 0.0f);
00349                 glEnable(GL_LIGHT0+i);
00350         }
00351 
00352         glEnable(GL_CULL_FACE);
00353         glCullFace(GL_BACK);
00354 
00355         glDisable(GL_LIGHTING);
00356         //---------------------------------------------------------
00357         // Cube map
00358         //---------------------------------------------------------
00359         m_parent->camera.setPrespective(0.0f, false);
00360         m_parent->camera.setProjection(90.0f, g_width, g_height, 1.0f, 100.0f);
00361 
00362         glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
00363         
00364         glPushMatrix();
00365         {
00366                 m_parent->renderer->setTextures(m_textures[JOIN_TEX_CUBEMAP]);
00367                 m_parent->renderer->setDepthFunc(DEPTH_NONE);
00368                 m_parent->renderer->apply();
00369 
00370                 glScalef(15.0f, -15.0f, 15.0f);
00371                 m_objects[JOIN_OBJ_CUBEMAP]->draw();
00372         }
00373         glPopMatrix();
00374 
00375         m_parent->camera.setProjection(45.0f, g_width, g_height, 1.0f, 500.0f);
00376 
00377 
00378         //---------------------------------------------------------
00379         // Camera
00380         //---------------------------------------------------------
00381         m_parent->camera.setPrespective(g_frameTime*0.001f);
00382         m_parent->camera.updateFrustum();
00383 
00384         //m_parent->camera.setHeading(sinf(g_time*0.0005f)*0.5f);
00385         //m_parent->camera.setPitch(sinf(g_time*0.00075f)*cosf(g_time*0.0005f)*0.5f);
00386 
00387         drawGalaxies();
00388         drawLevels();
00389 
00390         m_parent->renderer->apply();
00391 
00392         glDisable(GL_LIGHTING);
00393         glDisable(GL_CULL_FACE);
00394 
00395         m_parent->defaultFont->startTextMode();
00396         {
00397                 m_parent->defaultFont->setColor(1.0f, 1.0f, 1.0f, 1.0f);
00398                 m_parent->defaultFont->print(20.0f, (g_fullscreen ? 20.0f :  50.0f), "%s galaxy - %s", g_galaxies[m_selectedGalaxy].name, g_galaxies[m_selectedGalaxy].lvls[m_selectedLevel].name);
00399 
00400                 //----------------------------------------
00401                 // Selected levels
00402                 //----------------------------------------
00403                 m_parent->defaultFont->setColor(0.0f, 1.0f, 0.0f, 1.0f);
00404                 for (i=0; i<g_gameInfo.nLvls; i++) {
00405                         if (g_gameInfo.lvlList[i][0] == 1)
00406                                 m_parent->defaultFont->print((float)g_width - 150.0f, (g_fullscreen ? 20.0f :  50.0f) + 100.0f + (float)i*20.0f, "%s", 
00407                                                                                         g_galaxies[g_gameInfo.lvlList[i][1]].lvls[g_gameInfo.lvlList[i][2]].name
00408                                                                                         );
00409                 }
00410 
00411                 if (g_gameInfo.nLvls > 0 && gne->isServer()) {
00412                         m_parent->defaultFont->setColor(0.1f, 0.5f+sinf(g_time*0.001f)*0.4f, 0.1f, 1.0f);
00413                         m_parent->defaultFont->print((float)g_width-190.0f, (float)g_height-20.0f, "Press S to start game");
00414                 }
00415                 else if (gne->isServer()) {
00416                         m_parent->defaultFont->setColor(0.5f+sinf(g_time*0.001f)*0.4f, 0.1f, 0.1f, 1.0f);
00417                         m_parent->defaultFont->print((float)g_width-210.0f, (float)g_height-20.0f, "Press SPACE to add level");
00418                 }
00419 
00420                 //----------------------------------------
00421                 // Names
00422                 //----------------------------------------
00423                 n = 0;
00424                 m_parent->defaultFont->setColor(0.0f, 1.0f, 0.0f, 1.0f);
00425                 for (i=0; i<SPLAYER_MAX_PLAYERS; i++) {
00426                         if (g_players[i].state == PLAYER_STATE_INVISIBLE) {
00427                                 m_parent->defaultFont->setColor(g_players[i].chatClr);
00428                                 m_parent->defaultFont->print(30.0f, 125.0f+(float)n*45.0f, "%s",g_players[i].name);
00429                                 n++;
00430                         }
00431                 }
00432 
00433                 glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
00434 
00435                 n = 0;
00436                 for (i=0; i<SPLAYER_MAX_PLAYERS; i++) {
00437                         if (g_players[i].state == PLAYER_STATE_INVISIBLE) {
00438                                 drawQuad(m_texModels[g_players[i].model], 5.0f, 125.0f+(float)n*45.0f-25.0f, 40.0f, 40.0f);
00439                                 n++;
00440                         }
00441                 }
00442 
00443                 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
00444 
00445                 drawQuad(m_textures[JOIN_TEX_LVL_LIST], (float)g_width - 222.0f, 60.0f - (g_fullscreen ? 30.0f :  0.0f), 228.0f, 456.0f);
00446         }
00447         m_parent->defaultFont->endTextMode();
00448 
00449 
00450         m_parent->camera.setHeading(camHeading);
00451         m_parent->camera.setPitch(camPitch);
00452 
00453         return true;
00454 }
00455 
00456 /********************************************************************
00457  * Load galaxies
00458  */
00459 bool Join::loadGalaxies() {
00460         unsigned int i;
00461 
00462 
00463         //--------------------------------------------------
00464         // ICE
00465         //--------------------------------------------------
00466         if (!setGalaxy(JOIN_GALAXY_ICE, "Ice", 3)) return false;
00467 
00468         setLvl(JOIN_GALAXY_ICE, 0, "Cold",              "ice\\ice1.lvl");
00469         setLvl(JOIN_GALAXY_ICE, 1, "Skating",   "ice\\ice2.lvl");
00470         setLvl(JOIN_GALAXY_ICE, 2, "Heaven",    "ice\\ice3.lvl");
00471 
00472 
00473         //--------------------------------------------------
00474         // LAVA
00475         //--------------------------------------------------
00476         if (!setGalaxy(JOIN_GALAXY_LAVA, "Lava", 3)) return false;
00477 
00478         setLvl(JOIN_GALAXY_LAVA, 0, "HotHotHot",        "lava\\lava1.lvl");
00479         setLvl(JOIN_GALAXY_LAVA, 1, "A warm place", "lava\\lava2.lvl");
00480         setLvl(JOIN_GALAXY_LAVA, 2, "Volcano",          "lava\\lava3.lvl");
00481 
00482 
00483         //--------------------------------------------------
00484         // PINK
00485         //--------------------------------------------------
00486         if (!setGalaxy(JOIN_GALAXY_PINK, "Pink", 3)) return false;
00487 
00488         setLvl(JOIN_GALAXY_PINK, 0, "Fun",                      "pink\\pink1.lvl");
00489         setLvl(JOIN_GALAXY_PINK, 1, "Heartbeat",        "pink\\pink2.lvl");
00490         setLvl(JOIN_GALAXY_PINK, 2, "Fluffy",           "pink\\pink3.lvl");
00491 
00492         //--------------------------------------------------
00493         // ELECTRONIC
00494         //--------------------------------------------------
00495         if (!setGalaxy(JOIN_GALAXY_ELECTRONIC, "Electronic", 3)) return false;
00496 
00497         setLvl(JOIN_GALAXY_ELECTRONIC, 0, "ZeroOne",            "electronic\\electronic1.lvl");
00498         setLvl(JOIN_GALAXY_ELECTRONIC, 1, "Bits And Bugs",      "electronic\\electronic2.lvl");
00499         setLvl(JOIN_GALAXY_ELECTRONIC, 2, ":)",                         "electronic\\electronic3.lvl");
00500 
00501 
00502 
00503 
00504 
00505         //--------------------------------------------------
00506         // ICE
00507         //--------------------------------------------------
00508         if (!setGalaxy(JOIN_GALAXY_ICE2, "Ice", 3)) return false;
00509 
00510         setLvl(JOIN_GALAXY_ICE2, 0, "Cold",             "ice\\ice1.lvl");
00511         setLvl(JOIN_GALAXY_ICE2, 1, "Skating",  "ice\\ice2.lvl");
00512         setLvl(JOIN_GALAXY_ICE2, 2, "Heaven",   "ice\\ice3.lvl");
00513 
00514 
00515         //--------------------------------------------------
00516         // LAVA
00517         //--------------------------------------------------
00518         if (!setGalaxy(JOIN_GALAXY_LAVA2, "Lava", 3)) return false;
00519 
00520         setLvl(JOIN_GALAXY_LAVA2, 0, "HotHotHot",       "lava\\lava1.lvl");
00521         setLvl(JOIN_GALAXY_LAVA2, 1, "A warm place", "lava\\lava2.lvl");
00522         setLvl(JOIN_GALAXY_LAVA2, 2, "Volcano",         "lava\\lava3.lvl");
00523 
00548         //--------------------------------------------------
00549         // Set galaxy positions
00550         //--------------------------------------------------
00551         float r = 50.0f;
00552         float rad;
00553 
00554         for (i=0; i<JOIN_GALAXIES; i++) {
00555                 rad = ((float)i*(360.0f/(float)(JOIN_GALAXIES)))*PIdiv180;
00556                 g_galaxies[i].pos.x = sinf(rad) * r;
00557                 g_galaxies[i].pos.z = cosf(rad) * r*3.0f;
00558 
00559                 //LOG_MISC(("x:%f, y:%f, z:%f", g_galaxies[i].pos.x,g_galaxies[i].pos.y,g_galaxies[i].pos.z));
00560         }
00561 
00562         return true;
00563 }
00564 
00565 /********************************************************************
00566  * Set level
00567  */
00568 void Join::setLvl(int galaxy, int lvl, const char *name, const char *file) {
00569         g_galaxies[galaxy].lvls[lvl].isSet = true;
00570         strcpy(g_galaxies[galaxy].lvls[lvl].name, name);
00571         strcpy(g_galaxies[galaxy].lvls[lvl].file, file);
00572 }
00573 
00574 /********************************************************************
00575  * Set galaxy
00576  */
00577 bool Join::setGalaxy(int galaxy, const char *name, int levels) {
00578         g_galaxies[galaxy].isSet = true;
00579         strcpy(g_galaxies[galaxy].name, name);
00580         g_galaxies[galaxy].nLvls = levels;
00581         //g_galaxies[galaxy].pos = pos;
00582 
00583         char file[256] = {0};
00584 
00585         sprintf(file, "data\\textures\\galaxies\\%s.bmp", name);
00586 
00587         if ((g_galaxies[galaxy].tex = 
00588                 m_parent->renderer->addTexture(file)) == TEXTURE_NONE) return false;
00589 
00590         return true;
00591 }
00592 
00593 /********************************************************************
00594  * Unload galaxies
00595  */
00596 bool Join::unloadGalaxies() {
00597         unsigned int i;
00598 
00599         for (i=0; i<JOIN_GALAXIES; i++) {
00600                 if (g_galaxies[i].isSet) {
00601                         m_parent->renderer->deleteTexture(g_galaxies[i].tex);
00602                 }
00603         }
00604 
00605         return true;
00606 }
00607 
00608 /********************************************************************
00609  * Draw galaxies
00610  */
00611 void Join::drawGalaxies() {
00612         unsigned int i;
00613 
00614         Vec3 camPos = m_parent->camera.getPosition();
00615         Vec3 pos;
00616         float size = 5.0f;
00617         float depth = 1.0f;
00618         //float dist;
00619 
00620         glDisable(GL_LIGHTING);
00621         glDisable(GL_CULL_FACE);
00622 
00623         for (i=0; i<JOIN_GALAXIES; i++) {
00624                 if (g_galaxies[i].isSet) {
00625                         pos = g_galaxies[i].pos;
00626                         //dist = (pos - camPos).length()*0.003f;
00627                         //if (dist < 1.0f) dist = 1.0f;
00628 
00629                         m_parent->renderer->setDepthFunc(DEPTH_NONE);
00630                         m_parent->renderer->setBlending(ONE, ONE);
00631                         m_parent->renderer->setTextures(g_galaxies[i].tex);
00632                         m_parent->renderer->apply();
00633 
00634                         //if (m_camReached && m_selectedGalaxy == i)
00635                         //      glColor3f(0.2f, 0.2f, 0.2f);
00636                         //else
00637                                 //glColor3f(1.0f, 1.0f, 1.0f);
00638 
00639                         glPushMatrix();
00640                         glTranslatef(pos.x, pos.y, pos.z);
00641                         glRotatef(g_time*0.0055f, 0.25f, 0.32f, 1.0f);
00642 
00643                         glBegin(GL_QUADS);
00644                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0);
00645                                 glVertex3f(-size, -size, 0.0f);
00646 
00647                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1);
00648                                 glVertex3f(-size, size, 0.0f);
00649 
00650                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1);
00651                                 glVertex3f(size, size, 0.0f);
00652 
00653                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0);
00654                                 glVertex3f(size, -size, 0.0f);
00655                         glEnd();
00656 
00657 
00658                         //--------------------------------------------------
00659                         // Front side
00660                         //--------------------------------------------------
00661 
00662                         // left bottom
00663                         glBegin(GL_QUADS);
00664                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0);
00665                                 glVertex3f(-size, -size, 0.0f);
00666 
00667                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0.5f);
00668                                 glVertex3f(-size, 0.0f, 0.0f);
00669 
00670                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 0.5f);
00671                                 glVertex3f(0.0f, 0.0f, depth);
00672 
00673                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 0);
00674                                 glVertex3f(0.0f, -size, 0.0f);
00675                         glEnd();
00676 
00677                         // left top
00678                         glBegin(GL_QUADS);
00679                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0.5f);
00680                                 glVertex3f(-size, 0.0f, 0.0f);
00681 
00682                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1);
00683                                 glVertex3f(-size, size, 0.0f);
00684 
00685                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 1);
00686                                 glVertex3f(0.0f, size, 0.0f);
00687 
00688                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 0.5f);
00689                                 glVertex3f(0.0f, 0.0f, depth);
00690                         glEnd();
00691 
00692                         // right top
00693                         glBegin(GL_QUADS);
00694                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 0.5f);
00695                                 glVertex3f(0.0f, 0.0f, depth);
00696 
00697                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 1);
00698                                 glVertex3f(0.0f, size, 0.0f);
00699 
00700                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1);
00701                                 glVertex3f(size, size, 0.0f);
00702 
00703                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0.5f);
00704                                 glVertex3f(size, 0.0f, 0.0f);
00705                         glEnd();
00706 
00707                         // right bottom
00708                         glBegin(GL_QUADS);
00709                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 0);
00710                                 glVertex3f(0.0f, -size, 0.0f);
00711 
00712                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 0.5f);
00713                                 glVertex3f(0.0f, 0.0f, depth);
00714 
00715                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0.5f);
00716                                 glVertex3f(size, 0.0f, 0.0f);
00717 
00718                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0);
00719                                 glVertex3f(size, -size, 0.0f);
00720                         glEnd();
00721 
00722 
00723                         //--------------------------------------------------
00724                         // Back side
00725                         //--------------------------------------------------
00726 
00727                         // left bottom
00728                         glBegin(GL_QUADS);
00729                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0);
00730                                 glVertex3f(-size, -size, 0.0f);
00731 
00732                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0.5f);
00733                                 glVertex3f(-size, 0.0f, 0.0f);
00734 
00735                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 0.5f);
00736                                 glVertex3f(0.0f, 0.0f, -depth);
00737 
00738                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 0);
00739                                 glVertex3f(0.0f, -size, 0.0f);
00740                         glEnd();
00741 
00742                         // left top
00743                         glBegin(GL_QUADS);
00744                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0.5f);
00745                                 glVertex3f(-size, 0.0f, 0.0f);
00746 
00747                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1);
00748                                 glVertex3f(-size, size, 0.0f);
00749 
00750                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 1);
00751                                 glVertex3f(0.0f, size, 0.0f);
00752 
00753                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 0.5f);
00754                                 glVertex3f(0.0f, 0.0f, -depth);
00755                         glEnd();
00756 
00757                         // right top
00758                         glBegin(GL_QUADS);
00759                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 0.5f);
00760                                 glVertex3f(0.0f, 0.0f, -depth);
00761 
00762                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 1);
00763                                 glVertex3f(0.0f, size, 0.0f);
00764 
00765                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1);
00766                                 glVertex3f(size, size, 0.0f);
00767 
00768                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0.5f);
00769                                 glVertex3f(size, 0.0f, 0.0f);
00770                         glEnd();
00771 
00772                         // right bottom
00773                         glBegin(GL_QUADS);
00774                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 0);
00775                                 glVertex3f(0.0f, -size, 0.0f);
00776 
00777                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 0.5f);
00778                                 glVertex3f(0.0f, 0.0f, -depth);
00779 
00780                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0.5f);
00781                                 glVertex3f(size, 0.0f, 0.0f);
00782 
00783                                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0);
00784                                 glVertex3f(size, -size, 0.0f);
00785                         glEnd();
00786 
00787 
00788                         //m_objects[JOIN_OBJ_SPHERE]->draw();
00789 
00790                         glPopMatrix();
00791                 }
00792         }
00793 
00794         //glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
00795 
00796         glEnable(GL_CULL_FACE);
00797         glEnable(GL_LIGHTING);
00798 }
00799 
00800 /********************************************************************
00801  * Draw levels
00802  */
00803 void Join::drawLevels() {
00804         if (!g_galaxies[m_selectedGalaxy].isSet)
00805                 return;
00806 
00807         static float angle = 0.0f;
00808         static float selected = 0.0f;
00809         float diff, diffAbs;
00810 
00811         unsigned int i;
00812         float rad;
00813         SGalaxyInfo *galaxy;
00814 
00815         galaxy = &g_galaxies[m_selectedGalaxy];
00816 
00817         diff = (float)m_selectedLevel - selected;
00818         diffAbs = (diff < 0.0f) ? -diff : diff;
00819 
00820         if (diffAbs >= (float)(galaxy->nLvls-1)*0.9f && galaxy->nLvls > 2) {
00821                 if (diff > 0.0f)
00822                         selected = (float)(galaxy->nLvls);
00823                 else
00824                         selected = -1.0f;
00825                 //LOG_MISC(("CORRECTION, selected: %f", selected));
00826         }
00827         else if (diffAbs > 0.1f) {
00828                 selected += diff*0.01*g_frameTime;
00829                 //LOG_MISC(("selected: %f",selected));
00830         }
00831 
00832 
00833         glPushMatrix();
00834         glTranslatef(galaxy->pos.x, galaxy->pos.y, galaxy->pos.z);
00835 
00836         for (i=0; i<galaxy->nLvls; i++) {
00837                 if (!galaxy->lvls[i].isSet)
00838                         continue;
00839 
00840                 glPushMatrix();
00841 
00842                 rad = (((float)i-selected)*(360.0f/(float)(galaxy->nLvls)))*PIdiv180;
00843                 
00844                 //glTranslatef(0.0f, (float)i*2.0f, 0.0f);
00845                 glTranslatef(   sinf(rad)*5.0f,
00846                                                 cosf(rad)*5.0f,
00847                                                 0.0f);
00848 
00849                 m_parent->renderer->setTextures(m_textures[i%4]);
00850                 m_parent->renderer->apply();
00851                 m_objects[JOIN_OBJ_SPHERE]->draw();
00852 
00853                 //--------------------
00854                 // Select box
00855                 //--------------------
00856                 if (i == m_selectedLevel) {
00857                         glDisable(GL_LIGHTING);
00858                         glDisable(GL_CULL_FACE);
00859                         angle += g_frameTime*0.03f;
00860                         if (angle > 360.0f)
00861                                 angle = 0.0f;
00862 
00863                         glPushMatrix();
00864                         glRotatef(angle, 0.78f, 1.0f, 0.12f);
00865                         m_parent->renderer->setBlending(ONE, ONE);
00866                         m_parent->renderer->setMask(COLOR);
00867                         m_parent->renderer->setTextures(m_textures[JOIN_TEX_SELECTION]);
00868                         m_parent->renderer->apply();
00869 
00870                         m_objects[JOIN_OBJ_BOX]->draw();
00871                         glPopMatrix();
00872                         glEnable(GL_CULL_FACE);
00873                         glEnable(GL_LIGHTING);
00874                 }
00875 
00876                 glPopMatrix();
00877         }
00878 
00879         glPopMatrix();
00880 }
00881 
00882 /********************************************************************
00883  * Set camera
00884  */
00885 void Join::setCamera(Vec3 pos, float pitch, float heading, bool soft) {
00886         Vec3 camPos = m_parent->camera.getPosition();
00887         float camPitch = m_parent->camera.getPitch();
00888         float camHeading = m_parent->camera.getHeading();
00889 
00890         Vec3 distVec = camPos - pos;
00891         float dist = distVec.length();
00892         m_camDist = dist;
00893 
00894         m_camReached = true;
00895 
00896         if (dist > 1.0f)
00897                 m_camReached = false;
00898 
00899         if (dist > 0.01f) {
00900 
00901                 if (soft)
00902                         pos = camPos - distVec.normalize() * g_frameTime * (dist < 5.0f ? dist : 5.0f) * 0.003f;
00903                 else
00904                         pos = camPos - distVec.normalize() * g_frameTime * (dist < 60.0f ? dist : 60.0f) * 0.003f;
00905         }
00906 
00907         dist = camHeading - heading;
00908         float absDist = (dist < 0.0f) ? -dist : dist;
00909         if (absDist > 0.01f) {
00910 
00911                 if (soft)
00912                         heading = camHeading - g_frameTime * (dist < 0.0f ? -0.003f : 0.003f) * (absDist < 1.5f ? absDist : 1.5f);
00913                 else
00914                         heading = camHeading - g_frameTime * (dist < 0.0f ? -0.003f : 0.003f) * (absDist < 25.0f ? absDist : 25.0f);
00915         }
00916 
00917         dist = camPitch - pitch;
00918         absDist = (dist < 0.0f) ? -dist : dist;
00919         if (absDist > 0.01f) {
00920 
00921                 if (soft)
00922                         pitch = camPitch - g_frameTime * (dist < 0.0f ? -0.003f : 0.003f) * (absDist < 2.5f ? absDist : 2.5f);
00923                 else
00924                         pitch = camPitch - g_frameTime * (dist < 0.0f ? -0.003f : 0.003f) * (absDist < 25.0f ? absDist : 25.0f);
00925         }
00926 
00927         m_parent->camera.setPosition(pos);
00928         m_parent->camera.setHeading(heading);
00929         m_parent->camera.setPitch(pitch);
00930 }
00931 
00932 /********************************************************************
00933  * Add level
00934  */
00935 bool Join::addLevel(int galaxy, int level) {
00936         if (g_gameInfo.nLvls >= MAX_LVL_LIST - 1)
00937                 return false;
00938 
00939         if (!g_galaxies[galaxy].lvls[level].isSet)
00940                 return false;
00941 
00942         //g_gameInfo.lvlList[g_gameInfo.nLvls] = g_galaxies[galaxy].lvls[level];
00943         g_gameInfo.lvlList[g_gameInfo.nLvls][0] = 1;
00944         g_gameInfo.lvlList[g_gameInfo.nLvls][1] = galaxy;
00945         g_gameInfo.lvlList[g_gameInfo.nLvls][2] = level;
00946         g_gameInfo.nLvls++;
00947 
00948         m_sounds[JOIN_SOUND_ADD].play();
00949 
00950         if (gne->isServer()) {
00951                 gne->setPlayerExtras(JOIN_NET_ADD, galaxy, level);
00952         }
00953 
00954         return true;
00955 }
00956 
00957 /********************************************************************
00958  * Remove level
00959  */
00960 bool Join::removeLevel() {
00961         if (g_gameInfo.nLvls <= 0)
00962                 return false;
00963 
00964         //g_gameInfo.lvlList[g_gameInfo.nLvls].isSet = false;
00965         g_gameInfo.lvlList[g_gameInfo.nLvls][0] = 0;
00966         g_gameInfo.nLvls--;
00967 
00968         m_sounds[JOIN_SOUND_REMOVE].play();
00969 
00970         // this can cause some "list-order" bugs...
00971         if (gne->isServer()) {
00972                 gne->setPlayerExtras(JOIN_NET_REMOVE,0,0);
00973         }
00974 
00975         return true;
00976 }
00977 
00978 /********************************************************************
00979  * Draw quad
00980  */
00981 void Join::drawQuad(TextureID tex, float x, float y, float w, float h) {
00982         //float w = 200.0f;
00983         //float h = w/8.0f;
00984 
00985         m_parent->renderer->setMask(COLOR);
00986         //m_parent->renderer->setDepthFunc(DEPTH_NONE);
00987         m_parent->renderer->setBlending(ONE, ONE);
00988         //m_parent->renderer->setTextures(m_textures[tex]);
00989         m_parent->renderer->setTextures(tex);
00990         m_parent->renderer->apply();
00991 
00992         glBegin(GL_QUADS);
00993                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1);
00994                 glVertex2f(x, y);
00995 
00996                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0);
00997                 glVertex2f(x, y+h);
00998 
00999                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0);
01000                 glVertex2f(x+w, y+h);
01001 
01002                 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1);
01003                 glVertex2f(x+w, y);
01004         glEnd();
01005 }
01006 
01007 /********************************************************************
01008  * Get player chat color
01009  */
01010 Vec4 Join::getPlayerChatColor(int playerID) {
01011         Vec4 clr;
01012 
01013         switch (playerID) {
01014                 case 0:         clr = Vec4(1.0f, 0.0f, 0.0f, 1.0f);             break;
01015                 case 1:         clr = Vec4(0.0f, 1.0f, 0.0f, 1.0f);             break;
01016                 case 2:         clr = Vec4(0.0f, 0.0f, 1.0f, 1.0f);             break;
01017                 case 3:         clr = Vec4(1.0f, 1.0f, 0.0f, 1.0f);             break;
01018                 case 4:         clr = Vec4(1.0f, 0.0f, 1.0f, 1.0f);             break;
01019                 case 5:         clr = Vec4(0.0f, 1.0f, 1.0f, 1.0f);             break;
01020                 case 6:         clr = Vec4(0.5f, 1.0f, 0.5f, 1.0f);             break;
01021                 case 7:         clr = Vec4(0.5f, 0.5f, 1.0f, 1.0f);             break;
01022                 case 8:         clr = Vec4(1.0f, 0.5f, 0.5f, 1.0f);             break;
01023                 case 9:         clr = Vec4(0.75f, 0.75f, 0.25f, 1.0f);  break;
01024                 case 10:        clr = Vec4(0.75f, 0.25f, 0.75f, 1.0f);  break;
01025                 case 11:        clr = Vec4(0.25f, 0.75f, 0.75f, 1.0f);  break;
01026                 case 12:        clr = Vec4(1.0f, 0.25f, 0.75f, 1.0f);   break;
01027                 case 13:        clr = Vec4(0.25f, 1.0f, 0.75f, 1.0f);   break;
01028                 case 14:        clr = Vec4(0.25f, 0.75f, 1.0f, 1.0f);   break;
01029                 case 15:        clr = Vec4(1.0f, 0.75f, 0.25f, 1.0f);   break;
01030                 case 16:        clr = Vec4(0.75f, 0.25f, 1.0f, 1.0f);   break;
01031                 default:        clr = Vec4(1.0f, 1.0f, 1.0f, 1.0f);             break;
01032         }
01033 
01034         LOG_MISC(("x:%f, y:%f, z:%f, w:%f",clr.x, clr.y, clr.z, clr.w));
01035 
01036         return clr;
01037 }

Generated on Sun Jun 5 15:47:04 2005 for Defacto by  doxygen 1.4.3