麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

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

SFML game move

2019-11-14 09:19:29
字體:
來源:轉載
供稿:網友
#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; sf::Font font; // States bool rButton = false; // R button/key bool leftButton = false, rightButton = false; bool upButton = false, downButton = false; // Variables int rectRotation = 0; // Rotation of the shape int xVelocity = 0, yVelocity = 0; // Shapes sf::RectangleShape shape1; shape1.setSize(sf::Vector2f(100, 100)); shape1.setPosition(100, 300); // Shapes sf::RectangleShape shape2; shape2.setSize(sf::Vector2f(100, 200)); shape2.setPosition(200, 200); shape2.setFillColor(sf::Color::Blue); // game loop while (play == true) { // EVENTS while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { play = false; } if (event.type == sf::Event::KeyPRessed&&event.key.code == sf::Keyboard::R) { rButton = true; } if (event.type == sf::Event::KeyReleased&&event.key.code == sf::Keyboard::R) { rButton = false; } if (event.type == sf::Event::KeyPressed) { if (event.key.code == sf::Keyboard::Left) leftButton = true; if (event.key.code == sf::Keyboard::Right) rightButton = true; if (event.key.code == sf::Keyboard::Up) upButton = true; if (event.key.code == sf::Keyboard::Down) downButton = true; } // Realeased keyboard if (event.type == sf::Event::KeyReleased) { if (event.key.code == sf::Keyboard::Left) leftButton = false; if (event.key.code == sf::Keyboard::Right) rightButton = false; if (event.key.code == sf::Keyboard::Up) upButton = false; if (event.key.code == sf::Keyboard::Down) downButton = false; } } // LOGIC if (rButton == true) { rectRotation++; shape1.setRotation(rectRotation); } // Movement // x axis if (rightButton == true) { xVelocity = 5; } if (leftButton == true) { xVelocity = -5; } if (leftButton == true && rightButton == true) { xVelocity = 0; } if (leftButton == false && rightButton == false) { xVelocity = 0; } // Y axis if (downButton == true) { yVelocity = 5; } if (upButton == true) { yVelocity = -5; } if (upButton == true && downButton == true) { yVelocity = 0; } if (upButton == false && downButton == false) { yVelocity = 0; } // Move the shape by adding the velocity /*shape1.move(xVelocity, yVelocity); if (shape1.getGlobalBounds().intersects(shape2.getGlobalBounds()) == true) { shape1.move(-xVelocity, -yVelocity); }*/ shape1.move(xVelocity, 0); if (shape1.getGlobalBounds().intersects(shape2.getGlobalBounds()) == true) { shape1.move(-xVelocity, 0); } shape1.move(0, yVelocity); if (shape1.getGlobalBounds().intersects(shape2.getGlobalBounds()) == true) { shape1.move(0, -yVelocity); } // RENDERING window.clear(); window.draw(shape1); window.draw(shape2); window.display(); } // This is the end of the "While" loop // Clean up and close the window window.close(); return 0;}

效果圖,繼續~~

效果圖


上一篇:Sticks --dfs 剪枝

下一篇:Java內部類

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 日韩激情在线视频 | 孕妇体内谢精满日本电影 | 粉嫩av一区二区三区四区在线观看 | 久久人人人| wwwav国产| av视在线 | 九九热精品在线视频 | 中文字幕一区二区三区久久 | 国内精品久久久久影院不卡 | 成人毛片视频在线观看 | lutube成人福利在线观看 | 国产精品一区99 | 国产美女爽到喷白浆的 | 视频一区二区不卡 | 日本娇小videos高潮 | 大号bbwassbigav头交 | 在线免费观看毛片视频 | 国产免费小视频在线观看 | 国产一区二区欧美精品 | 免费在线看黄 | 中文字幕1区2区 | 黄色毛片视频在线观看 | 黄色高清视频网站 | 日韩视频中文 | 成人18免费观看 | 欧美成人午夜 | 久久国产精品二国产精品中国洋人 | 美女视频黄视大全视频免费网址 | 国产xxxxx在线观看 | xnxx 日本19 | 国产精品白嫩白嫩大学美女 | 国内精品久久久久久久久久久久 | 黄网站在线免费看 | 久久精品一二三区 | 一级做a爱片久久毛片a高清 | 国内精品久久久久久久久久 | 色播av在线| 色人阁五月天 | 欧美成人精品h版在线观看 久久久久久三区 | 一级毛片真人免费播放视频 | 亚洲午夜在线视频 |