/
Utility.cpp
223 lines (186 loc) · 4.91 KB
/
Utility.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// Utility Source
#include "DxLib.h"
#include "ConstantExpressionVariable.hpp"
#include "GameMenu.hpp"
#include "SaveData.hpp"
#include "ConfigMenu.hpp"
#include "Skip_Auto.hpp"
#include "BackLog.hpp"
#include <string>
#include <thread>
#include <chrono>
#include <array>
#include <functional>
//ゲームタイトル名
extern const char* GameTitle;
extern int Sp, Cp; // 参照する文字列番号と文字列中の文字ポインタ
//終了フラグ
extern int EndFlag;
//各種素材ハンドル
extern std::int32_t BackGroundHandle, CharacterHandle, BackGroundMusicHandle, SoundEffectHandle;
//文字列描画位置
extern int DrawPointX, DrawPointY;
//tempデータ
extern int EndFlagTemp, SpTemp;
extern ConfigData_t ConfigData;
namespace {
//処理停止時間計算関数
auto WaitTimeCalc(const int var) noexcept {
return var * var;
}
//ゲーム画面再描画処理
void DrawGameScreenAgain() noexcept {
Sp = SpTemp;
Cp = 0;
DrawPointX = 0;
DrawPointY = 0;
DxLib::PlaySoundMem(BackGroundMusicHandle, DX_PLAYTYPE_LOOP);
DxLib::DrawGraph(0, 0, BackGroundHandle, TRUE);
DxLib::DrawGraph(150, 130, CharacterHandle, TRUE);
}
}
//メッセージボックス(Yes or No)
int MessageBoxYesNo(LPCTSTR lpText) noexcept
{
return MessageBox(
DxLib::GetMainWindowHandle(),
lpText,
GameTitle,
MB_YESNO
);
}
//メッセージボックス(OK)
int MessageBoxOk(LPCTSTR lpText) noexcept
{
return MessageBox(
DxLib::GetMainWindowHandle(),
lpText,
GameTitle,
MB_OK
);
}
//画面クリア処理関数
void ScreenClear() noexcept {
SetDrawScreen(DX_SCREEN_BACK);
ClearDrawScreen();
SetDrawScreen(DX_SCREEN_FRONT);
}
//ゲーム終了確認ウインドウ
void GameEndMessageBox() noexcept {
if (IDYES == MessageBoxYesNo("終了しますか?"))
EndFlag = 99;
if (EndFlag != 99 && EndFlag != 0)
std::this_thread::sleep_for(std::chrono::milliseconds(WaitTimeCalc(WaitKeyTaskTime) / WaitGameTime));
else
std::this_thread::sleep_for(std::chrono::milliseconds(WaitKeyTaskTime));
}
//スクリーンショット取得関数
void ScreenShotGet() noexcept {
if (IDYES == MessageBoxYesNo("スクリーンショットを取得しますか?")) {
static std::int32_t ScreenShotCount;
std::string FileName = "DATA/SCREENSHOT/SCREENSHOT";
FileName += std::to_string(ScreenShotCount + 1);
FileName += ".png";
DxLib::SaveDrawScreenToPNG(0, 0, 640, 480, FileName.c_str());
ScreenShotCount++;
}
}
namespace {
//セーブデータ関連
void SaveData(const int Num) {
SpTemp = Sp;
SaveDataLoop(Num);
DrawGameScreenAgain();
}
//スキップ・オート関係
void SkipAndAuto(const int Num, const int EndFlag) {
SpTemp = Sp;
SkipAndAutoTask(Num, EndFlag);
DrawGameScreenAgain();
}
//バックログ関係
void BackLog() {
SpTemp = Sp;
BackLogLoop();
DrawGameScreenAgain();
}
//コンフィグ関係
void Config() {
SpTemp = Sp;
ConfigMenuLoop();
DrawGameScreenAgain();
}
//タイトルへ戻る
void BackToTitle() {
if (IDYES == MessageBoxYesNo("タイトル画面に戻りますか?")) {
DxLib::ClearDrawScreen();
EndFlag = 0;
Sp = 0;
Cp = 0;
DrawPointX = 0;
DrawPointY = 0;
BackGroundHandle = 0;
CharacterHandle = 0;
BackGroundMusicHandle = 0;
SoundEffectHandle = 0;
}
else
DrawGameScreenAgain();
}
//クイックセーブ関係
void QuickSave() {
SpTemp = Sp;
QuickSaveDataSave();
DrawGameScreenAgain();
}
//スクリーンショット関連
void ScreenShot() {
ScreenShotGet();
Cp = 0;
DrawPointX = 0;
DrawPointY = 0;
DxLib::PlaySoundMem(BackGroundMusicHandle, DX_PLAYTYPE_LOOP);
DxLib::DrawGraph(0, 0, BackGroundHandle, TRUE);
DxLib::DrawGraph(150, 130, CharacterHandle, TRUE);
}
//ゲームメニュー関連
void GameMenu() {
SaveDataScreenShotGet();
DxLib::StopSoundMem(BackGroundMusicHandle);
DxLib::StopSoundMem(SoundEffectHandle);
EndFlagTemp = EndFlag;
SpTemp = Sp;
EndFlag = 17;
std::this_thread::sleep_for(std::chrono::milliseconds(WaitTimeCalc(WaitKeyTaskTime) / WaitGameTime));
}
}
//各種ショートカットキー
void ShortCutKey() noexcept {
constexpr std::array<int, 12> FuncKey = { KEY_INPUT_F1, KEY_INPUT_F2, KEY_INPUT_F3, KEY_INPUT_F4,
KEY_INPUT_F5, KEY_INPUT_F6, KEY_INPUT_F7, KEY_INPUT_F8,
KEY_INPUT_F9, KEY_INPUT_F10, KEY_INPUT_F11, KEY_INPUT_F12 };
constexpr std::array<int, 4> SkipAndAutoFlag = { 3, 1, 2, 0 };
const std::array<std::function<void()>, 5> Funcs = { BackLog, Config, BackToTitle, QuickSave, ScreenShot };
for (std::int32_t i = 0; i < 3; i++) {
if (DxLib::CheckHitKey(FuncKey[i]) == 1)
SaveData(i + 1);
}
for (std::int32_t i = 0; i < 4; i++) {
if (DxLib::CheckHitKey(FuncKey[i + 3]) == 1)
SkipAndAuto(SkipAndAutoFlag[i], EndFlag);
}
for (std::int32_t i = 0; i < 5; i++) {
if (DxLib::CheckHitKey(FuncKey[i + 5]) == 1)
Funcs[i]();
}
if (DxLib::CheckHitKey(KEY_INPUT_BACK) == 1 || (DxLib::GetMouseInput() == MOUSE_INPUT_RIGHT))
GameMenu();
//ゲーム終了確認ウインドウ
if (CheckHitKey(KEY_INPUT_ESCAPE) == 1)
GameEndMessageBox();
}
//タイトルムービー処理
void TitleMoviePlay() noexcept {
PlayMovie("DATA/MOVIE/OP.wmv", 1, DX_MOVIEPLAYTYPE_BCANCEL);
ScreenClear();
}