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()); } } }
// 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; }