1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
4 // This file is part of Scorched3D.
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <client/ScorchedClient.h>
22 #include <landscapemap/LandscapeMaps.h>
23 #include <landscape/Wall.h>
24 #include <sound/SoundUtils.h>
25 #include <image/ImageFactory.h>
26 #include <common/Defines.h>
28 Wall::Wall() : createdTexture_(false)
30 for (int i
=0; i
<4; i
++) fadeTime_
[i
] = 0.0f
;
41 createdTexture_
= true;
42 std::string file1
= S3D::getDataFile("data/textures/bordershield/grid.bmp");
43 std::string file2
= S3D::getDataFile("data/textures/bordershield/grid.bmp");
44 ImageHandle map
= ImageFactory::loadImageHandle(file1
.c_str(), file2
.c_str(), false);
45 texture_
.create(map
, true);
48 float arenaX
= (float) ScorchedClient::instance()->getLandscapeMaps().
49 getGroundMaps().getArenaX();
50 float arenaY
= (float) ScorchedClient::instance()->getLandscapeMaps().
51 getGroundMaps().getArenaY();
52 float arenaWidth
= (float) ScorchedClient::instance()->getLandscapeMaps().
53 getGroundMaps().getArenaWidth();
54 float arenaHeight
= (float) ScorchedClient::instance()->getLandscapeMaps().
55 getGroundMaps().getArenaHeight();
57 Vector
botA(arenaX
, arenaY
, 0.0f
);
58 Vector
botB(arenaX
+ arenaWidth
, arenaY
, 0.0f
);
59 Vector
botC(arenaX
+ arenaWidth
, arenaY
+ arenaHeight
, 0.0f
);
60 Vector
botD(arenaX
, arenaY
+ arenaHeight
, 0.0f
);
61 Vector
topA(arenaX
, arenaY
, 256.0f
);
62 Vector
topB(arenaX
+ arenaWidth
, arenaY
, 256.0f
);
63 Vector
topC(arenaX
+ arenaWidth
, arenaY
+ arenaHeight
, 256.0f
);
64 Vector
topD(arenaX
, arenaY
+ arenaHeight
, 256.0f
);
66 if (fadeTime_
[OptionsTransient::LeftSide
] > 0.0f
||
67 fadeTime_
[OptionsTransient::BotSide
] > 0.0f
||
68 fadeTime_
[OptionsTransient::RightSide
] > 0.0f
||
69 fadeTime_
[OptionsTransient::TopSide
] > 0.0f
)
71 GLState
currentState(GLState::BLEND_ON
| GLState::TEXTURE_ON
);
74 drawWall(botA
, botB
, topB
, topA
, fadeTime_
[OptionsTransient::TopSide
]);
75 drawWall(botB
, botC
, topC
, topB
, fadeTime_
[OptionsTransient::RightSide
]);
76 drawWall(botC
, botD
, topD
, topC
, fadeTime_
[OptionsTransient::BotSide
]);
77 drawWall(botD
, botA
, topA
, topD
, fadeTime_
[OptionsTransient::LeftSide
]);
81 void Wall::drawWall(Vector
&cornerA
, Vector
&cornerB
,
82 Vector
&cornerC
, Vector
&cornerD
,
85 if (fade
<= 0.0f
) return;
87 int rot
= 0;//int(fade * 75) % 2;
88 float pos
= float(int(fade
* 75) % 2) * 5.0f
;
90 Vector
&wallColor
= ScorchedClient::instance()->getOptionsTransient().getWallColor();
91 glColor4f(wallColor
[0], wallColor
[1], wallColor
[2], fade
);
93 // Don't draw the wall if we are behind it
94 // as its z-ordering obscures other objects
97 case 0: glTexCoord2f(20.0f + pos, 20.0f + pos); break;
98 case 1: glTexCoord2f(0.0f + pos, 20.0f + pos); break;
100 glVertex3fv(cornerA);
103 case 0: glTexCoord2f(0.0f + pos, 20.0f + pos); break;
104 case 1: glTexCoord2f(0.0f + pos, 0.0f + pos); break;
106 glVertex3fv(cornerB);
109 case 0: glTexCoord2f(0.0f, 0.0f); break;
110 case 1: glTexCoord2f(20.0f, 0.0f); break;
112 glVertex3fv(cornerC);
115 case 0: glTexCoord2f(20.0f, 0.0f); break;
116 case 1: glTexCoord2f(20.0f, 20.0f); break;
118 glVertex3fv(cornerD);*/
122 case 0: glTexCoord2f(20.0f
+ pos
, 0.0f
+ pos
); break;
123 case 1: glTexCoord2f(20.0f
+ pos
, 20.0f
+ pos
); break;
125 glVertex3fv(cornerD
);
128 case 0: glTexCoord2f(0.0f
+ pos
, 0.0f
+ pos
); break;
129 case 1: glTexCoord2f(20.0f
+ pos
, 0.0f
+ pos
); break;
131 glVertex3fv(cornerC
);
134 case 0: glTexCoord2f(0.0f
, 20.0f
); break;
135 case 1: glTexCoord2f(0.0f
, 0.0f
); break;
137 glVertex3fv(cornerB
);
140 case 0: glTexCoord2f(20.0f
, 20.0f
); break;
141 case 1: glTexCoord2f(0.0f
, 20.0f
); break;
143 glVertex3fv(cornerA
);
147 void Wall::wallHit(Vector
&position
, OptionsTransient::WallSide side
)
149 fadeTime_
[side
] = 1.0f
;
150 CACHE_SOUND(sound
, S3D::getDataFile("data/wav/shield/hit2.wav"));
151 SoundUtils::playAbsoluteSound(VirtualSoundPriority::eAction
,
155 void Wall::simulate(float time
)
157 fadeTime_
[OptionsTransient::LeftSide
] -= time
/ 2.0f
;
158 fadeTime_
[OptionsTransient::BotSide
] -= time
/ 2.0f
;
159 fadeTime_
[OptionsTransient::TopSide
] -= time
/ 2.0f
;
160 fadeTime_
[OptionsTransient::RightSide
] -= time
/ 2.0f
;