mirror of
https://github.com/haya3218/SDfmL.git
synced 2024-08-14 23:57:09 +00:00
:)
This commit is contained in:
parent
a1aacff687
commit
e4dc4a8331
1 changed files with 21 additions and 22 deletions
|
@ -445,32 +445,21 @@ namespace sdfml {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const Uint8* kb;
|
static const Uint8* kb;
|
||||||
static const Uint8* kb_last;
|
static const Uint8* kb_jp;
|
||||||
|
static const Uint8* kb_jr;
|
||||||
|
|
||||||
|
static bool lockKeys = false;
|
||||||
|
|
||||||
inline bool key_just_pressed(SDL_Scancode code) {
|
inline bool key_just_pressed(SDL_Scancode code) {
|
||||||
while (SDL_PollEvent(&mContext.events))
|
return kb_jp[code] && !lockKeys;
|
||||||
{
|
|
||||||
if (mContext.events.type == SDL_KEYDOWN)
|
|
||||||
if (mContext.events.key.keysym.scancode == code)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool key_just_released(SDL_Scancode code) {
|
inline bool key_just_released(SDL_Scancode code) {
|
||||||
while (SDL_PollEvent(&mContext.events))
|
return kb_jr[code] && !lockKeys;
|
||||||
{
|
|
||||||
if (mContext.events.type == SDL_KEYUP)
|
|
||||||
if (mContext.events.key.keysym.scancode == code)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool key_pressed(SDL_Scancode code) {
|
inline bool key_pressed(SDL_Scancode code) {
|
||||||
if (kb[code])
|
return kb[code] && !lockKeys;
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int Sec2Tick(float time) {
|
inline int Sec2Tick(float time) {
|
||||||
|
@ -482,12 +471,22 @@ namespace sdfml {
|
||||||
inline int update() {
|
inline int update() {
|
||||||
int lastUpdate = SDL_GetTicks();
|
int lastUpdate = SDL_GetTicks();
|
||||||
bool run = true;
|
bool run = true;
|
||||||
|
kb_jp = SDL_GetKeyboardState(NULL);
|
||||||
|
kb_jr = SDL_GetKeyboardState(NULL);
|
||||||
while (run) {
|
while (run) {
|
||||||
while(SDL_PollEvent(&mContext.events)) {
|
while(SDL_PollEvent(&mContext.events)) {
|
||||||
if(mContext.events.type == SDL_QUIT) {
|
if(mContext.events.type == SDL_QUIT) {
|
||||||
run = false;
|
run = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (mContext.events.type == SDL_KEYDOWN) {
|
||||||
|
kb_jp = SDL_GetKeyboardState(NULL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (mContext.events.type == SDL_KEYUP) {
|
||||||
|
kb_jr = SDL_GetKeyboardState(NULL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int start = SDL_GetPerformanceCounter();
|
int start = SDL_GetPerformanceCounter();
|
||||||
|
@ -539,8 +538,6 @@ namespace sdfml {
|
||||||
|
|
||||||
SDL_Delay(floor((1000.0f/FRAMERATE) - elapsedMS));
|
SDL_Delay(floor((1000.0f/FRAMERATE) - elapsedMS));
|
||||||
|
|
||||||
kb_last = SDL_GetKeyboardState(NULL);
|
|
||||||
|
|
||||||
GPU_Flip(mContext.gpu_render);
|
GPU_Flip(mContext.gpu_render);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,20 +593,22 @@ namespace sdfml {
|
||||||
transitionSprite2.create(0, 0, "data/images/black.png");
|
transitionSprite2.create(0, 0, "data/images/black.png");
|
||||||
curState->add(&transitionSprite2);
|
curState->add(&transitionSprite2);
|
||||||
fadeTimer.start(0, []() {
|
fadeTimer.start(0, []() {
|
||||||
transitionSprite2.x = clamp(transitionSprite2.x - 10, -mContext.size.x, 0);
|
transitionSprite2.x = clamp(transitionSprite2.x - (mContext.size.x/FRAMERATE), -mContext.size.x, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}, true);
|
}, true);
|
||||||
|
lockKeys = false;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void switchState(sdState* state) {
|
inline void switchState(sdState* state) {
|
||||||
|
lockKeys = true;
|
||||||
try {
|
try {
|
||||||
if (curState != nullptr) {
|
if (curState != nullptr) {
|
||||||
transitionSprite.create(mContext.size.x, 0, "data/images/black.png");
|
transitionSprite.create(mContext.size.x, 0, "data/images/black.png");
|
||||||
curState->add(&transitionSprite);
|
curState->add(&transitionSprite);
|
||||||
fadeTimer.start(0, []() {
|
fadeTimer.start(0, []() {
|
||||||
transitionSprite.x = clamp(transitionSprite.x - 7, 0, mContext.size.x);
|
transitionSprite.x = clamp(transitionSprite.x - (mContext.size.x/FRAMERATE), 0, mContext.size.x);
|
||||||
return 0;
|
return 0;
|
||||||
}, true);
|
}, true);
|
||||||
switchTimer.start(1, [state](){
|
switchTimer.start(1, [state](){
|
||||||
|
|
Loading…
Reference in a new issue