a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

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

SFML game move

2019-11-14 10:00:59
字體:
來源:轉載
供稿:網友
#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;}

效果圖,繼續~~

效果圖


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久热官网 | 亚洲最大成人免费视频 | 欧美在线网站 | 男人都懂的www网站免费观看 | 超碰人人爱 | 日本欧美国产 | 精品999| 国产精自产拍久久久久久 | 国产日韩免费 | 亚洲黄色免费在线看 | 中文字幕一区二区三区乱码在线 | 亚洲日韩视频免费观看 | 欧美日韩亚洲视频 | 国产精品久久久久毛片软件 | 一区小视频| 成人福利在线观看 | 国产成人精品999在线观看 | 精品suv一区二区 | 亚洲天堂男人 | 亚洲一区二区精品视频 | 久热精品视频 | 精品99久久久久久 | 综合网视频 | 免费看a| 中文字幕在线观看精品视频 | 毛片链接 | 91大神免费在线观看 | 免费不卡视频在线观看 | 在线久草 | 日韩精品久久久久 | 久久精品国产99国产 | 97国产一区二区精品久久呦 | 黄色电影免费看 | 一区二区在线视频 | 午夜看片 | 日本免费在线观看 | 日韩精品一区二区三区免费视频 | 亚洲美女网站 | 成人免费激情视频 | 91精品麻豆日日躁夜夜躁 | 深夜av在线|