Last active
September 4, 2018 18:37
-
-
Save nekko1119/a2566a48892dfba1d189d42b4c55ee0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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