-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player.cpp
79 lines (68 loc) · 2.4 KB
/
Player.cpp
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
72
73
74
75
76
77
78
79
#include "Player.h"
#include "TextureManager.h"
#include "Utils.h"
#include "Game.h"
#include "Shape.h"
namespace typing
{
const float Player::FIRE_FADE_TIME = 1.0f;
const float Player::DAMAGE_FADE_TIME = 1.0f;
const float Player::PLAYER_SIDE = 32.0f;
const juzutil::Vector3 Player::PLAYER_ORIGIN(0.0f, 0.0f, 0.0f);
const BBox Player::PLAYER_BOUNDS(
-Player::PLAYER_SIDE / 2.0f, -Player::PLAYER_SIDE / 2.0f,
Player::PLAYER_SIDE / 2.0f, Player::PLAYER_SIDE / 2.0f);
void Player::Init()
{
}
void Player::Reset(unsigned int lives)
{
m_lives = lives;
m_lastFireTime = 0.0f;
m_damageTime = 0.0f;
}
void Player::Draw()
{
// Alpha fades between 0.1 and 0.5
const float alpha =
m_lives > 0 ?
0.1f + (1.0f + sinf(GAME.GetTime())) / 5.0f : 0.0f;
glPushMatrix();
glTranslatef(PLAYER_ORIGIN.GetX(),
PLAYER_ORIGIN.GetY(),
PLAYER_ORIGIN.GetZ());
glRotatef(45.0f, 0.0f, 0.0f, 1.0f);
glRotatef(45.0f, 0.0f, 1.0f, 0.0f);
glScalef(38.0f, 38.0f, 38.0f);
DrawCube(ColourRGBA(m_lives > 1 ? 0.7f : 1.0f,
m_lives > 1 ? 1.0f : 0.0f,
0.0f, alpha),
ColourRGBA(0.8f, 1.0f, 0.8f, 1.0f));
glPushMatrix();
glScalef(1.1f, 1.1f, 1.1f);
if (m_lastFireTime != 0.0f && GAME.GetTime() - m_lastFireTime < FIRE_FADE_TIME)
{
const float fireAlpha = 1.0f - (GAME.GetTime() - m_lastFireTime) / FIRE_FADE_TIME;
DrawCube(ColourRGBA(1.0f, 1.0f, 1.0f, fireAlpha));
}
if (m_damageTime != 0.0f && GAME.GetTime() - m_damageTime < DAMAGE_FADE_TIME)
{
const float damageAlpha = 1.0f - (GAME.GetTime() - m_damageTime) / DAMAGE_FADE_TIME;
DrawCube(ColourRGBA(1.0f, 0.0f, 0.0f, damageAlpha));
}
glPopMatrix();
glPopMatrix();
}
void Player::Update()
{
}
void Player::Fire()
{
m_lastFireTime = GAME.GetTime();
}
void Player::Damage()
{
m_lives--;
m_damageTime = GAME.GetTime();
}
}