Last active
August 27, 2018 07:16
-
-
Save kupp1/330d5e22bf1c31f8d52101123e2f09e9 to your computer and use it in GitHub Desktop.
SFML C++ SAMPLE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <SFML/Graphics.hpp> | |
| #include <SFML/System/Vector2.hpp> | |
| #include <SFML/Window/Keyboard.hpp> | |
| bool chkFunc(sf::Vector2i pos, sf::Vector2f pos_c) { | |
| if ( sf::Mouse::isButtonPressed(sf::Mouse::Left) && pos.x >= pos_c.x && pos.x <= pos_c.x+100 && pos.y >= pos_c.y && pos.y <= pos_c.y+100 ) { | |
| std::cout << "ya1" << "\n"; | |
| return true; | |
| } else { | |
| return false; | |
| } | |
| } | |
| int main() { | |
| bool chk; | |
| sf::RenderWindow window(sf::VideoMode(1024, 800), "Boll"); | |
| sf::CircleShape circle; | |
| circle.setRadius(50); | |
| circle.setFillColor(sf::Color::Green); | |
| circle.setPosition(462, 350); | |
| window.draw(circle); | |
| window.display(); | |
| while (window.isOpen() ) { | |
| sf::Event event; | |
| while (window.pollEvent(event)) { | |
| if (event.type == sf::Event::Closed) | |
| window.close(); | |
| if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) | |
| window.close(); | |
| sf::Vector2i pos = sf::Mouse::getPosition(window); | |
| sf::Vector2f pos_c = circle.getPosition(); | |
| if ( sf::Mouse::isButtonPressed(sf::Mouse::Left) && pos.x >= pos_c.x && pos.x <= pos_c.x+100 && pos.y >= pos_c.y && pos.y <= pos_c.y+100 ) { | |
| if (event.type == sf::Event::MouseMoved) { | |
| circle.setPosition(pos.x-50, pos.y-50); | |
| window.clear(); | |
| window.draw(circle); | |
| window.display(); | |
| } | |
| } | |
| if (event.type == sf::Event::MouseButtonReleased) { | |
| while (pos_c.y <= 700) { | |
| chk = chkFunc(pos, pos_c); | |
| if (chk == true) { | |
| std::cout << "ya" << "\n"; | |
| break; | |
| } | |
| pos_c.y += 1; | |
| //std::cout << pos_c.y << std::endl; | |
| circle.setPosition(pos_c.x, pos_c.y); | |
| window.clear(); | |
| window.draw(circle); | |
| window.display(); | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment