Add an alert icon when another kart is nearby
This commit is contained in:
parent
799f6d98c1
commit
dcec81c7d5
@ -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
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -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). */
|
||||
|
@ -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,163 +864,173 @@ 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;
|
||||
|
||||
// CTF
|
||||
if (ctf)
|
||||
{
|
||||
if (ctf->getRedHolder() == (int)kart_id)
|
||||
{
|
||||
video::ITexture* red =
|
||||
irr_driver->getTexture(FileManager::GUI_ICON, "red_flag.png");
|
||||
const core::rect<s32> rect(core::position2d<s32>(0, 0),
|
||||
red->getSize());
|
||||
const core::rect<s32> pos1
|
||||
(x - 20, y - 10, x + w - 20, y + w - 30);
|
||||
draw2DImage(red, pos1, rect, NULL, NULL, true);
|
||||
}
|
||||
else if (ctf->getBlueHolder() == (int)kart_id)
|
||||
{
|
||||
video::ITexture* blue =
|
||||
irr_driver->getTexture(FileManager::GUI_ICON, "blue_flag.png");
|
||||
const core::rect<s32> rect(core::position2d<s32>(0, 0),
|
||||
blue->getSize());
|
||||
const core::rect<s32> pos1
|
||||
(x - 20, y - 10, x + w - 20, y + w - 30);
|
||||
draw2DImage(blue, pos1, rect, NULL, NULL, true);
|
||||
}
|
||||
}
|
||||
|
||||
const core::rect<s32> pos(x, y, x+w, y+w);
|
||||
|
||||
//to bring to light the player's icon: add a background
|
||||
if (kart->getController()->isLocalPlayerController() &&
|
||||
m_icons_frame != NULL)
|
||||
{
|
||||
video::SColor colors[4];
|
||||
for (unsigned int i=0;i<4;i++)
|
||||
{
|
||||
colors[i]=kart->getKartProperties()->getColor();
|
||||
colors[i].setAlpha(
|
||||
100+(int)(100*cos(M_PI/2*i+World::getWorld()->getTime()*2)));
|
||||
}
|
||||
const core::rect<s32> rect(core::position2d<s32>(0,0),
|
||||
m_icons_frame->getSize());
|
||||
draw2DImage(m_icons_frame, pos, rect,NULL, colors, true);
|
||||
}
|
||||
|
||||
// Fixes crash bug, why are certain icons not showing up?
|
||||
if (icon && !kart->getKartAnimation() && !kart->isSquashed())
|
||||
{
|
||||
const core::rect<s32> rect(core::position2d<s32>(0,0),
|
||||
icon->getSize());
|
||||
draw2DImage(icon, pos, rect, NULL, NULL, true, kart->isGhostKart());
|
||||
}
|
||||
|
||||
//draw status info - icon fade out in case of rescue/explode
|
||||
|
||||
if (icon && dynamic_cast<RescueAnimation*>(kart->getKartAnimation()))
|
||||
{
|
||||
//icon fades to the left
|
||||
float t = kart->getKartAnimation()->getAnimationTimer();
|
||||
float t_anim=100*sin(0.5f*M_PI*t);
|
||||
const core::rect<s32> rect1(core::position2d<s32>(0,0),
|
||||
icon->getSize());
|
||||
const core::rect<s32> pos1((int)(x-t_anim), y,
|
||||
(int)(x+w-t_anim), y+w);
|
||||
draw2DImage(icon, pos1, rect1,
|
||||
NULL, NULL, true);
|
||||
}
|
||||
|
||||
if (icon && !kart->getKartAnimation() && kart->isSquashed() )
|
||||
{
|
||||
//syncs icon squash with kart squash
|
||||
const core::rect<s32> destRect(core::position2d<s32>(x,y+w/4),
|
||||
core::position2d<s32>(x+w,y+w*3/4));
|
||||
const core::rect<s32> sourceRect(core::position2d<s32>(0,0),
|
||||
icon->getSize());
|
||||
draw2DImage(icon, destRect,
|
||||
sourceRect, NULL, NULL,
|
||||
true);
|
||||
}
|
||||
|
||||
if (icon &&
|
||||
dynamic_cast<ExplosionAnimation*>(kart->getKartAnimation()) )
|
||||
{
|
||||
//exploses into 4 parts
|
||||
float t = kart->getKartAnimation()->getAnimationTimer();
|
||||
float t_anim=50.0f*sin(0.5f*M_PI*t);
|
||||
u16 icon_size_x=icon->getSize().Width;
|
||||
u16 icon_size_y=icon->getSize().Height;
|
||||
|
||||
const core::rect<s32> rect1(0, 0, icon_size_x/2,icon_size_y/2);
|
||||
const core::rect<s32> pos1((int)(x-t_anim), (int)(y-t_anim),
|
||||
(int)(x+w/2-t_anim),
|
||||
(int)(y+w/2-t_anim));
|
||||
draw2DImage(icon, pos1, rect1,
|
||||
NULL, NULL, true);
|
||||
|
||||
const core::rect<s32> rect2(icon_size_x/2,0,
|
||||
icon_size_x,icon_size_y/2);
|
||||
const core::rect<s32> pos2((int)(x+w/2+t_anim),
|
||||
(int)(y-t_anim),
|
||||
(int)(x+w+t_anim),
|
||||
(int)(y+w/2-t_anim));
|
||||
draw2DImage(icon, pos2, rect2,
|
||||
NULL, NULL, true);
|
||||
|
||||
const core::rect<s32> rect3(0, icon_size_y/2, icon_size_x/2,icon_size_y);
|
||||
const core::rect<s32> pos3((int)(x-t_anim), (int)(y+w/2+t_anim),
|
||||
(int)(x+w/2-t_anim), (int)(y+w+t_anim));
|
||||
draw2DImage(icon, pos3, rect3, NULL, NULL, true);
|
||||
|
||||
const core::rect<s32> rect4(icon_size_x/2,icon_size_y/2,icon_size_x,icon_size_y);
|
||||
const core::rect<s32> pos4((int)(x+w/2+t_anim), (int)(y+w/2+t_anim),
|
||||
(int)(x+w+t_anim), (int)(y+w+t_anim));
|
||||
draw2DImage(icon, pos4, rect4, NULL, NULL, true);
|
||||
}
|
||||
|
||||
//Plunger
|
||||
if (kart->getBlockedByPlungerTicks()>0)
|
||||
{
|
||||
video::ITexture *icon_plunger =
|
||||
powerup_manager->getIcon(PowerupManager::POWERUP_PLUNGER)->getTexture();
|
||||
if (icon_plunger != NULL)
|
||||
{
|
||||
const core::rect<s32> rect(core::position2d<s32>(0,0),
|
||||
icon_plunger->getSize());
|
||||
const core::rect<s32> pos1(x+10, y-10, x+w+10, y+w-10);
|
||||
draw2DImage(icon_plunger, pos1,
|
||||
rect, NULL, NULL,
|
||||
true);
|
||||
}
|
||||
}
|
||||
//attachment
|
||||
if (kart->getAttachment()->getType() != Attachment::ATTACH_NOTHING)
|
||||
{
|
||||
video::ITexture *icon_attachment =
|
||||
attachment_manager->getIcon(kart->getAttachment()->getType())
|
||||
->getTexture();
|
||||
if (icon_attachment != NULL)
|
||||
{
|
||||
const core::rect<s32> rect(core::position2d<s32>(0,0),
|
||||
icon_attachment->getSize());
|
||||
const core::rect<s32> pos1(x-20, y-10, x+w-20, y+w-10);
|
||||
draw2DImage(icon_attachment,
|
||||
pos1, rect, NULL,
|
||||
NULL, true);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (ctf->getRedHolder() == (int)kart_id)
|
||||
{
|
||||
video::ITexture* red =
|
||||
irr_driver->getTexture(FileManager::GUI_ICON, "red_flag.png");
|
||||
const core::rect<s32> rect(core::position2d<s32>(0, 0),
|
||||
red->getSize());
|
||||
const core::rect<s32> pos1
|
||||
(x - 20, y - 10, x + w - 20, y + w - 30);
|
||||
draw2DImage(red, pos1, rect, NULL, NULL, true);
|
||||
}
|
||||
else if (ctf->getBlueHolder() == (int)kart_id)
|
||||
{
|
||||
video::ITexture* blue =
|
||||
irr_driver->getTexture(FileManager::GUI_ICON, "blue_flag.png");
|
||||
const core::rect<s32> rect(core::position2d<s32>(0, 0),
|
||||
blue->getSize());
|
||||
const core::rect<s32> pos1
|
||||
(x - 20, y - 10, x + w - 20, y + w - 30);
|
||||
draw2DImage(blue, pos1, rect, NULL, NULL, true);
|
||||
}
|
||||
}
|
||||
|
||||
const core::rect<s32> pos(x, y, x+w, y+w);
|
||||
|
||||
//to bring to light the player's icon: add a background
|
||||
if (kart->getController()->isLocalPlayerController() &&
|
||||
m_icons_frame != NULL)
|
||||
{
|
||||
video::SColor colors[4];
|
||||
for (unsigned int i=0;i<4;i++)
|
||||
{
|
||||
colors[i]=kart->getKartProperties()->getColor();
|
||||
colors[i].setAlpha(
|
||||
100+(int)(100*cos(M_PI/2*i+World::getWorld()->getTime()*2)));
|
||||
}
|
||||
const core::rect<s32> rect(core::position2d<s32>(0,0),
|
||||
m_icons_frame->getSize());
|
||||
draw2DImage(m_icons_frame, pos, rect,NULL, colors, true);
|
||||
}
|
||||
|
||||
// Fixes crash bug, why are certain icons not showing up?
|
||||
if (icon && !kart->getKartAnimation() && !kart->isSquashed())
|
||||
{
|
||||
const core::rect<s32> rect(core::position2d<s32>(0,0),
|
||||
icon->getSize());
|
||||
draw2DImage(icon, pos, rect, NULL, NULL, true, kart->isGhostKart());
|
||||
}
|
||||
|
||||
//draw status info - icon fade out in case of rescue/explode
|
||||
|
||||
if (icon && dynamic_cast<RescueAnimation*>(kart->getKartAnimation()))
|
||||
{
|
||||
//icon fades to the left
|
||||
float t = kart->getKartAnimation()->getAnimationTimer();
|
||||
float t_anim=100*sin(0.5f*M_PI*t);
|
||||
const core::rect<s32> rect1(core::position2d<s32>(0,0),
|
||||
icon->getSize());
|
||||
const core::rect<s32> pos1((int)(x-t_anim), y,
|
||||
(int)(x+w-t_anim), y+w);
|
||||
draw2DImage(icon, pos1, rect1,
|
||||
NULL, NULL, true);
|
||||
}
|
||||
|
||||
if (icon && !kart->getKartAnimation() && kart->isSquashed() )
|
||||
{
|
||||
//syncs icon squash with kart squash
|
||||
const core::rect<s32> destRect(core::position2d<s32>(x,y+w/4),
|
||||
core::position2d<s32>(x+w,y+w*3/4));
|
||||
const core::rect<s32> sourceRect(core::position2d<s32>(0,0),
|
||||
icon->getSize());
|
||||
draw2DImage(icon, destRect,
|
||||
sourceRect, NULL, NULL,
|
||||
true);
|
||||
}
|
||||
|
||||
if (icon &&
|
||||
dynamic_cast<ExplosionAnimation*>(kart->getKartAnimation()) )
|
||||
{
|
||||
//exploses into 4 parts
|
||||
float t = kart->getKartAnimation()->getAnimationTimer();
|
||||
float t_anim=50.0f*sin(0.5f*M_PI*t);
|
||||
u16 icon_size_x=icon->getSize().Width;
|
||||
u16 icon_size_y=icon->getSize().Height;
|
||||
|
||||
const core::rect<s32> rect1(0, 0, icon_size_x/2,icon_size_y/2);
|
||||
const core::rect<s32> pos1((int)(x-t_anim), (int)(y-t_anim),
|
||||
(int)(x+w/2-t_anim),
|
||||
(int)(y+w/2-t_anim));
|
||||
draw2DImage(icon, pos1, rect1,
|
||||
NULL, NULL, true);
|
||||
|
||||
const core::rect<s32> rect2(icon_size_x/2,0,
|
||||
icon_size_x,icon_size_y/2);
|
||||
const core::rect<s32> pos2((int)(x+w/2+t_anim),
|
||||
(int)(y-t_anim),
|
||||
(int)(x+w+t_anim),
|
||||
(int)(y+w/2-t_anim));
|
||||
draw2DImage(icon, pos2, rect2,
|
||||
NULL, NULL, true);
|
||||
|
||||
const core::rect<s32> rect3(0, icon_size_y/2, icon_size_x/2,icon_size_y);
|
||||
const core::rect<s32> pos3((int)(x-t_anim), (int)(y+w/2+t_anim),
|
||||
(int)(x+w/2-t_anim), (int)(y+w+t_anim));
|
||||
draw2DImage(icon, pos3, rect3, NULL, NULL, true);
|
||||
|
||||
const core::rect<s32> rect4(icon_size_x/2,icon_size_y/2,icon_size_x,icon_size_y);
|
||||
const core::rect<s32> pos4((int)(x+w/2+t_anim), (int)(y+w/2+t_anim),
|
||||
(int)(x+w+t_anim), (int)(y+w+t_anim));
|
||||
draw2DImage(icon, pos4, rect4, NULL, NULL, true);
|
||||
}
|
||||
|
||||
//Plunger
|
||||
if (kart->getBlockedByPlungerTicks()>0)
|
||||
{
|
||||
video::ITexture *icon_plunger =
|
||||
powerup_manager->getIcon(PowerupManager::POWERUP_PLUNGER)->getTexture();
|
||||
if (icon_plunger != NULL)
|
||||
{
|
||||
const core::rect<s32> rect(core::position2d<s32>(0,0),
|
||||
icon_plunger->getSize());
|
||||
const core::rect<s32> pos1(x+10, y-10, x+w+10, y+w-10);
|
||||
draw2DImage(icon_plunger, pos1,
|
||||
rect, NULL, NULL,
|
||||
true);
|
||||
}
|
||||
}
|
||||
//attachment
|
||||
if (kart->getAttachment()->getType() != Attachment::ATTACH_NOTHING)
|
||||
{
|
||||
video::ITexture *icon_attachment =
|
||||
attachment_manager->getIcon(kart->getAttachment()->getType())
|
||||
->getTexture();
|
||||
if (icon_attachment != NULL)
|
||||
{
|
||||
const core::rect<s32> rect(core::position2d<s32>(0,0),
|
||||
icon_attachment->getSize());
|
||||
const core::rect<s32> pos1(x-20, y-10, x+w-20, y+w-10);
|
||||
draw2DImage(icon_attachment,
|
||||
pos1, rect, NULL,
|
||||
NULL, true);
|
||||
}
|
||||
}
|
||||
} // drawPlayerIcon
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/** Draws the plunger-in-face if necessary. Does nothing if there is no
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user