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

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

SFML game move

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

效果圖,繼續~~

效果圖


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 特黄一区二区三区 | japanese massage tube | 亚洲片在线观看 | 日日噜噜噜夜夜狠狠久久蜜桃 | 国产一级大片在线观看 | 免费观看三级毛片 | 久久精品久久久久 | 亚洲国产超高清a毛毛片 | 极品美女一级毛片 | 国产精品久久久久一区二区 | 免费人成在线观看网站 | 国产午夜精品久久久 | 91国内精品久久久久免费影院 | 成人一区二区在线观看视频 | 久久新网址 | 特级毛片全部免费播放器 | 高清国产午夜精品久久久久久 | 男女无遮挡羞羞视频 | 88xx成人永久免费观看 | 欧美乱论 | 久草中文网 | 在线成人免费观看 | 欧美乱淫 | 色淫网站免费视频 | 成年人黄色免费网站 | 91成人免费看 | 一夜新娘第三季免费观看 | 日韩剧情片 | 意大利av在线| 精品一区二区久久久久 | 欧美一级鲁丝片免费看 | 在线看一区二区三区 | 成人福利视频 | 日韩av片在线播放 | 一色屋任你操 | 日韩理论电影网 | 成人在线视频网 | 色婷婷一区二区三区 | 宅男噜噜噜66国产在线观看 | 国产午夜亚洲精品理论片大丰影院 | 羞羞的视频 |