- Implementat keyPressed
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,10 +36,14 @@ namespace input
|
||||
return keydown;
|
||||
}
|
||||
|
||||
void update(uint8_t key, uint8_t keyp)
|
||||
void updateKey(uint8_t key)
|
||||
{
|
||||
keypressed = keyp;
|
||||
keydown = key;
|
||||
}
|
||||
|
||||
void updateKeypressed(uint8_t key)
|
||||
{
|
||||
keypressed = key;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,5 +25,6 @@ namespace input
|
||||
/// @return Quina tecla està sent polsada
|
||||
const uint8_t whichKey();
|
||||
|
||||
void update(uint8_t key, uint8_t keyp);
|
||||
void updateKey(uint8_t key);
|
||||
void updateKeypressed(uint8_t key);
|
||||
}
|
||||
@@ -49,7 +49,7 @@ int sx=1, sy=0;
|
||||
|
||||
bool game::loop()
|
||||
{
|
||||
if ( input::keyDown(SDL_SCANCODE_Q) )
|
||||
if ( input::keyPressed(SDL_SCANCODE_Q) )
|
||||
{
|
||||
ii++;if(ii>3)ii=0;
|
||||
restart();
|
||||
|
||||
Reference in New Issue
Block a user