Hey guys, I've been 'playing around' with SFML, I'm a beginner, I don't know what I want my final result to be, probably two players trying to get each others in the black hole, but right now, I just want to move the circles on turns, but the circles move together, why is that?
UPDATE: I changed the code, now only one circle can move, the turns don't change, please help. Here is the new code:-
#include <iostream>
#include <SFML/Graphics.hpp>
int playerRound = 1;
int n = 1;
int turn(){
n++;
if (n % 2 == 0){
playerRound = 1;
}
else if (n%2!=0){
playerRound = 2;
}
return playerRound;
}
int main(){
sf::VideoMode videomode(400, 400);
sf::RenderWindow window(videomode, "GAME");
sf::CircleShape circle;
circle.setFillColor(sf::Color::Red);
circle.setPosition(100, 100);
circle.setRadius(20);
sf::CircleShape circle2;
circle2.setFillColor(sf::Color::Yellow);
circle2.setPosition(200, 200);
circle2.setRadius(20);
sf::CircleShape circle3;
circle3.setFillColor(sf::Color::Black);
circle3.setPosition(300, 300);
circle3.setRadius(50);
while (window.isOpen()){
window.clear(sf::Color::Blue);
window.draw(circle);
window.draw(circle2);
window.draw(circle3);
window.display();
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
turn();
if (playerRound == 1){
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Up)){
circle.move(0, -0.5);
}
else if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Down)){
circle.move(0, 0.5);
}
else if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Right)){
circle.move(0.5, 0);
}
else if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Left)){
circle.move(-0.5, 0);
}
turn();
}
else if (playerRound == 2)
{
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Up)){
circle2.move(0, -0.5);
}
else if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Down)){
circle2.move(0, 0.5);
}
else if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Right)){
circle2.move(0.5, 0);
}
else if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Left)){
circle2.move(-0.5, 0);
}
turn();
}
}
}
}
What I have tried:
I've tried changing the big if loops to while loops, I've also tried removing some braces, I've tried using sf::Keyboard::isKeyPressed.... instead, but nothing has worked so far, could you please help me? Thanks in advance :) [I'm a beginner btw, so excuse me]