rotations and teew some stats
This commit is contained in:
parent
ecd27fd8d9
commit
09f04ce82f
28
game.cpp
28
game.cpp
@ -3,15 +3,15 @@
|
||||
#define DELAY 30000
|
||||
|
||||
Game::Game()
|
||||
: x(0), y(0), max_x(800), max_y(600), direction(0), window(sf::VideoMode(max_x, max_y), "SFML Window"),
|
||||
racecar(200.0f, 20.0f, 1.0f) { // Adjust maxSpeed, acceleration, and steerSpeed values as needed
|
||||
: x(0), y(0), max_x(1000), max_y(800), direction(0), window(sf::VideoMode(max_x, max_y), "SFML Window"),
|
||||
racecar(300.0f, 30.0f, 1.7f) { // maxSpeed, acceleration, and steerSpeed values
|
||||
if (!font.loadFromFile("cascaydia.otf")) {
|
||||
std::cerr << "Failed to load font" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sf::Text text("o", font, 24); // This is just for the track, you can modify it as needed
|
||||
text.setFillColor(sf::Color::White);
|
||||
// Create a text object for displaying speed
|
||||
speedText.setFont(font);
|
||||
|
||||
racecar.setPosition(max_x / 2, max_y / 2); // Set initial position for the racecar
|
||||
}
|
||||
@ -54,8 +54,28 @@ void Game::run() {
|
||||
|
||||
racecar.update(dt);
|
||||
|
||||
speedText.setString(std::to_string(static_cast<int>(racecar.getSpeed())) + " km/h");
|
||||
speedText.setCharacterSize(24);
|
||||
speedText.setFillColor(sf::Color::Green);
|
||||
speedText.setPosition(10, 770);
|
||||
if(racecar.getSpeed() < 0){
|
||||
speedText.setFillColor(sf::Color::Blue);
|
||||
}
|
||||
if(racecar.getSpeed() >= 150){
|
||||
speedText.setPosition(10, 767);
|
||||
speedText.setCharacterSize(27);
|
||||
speedText.setFillColor(sf::Color::Yellow);
|
||||
}
|
||||
if(racecar.getSpeed() >= 260){
|
||||
speedText.setPosition(10, 764);
|
||||
speedText.setCharacterSize(30);
|
||||
speedText.setFillColor(sf::Color::Red);
|
||||
}
|
||||
|
||||
|
||||
window.clear();
|
||||
window.draw(racecar.getDrawable()); // Draw the racecar
|
||||
window.draw(speedText);
|
||||
window.display();
|
||||
|
||||
sf::sleep(sf::microseconds(DELAY));
|
||||
|
||||
1
game.h
1
game.h
@ -18,6 +18,7 @@ private:
|
||||
int direction;
|
||||
sf::RenderWindow window;
|
||||
sf::Font font;
|
||||
sf::Text speedText;
|
||||
Racecar racecar;
|
||||
};
|
||||
|
||||
|
||||
@ -7,10 +7,11 @@ Racecar::Racecar(float maxSpeed, float acceleration, float steerSpeed)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
carText.setString("0"); // Replace "o" with a racecar emoji or any desired character
|
||||
carText.setString("|:=:>"); // Replace "o" with a racecar emoji or any desired character
|
||||
carText.setFont(font);
|
||||
carText.setCharacterSize(24);
|
||||
carText.setCharacterSize(12);
|
||||
carText.setFillColor(sf::Color::White);
|
||||
|
||||
speed = 0;
|
||||
}
|
||||
|
||||
@ -34,6 +35,7 @@ void Racecar::decelerate(float dt) {
|
||||
|
||||
void Racecar::steer(float dt, float direction) {
|
||||
steeringAngle += steerSpeed * direction * dt;
|
||||
carText.setRotation(steeringAngle * 180 / M_PI);
|
||||
}
|
||||
|
||||
void Racecar::brake(float dt) {
|
||||
|
||||
BIN
terminal_racer
BIN
terminal_racer
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user