本文整理汇总了C++中Dot::handle_input方法的典型用法代码示例。如果您正苦于以下问题:C++ Dot::handle_input方法的具体用法?C++ Dot::handle_input怎么用?C++ Dot::handle_input使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dot
的用法示例。
在下文中一共展示了Dot::handle_input方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main ( int argc, char** argv )
{
Setup setup1;
//cerr << "address of Setup: " << &setup1 << '\n';
ImageManager im1;
SoundManager sm1;
Dot myDot;
World world1;
cout << "rest of main \n";
if(setup1.init() == false)
{
return 1;
}
//newScreen = setup1.getScreen();
if(im1.loadFont() == false)
{
return 1;
}
if(im1.getFiles() == false)
{
cout << "error loading images" << endl;
return 1;
}
if(sm1.soundFiles() == false)
{
cout << "error loading sounds \n";
return 1;
}
if(world1.set_tiles() == false)
{
cout << "error loading map \n";
return 1;
}
//Mix_Music* bgm = sm1.getTrack(0);
// make sure SDL cleans up before exit
atexit(SDL_Quit);
// centre the bitmap on screen
//SDL_Rect dstrect;
//dstrect.x = (screen->w - bmp->w) / 2;
//dstrect.y = (screen->h - bmp->h) / 2;
Timer frames1;
Timer delta;
delta.start();
// program main loop
bool done = false;
while (done == false)
{
frames1.start();
// message processing loop
SDL_Event event;
while (SDL_PollEvent(&event))
{
//cout << &event << endl;
//SDL_Event *e = &event;
myDot.change_heading(event);
myDot.handle_input(event);
if(event.type == SDL_QUIT)
{
done = true;
}
// get keystates
//Uint8 *keystates = SDL_GetKeyState(NULL);
if(event.type == SDL_KEYDOWN)
{
if(event.key.keysym.sym == SDLK_p)
{
if(Mix_PlayingMusic() == 0)
{
sm1.playAll();
}
else
{
if(Mix_PausedMusic() == 1)
{
Mix_ResumeMusic();
}
else
{
Mix_PauseMusic();
}
}
}
if(event.key.keysym.sym == SDLK_ESCAPE)
{
done = true;
//.........这里部分代码省略.........
示例2: move
//.........这里部分代码省略.........
clipsRight[1].h = FOO_HEIGHT;
clipsRight[2].x = FOO_WIDTH * 2;
clipsRight[2].y = 0;
clipsRight[2].w = FOO_WIDTH;
clipsRight[2].h = FOO_HEIGHT;
clipsRight[3].x = FOO_WIDTH * 3;
clipsRight[3].y = 0;
clipsRight[3].w = FOO_WIDTH;
clipsRight[3].h = FOO_HEIGHT;
clipsLeft[0].x = 0;
clipsLeft[0].y = FOO_HEIGHT;
clipsLeft[0].w = FOO_WIDTH;
clipsLeft[0].h = FOO_HEIGHT;
clipsLeft[1].x = FOO_WIDTH;
clipsLeft[1].y = FOO_HEIGHT;
clipsLeft[1].w = FOO_WIDTH;
clipsLeft[1].h = FOO_HEIGHT;
clipsLeft[2].x = FOO_WIDTH * 2;
clipsLeft[2].y = FOO_HEIGHT;
clipsLeft[2].w = FOO_WIDTH;
clipsLeft[2].h = FOO_HEIGHT;
clipsLeft[3].x = FOO_WIDTH * 3;
clipsLeft[3].y = FOO_HEIGHT;
clipsLeft[3].w = FOO_WIDTH;
clipsLeft[3].h = FOO_HEIGHT;
}*/
int main( int argc, char* args[] )
{
bool quit = false;
int frame = 0;
bool cap = true;
Timer fps;
Timer update;
if( init() == false )
return 1;
if( load_files() == false )
return 1;
//set_clips();
Dot myDot;
update.start();
while( quit == false)
{
fps.start();
while( SDL_PollEvent(&event) )
{
myDot.handle_input();
if( event.type == SDL_QUIT )
quit = true;
}
myDot.move();
myDot.set_camera();
//std::stringstream fpsm;
//fpsm << "FPS: " << frame / ( fps.get_ticks() / 1000.f );
apply_surface( 0, 0, background, screen, &camera );
//SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) );
myDot.show();
if( update.get_ticks() > 1000.f )
{
std::stringstream fpsm;
fpsm << "FPS: " << ( frame );
fpsmessage = TTF_RenderText_Solid(font, fpsm.str().c_str(), textColor );
frame = 0;
update.start();
}
apply_surface( 10, 10, fpsmessage, screen);
if( SDL_Flip( screen ) == -1 )
return 1;
frame++;
if( ( ( fps.get_ticks() ) < 1000 / FRAMES_PER_SECOND ) )
SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - ( fps.get_ticks() ) );
}
clean_up();
return 0;
}
示例3: main
int main(int argc, char* args[]) {
//Quit flag
bool quit = false;
//Make the dot
Dot myDot;
//The frame rate regulator
Timer fps;
//Initialize
if (init() == false) {
return 1;
}
//Load the files
if (load_files() == false) {
return 1;
}
//While the user hasn't quit
while (quit == false) {
//Start the frame timer
fps.start();
//While there's events to handle
while (SDL_PollEvent(&event)) {
//Handle events for the dot
myDot.handle_input();
//If the user has Xed out the window
if (event.type == SDL_QUIT) {
//Quit the program
quit = true;
}
}
//Move the dot
myDot.move();
//Fill the screen white
SDL_FillRect(screen, &screen->clip_rect,
SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF));
//Show the dot on the screen
myDot.show();
//Update the screen
if (SDL_Flip(screen) == -1) {
return 1;
}
//Cap the frame rate
if (fps.get_ticks() < 1000 / FRAMES_PER_SECOND) {
SDL_Delay((1000 / FRAMES_PER_SECOND) - fps.get_ticks());
}
}
//Clean up
clean_up();
return 0;
}
示例4: main
int main( int argc, char* args[] )
{
//Quit flag
bool quit = false;
//The dot that will be used
Dot myDot;
//Keeps track of time since last rendering
Timer delta;
//Initialize
if( init() == false )
{
return 1;
}
//Load the files
if( load_files() == false )
{
return 1;
}
//Start delta timer
delta.start();
//While the user hasn't quit
while( quit == false )
{
//While there's events to handle
while( SDL_PollEvent( &event ) )
{
//Handle events for the dot
myDot.handle_input();
//If the user has Xed out the window
if( event.type == SDL_QUIT )
{
//Quit the program
quit = true;
}
}
//Move the dot
myDot.move( delta.get_ticks() );
//Restart delta timer
delta.start();
//Fill the screen white
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) );
//Show the dot on the screen
myDot.show();
//Update the screen
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
}
//Clean up
clean_up();
return 0;
}
示例5: main
int main( int argc, char* args[] )
{
//Quit flag
bool quit = false;
//The dot
Dot myDot;
//The tiles that will be used
Tile *tiles[ TOTAL_TILES ];
//The frame rate regulator
Timer fps;
//Initialize
if( init() == false )
{
return 1;
}
//Load the files
if( load_files() == false )
{
return 1;
}
//Clip the tile sheet
clip_tiles();
//Set the tiles
if( set_tiles( tiles ) == false )
{
return 1;
}
//While the user hasn't quit
while( quit == false )
{
//Start the frame timer
fps.start();
//While there's events to handle
while( SDL_PollEvent( &event ) )
{
//Handle events for the dot
myDot.handle_input();
//If the user has Xed out the window
if( event.type == SDL_QUIT )
{
//Quit the program
quit = true;
}
}
//Move the dot
myDot.move( tiles );
//Set the camera
myDot.set_camera();
//Show the tiles
for( int t = 0; t < TOTAL_TILES; t++ )
{
tiles[ t ]->show();
}
//Show the dot on the screen
myDot.show();
//Update the screen
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
//Cap the frame rate
if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
{
SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );
}
}
//Clean up
clean_up( tiles );
return 0;
}
示例6: main
int main( int argc, char* args[] )
{
//Quit flag
bool quit = false;
//The dot
Dot myDot;
//The frame rate regulator
Timer fps;
//Initialize
if( init() == false )
{
return 1;
}
//Load the files
if( load_files() == false )
{
return 1;
}
//While the user hasn't quit
while( quit == false )
{
//Start the frame timer
fps.start();
//While there's events to handle
while( SDL_PollEvent( &event ) )
{
//Handle events for the dot
myDot.handle_input();
//If the user has Xed out the window
if( event.type == SDL_QUIT )
{
//Quit the program
quit = true;
}
}
//Move the dot
myDot.move();
//Set the camera
myDot.set_camera();
//Show the background
apply_surface( 0, 0, background, screen, &camera );
//Show the dot on the screen
myDot.show();
//Update the screen
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
//Cap the frame rate
if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
{
SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );
}
}
//Clean up
clean_up();
return 0;
}