How do I go about moving and turning the rectangle at the same time. He is my code..
#include<SFML/Graphics.hpp>
#include<iostream>
#include<cmath>
#define PI 3.14159265
using namespace std;
void displace(sf::RectangleShape *shape, float angle)
{
}
int main()
{
const int xRes= 800;
const int yRes= 600;
sf::RenderWindow window(sf::VideoMode(xRes, yRes), "Window");
float rectLength= 20, rectBreadth= 10;
sf::RectangleShape rectangle(sf::Vector2f(rectLength, rectBreadth));
float xCod= 100, yCod= 100;
rectangle.setPosition(xCod, yCod);
rectangle.setFillColor(sf::Color::Black);
rectangle.setOrigin(rectLength/2, rectBreadth/2);
float direction, speed= 0.5;
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type== sf::Event::Closed || (event.type== sf::Event::KeyReleased) && (event.key.code== sf::Keyboard::Escape))
window.close();
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
direction= rectangle.getRotation();
rectangle.move(speed*cos(direction*PI/180), speed*sin(direction*PI/180));
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
direction= rectangle.getRotation();
rectangle.move(-speed*cos(direction*PI/180), -speed*sin(direction*PI/180));
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
rectangle.rotate(-0.5);
direction= rectangle.getRotation();
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
rectangle.rotate(0.5);
direction= rectangle.getRotation();
}
window.clear(sf::Color::White);
window.draw(rectangle);
window.display();
}
return 0;
}