-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameUtility.cpp
More file actions
50 lines (41 loc) · 1.57 KB
/
GameUtility.cpp
File metadata and controls
50 lines (41 loc) · 1.57 KB
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
#include "GameUtility.h"
#include <DxLib.h>
namespace KeyInput {
const int KEYCOUNT = 256;
char beforeKeyBuf[KEYCOUNT] = {};
char afterKeyBuf[KEYCOUNT] = {};
char fixDownKeyBuf[KEYCOUNT] = {};
char fixUpKeyBuf[KEYCOUNT] = {};
}
void GameUtility::DrawFix2DText(DrawType type, int x, int y, int size, string text, unsigned int textColor, unsigned int edgeColor) {
SetFontSize(size);
int strWidth = GetDrawStringWidth(text.c_str(), strlen(text.c_str()));
switch (type)
{
case LEFT:
break;
case CENTER:
x -= strWidth / 2;
y -= size / 2;
break;
case RIGHT:
x -= strWidth;
break;
}
DrawString(x, y, text.c_str(), textColor, edgeColor);
}
void GameUtility::UpdateKey() {
memcpy_s(KeyInput::beforeKeyBuf, sizeof(char) * KeyInput::KEYCOUNT, KeyInput::afterKeyBuf, sizeof(char) * KeyInput::KEYCOUNT); //after(後フレーム)から before(前フレーム)にコピー
GetHitKeyStateAll(KeyInput::afterKeyBuf); //後フレームに代入
for (int n = 0; n < KeyInput::KEYCOUNT; n++) {
int key_xor = KeyInput::beforeKeyBuf[n] ^ KeyInput::afterKeyBuf[n]; //前と後が0と1なら、1を返す(XOR)
KeyInput::fixDownKeyBuf[n] = key_xor & KeyInput::afterKeyBuf[n]; //押された瞬間 = (XORと後フレームのANDを取る)
KeyInput::fixUpKeyBuf[n] = key_xor & KeyInput::beforeKeyBuf[n]; //離された瞬間 = (XORと前フレームのANDを取る)
}
}
bool GameUtility::IsKeyDown(int keyCode) {
return KeyInput::fixDownKeyBuf[keyCode];
}
bool GameUtility::IsKeyUp(int keyCode) {
return KeyInput::fixUpKeyBuf[keyCode];
}