00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <client/ScorchedClient.h>
00022 #include <landscapemap/LandscapeMaps.h>
00023 #include <landscape/Wall.h>
00024 #include <sound/SoundUtils.h>
00025 #include <image/ImageFactory.h>
00026 #include <common/Defines.h>
00027
00028 Wall::Wall() : createdTexture_(false)
00029 {
00030 for (int i=0; i<4; i++) fadeTime_[i] = 0.0f;
00031 }
00032
00033 Wall::~Wall()
00034 {
00035 }
00036
00037 void Wall::draw()
00038 {
00039 if (!createdTexture_)
00040 {
00041 createdTexture_ = true;
00042 std::string file1 = S3D::getDataFile("data/textures/bordershield/grid.bmp");
00043 std::string file2 = S3D::getDataFile("data/textures/bordershield/grid.bmp");
00044 ImageHandle map = ImageFactory::loadImageHandle(file1.c_str(), file2.c_str(), false);
00045 texture_.create(map, true);
00046 }
00047
00048 float arenaX = (float) ScorchedClient::instance()->getLandscapeMaps().
00049 getGroundMaps().getArenaX();
00050 float arenaY = (float) ScorchedClient::instance()->getLandscapeMaps().
00051 getGroundMaps().getArenaY();
00052 float arenaWidth = (float) ScorchedClient::instance()->getLandscapeMaps().
00053 getGroundMaps().getArenaWidth();
00054 float arenaHeight = (float) ScorchedClient::instance()->getLandscapeMaps().
00055 getGroundMaps().getArenaHeight();
00056
00057 Vector botA(arenaX, arenaY, 0.0f);
00058 Vector botB(arenaX + arenaWidth, arenaY, 0.0f);
00059 Vector botC(arenaX + arenaWidth, arenaY + arenaHeight, 0.0f);
00060 Vector botD(arenaX, arenaY + arenaHeight, 0.0f);
00061 Vector topA(arenaX, arenaY, 256.0f);
00062 Vector topB(arenaX + arenaWidth, arenaY, 256.0f);
00063 Vector topC(arenaX + arenaWidth, arenaY + arenaHeight, 256.0f);
00064 Vector topD(arenaX, arenaY + arenaHeight, 256.0f);
00065
00066 if (fadeTime_[OptionsTransient::LeftSide] > 0.0f ||
00067 fadeTime_[OptionsTransient::BotSide] > 0.0f ||
00068 fadeTime_[OptionsTransient::RightSide] > 0.0f ||
00069 fadeTime_[OptionsTransient::TopSide] > 0.0f)
00070 {
00071 GLState currentState(GLState::BLEND_ON | GLState::TEXTURE_ON);
00072
00073 texture_.draw();
00074 drawWall(botA, botB, topB, topA, fadeTime_[OptionsTransient::TopSide]);
00075 drawWall(botB, botC, topC, topB, fadeTime_[OptionsTransient::RightSide]);
00076 drawWall(botC, botD, topD, topC, fadeTime_[OptionsTransient::BotSide]);
00077 drawWall(botD, botA, topA, topD, fadeTime_[OptionsTransient::LeftSide]);
00078 }
00079 }
00080
00081 void Wall::drawWall(Vector &cornerA, Vector &cornerB,
00082 Vector &cornerC, Vector &cornerD,
00083 float fade)
00084 {
00085 if (fade <= 0.0f) return;
00086
00087 int rot = 0;
00088 float pos = float(int(fade * 75) % 2) * 5.0f;
00089
00090 Vector &wallColor = ScorchedClient::instance()->getOptionsTransient().getWallColor();
00091 glColor4f(wallColor[0], wallColor[1], wallColor[2], fade);
00092 glBegin(GL_QUADS);
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 switch(rot)
00121 {
00122 case 0: glTexCoord2f(20.0f + pos, 0.0f + pos); break;
00123 case 1: glTexCoord2f(20.0f + pos, 20.0f + pos); break;
00124 }
00125 glVertex3fv(cornerD);
00126 switch(rot)
00127 {
00128 case 0: glTexCoord2f(0.0f + pos, 0.0f + pos); break;
00129 case 1: glTexCoord2f(20.0f + pos, 0.0f + pos); break;
00130 }
00131 glVertex3fv(cornerC);
00132 switch(rot)
00133 {
00134 case 0: glTexCoord2f(0.0f, 20.0f); break;
00135 case 1: glTexCoord2f(0.0f, 0.0f); break;
00136 }
00137 glVertex3fv(cornerB);
00138 switch(rot)
00139 {
00140 case 0: glTexCoord2f(20.0f, 20.0f); break;
00141 case 1: glTexCoord2f(0.0f, 20.0f); break;
00142 }
00143 glVertex3fv(cornerA);
00144 glEnd();
00145 }
00146
00147 void Wall::wallHit(Vector &position, OptionsTransient::WallSide side)
00148 {
00149 fadeTime_[side] = 1.0f;
00150 CACHE_SOUND(sound, S3D::getDataFile("data/wav/shield/hit2.wav"));
00151 SoundUtils::playAbsoluteSound(VirtualSoundPriority::eAction,
00152 sound, position);
00153 }
00154
00155 void Wall::simulate(float time)
00156 {
00157 fadeTime_[OptionsTransient::LeftSide] -= time / 2.0f;
00158 fadeTime_[OptionsTransient::BotSide] -= time / 2.0f;
00159 fadeTime_[OptionsTransient::TopSide] -= time / 2.0f;
00160 fadeTime_[OptionsTransient::RightSide] -= time / 2.0f;
00161 }