想破脑子都想不会。。求各位帮帮忙
第一段函数,mySquare代表一个小人,通过handle_input键盘操作赋予小人方向和速度,move()和show()函数则是控制小人的移动和展示小人在屏幕上。//While there's events to handle
while( SDL_PollEvent( &event ) )
{
//Handle events for the square
mySquare.handle_input();
//If the user has Xed out the window
if( event.type == SDL_QUIT )
{
//Quit the program
quit = true;
}
}
//Move the square
mySquare.move();
//Show the square on the screen
mySquare.show();
第二段函数则是控制游戏背景的自动滚动,
//Scroll background
bgY -= 2;
//If the background has gone too far
if( bgY <= -background2->h )
{
//Reset the offset
bgY = 0;
}
//Show the background
apply_surface( bgX, bgY, background2, screen );
apply_surface( bgX,bgY + background2->h, background2, screen );
//Cap the frame rate
if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
{
SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );
}
现在我想在游戏背景自动滚动的前提下,能通过键盘控制小人的移动,请问这段函数应该如何拼凑,如果放在同一个while里面我试过了不行啊。。。该怎么弄,老师让我们做一个雷电的游戏。好难好难。。。。是SDL的