1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
#include <iostream>
#include <ctime>
#define ESC char(27)
#define FUSEMIN 800
#define FUSEMAX 1000
//lets just send the thing on a parabolic curve for this version. like catapult fireworks. no wind resistance...
#define GRAV 0.0001 //acceleration applied to velocity each FUSE tick
#define YLAUNCHMAX .085 //fastest we want it going up..
#define YLAUNCHMIN .075 //slowest launch. too low and it'll fall back to earth undetonated...
#define XLAUNCHMAX .08
#define XLAUNCHMIN -.08 //These give angle so you see a parabola..
#define FLOOR 40 //y coordinate of the horizon
#define LAUNCHER 70 //x coordinate of the launcher & midscreen
#define BOMBS 5 //number to launch
using std::cout;
void vt100clear();
void vt100gotoxy(int x, int y);
void vt100setbackground(int c);
void vt100setcolor(int c);
void spinner(int x, int y);
int main () {
int x=0,y=0,c=0;
int fuse, fuseloop=0;
int bombloop;
//the floats are for the math section and the horizon is at y=0 and the launcher is at x=0.
//when converted to integers, the y coordinate is inverted and 0,0 is shifted to LAUNCHER,FLOOR
float xvelocity=0,yvelocity=0;
float xpos=0,ypos=0 ;
vt100clear();
srand(time(0));
for (bombloop=0 ; bombloop < BOMBS; bombloop++) {
xpos=0,ypos=0;
yvelocity= YLAUNCHMIN*1000 + rand()%1000*(YLAUNCHMAX-YLAUNCHMIN);
yvelocity=yvelocity/1000;
xvelocity= XLAUNCHMIN*1000 + rand()%1000*(XLAUNCHMAX-XLAUNCHMIN);
xvelocity=xvelocity/1000;
fuse= FUSEMIN*1000 + rand()%1000*(FUSEMAX-FUSEMIN);
fuse= fuse/1000;
for (fuseloop=0; fuseloop < fuse; fuseloop++) {
yvelocity-=GRAV;
xpos+=xvelocity; ypos+=yvelocity;
// cout << fuseloop << ": " << "yvelocity=" << yvelocity << " xvelocity=" << xvelocity <<"\n"; //DEBUG LINE
// cout << fuseloop << ": " << "xpos=" << xpos << " ypos=" << ypos << "\n"; //DEBUG LINE
x=xpos+LAUNCHER; y=FLOOR-ypos;
spinner (x,y); //draw the bomb
vt100gotoxy(x,y); cout << "." ; //erase it with smoke
}
}
vt100gotoxy(1,FLOOR);
}
void spinner(int x, int y) {
int counter=0, c=0;
for (counter=0; counter < 100 ; counter++) {
c=1+counter%6;
vt100setcolor(c); //1-6, not black, not white.
vt100gotoxy(x,y);
cout << "O";
vt100gotoxy(x,y);
cout << "-";
vt100gotoxy(x,y);
cout << "/";
vt100gotoxy(x,y);
cout << "|";
vt100gotoxy(x,y);
cout << "\\";
}
vt100gotoxy(x,y);
c=7;
vt100setcolor(c);
cout << "O";
}
void vt100clear() {
cout << ESC << "[2J" << ESC << "[f";
}
void vt100gotoxy(int x, int y) {
cout << ESC << "[" << y << ";" << x << "H";
}
void vt100setcolor(int c) {
cout << ESC << "[3" << c << "m";
}
void vt100setbackground(int c) {
cout << ESC << "[4" << c << "m";
}
|