#include <DxLib.h> | |
#include <experimental/generator> | |
class App { | |
char input[256]; | |
public: | |
std::experimental::generator<int> update() { | |
while (ProcessMessage() == 0) { | |
GetHitKeyStateAll(this->input); | |
ClearDrawScreen(); | |
clsDx(); | |
co_yield input[KEY_INPUT_Z]; | |
ScreenFlip(); | |
} | |
} | |
}; | |
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { | |
ChangeWindowMode(TRUE); | |
if (DxLib_Init() == -1) { | |
return 1; | |
} | |
SetDrawScreen(DX_SCREEN_BACK); | |
App app; | |
int counter = 0; | |
int prev_hit = 0; | |
for (auto const& state : app.update()) { | |
auto const current_hit = state; | |
// キーを押している間 | |
if (current_hit != 0) { | |
++counter; | |
} | |
// キーが離された瞬間 | |
auto const released = prev_hit != 0 && current_hit == 0; | |
// 一瞬背景が赤くなる | |
if (released) { | |
SetBackgroundColor(255, 0, 0); | |
} | |
else { | |
SetBackgroundColor(0, 0, 0); | |
} | |
// 押している間だけcounterがインクリメントされる | |
printfDx("key down count %d\n", counter); | |
prev_hit = current_hit; | |
} | |
DxLib_End(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment