Add thunder to lighthouse

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7906 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2011-03-15 22:48:59 +00:00
parent 93900adace
commit bfeb8b6f31
4 changed files with 72 additions and 0 deletions

View File

@@ -17,12 +17,17 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "audio/sfx_base.hpp"
#include "audio/sfx_manager.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/material.hpp"
#include "graphics/per_camera_node.hpp"
#include "graphics/rain.hpp"
#include "modes/world.hpp"
#include "states_screens/race_gui.hpp"
#include "utils/constants.hpp"
#include "utils/random_generator.hpp"
const float RAIN_RADIUS[RAIN_RING_COUNT] = { 1.0f, 3.0f, 6.0f, 12.0f, 24.0f };
const float RAIN_Y_TO = 25.0f;
@@ -36,9 +41,14 @@ const float TEXTURE_Y_TILES[RAIN_RING_COUNT] = { 8.0f, 7.0f, 6.0f, 4.0f, 4.0f };
Rain::Rain(irr::scene::ICameraSceneNode* camera, irr::scene::ISceneNode* parent)
{
m_thunder_sound = sfx_manager->createSoundSource("thunder");
Material* m = material_manager->getMaterial("rain.png");
assert(m != NULL);
RandomGenerator g;
m_next_lightning = g.get(35);
for (int r=0; r<RAIN_RING_COUNT; r++)
{
m_x[r] = r/(float)RAIN_RING_COUNT;
@@ -109,6 +119,8 @@ Rain::~Rain()
{
m_node[r]->remove();
}
if (m_thunder_sound) sfx_manager->deleteSFX(m_thunder_sound);
}
// ----------------------------------------------------------------------------
@@ -127,6 +139,23 @@ void Rain::update(float dt)
matrix.setTextureTranslate(m_x[m], m_y[m]);
}
m_next_lightning -= dt;
if (m_next_lightning < 0.0f)
{
RaceGUIBase* gui_base = World::getWorld()->getRaceGUI();
RaceGUI* gui = dynamic_cast<RaceGUI*>(gui_base);
if (gui != NULL)
{
gui->lightning();
if (m_thunder_sound) m_thunder_sound->play();
}
RandomGenerator g;
m_next_lightning = g.get(35);
}
} // update
// ----------------------------------------------------------------------------

View File

@@ -25,6 +25,8 @@ class PerCameraNode;
#include <irrlicht.h>
const int RAIN_RING_COUNT = 5;
class SFXBase;
class Rain
{
PerCameraNode* m_node[RAIN_RING_COUNT];
@@ -34,6 +36,9 @@ class Rain
float m_x[RAIN_RING_COUNT];
float m_y[RAIN_RING_COUNT];
float m_next_lightning;
SFXBase* m_thunder_sound;
public:
Rain(irr::scene::ICameraSceneNode* camera, irr::scene::ISceneNode* parent);
~Rain();

View File

@@ -23,6 +23,8 @@
#include "irrlicht.h"
using namespace irr;
#include <algorithm>
#include "audio/music_manager.hpp"
#include "config/user_config.hpp"
#include "graphics/camera.hpp"
@@ -47,6 +49,9 @@ using namespace irr;
#include "utils/string_utils.hpp"
#include "utils/translation.hpp"
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
/** The constructor is called before anything is attached to the scene node.
* So rendering to a texture can be done here. But world is not yet fully
* created, so only the race manager can be accessed safely.
@@ -65,6 +70,7 @@ RaceGUI::RaceGUI()
m_map_height = (int)(100.0f * scaling);
m_map_left = (int)( 10.0f * scaling);
m_map_bottom = (int)( 10.0f * scaling);
m_lightning = 0.0f;
// Minimap is also rendered bigger via OpenGL, so find power-of-two again
const int map_texture = 2 << ((int) ceil(1.0 + log(128.0 * scaling)));
@@ -267,6 +273,8 @@ void RaceGUI::renderGlobal(float dt)
{
cleanupMessages(dt);
if (m_lightning > 0.0f) m_lightning -= dt;
// Special case : when 3 players play, use 4th window to display such
// stuff (but we must clear it)
if (race_manager->getNumLocalPlayers() == 3 &&
@@ -315,6 +323,7 @@ void RaceGUI::renderPlayerView(const Kart *kart)
if (!m_enabled) return;
const core::recti &viewport = kart->getCamera()->getViewport();
core::vector2df scaling = kart->getCamera()->getScaling();
//std::cout << "Applied ratio : " << viewport.getWidth()/800.0f << std::endl;
@@ -349,6 +358,7 @@ void RaceGUI::renderPlayerView(const Kart *kart)
drawAllMessages (kart, viewport, scaling);
if(!World::getWorld()->isRacePhase()) return;
RaceGUI::KartIconDisplayInfo* info = World::getWorld()->getKartsDisplayInfo();
@@ -357,6 +367,30 @@ void RaceGUI::renderPlayerView(const Kart *kart)
drawSpeedAndEnergy (kart, viewport, scaling);
drawRankLap (info, kart, viewport);
if (m_lightning > 0.0f)
{
GLint glviewport[4];
glGetIntegerv(GL_VIEWPORT, glviewport);
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
glColor4f(m_lightning, m_lightning, std::min(1.0f, m_lightning*1.5f), 1.0f);
glEnable(GL_COLOR_MATERIAL);
glDisable(GL_CULL_FACE);
glBegin(GL_QUADS);
glVertex3d(glviewport[0],glviewport[1],0);
glVertex3d(glviewport[0],glviewport[3],0);
glVertex3d(glviewport[2],glviewport[3],0);
glVertex3d(glviewport[2],glviewport[1],0);
glEnd();
glEnable(GL_BLEND);
}
} // renderPlayerView
//-----------------------------------------------------------------------------

View File

@@ -82,6 +82,8 @@ private:
typedef std::vector<TimedMessage> AllMessageType;
AllMessageType m_messages;
float m_lightning;
/** A texture with all mini dots to be displayed in the minimap for all karts. */
video::ITexture *m_marker;
@@ -203,6 +205,8 @@ public:
/** Returns the size of the texture on which to render the minimap to. */
virtual const core::dimension2du getMiniMapSize() const
{ return core::dimension2du(m_map_width, m_map_height); }
void lightning() { m_lightning = 1.0f; }
}; // RaceGUI
#endif