ddnet/src/game/client/components/damageind.cpp

67 lines
1.4 KiB
C++
Raw Normal View History

2010-05-29 07:25:38 +00:00
#include <engine/graphics.h>
#include <game/generated/protocol.h>
#include <game/generated/client_data.h>
2010-05-29 07:25:38 +00:00
#include <game/gamecore.h> // get_angle
#include <game/client/ui.h>
#include <game/client/render.h>
#include "damageind.h"
2010-05-29 07:25:38 +00:00
CDamageInd::CDamageInd()
{
2010-05-29 07:25:38 +00:00
m_Lastupdate = 0;
m_NumItems = 0;
}
2010-05-29 07:25:38 +00:00
CDamageInd::CItem *CDamageInd::CreateI()
{
2010-05-29 07:25:38 +00:00
if (m_NumItems < MAX_ITEMS)
{
2010-05-29 07:25:38 +00:00
CItem *p = &m_aItems[m_NumItems];
m_NumItems++;
return p;
}
return 0;
}
2010-05-29 07:25:38 +00:00
void CDamageInd::DestroyI(CDamageInd::CItem *i)
{
2010-05-29 07:25:38 +00:00
m_NumItems--;
*i = m_aItems[m_NumItems];
}
2010-05-29 07:25:38 +00:00
void CDamageInd::Create(vec2 Pos, vec2 Dir)
{
2010-05-29 07:25:38 +00:00
CItem *i = CreateI();
if (i)
{
2010-05-29 07:25:38 +00:00
i->m_Pos = Pos;
i->m_Life = 0.75f;
i->m_Dir = Dir*-1;
i->m_StartAngle = (( (float)rand()/(float)RAND_MAX) - 1.0f) * 2.0f * pi;
}
}
2010-05-29 07:25:38 +00:00
void CDamageInd::OnRender()
{
2010-05-29 07:25:38 +00:00
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
2009-10-27 14:38:53 +00:00
Graphics()->QuadsBegin();
2010-05-29 07:25:38 +00:00
for(int i = 0; i < m_NumItems;)
{
2010-05-29 07:25:38 +00:00
vec2 Pos = mix(m_aItems[i].m_Pos+m_aItems[i].m_Dir*75.0f, m_aItems[i].m_Pos, clamp((m_aItems[i].m_Life-0.60f)/0.15f, 0.0f, 1.0f));
2010-05-29 07:25:38 +00:00
m_aItems[i].m_Life -= Client()->FrameTime();
if(m_aItems[i].m_Life < 0.0f)
DestroyI(&m_aItems[i]);
else
{
2010-05-29 07:25:38 +00:00
Graphics()->SetColor(1.0f,1.0f,1.0f, m_aItems[i].m_Life/0.1f);
Graphics()->QuadsSetRotation(m_aItems[i].m_StartAngle + m_aItems[i].m_Life * 2.0f);
RenderTools()->SelectSprite(SPRITE_STAR1);
RenderTools()->DrawSprite(Pos.x, Pos.y, 48.0f);
i++;
}
}
2009-10-27 14:38:53 +00:00
Graphics()->QuadsEnd();
}