国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

SFML game fun

2019-11-14 13:06:58
字體:
來源:轉載
供稿:網友
#include"SFML/Graphics.hpp"using namespace std;#include<iostream>;#include<SFML/Audio.hpp>int main(){ sf::RenderWindow window(sf::VideoMode(800, 600), "Hello from SFML"); // setting the framerate limit to 60 FPS window.setFramerateLimit(60); window.setKeyRepeatEnabled(false); bool play = true; // Event object holding all events sf::Event event; bool aPRessed = false; bool aReleased = false; bool space = false; bool leftClick = false; bool rightClick = false; bool returnReleased = false; bool leftPressed = false; bool rightPressed = false; //Variables int numberOfClicks = 0; int mouseX=0; int mouseY=0; int rectXPosition = 0; // Images sf::Texture image1; if (image1.loadFromFile("Data/image2.png") == -1) { return -1; } // Render shapes sf::RectangleShape rect; rect.setSize(sf::Vector2f(150, 150)); rect.setPosition(0, 0); rect.setFillColor(sf::Color::White); rect.setTexture(&image1); sf::CircleShape circle; circle.setRadius(50); circle.setPosition(100, 100); circle.setFillColor(sf::Color::Blue); // Font sf::Font font; if (font.loadFromFile("Data/28 Days Later.ttf") == 0) { return 1; } // Text sf::Text title; title.setFont(font); title.setCharacterSize(100); title.setString("Hello Game"); title.setPosition(300, 80); title.setColor(sf::Color::Magenta); // Sounds /*sf::SoundBuffer ExplosionBuffer; if (ExplosionBuffer.loadFromFile("Data/Explosion4.wav") == 0) { return 1; } sf::Sound explosion; explosion.setBuffer(ExplosionBuffer); explosion.play(); explosion.setLoop(true); explosion.setVolume(100);*/ // Music sf::Music drumLoop; if (drumLoop.openFromFile("Data/music.ogg") == 0) { return 1; } drumLoop.setLoop(true); drumLoop.play(); // game loop while (play == true) { // EVENTS while (window.pollEvent(event)) { if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::A) { aPressed = true; } if (event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::A) { aReleased = true; } // Space key pressed if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Space) { space = true; } // Space key released if (event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Space) { space = false; } if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Left) { leftPressed = true; } if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Right) { rightPressed = true; } if (event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Left) { leftPressed = false; } if (event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Right) { rightPressed = false; } if (event.type == sf::Event::MouseButtonPressed&& event.mouseButton.button == sf::Mouse::Left) { leftClick = true; } if (event.type == sf::Event::MouseButtonPressed&& event.mouseButton.button == sf::Mouse::Right) { rightClick = true; } if (event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Return) { returnReleased = true; } if (event.type == sf::Event::MouseMoved) { mouseX = event.mouseMove.x; mouseY = event.mouseMove.y; } if (event.type == sf::Event::Closed) { play = false; } }// LOGIC if (aPressed == true) { // print to the console std::cout << "The A key has been pressed!/n"; aPressed = false; } if (aPressed == true) { std::cout << "The A key has been released!/n"; aReleased = false; } if (leftClick == true) { numberOfClicks++; std::cout << "Number of clicks is" << numberOfClicks << "/n"; if (mouseX < 200) { play = false; } leftClick = false; } if (rightClick == true) { numberOfClicks--; std::cout << "Number of clicks is" << numberOfClicks << "/n"; rightClick = false; } if (returnReleased == true) { std::cout << "Return has been released/n"; returnReleased = false; } if (leftPressed == true && rightPressed == true) { std::cout << "left and right are pressed down/n"; } // Print out the position of mouse. std::cout << "Mouse x:" << mouseX << "mouse y:" << mouseY << endl; rectXPosition++; // X position variable of the rectangle rect.setPosition(rectXPosition, rectXPosition); // we set the rectangles X // and Y position to the variable rectPosition // RENGERING window.clear(); window.draw(rect); window.draw(circle); window.draw(title); window.display(); } // This is the end of the "While" loop // Clean up and close the window window.close(); return 0;}

這里寫圖片描述


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乐业县| 新余市| 武夷山市| 潼南县| 同仁县| 西充县| 苗栗县| 龙江县| 榆林市| 瑞安市| 郸城县| 榆林市| 太仓市| 陆川县| 昆明市| 枣强县| 台南县| 新宾| 汉川市| 鄄城县| 保定市| 靖边县| 高清| 房产| 沈丘县| 六安市| 潮安县| 常熟市| 大安市| 永定县| 蒙阴县| 荔浦县| 科技| 马尔康县| 夏河县| 上饶市| 册亨县| 准格尔旗| 大方县| 甘德县| 旅游|