#include <iostream>
#include <iomanip>
#include <thread>
#include <chrono>
using namespace std;
// Function to update aircraft position
void updatePosition(float& x, float& y, float throttle, float direction) {
x += throttle * cos(direction); // Update x based on throttle and direction
y += throttle * sin(direction); // Update y based on throttle and direction
}
int main() {
float x = 0.0f; // Initial x position
float y = 0.0f; // Initial y position
float throttle = 0.0f; // Throttle (speed)
float direction = 0.0f; // Direction in radians
char command;
cout << "Aircraft Flight Simulation" << endl;
cout << "Use 'w' to increase throttle, 's' to decrease throttle" << endl;
cout << "'a' to turn left, 'd' to turn right, and 'q' to quit" << endl;
while (true) {
cout << fixed << setprecision(2); // Set precision for position output
cout << "Position: (" << x << ", " << y << ") | Throttle: " << throttle
<< " | Direction: " << direction << " radians" << endl;
cout << "Enter command: ";
cin >> command;
switch (command) {
case 'w': // Increase throttle
throttle += 0.1f;
break;
case 's': // Decrease throttle
throttle = max(0.0f, throttle - 0.1f); // Throttle can't be negative
break;
case 'a': // Turn left
direction -= 0.1f; // Turn left by decreasing direction
break;
case 'd': // Turn right
direction += 0.1f; // Turn right by increasing direction
break;
case 'q': // Quit simulation
cout << "Quitting simulation..." << endl;
return 0;
default:
cout << "Invalid command. Please try again." << endl;
break;
}
// Update position based on throttle and direction
updatePosition(x, y, throttle, direction);
// Sleep to simulate real-time movement
this_thread::sleep_for(chrono::milliseconds(100));
}
return 0;
}