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

103 lines
2.6 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()
{
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);
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);
}
2012-01-09 23:49:31 +00:00
else
{
if(m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED)
m_aItems[i].m_StartTime += Client()->LocalTime()-s_LastLocalTime;
}
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);
Graphics()->RenderQuadContainerAsSprite(m_DmgIndQuadContainerIndex, 0, Pos.x, Pos.y);
i++;
}
}
s_LastLocalTime = Client()->LocalTime();
Graphics()->QuadsSetRotation(0);
Graphics()->SetColor(1.f, 1.f, 1.f, 1.f);
}
void CDamageInd::OnInit()
{
Graphics()->QuadsSetRotation(0);
Graphics()->SetColor(1.f, 1.f, 1.f, 1.f);
m_DmgIndQuadContainerIndex = Graphics()->CreateQuadContainer();
RenderTools()->SelectSprite(SPRITE_STAR1);
RenderTools()->QuadContainerAddSprite(m_DmgIndQuadContainerIndex, 48.f);
}
2011-12-31 09:15:54 +00:00
void CDamageInd::Reset()
{
for(int i = 0; i < m_NumItems;)
{
DestroyI(&m_aItems[i]);
}
}