i dont know if im dumb or something but I still cant figure it out here my code I want make the line rotate 360 degree around the player but when I do it not very accurate
[8] ={
{1,1,1,1,1,1,1,1},
{1,0,0,0,0,1,0,1},
{1,0,0,0,0,0,0,1},
{1,0,0,1,1,0,0,1},
{1,0,1,1,0,0,0,1},
{1,0,0,0,0,0,0,1},
{1,0,0,1,0,0,0,1},
{1,1,1,1,1,1,1,1}
};
sf::View view;
//float viewSpeed= 200.f;
float dtMultiplier = 60.f;
float dt;
float gridF= 100.f;
int mapX = 8;
int mapY = 8;
px = 300.f;
py = 300.f;
pdx =cos(pa) * 5;
pdy = sin(pa) * 5;
int mapS = 16;
sf::Clock clock;
sf::RectangleShape tile[mapY][mapX];
for(int y =0;y < mapY;y++){
for(int x =0;x < mapX;x++){
if(map[y][x] == 1){
tile[y][x].setSize(sf::Vector2f(gridF,gridF));
tile[y][x].setFillColor(sf::Color(55,55,55,255));
tile[y][x].setOutlineThickness(1.f);
tile[y][x].setOutlineColor(sf::Color::White);
tile[y][x].setPosition(x * gridF + 50.f,y* gridF + 50.f);
}
else{
tile[y][x].setSize(sf::Vector2f(gridF,gridF));
tile[y][x].setFillColor(sf::Color::Transparent);
tile[y][x].setOutlineThickness(1.f);
tile[y][x].setOutlineColor(sf::Color::White);
tile[y][x].setPosition(x * gridF + 50.f,y* gridF + 50.f);
}
}
}
while (window.isOpen())
{
dt = clock.restart().asSeconds();
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)){
pa -= 0.1 * dt * dtMultiplier;
if(pa < 0){
pa += 2* PI;
}
pdx =cos(pa) * 5;
pdy = sin(pa) * 5;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)){
pa += 0.1 * dt * dtMultiplier;
if(pa >PI * 2){
pa -= 2 * PI;
}
pdx =cos(pa) * 5;
pdy = sin(pa) * 5;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::W)){
px -= pdx * dt * dtMultiplier;
py -= pdy * dt * dtMultiplier;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)){
px += pdx * dt * dtMultiplier;
py += pdy * dt * dtMultiplier;
}
shape.setPosition(px,py);
line.setPosition(shape.getPosition().x - (shape.getSize().x),shape.getPosition().y + (shape.getSize().y/2));
window.clear();
window.draw(line);
window.draw(shape);
for(int y =0;y < mapY;y++) {
for (int x = 0; x < mapX; x++) {
window.draw(tile[y][x]);
}
}
window.display();
}
}