I am trying to apply a simple gravity via SDL. I can't seem to allow for one user input for each drop gravity creates... for some reason when I key left or right on the keyboard that input gets stuck everytime gravity is enacted.
Should I not allow event handling during any function except main?Code:int gravity() { bool ground; ground = false; while(ground == false) { SDL_PollEvent(&jevent); if(jevent.type == SDL_QUIT) { ground = true; } else if(jevent.type == SDL_KEYDOWN) { switch( jevent.key.keysym.sym ) { case SDLK_UP: break; case SDLK_DOWN: break; case SDLK_LEFT: xxx -= 20; apply_surface(0,0, background, screen); apply_surface(xxx,yyy, unit, screen); if (SDL_Flip(screen) == -1) { return 1; } if(yyy<=(460-15)) { yyy+=20; apply_surface(0,0, background, screen); apply_surface(xxx,yyy, unit, screen); if (SDL_Flip(screen) == -1) { return 1; } } else { ground = true; } break; case SDLK_RIGHT: xxx += 20; apply_surface(0,0, background, screen); apply_surface(xxx,yyy, unit, screen); if (SDL_Flip(screen) == -1) { return 1; } if(yyy<=(460-15)) { yyy+=20; apply_surface(0,0, background, screen); apply_surface(xxx,yyy, unit, screen); if (SDL_Flip(screen) == -1) { return 1; } } else { ground = true; } break; } } } }
I have tried to word this code a ton of different ways and can't seem to allow for it. I have not even started collision detection yet, because I can't get the jump to work the way I want it too.
Thank you for your time.



LinkBack URL
About LinkBacks


