-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstructions.cpp
169 lines (138 loc) · 3.66 KB
/
Instructions.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
#include "Instructions.h"
Instructions::Instructions()
{
}
Instructions::~Instructions()
{
D3D::Release(background);
D3D::Release(title);
for (int i = 0; i < 6; i++) {
D3D::Release(button[i]);
D3D::Release(buttonOver[i]);
}
D3D::Release<ID3DXSprite*>(sprite);
}
bool Instructions::Init()
{
// create sprite
D3DXCreateSprite(Device, &sprite);
// set center of textures
buttonCenter = D3DXVECTOR3(440, 60, 0);
titleCenter = D3DXVECTOR3(800, 100, 0);
// set current button
currentButton = 0;
// set the timer
timer = 0;
canSwitch = false;
// load textures
background = D3D::LoadTexture("sprites/background.png");
title = D3D::LoadTexture("sprites/titles/instructions.png");
text = D3D::LoadTexture("sprites/instructions.png");
button[0] = D3D::LoadTexture("sprites/buttons/mainmenu.png");
button[1] = D3D::LoadTexture("sprites/buttons/options.png");
buttonOver[0] = D3D::LoadTexture("sprites/buttons/over/mainmenu.png");
buttonOver[1] = D3D::LoadTexture("sprites/buttons/over/options.png");
return true;
}
void Instructions::Enter()
{
if (!isInit)
isInit = Init();
// start playing sounds for level
if (previousState == 0 || previousState == onePlayer || previousState == twoPlayer)
SoundEngine->PlayMusic(Sound::MENUBACKGROUND);
}
bool Instructions::Render(float deltaTime)
{
Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, 0xFF000000, 1.0f, 0);
Device->BeginScene();
sprite->Begin(D3DXSPRITE_ALPHABLEND);
sprite->Draw(background, NULL, NULL, NULL, D3D::WHITE);
sprite->Draw(title, NULL, &titleCenter, &D3DXVECTOR3(800, 100, 0), D3D::WHITE);
sprite->Draw(text, NULL, NULL, &D3DXVECTOR3(15, 250, 0), D3D::WHITE);
for (int i = 0; i < 2; i++) {
if (i != currentButton) {
sprite->Draw(button[i], NULL, &buttonCenter, &D3DXVECTOR3(1250, (float)300 + (100 * i), 0), D3D::WHITE);
}
else {
sprite->Draw(buttonOver[i], NULL, &buttonCenter, &D3DXVECTOR3(1250, (float)300 + (100 * i), 0), D3D::WHITE);
}
}
sprite->End();
Device->EndScene();
Device->Present(0, 0, 0, 0);
return true;
}
void Instructions::Update(float deltaTime)
{
// timer control for button switching
if (timer >= .5f) {
timer = 0;
canSwitch = true;
}
else {
timer += deltaTime;
}
//-------------------
// Change States
//-------------------
if (((GetAsyncKeyState(VK_RETURN) && 0x8000) || controller->isPressed(XINPUT_GAMEPAD_A)) && canSwitch) {
SoundEngine->PlayFX(Sound::ENEMYSHOT);
canSwitch = false;
timer = 0;
switch (currentButton) {
case 0:
Exit(menu);
break;
case 1:
Exit(options);
break;
default:
break;
}
}
//-------------------
// Keyboard Input
//-------------------
if (GetAsyncKeyState(VK_DOWN) && 0x8000 && canSwitch) {
SoundEngine->PlayFX(Sound::RELOAD);
currentButton += 1;
canSwitch = false;
timer = 0;
}
if (GetAsyncKeyState(VK_UP) && 0x8000 && canSwitch) {
SoundEngine->PlayFX(Sound::RELOAD);
currentButton -= 1;
canSwitch = false;
timer = 0;
}
//-------------------
// Controller Input
//-------------------
if (controller->isConnected) {
if (controller->leftY && canSwitch) {
SoundEngine->PlayFX(Sound::RELOAD);
currentButton -= controller->leftY / abs(controller->leftY);
canSwitch = false;
timer = 0;
}
}
// keep current button in range
if (currentButton >= 2)
currentButton = 0;
if (currentButton <= -1)
currentButton = 1;
}
void Instructions::Exit(GameState *nextState)
{
// stop playing sounds for level
if(nextState == onePlayer || nextState == twoPlayer)
SoundEngine->StopMusic();
// reset variables
currentButton = 0;
timer = 0;
// go to the next state
previousState = currentState;
currentState = nextState;
currentState->Enter();
}