SFML и C++ Уроки \ Разработка игр › Форумы › SFML Graphics › стратегия › Ответ в теме: стратегия
спасибо что ответили так быстро
проблема как я уже писал с математикой у меня ))
в том примере что я описал перс идет к точке клика мыши по прямой и (тут то и есть моя трудность) как только между центром спрайта и местом клика мыши угол становится 45 градусов, сменяется ролик и перс идет по диагонали. как это реализовать? сплошная математика (
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
#include < SFML/Graphics.hpp > int main() { sf::RenderWindow window(sf::VideoMode(1024, 768), "GAME"); sf::Texture t_hero; t_hero.loadFromFile("C:/res/troll.png"); float currentFrame=0; sf::Sprite s_hero; s_hero.setTexture(t_hero); s_hero.setPosition(480,352); s_hero.setTextureRect(sf::IntRect(0,63,63,63)); sf::Clock clock; while (window.isOpen()) { float time = clock.getElapsedTime().asMicroseconds(); clock.restart(); time = time/800; sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { s_hero.move(-0.1*time,0); currentFrame += 0.007*time; if(currentFrame>5)currentFrame -= 5; s_hero.setTextureRect(sf::IntRect(64*int(currentFrame),384,63,63)); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { s_hero.move(0.1*time,0); currentFrame += 0.007*time; if(currentFrame>5)currentFrame -= 5; s_hero.setTextureRect(sf::IntRect(64*int(currentFrame),128,63,63)); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { s_hero.move(0,-0.1*time); currentFrame += 0.007*time; if(currentFrame>5)currentFrame -= 5; s_hero.setTextureRect(sf::IntRect(64*int(currentFrame),0,63,63)); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { s_hero.move(0,0.1*time); currentFrame += 0.007*time; if(currentFrame>5)currentFrame -= 5; s_hero.setTextureRect(sf::IntRect(64*int(currentFrame),256,63,63)); } window.clear(sf::Color::White); window.draw(s_hero); window.display(); } return 0; } |