I have two different instances of the same cold. One works as accordingly planned and the other messes up. Possibly I dont' see the erroneous lines of code that I posted. I was therefore looking for some help on finding them or identifying the underlying problem.
Code 1 that works
#include <SFML/Graphics.hpp>
#define CIRCLE sf::Shape::Circle(0.f, 300.f, 5.f, sf::Color::Red, 1.f, sf::Color::Blue);
#define CIRCLE1 sf::Shape::Circle(800.f, 300.f, 5.f, sf::Color::Red, 1.f, sf::Color::Blue);
int main () {
sf::RenderWindow App(sf::VideoMode(800,600,32), "Horizontal Circles");
App.SetFramerateLimit(60);
sf::Shape C1 = CIRCLE;
sf::Shape C2 = CIRCLE1;
int dir = 0;
int dir2 = 0;
while(App.IsOpened()) {
sf::Event ev1;
if(App.GetEvent(ev1))
if(ev1.Type == sf::Event::Closed)
App.Close();
if(dir == 1 && C1.GetPosition().x < 2.f)
dir = 0;
if(dir == 0 && C1.GetPosition().x > 798.f) {
dir = 1;
}
if (dir == 1 )
C1.Move(-2.2,0.f);
if (dir == 0)
C1.Move(2.2, 0.f);
if(dir2 == 1 && C1.GetPosition().x < 2.f)
dir2 = 0;
if(dir2 == 0 && C1.GetPosition().x > 798.f) {
dir2 = 1;
}
if (dir2 == 0 )
C2.Move(-2.2,0.f);
if (dir2 == 1)
C2.Move(2.2, 0.f);
App.Clear();
App.Draw(C1);
App.Draw(C2);
App.Display();
}
return EXIT_SUCCESS;
}
This is code 2. It does half of what it's suppose to
#include <SFML/Graphics.hpp>
#include <iostream>
#define CIRCLE sf::Shape::Circle(0.f, 300.f, 5.f, sf::Color::Red, 1.f, sf::Color::Blue);
#define CIRCLE1 sf::Shape::Circle(800.f, 280.f, 5.f, sf::Color::Green, 1.f, sf::Color::Blue);
int main () {
sf::RenderWindow App(sf::VideoMode(800,600,32), "Horizontal Circles");
App.SetFramerateLimit(60);
sf::Shape C1 = CIRCLE;
sf::Shape C2 = CIRCLE1;
int dir = 0;
int dir2 = 0;
while(App.IsOpened()) {
sf::Event ev1;
if(App.GetEvent(ev1))
if(ev1.Type == sf::Event::Closed)
App.Close();
//where ball 1 testing begins
if(dir == 0 && 800.f - C1.GetPosition().x < 1.0 ){
//std::cout << (800.f- (C1.GetPosition().x)) << "Red This is Direction 0 ch to 1\n";
dir = 1;
}
if(C1.GetPosition().x - 2.f < 1.0 && dir == 1) {
dir = 0;
//std::cout << ((C1.GetPosition()).x - 2.f ) << "Red This is Direction 1 ch to 0\n";
}
//where ball 2 testing begins
if(dir2 == 1 && C1.GetPosition().x < 2.f){
dir2 = 0;
//change
}
if(dir2 == 0 && C1.GetPosition().x > 799.f) {
dir2 = 1;
}
//where ball2 movement two begins
if (dir2 == 0 )
C2.Move(-2.2,0.f);
if (dir2 == 1)
C2.Move(2.2, 0.f);
// This is where Ball movement 1 begins
if (dir == 1 ){
C1.Move(-2.2,0.f);
// std::cout << C1.GetPosition().x << std::endl;
}
if (dir == 0) {
C1.Move(2.2, 0.f);
// std::cout << C1.GetPosition().x << std::endl;
}
App.Clear();
App.Draw(C1);
App.Draw(C2);
App.Display();
}
return EXIT_SUCCESS;
}