2010-02-20 21:22:05 -05:00
|
|
|
|
|
|
|
#include "states_screens/grand_prix_over.hpp"
|
|
|
|
|
2010-02-21 19:46:04 -05:00
|
|
|
#include "audio/sound_manager.hpp"
|
2010-02-21 18:10:24 -05:00
|
|
|
#include "graphics/irr_driver.hpp"
|
2010-02-20 21:22:05 -05:00
|
|
|
#include "guiengine/engine.hpp"
|
|
|
|
#include "io/file_manager.hpp"
|
|
|
|
#include "items/item_manager.hpp"
|
2010-02-21 18:10:24 -05:00
|
|
|
#include "karts/kart_properties_manager.hpp"
|
2010-02-20 21:22:05 -05:00
|
|
|
#include "states_screens/state_manager.hpp"
|
|
|
|
#include "utils/translation.hpp"
|
|
|
|
|
|
|
|
#include <SColor.h>
|
2010-02-21 18:10:24 -05:00
|
|
|
#include <iostream>
|
2010-02-20 21:22:05 -05:00
|
|
|
|
|
|
|
using namespace irr::core;
|
|
|
|
using namespace irr::gui;
|
|
|
|
using namespace irr::video;
|
|
|
|
|
2010-02-21 18:10:24 -05:00
|
|
|
const float INITIAL_Y = -3.0f;
|
|
|
|
const float INITIAL_PODIUM_Y = -3.6f;
|
|
|
|
const float PODIUM_HEIGHT[3] = { 0.325f, 0.5f, 0.15f };
|
|
|
|
|
2010-02-20 21:22:05 -05:00
|
|
|
// -------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
GrandPrixOver::GrandPrixOver() : Screen("grand_prix_over.stkgui")
|
|
|
|
{
|
|
|
|
setNeeds3D(true);
|
|
|
|
|
|
|
|
throttleFPS = false;
|
2010-02-21 18:10:24 -05:00
|
|
|
|
|
|
|
m_kart_node[0] = NULL;
|
|
|
|
m_kart_node[1] = NULL;
|
|
|
|
m_kart_node[2] = NULL;
|
2010-02-21 19:46:04 -05:00
|
|
|
|
|
|
|
m_podium_x[0] = 1.4f;
|
|
|
|
m_podium_z[0] = 0.0f;
|
|
|
|
|
|
|
|
m_podium_x[1] = 2.2f;
|
|
|
|
m_podium_z[1] = 0.5f;
|
|
|
|
|
|
|
|
m_podium_x[2] = 3.0f;
|
|
|
|
m_podium_z[2] = 0.0f;
|
2010-02-20 21:22:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------
|
|
|
|
|
2010-02-22 11:51:48 -05:00
|
|
|
void traverse(scene::ISceneNode* curr, int level=0)
|
|
|
|
{
|
|
|
|
for (int n=0; n<level; n++) std::cout << "| ";
|
|
|
|
|
|
|
|
unsigned int type = curr->getType();
|
|
|
|
const char* ptr = (const char*)&type;
|
|
|
|
|
|
|
|
std::cout << "+ " << curr->getName() << " ("
|
|
|
|
<< char(ptr[0]) << char(ptr[1])
|
|
|
|
<< char(ptr[2]) << char(ptr[3]) << std::endl;
|
|
|
|
|
|
|
|
const core::list< scene::ISceneNode * >& children = curr->getChildren();
|
|
|
|
for (core::list<scene::ISceneNode*>::ConstIterator it=children.begin(); it != children.end(); it++)
|
|
|
|
{
|
|
|
|
traverse(*it, level+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-02-20 21:22:05 -05:00
|
|
|
void GrandPrixOver::init()
|
|
|
|
{
|
2010-02-21 19:46:04 -05:00
|
|
|
sound_manager->startMusic(sound_manager->getMusicInformation(file_manager->getMusicFile("win_theme.music")));
|
|
|
|
|
2010-02-21 18:10:24 -05:00
|
|
|
m_phase = 1;
|
2010-02-20 21:22:05 -05:00
|
|
|
m_sky_angle = 0.0f;
|
|
|
|
m_global_time = 0.0f;
|
|
|
|
|
2010-02-21 18:10:24 -05:00
|
|
|
m_sky = irr_driver->addSkyDome(file_manager->getTextureFile("clouds.png"),
|
|
|
|
16 /* hori_res */, 16 /* vert_res */,
|
|
|
|
1.0f /* texture_percent */, 2.0f /* sphere_percent */);
|
2010-02-20 21:22:05 -05:00
|
|
|
|
|
|
|
m_camera = irr_driver->addCameraSceneNode();
|
2010-02-21 19:15:36 -05:00
|
|
|
m_camera_x = 3.0f;
|
|
|
|
m_camera_y = 0.0f;
|
|
|
|
m_camera_z = -5.0f;
|
|
|
|
m_camera->setPosition( core::vector3df(m_camera_x, m_camera_y, m_camera_z) );
|
2010-02-20 21:22:05 -05:00
|
|
|
m_camera->setUpVector( core::vector3df(0.0, 1.0, 0.0) );
|
2010-02-21 19:15:36 -05:00
|
|
|
|
|
|
|
m_camera_target_x = 1.5f;
|
|
|
|
m_camera_target_z = 0.0f;
|
|
|
|
m_camera->setTarget( core::vector3df(m_camera_target_x, -2.0f, m_camera_target_z) );
|
2010-02-20 21:22:05 -05:00
|
|
|
m_camera->setFOV( DEGREE_TO_RAD*50.0f );
|
|
|
|
m_camera->updateAbsolutePosition();
|
|
|
|
|
2010-02-21 18:10:24 -05:00
|
|
|
|
|
|
|
scene::IMesh* model_village = irr_driver->getMesh( file_manager->getModelFile("village.b3d") );
|
|
|
|
assert(model_village != NULL);
|
|
|
|
m_village = irr_driver->addMesh(model_village);
|
|
|
|
m_village->setPosition( core::vector3df(2, INITIAL_Y, 0) );
|
|
|
|
|
|
|
|
|
|
|
|
scene::IMesh* podium_model = irr_driver->getMesh( file_manager->getModelFile("wood_podium.b3d") );
|
|
|
|
assert(podium_model != NULL);
|
|
|
|
|
|
|
|
|
|
|
|
m_podium_step[0] = irr_driver->addMesh(podium_model);
|
|
|
|
m_podium_step[0]->setPosition( core::vector3df(m_podium_x[0], INITIAL_PODIUM_Y, m_podium_z[0]) );
|
|
|
|
|
|
|
|
m_podium_step[1] = irr_driver->addMesh(podium_model);
|
|
|
|
m_podium_step[1]->setPosition( core::vector3df(m_podium_x[1], INITIAL_PODIUM_Y, m_podium_z[1]) );
|
|
|
|
|
|
|
|
m_podium_step[2] = irr_driver->addMesh(podium_model);
|
|
|
|
m_podium_step[2]->setPosition( core::vector3df(m_podium_x[2], INITIAL_PODIUM_Y, m_podium_z[2]) );
|
|
|
|
|
2010-02-22 11:51:48 -05:00
|
|
|
scene::ISceneManager* sceneManager = irr_driver->getSceneManager();
|
|
|
|
sceneManager->setAmbientLight(video::SColor(255, 120, 120, 120));
|
2010-02-20 21:22:05 -05:00
|
|
|
|
|
|
|
const core::vector3df &sun_pos = core::vector3df( 0, 200, 100.0f );
|
2010-02-22 14:01:00 -05:00
|
|
|
m_light = irr_driver->getSceneManager()->addLightSceneNode(NULL, sun_pos,
|
|
|
|
video::SColorf(1.0f,1.0f,1.0f),
|
|
|
|
300.0f /* radius */);
|
2010-02-20 21:22:05 -05:00
|
|
|
m_light->getLightData().DiffuseColor = irr::video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
|
2010-02-22 14:01:00 -05:00
|
|
|
m_light->getLightData().SpecularColor = irr::video::SColorf(1.0f, 0.0f, 0.0f, 0.0f);
|
2010-02-20 21:22:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void GrandPrixOver::tearDown()
|
|
|
|
{
|
|
|
|
irr_driver->removeNode(m_sky);
|
|
|
|
m_sky = NULL;
|
|
|
|
|
|
|
|
irr_driver->removeCameraSceneNode(m_camera);
|
|
|
|
m_camera = NULL;
|
|
|
|
|
|
|
|
irr_driver->removeNode(m_light);
|
|
|
|
m_light = NULL;
|
2010-02-21 18:10:24 -05:00
|
|
|
|
|
|
|
irr_driver->removeNode(m_village);
|
|
|
|
m_village = NULL;
|
|
|
|
|
|
|
|
for (int n=0; n<3; n++)
|
|
|
|
{
|
|
|
|
irr_driver->removeNode(m_podium_step[n]);
|
|
|
|
m_podium_step[n] = NULL;
|
2010-02-21 18:35:01 -05:00
|
|
|
if (m_kart_node[n] != NULL) irr_driver->removeNode(m_kart_node[n]);
|
2010-02-21 18:10:24 -05:00
|
|
|
m_kart_node[n] = NULL;
|
|
|
|
}
|
2010-02-21 19:46:04 -05:00
|
|
|
|
|
|
|
// restore menu music when leaving (FIXME: this assume we always go to menu after)
|
|
|
|
sound_manager->stopMusic();
|
|
|
|
sound_manager->startMusic(stk_config->m_title_music);
|
|
|
|
|
2010-02-20 21:22:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void GrandPrixOver::onUpdate(float dt, irr::video::IVideoDriver* driver)
|
|
|
|
{
|
|
|
|
m_global_time += dt;
|
|
|
|
|
|
|
|
m_sky_angle += dt*2;
|
|
|
|
if (m_sky_angle > 360) m_sky_angle -= 360;
|
|
|
|
m_sky->setRotation( core::vector3df(0, m_sky_angle, 0) );
|
|
|
|
|
|
|
|
|
2010-02-21 18:10:24 -05:00
|
|
|
// ---- karts move
|
|
|
|
if (m_phase == 1)
|
|
|
|
{
|
2010-02-21 18:45:13 -05:00
|
|
|
int karts_not_yet_done = 0;
|
2010-02-21 18:10:24 -05:00
|
|
|
for (int k=0; k<3; k++)
|
|
|
|
{
|
|
|
|
if (m_kart_node[k] != NULL)
|
|
|
|
{
|
2010-02-21 19:46:04 -05:00
|
|
|
|
2010-02-21 18:10:24 -05:00
|
|
|
if (fabsf(m_kart_z[k] - m_podium_z[k]) > dt)
|
|
|
|
{
|
|
|
|
if (m_kart_z[k] < m_podium_z[k])
|
|
|
|
{
|
|
|
|
m_kart_z[k] += dt;
|
|
|
|
}
|
|
|
|
else if (m_kart_z[k] > m_podium_z[k])
|
|
|
|
{
|
|
|
|
m_kart_z[k] -= dt;
|
|
|
|
}
|
2010-02-21 19:46:04 -05:00
|
|
|
karts_not_yet_done++;
|
2010-02-21 18:10:24 -05:00
|
|
|
}
|
2010-02-21 19:46:04 -05:00
|
|
|
|
2010-02-21 18:10:24 -05:00
|
|
|
m_kart_node[k]->setPosition( core::vector3df(m_kart_x[k], m_kart_y[k], m_kart_z[k]) );
|
|
|
|
}
|
|
|
|
} // end for
|
|
|
|
|
2010-02-21 18:45:13 -05:00
|
|
|
if (karts_not_yet_done == 0)
|
2010-02-21 18:10:24 -05:00
|
|
|
{
|
|
|
|
m_phase = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---- Karts Rotate
|
|
|
|
else if (m_phase == 2)
|
|
|
|
{
|
2010-02-21 18:45:13 -05:00
|
|
|
int karts_not_yet_done = 0;
|
2010-02-21 18:10:24 -05:00
|
|
|
for (int k=0; k<3; k++)
|
|
|
|
{
|
|
|
|
if (m_kart_node[k] != NULL)
|
|
|
|
{
|
|
|
|
if (m_kart_rotation[k] < 180.f)
|
|
|
|
{
|
|
|
|
m_kart_rotation[k] += 25.0f*dt;
|
|
|
|
m_kart_node[k]->setRotation( core::vector3df(0, m_kart_rotation[k], 0) );
|
|
|
|
m_podium_step[k]->setRotation( core::vector3df(0, m_kart_rotation[k], 0) );
|
2010-02-21 18:45:13 -05:00
|
|
|
karts_not_yet_done++;
|
2010-02-21 18:10:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // end for
|
|
|
|
|
2010-02-21 18:45:13 -05:00
|
|
|
if (karts_not_yet_done == 0) m_phase = 3;
|
2010-02-21 18:10:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---- Podium Rises
|
|
|
|
else if (m_phase == 3)
|
|
|
|
{
|
|
|
|
for (int k=0; k<3; k++)
|
|
|
|
{
|
|
|
|
if (m_kart_node[k] != NULL)
|
|
|
|
{
|
|
|
|
const float y_target = INITIAL_Y + PODIUM_HEIGHT[k];
|
|
|
|
if (m_kart_y[k] < y_target)
|
|
|
|
{
|
|
|
|
m_kart_y[k] += dt*(PODIUM_HEIGHT[k]);
|
|
|
|
m_kart_node[k]->setPosition( core::vector3df(m_kart_x[k], m_kart_y[k], m_kart_z[k]) );
|
|
|
|
m_podium_step[k]->setPosition( core::vector3df(m_podium_x[k],
|
|
|
|
INITIAL_PODIUM_Y - (INITIAL_Y - m_kart_y[k]),
|
|
|
|
m_podium_z[k]) );
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // end for
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-02-21 19:15:36 -05:00
|
|
|
if (m_phase > 1)
|
|
|
|
{
|
|
|
|
//m_camera_x = 3.0f;
|
|
|
|
if (m_camera_z < -2.0f) m_camera_z += dt*0.2f;
|
|
|
|
if (m_camera_x < m_podium_x[1]) m_camera_x += dt*0.1f;
|
|
|
|
else if (m_camera_x > m_podium_x[1]) m_camera_x -= dt*0.1f;
|
|
|
|
|
|
|
|
if (m_camera_target_x < m_podium_x[1]) m_camera_target_x += dt*0.1f;
|
|
|
|
|
|
|
|
if (m_camera_y > -1.8f) m_camera_y -= dt*0.1f;
|
|
|
|
//else if (m_camera_y < -3.0f) m_camera_y += dt*0.1f;
|
|
|
|
|
|
|
|
|
|
|
|
m_camera->setTarget( core::vector3df(m_camera_target_x, -2.0f, m_camera_target_z) );
|
|
|
|
|
|
|
|
m_camera->setPosition( core::vector3df(m_camera_x, m_camera_y, m_camera_z) );
|
|
|
|
m_camera->setUpVector( core::vector3df(0.0, 1.0, 0.0) );
|
|
|
|
m_camera->updateAbsolutePosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-21 18:10:24 -05:00
|
|
|
// ---- title
|
2010-02-20 21:22:05 -05:00
|
|
|
static const int w = irr_driver->getFrameSize().Width;
|
|
|
|
static const int h = irr_driver->getFrameSize().Height;
|
|
|
|
const irr::video::SColor color(255, 255, 255, 255);
|
|
|
|
|
|
|
|
static int test_y = 0;
|
|
|
|
|
|
|
|
GUIEngine::getTitleFont()->draw(_("Grand Prix Results"),
|
|
|
|
core::rect< s32 >( 0, test_y, w, h/10 ),
|
|
|
|
color,
|
|
|
|
true/* center h */, true /* center v */ );
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void GrandPrixOver::eventCallback(GUIEngine::Widget* widget,
|
|
|
|
const std::string& name,
|
|
|
|
const int playerID)
|
|
|
|
{
|
|
|
|
if (name == "continue")
|
|
|
|
{
|
|
|
|
// we assume the main menu was pushed before showing this menu
|
|
|
|
StateManager::get()->popMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------
|
2010-02-21 18:10:24 -05:00
|
|
|
|
|
|
|
void GrandPrixOver::setKarts(const std::string idents_arg[3])
|
|
|
|
{
|
|
|
|
// reorder in "podium order" (i.e. second player to the left, first player in the middle, last at the right)
|
|
|
|
std::string idents[3];
|
|
|
|
idents[0] = idents_arg[1];
|
|
|
|
idents[1] = idents_arg[0];
|
|
|
|
idents[2] = idents_arg[2];
|
|
|
|
|
|
|
|
for (int n=0; n<3; n++)
|
|
|
|
{
|
|
|
|
if (idents[n].size() == 0) continue;
|
|
|
|
|
|
|
|
scene::ISceneNode* kart_main_node = NULL;
|
|
|
|
|
|
|
|
const KartProperties* kart = kart_properties_manager->getKart(idents[n]);
|
|
|
|
if (kart != NULL)
|
|
|
|
{
|
|
|
|
KartModel* kartModel = kart->getKartModel();
|
|
|
|
|
2010-02-21 19:46:04 -05:00
|
|
|
m_kart_x[n] = m_podium_x[n];
|
2010-02-21 18:10:24 -05:00
|
|
|
m_kart_y[n] = INITIAL_Y;
|
|
|
|
m_kart_z[n] = -4;
|
|
|
|
m_kart_rotation[n] = 0.0f;
|
|
|
|
|
|
|
|
kart_main_node = irr_driver->addMesh(kartModel->getModel());
|
|
|
|
kart_main_node->setPosition( core::vector3df(m_kart_x[n], m_kart_y[n], m_kart_z[n]) );
|
2010-02-22 07:02:13 -05:00
|
|
|
kart_main_node->setScale( core::vector3df(0.4f, 0.4f, 0.4f) );
|
2010-02-21 18:10:24 -05:00
|
|
|
kart_main_node->updateAbsolutePosition();
|
|
|
|
|
|
|
|
for (int wheel=0; wheel<4; wheel++)
|
|
|
|
{
|
|
|
|
scene::ISceneNode* wheel_model = irr_driver->getSceneManager()->addMeshSceneNode(
|
|
|
|
kartModel->getWheelModel(wheel),
|
|
|
|
kart_main_node);
|
|
|
|
wheel_model->setPosition( kartModel->getWheelGraphicsPosition(wheel).toIrrVector() );
|
|
|
|
wheel_model->updateAbsolutePosition();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_kart_node[n] = kart_main_node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------
|