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

83 lines
2 KiB
C++
Raw Normal View History

2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <engine/demo.h>
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;
2011-12-31 09:15:54 +00:00
i->m_StartTime = Client()->LocalTime();
2010-05-29 07:25:38 +00:00
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();
static float s_LastLocalTime = Client()->LocalTime();
2010-05-29 07:25:38 +00:00
for(int i = 0; i < m_NumItems;)
{
if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
{
const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo();
if(pInfo->m_Paused)
m_aItems[i].m_StartTime += Client()->LocalTime()-s_LastLocalTime;
else
m_aItems[i].m_StartTime += (Client()->LocalTime()-s_LastLocalTime)*(1.0f-pInfo->m_Speed);
}
2011-12-31 09:15:54 +00:00
float Life = 0.75f - (Client()->LocalTime() - m_aItems[i].m_StartTime);
if(Life < 0.0f)
2010-05-29 07:25:38 +00:00
DestroyI(&m_aItems[i]);
else
{
2011-12-31 09:15:54 +00:00
vec2 Pos = mix(m_aItems[i].m_Pos+m_aItems[i].m_Dir*75.0f, m_aItems[i].m_Pos, clamp((Life-0.60f)/0.15f, 0.0f, 1.0f));
Graphics()->SetColor(1.0f,1.0f,1.0f, Life/0.1f);
Graphics()->QuadsSetRotation(m_aItems[i].m_StartAngle + Life * 2.0f);
2010-05-29 07:25:38 +00:00
RenderTools()->SelectSprite(SPRITE_STAR1);
RenderTools()->DrawSprite(Pos.x, Pos.y, 48.0f);
i++;
}
}
s_LastLocalTime = Client()->LocalTime();
2009-10-27 14:38:53 +00:00
Graphics()->QuadsEnd();
}
2011-12-31 09:15:54 +00:00