Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML\Main.hpp>
- #include <SFML\Window.hpp>
- #include <SFML\System.hpp>
- #include <SFML\Graphics.hpp>
- #if !defined(NDEBUG)
- #pragma comment(lib, "sfml-main-d.lib")
- #pragma comment(lib, "sfml-window-d.lib")
- #pragma comment(lib, "sfml-system-d.lib")
- #pragma comment(lib, "sfml-graphics-d.lib")
- #else
- #pragma comment(lib, "sfml-main.lib")
- #pragma comment(lib, "sfml-window.lib")
- #pragma comment(lib, "sfml-system.lib")
- #pragma comment(lib, "sfml-graphics.lib")
- #endif
- int main(int argc, char** argv)
- {
- sf::RenderWindow window(sf::VideoMode(1000, 1000), "sfml works!", sf::Style::Titlebar | sf::Style::Close);
- sf::RectangleShape crosshair(sf::Vector2f(10, 10));
- sf::RectangleShape bullet[x](sf::Vector2f(20, 5));
- sf::CircleShape player(10.f);
- sf::Vector2f playerPos(490, 490);
- sf::Vector2f shotPos(500,500);
- float bulletSpeed = 3.f;
- sf::Vector2f v(0, 0);
- player.setPosition(playerPos);
- player.setFillColor(sf::Color::Yellow);
- bool shot = false;
- crosshair.setFillColor(sf::Color::Cyan);
- if (!window.isOpen())return-1;
- const float targetTime = 1.0f / 60.f;
- float accumalotor = 0.0f;
- float frameTime = 0.0f;
- sf::Clock clock;
- while (window.isOpen())
- {
- sf::Time deltaTime = clock.restart();
- frameTime = std::min(deltaTime.asSeconds(), 0.1f);
- accumalotor += frameTime;
- while (accumalotor > targetTime)
- {
- accumalotor -= targetTime;
- sf::Event event;
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- {
- window.close();
- }
- }
- }
- sf::Vector2f mouse(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y);
- sf::Vector2f aimPos(mouse.x - playerPos.x, mouse.y - playerPos.y);
- crosshair.setPosition(mouse.x, mouse.y);
- window.clear(sf::Color(0x11,0x12,0x33,0xff));
- if (sf::Mouse::isButtonPressed(sf::Mouse::Left)&&shot==false)
- {
- shot = true;
- }
- if (shot == true)
- {
- bullet[x].setPosition(shotPos.x, shotPos.y);
- sf::Vector2f v;
- float distance = sqrt((aimPos.x - playerPos.x)*(aimPos.x - playerPos.x) + (aimPos.y - playerPos.y)*(aimPos.y - playerPos.y));
- shotPos.x += aimPos.x/distance;
- shotPos.y += aimPos.y/distance;
- window.draw(bullet[x]);
- //shot = false;
- }
- window.draw(crosshair);
- window.draw(player);
- window.display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement