follow the player
This commit is contained in:
parent
abacd48eee
commit
defc393748
19
game.cpp
19
game.cpp
@ -13,12 +13,23 @@ Game::Game()
|
|||||||
// Create a text object for displaying speed
|
// Create a text object for displaying speed
|
||||||
speedText.setFont(font);
|
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
|
racecar.setPosition(max_x / 2, max_y / 2); // Set initial position for the racecar
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::run() {
|
void Game::run() {
|
||||||
sf::Clock clock;
|
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()) {
|
while (window.isOpen()) {
|
||||||
float dt = clock.restart().asSeconds();
|
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.clear();
|
||||||
window.draw(racecar.getDrawable()); // Draw the racecar
|
mapText.setString(asciiMap);
|
||||||
|
window.draw(mapText);
|
||||||
|
window.draw(racecar.getDrawable());
|
||||||
window.draw(speedText);
|
window.draw(speedText);
|
||||||
window.display();
|
window.display();
|
||||||
|
|
||||||
|
|||||||
34
game.h
34
game.h
@ -17,7 +17,41 @@ private:
|
|||||||
sf::RenderWindow window;
|
sf::RenderWindow window;
|
||||||
sf::Font font;
|
sf::Font font;
|
||||||
sf::Text speedText;
|
sf::Text speedText;
|
||||||
|
sf::Text mapText;
|
||||||
Racecar racecar;
|
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
|
#endif // GAME_H
|
||||||
|
|||||||
81
map
81
map
@ -1,48 +1,33 @@
|
|||||||
/¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\
|
/¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\
|
||||||
/ \
|
/ \
|
||||||
/ |
|
/ |
|
||||||
/ |
|
/ |
|
||||||
/ _____________________________________________________________________________________________________________________________________________________________ |
|
/ _____________________________________________________________________________________________________________________________________________________________ |
|
||||||
/ / \ |
|
/ / \ |
|
||||||
/ / | |
|
/ / | |
|
||||||
/ | /¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\ / |
|
/ | /¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\ / |
|
||||||
/ | / \ _____ __________________ .___.___ / /
|
/ | / \ _____ __________________ .___.___ / /
|
||||||
| || | / _ \ / _____/\_ ___ \| | | / /
|
| || | / _ \ / _____/\_ ___ \| | | / /
|
||||||
| || | / /_\ \ \_____ \ / \ \/| | | / /
|
| || | / /_\ \ \_____ \ / \ \/| | | / /
|
||||||
| || __________________________ | / | \/ \\ \___| | | / /
|
| || __________________________ | / | \/ \\ \___| | | / /
|
||||||
| || / \ | \____|__ /_______ / \______ /___|___| / /
|
| || / \ | \____|__ /_______ / \______ /___|___| / /
|
||||||
| || / | | \/ \/ \/ / /
|
| || / | | \/ \/ \/ / /
|
||||||
| || | | | __________ _____ _________ _____________________ / /
|
| || | | | __________ _____ _________ _____________________ / /
|
||||||
| || | / / \______ \ / _ \ \_ ___ \\_ _____/\______ \ / /
|
| || | / / \______ \ / _ \ \_ ___ \\_ _____/\______ \ / /
|
||||||
| || | / / | _/ / /_\ \/ \ \/ | __)_ | _/ / /
|
| || | / / | _/ / /_\ \/ \ \/ | __)_ | _/ / /
|
||||||
| || | / / | | \/ | \ \____| \ | | \ / /
|
| || | / / | | \/ | \ \____| \ | | \ / /
|
||||||
| || | / / |____|_ /\____|__ /\______ /_______ / |____|_ / / /
|
| || | / / |____|_ /\____|__ /\______ /_______ / |____|_ / / /
|
||||||
| || | / / \/ \/ \/ \/ \/ / /
|
| || | / / \/ \/ \/ \/ \/ / /
|
||||||
| || | / / / /
|
| || | / / / /
|
||||||
| || | / / / /
|
| || | / / / /
|
||||||
| || | / / / /
|
| || | / / / /
|
||||||
| || | | | / /
|
| || | | | / /
|
||||||
| || | | | / /
|
| || | | | / /
|
||||||
| || | \ \ / /
|
| || | \ \ / /
|
||||||
| || | \ \ / /
|
| || | \ \ / /
|
||||||
\ \/ / \ \____________________________________________________________________________________/ /
|
\ \/ / \ \____________________________________________________________________________________/ /
|
||||||
\ / \ /
|
\ / \ /
|
||||||
\ / \ /
|
\ / \ /
|
||||||
\ / \ /
|
\ / \ /
|
||||||
\ / \ /
|
\ / \ /
|
||||||
\____________________/ \_________________________________________________________________________________________________________/
|
\____________________/ \_________________________________________________________________________________________________________/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -65,3 +65,10 @@ float Racecar::getSpeed() const {
|
|||||||
return speed;
|
return speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Racecar::getX() const {
|
||||||
|
return carText.getPosition().x;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Racecar::getY() const {
|
||||||
|
return carText.getPosition().y;
|
||||||
|
}
|
||||||
|
|||||||
@ -17,6 +17,8 @@ public:
|
|||||||
sf::Text getDrawable();
|
sf::Text getDrawable();
|
||||||
void setPosition(float x, float y);
|
void setPosition(float x, float y);
|
||||||
float getSpeed() const; // Get the current speed of the car
|
float getSpeed() const; // Get the current speed of the car
|
||||||
|
float getX() const;
|
||||||
|
float getY() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sf::Text carText;
|
sf::Text carText;
|
||||||
|
|||||||
BIN
terminal_racer
BIN
terminal_racer
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user