本文整理汇总了C++中window::handle_events方法的典型用法代码示例。如果您正苦于以下问题:C++ window::handle_events方法的具体用法?C++ window::handle_events怎么用?C++ window::handle_events使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类window
的用法示例。
在下文中一共展示了window::handle_events方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkInventory
void player::checkInventory(window &mainWindow)
{
int j = 0;
inventoryFlag = false;
SDL_Event event;
tile select;
select.x = 0;
select.y = 0;
select.w = 32;
select.h = 32;
select.texture = load_image("../data/sprites/outline.bmp");
timer fps;
Uint32 windowColour = SDL_MapRGB(mainWindow.screen->format, 255, 255, 255);
bool quit(false);
while(!quit)
{
fps.start();
while(SDL_PollEvent(&event))
{
mainWindow.handle_events(event);
if(event.type == SDL_QUIT)
{
exit(0);
}
}
Uint8 *keystates = SDL_GetKeyState(NULL);
if(keystates[SDLK_q])
{quit=true;}
else if(keystates[SDLK_UP])
{
j -= SCREENHEIGHT/(SPRITEHEIGHT*2);
select.y -= SPRITEHEIGHT*2;
if(select.y<0){select.y+=SPRITEHEIGHT*2;
j+=SCREENHEIGHT/(SPRITEHEIGHT*2);}
}else if(keystates[SDLK_DOWN])
{
j += SCREENHEIGHT/(SPRITEHEIGHT*2);
select.y += SPRITEHEIGHT*2;
if(select.y+select.h>SCREENHEIGHT){select.y-=SPRITEHEIGHT*2;
j-=SCREENHEIGHT/(SPRITEHEIGHT*2);}
}else if(keystates[SDLK_RIGHT])
{
j += 1;
select.x += SPRITEWIDTH*2;
if(select.x+select.w>SCREENWIDTH){select.x-=SPRITEWIDTH*2; j-=1;}
}else if(keystates[SDLK_LEFT])
{
j -= 1;
select.x -= SPRITEWIDTH*2;
if(select.x<0){select.x+=SPRITEWIDTH*2; j+=1;}
}else if(keystates[SDLK_SPACE])
{
if(inventory[j]->type == itemType::weapon)
{
primaryWeapon = *reinterpret_cast<weapon*>(inventory[j]);
}
}
SDL_FillRect(mainWindow.screen, NULL, windowColour);
int itemX(0), itemY(0);
for(unsigned int i=0;i<inventory.size();i++)
{
apply_surface(itemX, itemY, inventory[i]->texture[0],
mainWindow.screen);
if(itemX+inventory[i]->w+SPRITEWIDTH > SCREENWIDTH)
{itemY += inventory[i]->w + SPRITEWIDTH; itemX = 0;}
else{itemX += inventory[i]->w+SPRITEWIDTH;}
}
apply_surface(select.x, select.y, select.texture, mainWindow.screen);
SDL_Flip(mainWindow.screen);
if(fps.get_ticks() < 1000/12)
{
SDL_Delay((1000/12) - fps.get_ticks());
}
}
}
示例2: list
// container
//
bool container::list(window &mainWindow)
{
int j = 0;
SDL_Event event;
timer fps;
tile select;
select.x = 0;
select.y = 0;
select.w = 32;
select.h = 32;
select.texture = load_image("../data/outline.bmp");
bool quit(false);
Uint32 windowColour = SDL_MapRGB(mainWindow.screen->format, 255,255,255);
while(!quit)
{
fps.start();
while(SDL_PollEvent(&event))
{
mainWindow.handle_events(event);
if(event.type == SDL_QUIT)
{
quit = true;
}
}
Uint8 *keystates = SDL_GetKeyState(NULL);
if(keystates[SDLK_q])
{quit = true;}
else if(keystates[SDLK_UP])
{
select.y -= SPRITEHEIGHT*2;
if(select.y<0){select.y+=SPRITEHEIGHT*2;}
}else if(keystates[SDLK_DOWN])
{
select.y += SPRITEHEIGHT*2;
if(select.y+select.h>SCREENHEIGHT){select.y-=SPRITEHEIGHT*2;}
}else if(keystates[SDLK_RIGHT])
{
select.x += SPRITEWIDTH*2;
if(select.x+select.w>SCREENWIDTH)
{
select.x -= SPRITEWIDTH*2;
j += 1;
}
}else if(keystates[SDLK_LEFT])
{
select.x -= SPRITEWIDTH*2;
if(select.x-select.w<0)
{
select.x += SPRITEWIDTH*2;
j += 1;
}
}else if(keystates[SDLK_SPACE])
{
}
SDL_FillRect(mainWindow.screen, NULL, windowColour);
int itemX(0), itemY(0);
for(unsigned int i=0;i<contents.size();i++)
{
apply_surface(itemX, itemY, contents[i]->texture[0],
mainWindow.screen);
if(itemX+contents[i]->w+SPRITEWIDTH > SCREENWIDTH)
{
itemY += contents[i]->w+SPRITEWIDTH > SCREENWIDTH;
itemX = 0;
}else
{
itemX += contents[i]->w+SPRITEWIDTH;
}
}
apply_surface(select.x, select.y, select.texture, mainWindow.screen);
SDL_Flip(mainWindow.screen);
if(fps.get_ticks() < 1000/12)
{
SDL_Delay((1000/12) - fps.get_ticks());
}
}
return true;
}