Add an alert icon when another kart is nearby

This commit is contained in:
Alayan 2018-09-29 15:42:50 +02:00
parent 799f6d98c1
commit dcec81c7d5
4 changed files with 216 additions and 151 deletions

View File

@ -39,6 +39,7 @@ using namespace irr;
#include "guiengine/scalable_font.hpp"
#include "io/file_manager.hpp"
#include "items/powerup_manager.hpp"
#include "items/projectile_manager.hpp"
#include "karts/abstract_kart.hpp"
#include "karts/controller/controller.hpp"
#include "karts/controller/spare_tire_ai.hpp"
@ -193,6 +194,9 @@ RaceGUI::RaceGUI()
m_blue_flag = irr_driver->getTexture(FileManager::GUI_ICON, "blue_flag.png");
m_soccer_ball = irr_driver->getTexture(FileManager::GUI_ICON, "soccer_ball_normal.png");
m_heart_icon = irr_driver->getTexture(FileManager::GUI_ICON, "heart.png");
m_danger[0] = irr_driver->getTexture(FileManager::GUI_ICON, "alert_nodanger.png");
m_danger[1] = irr_driver->getTexture(FileManager::GUI_ICON, "alert_danger.png");
m_danger[2] = irr_driver->getTexture(FileManager::GUI_ICON, "alert_bigdanger.png");
} // RaceGUI
//-----------------------------------------------------------------------------
@ -812,6 +816,56 @@ void RaceGUI::drawMiscInfo(const AbstractKart *kart,
font->setScale(1.0f);
return;
}
else if (race_manager->isLinearRaceMode())
{
float closest_kart_dist_squared = 99999.9f;
int closest_kart_id = -1;
World *world = World::getWorld();
for(unsigned int i=0;i<world->getNumKarts();i++)
{
float dist2 = world->getKart(i)->getXYZ().distance2(kart->getXYZ());
if (dist2 > 0 && dist2 < closest_kart_dist_squared)
{
closest_kart_id = i;
closest_kart_dist_squared = dist2;
}
}
int projectile_types[4]; //[3] basket, [2] cakes, [1] plunger, [0] bowling
projectile_types[0] = projectile_manager->getNearbyProjectileCount(kart, 15.0f /*alert radius*/,
PowerupManager::POWERUP_BOWLING);
projectile_types[1] = projectile_manager->getNearbyProjectileCount(kart, 20.0f /*alert radius*/,
PowerupManager::POWERUP_PLUNGER);
projectile_types[2] = projectile_manager->getNearbyProjectileCount(kart, 25.0f /*alert radius*/,
PowerupManager::POWERUP_CAKE);
projectile_types[3] = projectile_manager->getNearbyProjectileCount(kart, 50.0f /*alert radius*/,
PowerupManager::POWERUP_RUBBERBALL);
int icon_to_use = 0;
if (closest_kart_id >= 0 && closest_kart_dist_squared < 900.0f)
icon_to_use = 1;
int icon_width = meter_width/2;
int x = int(offset.X + 0.375f*meter_width);
int y = int(offset.Y - 0.235f*meter_height) - icon_width;
core::rect<s32> indicator_pos(x, y, x + icon_width, y + icon_width);
core::rect<s32> source_rect(core::position2d<s32>(0,0),
m_danger[icon_to_use]->getSize());
draw2DImage(m_danger[icon_to_use],indicator_pos,source_rect,
NULL,NULL,true);
// Draw kart's icon
if (icon_to_use == 1)
{
drawPlayerIcon(world->getKart(closest_kart_id),
x+0.1875f*icon_width,y+0.1875f*icon_width,
0.625f*icon_width);
}
}
} // drawMiscInfo
//-----------------------------------------------------------------------------

View File

@ -100,6 +100,7 @@ private:
irr::video::ITexture *m_blue_flag;
irr::video::ITexture *m_soccer_ball;
irr::video::ITexture *m_heart_icon;
irr::video::ITexture *m_danger[2];
/** Animation state: none, getting smaller (old value),
* getting bigger (new number). */

View File

@ -717,7 +717,6 @@ void RaceGUIBase::drawGlobalPlayerIcons(int bottom_margin)
int ICON_WIDTH = ICON_PLAYER_WIDTH * 5 / 6;
WorldWithRank* world = dynamic_cast<WorldWithRank*>(World::getWorld());
CaptureTheFlag* ctf = dynamic_cast<CaptureTheFlag*>(World::getWorld());
//initialize m_previous_icons_position
if(m_previous_icons_position.size()==0)
@ -865,12 +864,25 @@ void RaceGUIBase::drawGlobalPlayerIcons(int bottom_margin)
true /* ignore RTL */);
}
// draw icon
video::ITexture *icon =
kart->getKartProperties()->getIconMaterial()->getTexture();
int w = kart->getController()
->isLocalPlayerController() ? ICON_PLAYER_WIDTH
: ICON_WIDTH;
drawPlayerIcon(kart, x, y, w);
} //next position
#endif
} // drawGlobalPlayerIcons
//-----------------------------------------------------------------------------
/** Draw one player icon
* Takes care of icon looking different due to plumber, squashing, ...
*/
void RaceGUIBase::drawPlayerIcon(AbstractKart *kart, int x, int y, int w)
{
video::ITexture *icon =
kart->getKartProperties()->getIconMaterial()->getTexture();
CaptureTheFlag* ctf = dynamic_cast<CaptureTheFlag*>(World::getWorld());
unsigned int kart_id = kart->getWorldKartId();
// CTF
if (ctf)
@ -1017,10 +1029,7 @@ void RaceGUIBase::drawGlobalPlayerIcons(int bottom_margin)
NULL, true);
}
}
} //next position
#endif
} // drawGlobalPlayerIcons
} // drawPlayerIcon
// ----------------------------------------------------------------------------

View File

@ -246,6 +246,7 @@ public:
virtual void clearAllMessages() { m_messages.clear(); }
void drawGlobalPlayerIcons(int bottom_margin);
void drawPlayerIcon(AbstractKart *kart, int x, int y, int w);
virtual void drawEnergyMeter(int x, int y, const AbstractKart *kart,
const core::recti &viewport,