QuoteI am making a Tetris clone using SDL. I have made a class for input, and in the past this has worked fine for me. But I do not think it is suited for what i am doing because all my inputs are laggy. The basic code is this:
int main(int argc, char* argv[]) { Input input; int game_timer = 2000; while(true){ bool a; bool d; if(game_timer > 200){ string event = input.check_event(); if(event == "a_d"){ a = true; }else if(event == "d_d"){ d = true; }else if(event == "a_u"){ a = false; }else if(event == "d_u"){ d = false; } if(a == true){ tet_left() //moves tetrimino to the left } if(d == true){ tet_right() //Moves tetrimino to the right } move_tet_down() //Moves tetrimino down draw_tet() //Draws the tetrimino game_timer = 0; } game_timer++; }
WIth my input class being:
string Input::check_event() { while (SDL_PollEvent(&event)) { if (event.type == SDL_KEYDOWN) { switch (event.key.keysym.sym) { case SDLK_a: return "a_d"; case SDLK_d: return "d_d"; case SDLK_e: return "space_d"; case SDLK_RETURN: return "e_d"; } } else if (event.type == SDL_KEYUP) { switch (event.key.keysym.sym) { case SDLK_a: return "a_u"; case SDLK_d: return "d_u"; case SDLK_e: return "e_u"; } } else if (event.type == SDL_QUIT) { return "quit"; } } return "nothing"; }
Please note this is example code.
I believe the issue is that I am drawing the tetrimino after if moves, so it only appears so move to the side after it moves down. But drawing it right after the player moves the block doesnt help either so any ideas are appreciated.