Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- using namespace std;
- #define PI 3.14159265
- //int x,y,sizex,sizey;
- //double initialx,initialy,force,angle,mass,gravity,time,timeskip;
- double initialx = 1.0;
- double initialy = 1.0;
- int sizex = 75;
- int sizey = 50;
- double mass = 0.7;
- double gravity = 9.8;
- double time = 20;
- double timeskip = 0.05;
- print(vector <vector <bool> >& map) {
- for (int i=map.size()-1; i>=0; --i) {
- for (int j=0; j<map[0].size(); ++j) {
- if (i==initialy and j==initialx) cout<<"x";
- else {
- if (map[i][j]) cout << "*";
- else cout << " ";
- }
- }
- cout<<endl;
- }
- for (int j=0; j<map[0].size(); ++j) cout<<"=";
- cout<<endl;
- }
- void clear(int n) {for (int i=0; i<n; ++i) cout<<endl;}
- //string tolower(string s) {for (int i=0; i<s.length(); i++) tolower(s[i]); return s;}
- int main() {
- int x,y;
- double force,angle;
- string s;
- mainMenu:
- cout << "Type to select:\n";
- cout << "\n";
- cout << " [Play]\n";
- cout << " [Settings]\n";
- cin>>s;
- //s = tolower(s);
- if (s=="play") goto Play;
- else if (s=="settings") goto Settings;
- cout << "ERROR: Unknown command. Try writing in lowercase."<<endl;
- goto mainMenu;
- Settings:
- clear(50);
- cout<<" ~ Table size: "<<sizex<<"x"<<sizey<<" <size>"<<endl;
- cout<<" ~ Gravity: "<<gravity<<"m/s2 <gravity>"<<endl;
- cout<<" ~ Ball Mass: "<<mass<<"kg <mass>"<<endl;
- cout<<" ~ Simulation Time: "<<time<<"s <time>"<<endl;
- cout<<" ~ Time skipping: "<<timeskip<<"s <skip>"<<endl;
- cout<<" ~ Launch position: ["<<initialx<<"]["<<initialy<<"] <position>"<<endl;
- cout<<endl<<endl<<" [Menu]"<<endl;
- cin>>s;
- if (s=="size") {
- cout<<endl<<endl<<"Enter new size: ";
- cin>>sizex>>sizey;
- goto Settings;
- }
- if (s=="gravity") {
- cout<<endl<<endl<<"Enter new gravity: ";
- cin>>gravity;
- goto Settings;
- }
- if (s=="mass") {
- cout<<endl<<endl<<"Enter new mass: ";
- cin>>mass;
- goto Settings;
- }
- if (s=="time") {
- cout<<endl<<endl<<"Enter new time: ";
- cin>>time;
- goto Settings;
- }
- if (s=="skip") {
- cout<<endl<<endl<<"Enter new skip time: ";
- cin>>timeskip;
- goto Settings;
- }
- if (s=="position") {
- cout<<endl<<endl<<"Enter new launch position: ";
- cin>>initialx>>initialy;
- goto Settings;
- }
- if (s=="menu") goto mainMenu;
- else goto Settings;
- Play:
- clear(50);
- vector <vector <bool> > map(sizey, vector <bool> (sizex));
- print(map);
- cout << "Angle: ";
- cin >> angle;
- cout << "Force: ";
- cin >> force;
- cout << endl;
- for (double t=0; t<time; t = t + timeskip) {
- //x = initialx + (cos(angle)*force*t*t)/(2*mass));
- x = initialx + (cos(angle*PI/180))*force*t;
- y = initialy + (sin(angle*PI/180))*force*t - (gravity/2)*t*t;
- if (x>=0 and x<map[0].size() and y>=0 and y<map.size()) {
- map[y][x] = true;
- cout << "[" << x << "] [" << y << "]" << endl;
- }
- }
- print(map);
- cout<<endl<<" [Restart]"<<endl<<" [Menu]"<<endl<<endl;
- cin>>s;
- if (s=="restart") goto Play;
- else if (s=="menu") goto mainMenu;
- else cout << "ERROR: Unknown command. Try writing in lowercase."<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment