blob: 9be6722a65b1ce14b7bbb13c654bc2d0c7e16b8e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
/* (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/graphics.h>
#include <game/generated/protocol.h>
#include <game/generated/client_data.h>
#include <game/gamecore.h> // get_angle
#include <game/client/ui.h>
#include <game/client/render.h>
#include "damageind.h"
CDamageInd::CDamageInd()
{
m_Lastupdate = 0;
m_NumItems = 0;
}
CDamageInd::CItem *CDamageInd::CreateI()
{
if (m_NumItems < MAX_ITEMS)
{
CItem *p = &m_aItems[m_NumItems];
m_NumItems++;
return p;
}
return 0;
}
void CDamageInd::DestroyI(CDamageInd::CItem *i)
{
m_NumItems--;
*i = m_aItems[m_NumItems];
}
void CDamageInd::Create(vec2 Pos, vec2 Dir)
{
CItem *i = CreateI();
if (i)
{
i->m_Pos = Pos;
i->m_StartTime = Client()->LocalTime();
i->m_Dir = Dir*-1;
i->m_StartAngle = (( (float)rand()/(float)RAND_MAX) - 1.0f) * 2.0f * pi;
}
}
void CDamageInd::OnRender()
{
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
Graphics()->QuadsBegin();
for(int i = 0; i < m_NumItems;)
{
float Life = 0.75f - (Client()->LocalTime() - m_aItems[i].m_StartTime);
if(Life < 0.0f)
DestroyI(&m_aItems[i]);
else
{
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);
RenderTools()->SelectSprite(SPRITE_STAR1);
RenderTools()->DrawSprite(Pos.x, Pos.y, 48.0f);
i++;
}
}
Graphics()->QuadsEnd();
}
|