Programación General > C/C++
colaborar con esta idea en sdl c++
(1/1)
luchojimenez:
lo quiero es hacer es es un interrruptor en OFF junto a un bombillo y que cuando se presione una tecla se ponga en ON y se encienda el bombillo, por favor orientacion en sdl c++, no estoy pidiendo codigo he adui my gameloop
--- Código: C++ --- while( gameIsRunning ) { //Events //Logic //Rendering } //Game Loop while( quit == false ) { //Start the frame timer fps.start();//Events while( SDL_PollEvent( &event ) ) { myDot.handle_input(); if( event.type == SDL_QUIT ) { quit = true; } }//Logic myDot.move();//Rendering SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) ); myDot.show(); if( SDL_Flip( screen ) == -1 ) { return 1; }while( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ){} } void Dot::handle_input() { if( event.type == SDL_KEYDOWN ) { switch( event.key.keysym.sym ) { case SDLK_UP: yVel -= DOT_HEIGHT / 2; break; case SDLK_DOWN: yVel += DOT_HEIGHT / 2; break; case SDLK_LEFT: xVel -= DOT_WIDTH / 2; break; case SDLK_RIGHT: xVel += DOT_WIDTH / 2; break; } } else if( event.type == SDL_KEYUP ) { switch( event.key.keysym.sym ) { case SDLK_UP: yVel += DOT_HEIGHT / 2; break; case SDLK_DOWN: yVel -= DOT_HEIGHT / 2; break; case SDLK_LEFT: xVel += DOT_WIDTH / 2; break; case SDLK_RIGHT: xVel -= DOT_WIDTH / 2; break; } } x += xVel; if( ( x < 0 ) || ( x + DOT_WIDTH > SCREEN_WIDTH ) ) { x -= xVel; } y += yVel; if( ( y < 0 ) || ( y + DOT_HEIGHT > SCREEN_HEIGHT ) ) { y -= yVel; } }
Navegación
Ir a la versión completa