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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

SFML game move

2019-11-14 10:00:59
字體:
供稿:網(wǎng)友
#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;}

效果圖,繼續(xù)~~

效果圖


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 亚洲网在线 | 天堂精品在线 | 久久精品欧美视频 | av日韩一区二区三区 | 久久精品视频免费 | 丰满年轻岳中文字幕一区二区 | 日本欧美一区二区三区视频麻豆 | 欧美性受xxxx白人性爽 | 极品一级片| 日本欧美一区二区三区在线播 | 免费的性爱视频 | 91福利免费视频 | 日日草夜夜 | 欧美黑人xx | 午夜视频中文字幕 | 国产成人在线网址 | 久草在线视频精品 | av大全在线免费观看 | 国产一区二区视频精品 | 亚洲第五色综合网 | xxxxhdvideosex| 康妮卡特欧美精品一区 | 亚洲男人的天堂在线视频 | 狠狠操夜夜爱 | 一级做a爱视频 | 一级毛片播放 | 日韩精品久久久久久久电影99爱 | 激情亚洲一区二区 | 毛片免费一区二区三区 | 99爱视频 | 伊人在线视频 | 成人福利视频网站 | 美女羞羞视频网站 | 久久毛片| 精品国产96亚洲一区二区三区 | 久久久久国产成人精品亚洲午夜 | 在线 日本 制服 中文 欧美 | 天天夜碰日日摸日日澡性色av | 91久久线看在观草草青青 | 最新福利在线 | 海外中文字幕在线观看 |