Skip to content

Instantly share code, notes, and snippets.

@nekko1119
Last active September 4, 2018 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nekko1119/a2566a48892dfba1d189d42b4c55ee0e to your computer and use it in GitHub Desktop.
Save nekko1119/a2566a48892dfba1d189d42b4c55ee0e to your computer and use it in GitHub Desktop.
#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