0 Members and 1 Guest are viewing this topic.
#include <SFML/Window.hpp>#include <SFML/System.hpp>#include <SFML/Graphics.hpp>#include <cmath>#include <iostream>typedef sf::Vector2<double> Point;int main(){ sf::RenderWindow App(sf::VideoMode(100, 200, 32), "Eye"); double radius = 7.5; int dir = 0; sf::Image imageEye; imageEye.LoadFromFile("eye.png"); imageEye.SetSmooth(false); sf::Sprite spriteEye(imageEye); Point eye(50,100); while (App.IsOpened()) { sf::Event Event; while (App.GetEvent(Event)) { // Close window : exit if (Event.Type == sf::Event::Closed) App.Close(); // Escape key : exit if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)) App.Close(); } if (App.GetInput().IsKeyDown(sf::Key::Space)) { dir = 1; } else dir = 0; if(dir) { eye.x -= cos(45 * 3.14 / 180) * 0.5; eye.y += sin(45 * 3.14 / 180) * 0.5; } else { eye.x += cos(45 * 3.14 / 180) * 0.5; eye.y += sin(45 * 3.14 / 180) * 0.5; } App.Clear(sf::Color(64,64,64)); if(dir) spriteEye.SetRotation(45); else spriteEye.SetRotation(135); spriteEye.SetPosition(eye.x,eye.y); App.Draw(spriteEye); App.Display(); std::cout<<"eye x = "<< eye.x<<std::endl; std::cout<<"eye y = "<< eye.y<<std::endl; sf::Sleep(0.025f); } return EXIT_SUCCESS;}