Created
October 15, 2017 17:31
-
-
Save nekko1119/954f3b9355df2b159cc3ebb87b1edbf3 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 <rx.hpp> | |
class Input { | |
char input[256]; | |
rxcpp::subjects::subject<int> zInput; | |
public: | |
void update() { | |
GetHitKeyStateAll(this->input); | |
zInput.get_subscriber().on_next(input[KEY_INPUT_Z]); | |
} | |
rxcpp::observable<int> onZInput() const { | |
return zInput.get_observable(); | |
} | |
}; | |
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { | |
ChangeWindowMode(TRUE); | |
if (DxLib_Init() == -1) { | |
return 1; | |
} | |
SetDrawScreen(DX_SCREEN_BACK); | |
Input input; | |
int counter = 0; | |
bool released = false; | |
// キーを押している間 | |
input.onZInput() | |
.filter([](int value) { return value != 0; }) | |
.subscribe([&counter](int) { ++counter; }); | |
// キーが離された瞬間 | |
input.onZInput() | |
.buffer(2, 1) | |
.subscribe([&released](std::vector<int> input) { released = input[0] != 0 && input[1] == 0; }); | |
while (ProcessMessage() == 0) { | |
input.update(); | |
// 一瞬背景が赤くなる | |
if (released) { | |
SetBackgroundColor(255, 0, 0); | |
} else { | |
SetBackgroundColor(0, 0, 0); | |
} | |
ClearDrawScreen(); | |
clsDx(); | |
// 押している間だけcounterがインクリメントされる | |
printfDx("key down count %d\n", counter); | |
ScreenFlip(); | |
} | |
DxLib_End(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment