int showWelcome(RenderWindow *window){ Texture texBack, texWelcome, texSprite1, texSprite2, texSprite3, texSprite4, texSprite5, texSprite6; if (!texBack.loadFromFile("../data/background.png") || !texWelcome.loadFromFile("../data/welcome.png") || !texSprite1.loadFromFile("../data/sprite1.png") || !texSprite2.loadFromFile("../data/sprite2.png") || !texSprite3.loadFromFile("../data/sprite3.png") || !texSprite4.loadFromFile("../data/sprite4.png") || !texSprite5.loadFromFile("../data/sprite5.png") || !texSprite6.loadFromFile("../data/sprite6.png")) { return EXIT_FAILURE; } Sprite spriteWelcome(texWelcome), sprite1(texSprite1), sprite2(texSprite2), sprite3(texSprite3), sprite4(texSprite4), sprite5(texSprite5), sprite6(texSprite6), spriteBack(texBack); float y = 0; Clock clk; clk.restart(); Time tme = clk.getElapsedTime(); while (tme.asSeconds() < 5) { window->clear(); window->draw(spriteBack); sprite1.setPosition(100.0, 1.5*y + 50.0); sprite2.setPosition(300.0, 0.5*y + 400.0); sprite3.setPosition(500.0, y + 200.0); sprite4.setPosition(700.0, 2 * y + 700.0); sprite5.setPosition(900.0, y + 100.0); sprite6.setPosition(1100.0, 1.75*y + 750); window->draw(sprite1); window->draw(sprite2); window->draw(sprite3); window->draw(sprite4); window->draw(sprite5); window->draw(sprite6); window->draw(spriteWelcome); window->display(); tme = clk.getElapsedTime(); y -= 1; } }
/** @SYMTestCaseID GRAPHICS-WSERV-00-0001 @SYMDEF PDEF117721 @SYMTestCaseDesc Test Screenrotation does not cause panic by sprite with NULL bitmap and NULL maskbitmap @SYMTestPriority High @SYMTestStatus Implemented @SYMTestActions Defines two sprites and one with Null iBitmap and Null iMaskBitmap, then rotate the screen to 90 degrees @SYMTestExpectedResults the screen rotation will not cause wserv a panic */ void CTTSprite::RotateNullSpriteL() { if (TheClient->iScreen->NumScreenModes() < 2) { LOG_MESSAGE(_L("WARNING: Unable to rotate screen")); return; } // Sprite Members TSpriteMember spriteMember1,spriteMember2; SetUpMember(spriteMember1); SetUpMember(spriteMember2); spriteMember2.iBitmap = NULL; // Create windows RWindowGroup group(TheClient->iWs); User::LeaveIfError(group.Construct(ENullWsHandle,EFalse)); //Creates a Group Window CleanupClosePushL(group); RBlankWindow win(TheClient->iWs); User::LeaveIfError(win.Construct(group,ENullWsHandle)); //Creates a Blank Window CleanupClosePushL(win); win.SetVisible(ETrue); win.SetColor(TRgb::Gray4(2)); win.Activate(); TheClient->Flush(); // Create Sprites RWsSprite sprite1(TheClient->iWs); CleanupClosePushL(sprite1); SetUpSpriteL(sprite1, win,TPoint(20,70),spriteMember1,0); RWsSprite sprite2(TheClient->iWs); CleanupClosePushL(sprite2); SetUpSpriteL(sprite2, win,TPoint(80,130),spriteMember2,0); RWsSprite sprite3(TheClient->iWs); CleanupClosePushL(sprite3); SetUpSpriteL(sprite3, win,TPoint(2800,2130),spriteMember1,0); TheClient->Flush(); // Get the original screen mode CWsScreenDevice* device = TheClient->iScreen; TInt originalScreenMode = device->CurrentScreenMode(); TPixelsTwipsAndRotation originalModeSettings; device->GetScreenModeSizeAndRotation(originalScreenMode,originalModeSettings); // Rotate screens TPixelsAndRotation pixelsAndRotation; device->SetScreenMode( 1 ); device->GetDefaultScreenSizeAndRotation(pixelsAndRotation); device->SetCurrentRotations(1,pixelsAndRotation.iRotation); device->SetScreenSizeAndRotation(pixelsAndRotation); User::After(1000000); CleanupStack::PopAndDestroy(5,&group); // Restore the original screen mode device->SetScreenMode(originalScreenMode); device->SetCurrentRotations(originalScreenMode,originalModeSettings.iRotation); device->SetScreenSizeAndRotation(originalModeSettings); TheClient->Flush(); }
void GUI::drawObs(Obstacles *obs) { for(int i=0 ; i<56 ; i++) { if(obs[i].getISExist()==1) { sf::Texture texture3; if (!texture3.loadFromFile("obs.png")){} sf::Sprite sprite3(texture3); sprite3.setPosition(sf::Vector2f(obs[i].getX(), obs[i].getY())); window->draw(sprite3); } } }
MainMenu::MenuResult MainMenu::ChooseGreedy (sf::RenderWindow& window, int& greedytype) { window.clear(); sf::Texture texture; texture.loadFromFile("images/MainMenu.png"); sf::Sprite sprite(texture); window.draw(sprite); texture.loadFromFile("images/GreedyByValue.png"); sf::Sprite sprite2(texture); sprite2.setPosition(100, 300); window.draw(sprite2); texture.loadFromFile("images/GreedyByPath.png"); sf::Sprite sprite3(texture); sprite3.setPosition(400, 300); window.draw(sprite3); window.display(); //minta input user, waktu diklik nge return sf::Event event; while (true) { while (window.pollEvent(event)) { if (event.type == sf:: Event::MouseButtonPressed) { if (event.mouseButton.x >= 100 && event.mouseButton.x <= 300 && event.mouseButton.y >= 300 && event.mouseButton.y <= 600 && greedytype == 1) { return AIonlyByValue; } else if (event.mouseButton.x >= 400 && event.mouseButton.x <= 600 && event.mouseButton.y >= 300 && event.mouseButton.y <= 600 && greedytype == 1) { return AIonlyByDist; } else if (event.mouseButton.x >= 100 && event.mouseButton.x <= 300 && event.mouseButton.y >= 300 && event.mouseButton.y <= 600 && greedytype == 2) { return VSAIByValue; } else if (event.mouseButton.x >= 400 && event.mouseButton.x <= 600 && event.mouseButton.y >= 300 && event.mouseButton.y <= 600 && greedytype == 2) { return VSAIByDist; } } } } }
int main() { try { std::string mediaPath = UTILS::GetMediaFolder(); std::string fontPath = mediaPath + "Fonts/courier.ttf"; RenderContextSetup setup; setup.Width = 640; setup.Height = 480; RenderContext renderContext(setup); //LayoutManager layout(&renderContext); // Sprite setup Sprite sprite0(&renderContext); Sprite sprite1(&renderContext); Sprite sprite2(&renderContext); Sprite sprite3(&renderContext); sprite0.SetSize(SPRITE_SIZE, SPRITE_SIZE); sprite1.SetSize(SPRITE_SIZE, SPRITE_SIZE); sprite2.SetSize(SPRITE_SIZE, SPRITE_SIZE); sprite3.SetSize(SPRITE_SIZE, SPRITE_SIZE); sprite0.SetPosition(0, 0); sprite1.SetPosition(renderContext.GetWindowWidth() - SPRITE_SIZE, 0); sprite2.SetPosition(0, renderContext.GetWindowHeight() - SPRITE_SIZE); sprite3.SetPosition(renderContext.GetWindowWidth() - SPRITE_SIZE, renderContext.GetWindowHeight() - SPRITE_SIZE); sprite0.SetTexture(mediaPath + "Textures/Smile.png"); sprite1.SetTexture(mediaPath + "Textures/Smile.png"); sprite2.SetTexture(mediaPath + "Textures/Smile.png"); sprite3.SetTexture(mediaPath + "Textures/Smile.png"); //Console console(&renderContext); // Text setup Text text(&renderContext, fontPath); text << Text::set_size(32) << "Font rendering is guano!"; float opacity = 1.0f; bool direction = true; while (renderContext.ProcessMessage()) { renderContext.Clear(); if (direction) { opacity -= 0.01f; sprite0.SetPosition(sprite0.GetX() + 1, sprite0.GetY() + 1); sprite3.SetPosition(sprite3.GetX() - 1, sprite3.GetY() - 1); if (opacity <= 0.0f) { direction = false; } } else { opacity += 0.01f; sprite0.SetPosition(sprite0.GetX() - 1, sprite0.GetY() - 1); sprite3.SetPosition(sprite3.GetX() + 1, sprite3.GetY() + 1); if (opacity >= 1.0f) { direction = true; } } sprite0.SetOpacity(opacity); sprite3.SetOpacity(opacity); sprite0.Render(); sprite1.Render(); sprite2.Render(); sprite3.Render(); //console.Render(); text.Render(); renderContext.Present(); } return 0; } catch (std::exception& ex) { ::MessageBoxA(NULL, ex.what(), NULL, NULL); } }
MainMenu::MenuResult MainMenu::Show(sf::RenderWindow& window) { //Load menu image from file sf::Texture texture; texture.loadFromFile("images/MainMenu.png"); sf::Sprite sprite(texture); window.draw(sprite); //load gambar peti texture.loadFromFile("images/chest1.png"); sf::Sprite sprite2(texture); sprite2.setPosition(400, 250); window.draw(sprite2); //load gambar orang texture.loadFromFile("images/hunter1.png"); sf::Sprite sprite3(texture); sprite3.setPosition(270, 350); window.draw(sprite3); //load gambar kaki texture.loadFromFile("images/footprints1.png"); sf::Sprite sprite4(texture); sprite4.setPosition(100, 250); window.draw(sprite4); sprite4.setPosition(160, 350); window.draw(sprite4); sprite4.setPosition(220, 430); window.draw(sprite4); //Play menu item coordinates MenuItem PlayButton; PlayButton.texture.loadFromFile("images/PlayButton.png"); PlayButton.sprite.setTexture(PlayButton.texture); PlayButton.sprite.setPosition(840,325); PlayButton.action = Play; window.draw(PlayButton.sprite); //Credit menu item coordinates MenuItem CreditsButton; CreditsButton.texture.loadFromFile("images/CreditsButton.png"); CreditsButton.sprite.setTexture(CreditsButton.texture); CreditsButton.sprite.setPosition(840,405); CreditsButton.action = Credits; window.draw(CreditsButton.sprite); //Exit menu item coordinates MenuItem ExitButton; ExitButton.texture.loadFromFile("images/ExitButton.png"); ExitButton.sprite.setTexture(ExitButton.texture); ExitButton.sprite.setPosition(840,485); ExitButton.action = Exit; window.draw(ExitButton.sprite); window.display(); _menuItems.push_back(PlayButton); _menuItems.push_back(CreditsButton); _menuItems.push_back(ExitButton); return GetMenuResponse(window); }
void MainMenu::ShowBeliBarang(sf::RenderWindow& window,int &modal, int &toolsmerah, int &toolskuning, int &toolshijau) { while (true) { window.clear(); //Load menu image from file sf::Texture texture; texture.loadFromFile("images/MainMenu.png"); sf::Sprite sprite(texture); window.draw(sprite); //gambar tools sf::Texture texture1; texture1.loadFromFile("images/toolsmerah.png"); sf::Sprite sprite1(texture1); sprite1.setPosition(100, 330); window.draw(sprite1); texture1.loadFromFile("images/toolskuning.png"); sprite1.setPosition(400, 330); window.draw(sprite1); texture1.loadFromFile("images/toolshijau.png"); sprite1.setPosition(700, 330); window.draw(sprite1); //angka sf::Font font1; font1.loadFromFile("fonts/BACHELOR.TTF"); sf::Text text1; text1.setFont(font1); text1.setColor(sf::Color::Black); text1.setCharacterSize(50); text1.setStyle(sf::Text::Bold); text1.setPosition(230, 360); string Tempstr = to_string(toolsmerah); text1.setString(Tempstr); window.draw(text1); //angka sf::Text text2; text2.setFont(font1); text2.setColor(sf::Color::Black); text2.setCharacterSize(50); text2.setStyle(sf::Text::Bold); text2.setPosition(530, 360); string Tempstr1 = to_string(toolskuning); text2.setString(Tempstr1); window.draw(text2); sf::Text text3; text3.setFont(font1); text3.setColor(sf::Color::Black); text3.setCharacterSize(50); text3.setStyle(sf::Text::Bold); text3.setPosition(830, 360); string Tempstr2 = to_string(toolshijau); text3.setString(Tempstr2); window.draw(text3); //modal texture.loadFromFile("images/Modal.png"); sf::Sprite sprite3(texture); sprite3.setPosition(50, 550); window.draw(sprite3); sf::Text text4; text4.setFont(font1); text4.setColor(sf::Color::Red); text4.setCharacterSize(70); text4.setStyle(sf::Text::Bold); //text4.setStyle(sf::Text::Italic); text4.setPosition(350, 550); string Tempstr3 = to_string(modal); text4.setString(Tempstr3); window.draw(text4); //plus button MenuItem PlusButton; PlusButton.texture.loadFromFile("images/PlusButton.png"); PlusButton.sprite.setTexture(PlusButton.texture); PlusButton.sprite.setPosition(200, 210); window.draw(PlusButton.sprite); PlusButton.sprite.setPosition(500, 210); window.draw(PlusButton.sprite); PlusButton.sprite.setPosition(800, 210); window.draw(PlusButton.sprite); //minus button MenuItem MinusButton; MinusButton.texture.loadFromFile("images/MinusButton.png"); MinusButton.sprite.setTexture(MinusButton.texture); MinusButton.sprite.setPosition(200, 460); window.draw(MinusButton.sprite); MinusButton.sprite.setPosition(500, 460); window.draw(MinusButton.sprite); MinusButton.sprite.setPosition(800, 460); window.draw(MinusButton.sprite); //ready button texture.loadFromFile("images/Ready.png"); sf::Sprite sprite2(texture); sprite2.setPosition(900, 580); window.draw(sprite2); //Setup clickable regions sf::Event event; while(window.pollEvent (event)) { if(event.type == sf::Event::MouseButtonPressed) { if(event.mouseButton.x < 300 && event.mouseButton.x > 200 && event.mouseButton.y < 290 && event.mouseButton.y > 210 && modal>=3) { toolsmerah++; modal-=3; } if(event.mouseButton.x < 600 && event.mouseButton.x > 500 && event.mouseButton.y < 290 && event.mouseButton.y > 210 && modal>=2) { toolskuning++; modal-=2; } if(event.mouseButton.x < 900 && event.mouseButton.x > 800 && event.mouseButton.y < 290 && event.mouseButton.y > 210 && modal>=1) { toolshijau++; modal--; } if(event.mouseButton.x < 300 && event.mouseButton.x > 200 && event.mouseButton.y < 540 && event.mouseButton.y > 460) { if(toolsmerah>0) { toolsmerah--; modal+=3; } } if(event.mouseButton.x < 600 && event.mouseButton.x > 500 && event.mouseButton.y < 540 && event.mouseButton.y > 460) { if(toolskuning>0) { toolskuning--; modal+=2; } } if(event.mouseButton.x < 900 && event.mouseButton.x > 800 && event.mouseButton.y < 540 && event.mouseButton.y > 460) { if(toolshijau>0) { toolshijau--; modal++; } } if(event.mouseButton.x < 1000 && event.mouseButton.x > 900 && event.mouseButton.y <746 && event.mouseButton.y > 600) { return; } } } window.display(); } }