-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcPlayer.cpp
108 lines (92 loc) · 2.41 KB
/
cPlayer.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright 2015 Kelvin Chandra, Software Laboratory Center, Binus University. All Rights Reserved.
#include "cPlayer.h"
#include "cGame.h"
cPlayer::cPlayer()
{
}
cPlayer::~cPlayer()
{
}
void cPlayer::Render()
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, playerSheet->at(animControl->Index())->Texture());
glBegin(GL_QUADS);
glTexCoord2f(playerSheet->at(animControl->Index())->X0(), playerSheet->at(animControl->Index())->Y1()); glVertex3i(x, y, 49);
glTexCoord2f(playerSheet->at(animControl->Index())->X1(), playerSheet->at(animControl->Index())->Y1()); glVertex3i(x + Width(), y, 49);
glTexCoord2f(playerSheet->at(animControl->Index())->X1(), playerSheet->at(animControl->Index())->Y0()); glVertex3i(x + Width(), y + Height(), 49);
glTexCoord2f(playerSheet->at(animControl->Index())->X0(), playerSheet->at(animControl->Index())->Y0()); glVertex3i(x, y + Height(), 49);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void cPlayer::Init()
{
animControl = new cAnimControl();
animControl->AddAnim("NoLoop", "walk_forward", 9, 16, 0.2f);
animControl->AddAnim("NoLoopBackward", "walk_backward", 7, 0, 0.2f);
animControl->AddAnim("NoLoop", "idle", 8, 8, 0.2f);
}
void cPlayer::Update(float tpf /*= 0.0333*/)
{
animControl->UpdateAnim(tpf);
if (keys['D'] || keys['d'])
{
if (animControl->ActiveName() != "walk_forward")
animControl->SetActiveAnim("walk_forward");
}
else if (keys['A'] || keys['a'])
{
if (animControl->ActiveName() != "walk_backward")
animControl->SetActiveAnim("walk_backward");
}
else
{
if (animControl->ActiveName() != "idle")
animControl->SetActiveAnim("idle");
}
if (keys['W'] || keys['w']) {
if (y <= GAME_HEIGHT-32) {
y += 10 * unitpersec;
}
}
else if (keys['A'] || keys['a']) {
if (x > 8) {
x -= 10 * unitpersec;
}
}
else if (keys['S'] || keys['s']) {
if (y > 8) {
y -= 10 * unitpersec;
}
}
else if (keys['D'] || keys['d']) {
if (x <= GAME_WIDTH-40){
x += 10 * unitpersec;
}
}
}
void cPlayer::ReadKeyboard(unsigned char key, int x, int y, bool press)
{
if (press)
{
keys[key] = true;
}
else
{
keys[key] = false;
}
}
void cPlayer::ReadSpecialKeyboard(unsigned char key, int x, int y, bool press)
{
if (press)
{
keys[key] = true;
}
else
{
keys[key] = false;
}
}
void cPlayer::ReadMouse(int button, int state, int x, int y)
{
}