- Implementat keyPressed

This commit is contained in:
2023-06-04 14:26:34 +02:00
parent 312bed64da
commit f92d483cde
4 changed files with 13 additions and 8 deletions

View File

@@ -24,24 +24,24 @@ int main(int argc, char *argv[])
SDL_Event e;
while (!should_exit)
{
uint8_t keyp=SDL_SCANCODE_UNKNOWN, keydown=SDL_SCANCODE_UNKNOWN;
while(SDL_PollEvent(&e))
{
if (e.type==SDL_QUIT) { should_exit = true; break; }
if (e.type==SDL_KEYDOWN)
{
keydown = e.key.keysym.scancode;
input::updateKey(e.key.keysym.scancode);
}
if (e.type==SDL_KEYUP)
{
keyp = e.key.keysym.scancode;
input::updateKeypressed(e.key.keysym.scancode);
}
}
input::update(keydown,keyp);
if (SDL_GetTicks()-current_ticks >= game::ticks_per_frame)
{
if (!game::loop()) should_exit = true;
input::updateKey(SDL_SCANCODE_UNKNOWN);
input::updateKeypressed(SDL_SCANCODE_UNKNOWN);
current_ticks = SDL_GetTicks();
}
}