//This is a comment ///This is a comment too /*This is also a comment*/ /* Hey, this is a basic player movement program written in C++ with SFML 2.1... The comments written are to help you understand what is going on at each specific line. Of course, I don't have enough time to comment them all, so I simply commented the more important ones. If you have any further questions, please feel free to ask in the comments section below. Enjoy! */ #include #include using namespace std; int main() { //Intitiating the Window sf::RenderWindow game(sf::VideoMode(640, 480), "Player Movement"); game.setFramerateLimit(60); //Limiting the framerate for constant speed on all CPUs sf::Event gameEvent; //Initiating the Player Object sf::RectangleShape player(sf::Vector2f(64, 64)); player.setFillColor(sf::Color::Blue); // Specifies the rectangle's color float playerSpeed = 2; /*Specifies the player's movement speed (Which is used later in the Keyboard Input section)*/ while(game.isOpen()) { //Handling Window Events while(game.pollEvent(gameEvent)) { switch(gameEvent.type) { case sf::Event::Closed: game.close(); break; default: break; } } //Keyboard Input if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) //When the Up Arrow is pressed... { player.move(0, -playerSpeed); //Move 0 pixels horizontally and 1 up vertically } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) //When the Down Arrow is pressed... { player.move(0, playerSpeed); //Move 0 pixels horizontally and 1 down vertically } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) //When the Left Arrow is pressed... { player.move(-playerSpeed, 0); //Move 1 pixels to the left horizontally and 0 vertically } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) //When the Right Arrow is pressed... { player.move(playerSpeed, 0); //Move 1 pixels to the right horizontally and 0 vertically } //Rendering game.clear(); game.draw(player); game.display(); } return (0); }