-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQBert.cpp
186 lines (176 loc) · 4.99 KB
/
QBert.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include <sstream>
#include <string>
#include "Qbert.h"
#include "Disk.h"
QBert::QBert(Node ArgCurNode) : NPC(ArgCurNode)
{
FramesPerJump = 4;
FramesPerWait = 4;
InitGraphics("QBert");
}
void QBert::InitGraphics(const char *TexName)
{
D3DXMATRIX pos;
D3DXMATRIX rota;
D3DXMATRIX trans;
CurNode.RelCube->get_transform(&pos);
D3DXMatrixRotationY(&rota, -D3DX_PI/2.0f);
D3DXMatrixTranslation(&trans, 0, 5.0f, 0);
load("TriPrism.x", "myQBert/Models");
std::stringstream ss;
ss <<"myQBert/Textures/" <<TexName <<"-Down-Left.png";
TexDownLeft.load((char*)ss.str().c_str());
ss.str(std::string()); ss.clear();
ss <<"myQBert/Textures/" <<TexName <<"-Down-Left-Jump.png";
TexDownLeftJump.load((char*)ss.str().c_str());
ss.str(std::string()); ss.clear();
ss <<"myQBert/Textures/" <<TexName <<"-Down-Left-Balloon.png";
TexDownLeftBalloon.load((char*)ss.str().c_str());
ss.str(std::string()); ss.clear();
ss <<"myQBert/Textures/" <<TexName <<"-Down-Right.png";
TexDownRight.load((char*)ss.str().c_str());
ss.str(std::string()); ss.clear();
ss <<"myQBert/Textures/" <<TexName <<"-Down-Right-Jump.png";
TexDownRightJump.load((char*)ss.str().c_str());
ss.str(std::string()); ss.clear();
ss <<"myQBert/Textures/" <<TexName <<"-Down-Right-Balloon.png";
TexDownRightBalloon.load((char*)ss.str().c_str());
ss.str(std::string()); ss.clear();
ss <<"myQBert/Textures/" <<TexName <<"-Up-Left.png";
TexUpLeft.load((char*)ss.str().c_str());
ss.str(std::string()); ss.clear();
ss <<"myQBert/Textures/" <<TexName <<"-Up-Left-Jump.png";
TexUpLeftJump.load((char*)ss.str().c_str());
ss.str(std::string()); ss.clear();
ss <<"myQBert/Textures/" <<TexName <<"-Up-Left-Balloon.png";
TexUpLeftBalloon.load((char*)ss.str().c_str());
ss.str(std::string()); ss.clear();
ss <<"myQBert/Textures/" <<TexName <<"-Up-Right.png";
TexUpRight.load((char*)ss.str().c_str());
ss.str(std::string()); ss.clear();
ss <<"myQBert/Textures/" <<TexName <<"-Up-Right-Jump.png";
TexUpRightJump.load((char*)ss.str().c_str());
ss.str(std::string()); ss.clear();
ss <<"myQBert/Textures/" <<TexName <<"-Up-Right-Balloon.png";
TexUpRightBalloon.load((char*)ss.str().c_str());
ss.str(std::string()); ss.clear();
set_texture(0, &TexDownLeft);
disable_reflections();
add_transform(&rota);
add_transform(&pos);
add_transform(&trans);
return;
}
void QBert::Step(applikation &myqbert, const AdjacencyList &adjacency_list, GameStats &stats, DirectionEnum direction)
{
// Wartet der NPC?
if (isWaiting)
{
// Weiter warten..
FramesWaited++;
// Hat der NPC genug gewartet?
if (FramesWaited == FramesPerWait)
{
// Freigeben
FramesWaited = 0;
isWaiting = false;
}
}
else
{
// Bewegt sich der NPC?
if (isMoving)
{
// Weiter bewegen..
Move(MoveDirection);
// Bewegung fertig?
if (!isMoving)
{
// Würfel umfärben
if ((CurNode.NodeNum != 0) && (CurNode.NodeNum != 29) && (CurNode.NodeNum != 30))
NodeEffect(stats);
// Ist Q*Bert runtergefallen?
else if (CurNode.NodeNum == 0)
myqbert.play_sound(14, 0);
}
}
else
{
// Soll der NPC sich bewegen?
if (direction != DIR_NONE)
{
// nächsten Knoten und Richtung gemäß Tastatureingabe festlegen
if (direction == DIR_RIGHTUP)
TargetNode = adjacency_list[CurNode.NodeNum][0].target;
else if (direction == DIR_RIGHTDOWN)
TargetNode = adjacency_list[CurNode.NodeNum][1].target;
else if (direction == DIR_LEFTDOWN)
TargetNode = adjacency_list[CurNode.NodeNum][2].target;
else if (direction == DIR_LEFTUP)
TargetNode = adjacency_list[CurNode.NodeNum][3].target;
MoveDirection = direction;
// Sound abspielen
myqbert.play_sound(16, 0);
// NPC bewegen
isMoving = true;
Move(MoveDirection);
}
}
}
}
void QBert::NodeEffect(GameStats &stats)
{
if ((stats.Level == 1) || (stats.Level == 2))
{
if (this->CurNode.RelCube->cur < stats.Level)
{
this->CurNode.RelCube->cur++;
this->CurNode.RelCube->update_texture();
if (this->CurNode.RelCube->cur == stats.Level)
stats.Score += 25;
else
stats.Score += 15;
}
}
else if (stats.Level == 3)
{
if (this->CurNode.RelCube->cur == 0)
{
this->CurNode.RelCube->cur++;
stats.Score += 25;
}
else
{
this->CurNode.RelCube->cur--;
stats.Score -= 25;
}
this->CurNode.RelCube->update_texture();
}
return;
}
void QBert::SetTexture(void)
{
if (isMoving)
{
if (MoveDirection == DIR_LEFTDOWN)
set_texture(0, &this->TexDownLeftJump);
else if (MoveDirection == DIR_RIGHTDOWN)
set_texture(0, &this->TexDownRightJump);
else if (MoveDirection == DIR_LEFTUP)
set_texture(0, &this->TexUpLeftJump);
else if (MoveDirection == DIR_RIGHTUP)
set_texture(0, &this->TexUpRightJump);
}
else
{
if (MoveDirection == DIR_LEFTDOWN)
set_texture(0, &this->TexDownLeft);
else if (MoveDirection == DIR_RIGHTDOWN)
set_texture(0, &this->TexDownRight);
else if (MoveDirection == DIR_LEFTUP)
set_texture(0, &this->TexUpLeft);
else if (MoveDirection == DIR_RIGHTUP)
set_texture(0, &this->TexUpRight);
}
return;
}