diff --git a/game.cpp b/game.cpp index a094bbf..55e866c 100644 --- a/game.cpp +++ b/game.cpp @@ -13,12 +13,23 @@ Game::Game() // Create a text object for displaying speed speedText.setFont(font); + // Create a map text object and set its properties + mapText.setFont(font); + mapText.setCharacterSize(24); + mapText.setFillColor(sf::Color::White); + mapText.setPosition(10, 10); + racecar.setPosition(max_x / 2, max_y / 2); // Set initial position for the racecar } void Game::run() { sf::Clock clock; + // Create a view that will follow the racecar + sf::View view(sf::FloatRect(0, 0, max_x, max_y)); + view.setCenter(racecar.getX(), racecar.getY()); // Center the view on the racecar + window.setView(view); + while (window.isOpen()) { float dt = clock.restart().asSeconds(); @@ -73,8 +84,14 @@ void Game::run() { } + // Update the view to follow the racecar + view.setCenter(racecar.getX(), racecar.getY()); + window.setView(view); + window.clear(); - window.draw(racecar.getDrawable()); // Draw the racecar + mapText.setString(asciiMap); + window.draw(mapText); + window.draw(racecar.getDrawable()); window.draw(speedText); window.display(); diff --git a/game.h b/game.h index cf22422..506f464 100644 --- a/game.h +++ b/game.h @@ -17,7 +17,41 @@ private: sf::RenderWindow window; sf::Font font; sf::Text speedText; + sf::Text mapText; Racecar racecar; + std::string asciiMap = " /------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\ \n" + " / \\ \n" + " / | \n" + " / | \n" + " / _____________________________________________________________________________________________________________________________________________________________ | \n" + " / / \\ | \n" + " / / | | \n" + " / | /------------------------------------------------------\\ / | \n" + "/ | / \\ _____ __________________ .___.___ / / \n" + "| || | / _ \\ / _____/\\_ ___ \\| | | / / \n" + "| || | / /_\\ \\ \\_____ \\ / \\ \\/| | | / / \n" + "| || __________________________ | / | \\/ \\ \\___| | | / / \n" + "| || / \\ | \\____|__ /_______ / \\______ /___|___| / / \n" + "| || / | | \\/ \\/ \\/ / / \n" + "| || | | | __________ _____ _________ _____________________ / / \n" + "| || | / / \\______ \\ / _ \\ \\_ ___ \\_ _____/\\______ \\ / / \n" + "| || | / / | _/ / /_\\ \\/ \\ \\/ | __)_ | _/ / / \n" + "| || | / / | | \\/ | \\ \\____| \\ | | \\ / / \n" + "| || | / / |____|_ /\\____|__ /\\______ /_______ / |____|_ / / / \n" + "| || | / / \\/ \\/ \\/ \\/ \\/ / / \n" + "| || | / / / / \n" + "| || | / / / / \n" + "| || | / / / / \n" + "| || | | | / / \n" + "| || | | | / / \n" + "| || | \\ \\ / / \n" + "| || | \\ \\ / / \n" + "\\ \\/ / \\ \\____________________________________________________________________________________/ / \n" + " \\ / \\ / \n" + " \\ / \\ / \n" + " \\ / \\ / \n" + " \\ / \\ / \n" + " \\____________________/ \\_________________________________________________________________________________________________________/ "; }; #endif // GAME_H diff --git a/map b/map index 357522e..05d4be5 100644 --- a/map +++ b/map @@ -1,48 +1,33 @@ - /¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\ - / \ - / | - / | - / _____________________________________________________________________________________________________________________________________________________________ | - / / \ | - / / | | - / | /¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\ / | - / | / \ _____ __________________ .___.___ / / - | || | / _ \ / _____/\_ ___ \| | | / / - | || | / /_\ \ \_____ \ / \ \/| | | / / - | || __________________________ | / | \/ \\ \___| | | / / - | || / \ | \____|__ /_______ / \______ /___|___| / / - | || / | | \/ \/ \/ / / - | || | | | __________ _____ _________ _____________________ / / - | || | / / \______ \ / _ \ \_ ___ \\_ _____/\______ \ / / - | || | / / | _/ / /_\ \/ \ \/ | __)_ | _/ / / - | || | / / | | \/ | \ \____| \ | | \ / / - | || | / / |____|_ /\____|__ /\______ /_______ / |____|_ / / / - | || | / / \/ \/ \/ \/ \/ / / - | || | / / / / - | || | / / / / - | || | / / / / - | || | | | / / - | || | | | / / - | || | \ \ / / - | || | \ \ / / - \ \/ / \ \____________________________________________________________________________________/ / - \ / \ / - \ / \ / - \ / \ / - \ / \ / - \____________________/ \_________________________________________________________________________________________________________/ - - - - - - - - - - - - - - - + /¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\ + / \ + / | + / | + / _____________________________________________________________________________________________________________________________________________________________ | + / / \ | + / / | | + / | /¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\ / | +/ | / \ _____ __________________ .___.___ / / +| || | / _ \ / _____/\_ ___ \| | | / / +| || | / /_\ \ \_____ \ / \ \/| | | / / +| || __________________________ | / | \/ \\ \___| | | / / +| || / \ | \____|__ /_______ / \______ /___|___| / / +| || / | | \/ \/ \/ / / +| || | | | __________ _____ _________ _____________________ / / +| || | / / \______ \ / _ \ \_ ___ \\_ _____/\______ \ / / +| || | / / | _/ / /_\ \/ \ \/ | __)_ | _/ / / +| || | / / | | \/ | \ \____| \ | | \ / / +| || | / / |____|_ /\____|__ /\______ /_______ / |____|_ / / / +| || | / / \/ \/ \/ \/ \/ / / +| || | / / / / +| || | / / / / +| || | / / / / +| || | | | / / +| || | | | / / +| || | \ \ / / +| || | \ \ / / +\ \/ / \ \____________________________________________________________________________________/ / + \ / \ / + \ / \ / + \ / \ / + \ / \ / + \____________________/ \_________________________________________________________________________________________________________/ diff --git a/racecar.cpp b/racecar.cpp index 31259d5..8c20f26 100644 --- a/racecar.cpp +++ b/racecar.cpp @@ -65,3 +65,10 @@ float Racecar::getSpeed() const { return speed; } +float Racecar::getX() const { + return carText.getPosition().x; +} + +float Racecar::getY() const { + return carText.getPosition().y; +} diff --git a/racecar.h b/racecar.h index 3ae4890..740a281 100644 --- a/racecar.h +++ b/racecar.h @@ -17,6 +17,8 @@ public: sf::Text getDrawable(); void setPosition(float x, float y); float getSpeed() const; // Get the current speed of the car + float getX() const; + float getY() const; private: sf::Text carText; diff --git a/terminal_racer b/terminal_racer index 8264f95..87573dc 100755 Binary files a/terminal_racer and b/terminal_racer differ