// be warned. This keyboard i am on sucks. Typo's galore. #include "CarnegieMellonGraphics.h" #include "particle.h" #include using namespace std; // ********* void resetParticles(vector& particle, double X, double Y); void KillParticles(vector& particle); int KeyTime = 500; double ExplosionSize; double GravY = 1; // gravity double GravX = 0; // wind? but can be used for it. int red = 255;//CurrentColor.red; int green = 255;//CurrentColor.green; int blue = 0;//CurrentColor.blue; int MaxMass = 5; int Direction = 1; int WaitTime = 50; bool Done = false; bool Message = false; int MAX_PARTICLES = 200; clock_t Play; clock_t LastUpdate; clock_t NextUpdate; clock_t NextKeyP; // ********* /* vector clocks(3); clocks[0] = new Clock(true); clocks[1] = new TravelClock(true, "Rome", 9); clocks[2] = new TravelClock(false, "Tokyo", -7); */ void DrawParticle(Window& window, Color color, int x, int y, int size) { // draws the particle window.drawCircleFilled( color, x, y, size ); // color? } void Draw(vector& particle, Window& window) { // gets every thing set int w = window.getWidth(); int h = window.getHeight(); int dead = 0; int Left = 20; int Right = w-20; int up = 20; int down = h-20; Font myfont(Font::ROMAN,14); window.drawRectangleFilled(Style::BLACK, 0, 0, w, h); // back ground const char *rocket = "rocket.jpg";//leave Image imgRocket(rocket,Image::JPEG); for (int i=0; i < MAX_PARTICLES; i++) // for particles { if (!(particle[i]->Dead())) // if it exists. (in area, not dead) { if (particle[i]->GetType() == PARTICLE) { // if particle drraw one //RBG CurrentColor = particle[i].GetColor(); DrawParticle(window, Color(red,green,blue), particle[i]->GetX(),particle[i]->GetY(), particle[i]->GetMass()); // call it } if (particle[i]->GetType() == OBJECT) // for images ones. window.drawImage( imgRocket, particle[i]->GetX(),particle[i]->GetY()); //drawImage( const Image& image, const int x, const int y ) } // its going to be off a bit. } for (int m=0; m < MAX_PARTICLES; m++) { // hmm count if ((particle[m]->Dead())) dead++; } // are enough dead if (dead >= MAX_PARTICLES) window.drawText(Style::GREEN,myfont,200,300,"Press Y for another burst."); // text ehh? "Test" ehH? // background draw text // xy, xy start at, stop at. // walls, stuff, particles cannot get into. window.drawRectangleFilled(Style::RED, 0, 0, Left, h ); // left window.drawRectangleFilled(Style::RED, Right, 0, w, h ); // right window.drawRectangleFilled(Style::BLUE, 0, 0, w, up); // up window.drawRectangleFilled(Style::GREEN, 0, down, w, h ); // down window.flipPage(); // bla flip the page? } // add a getcolor void Update(vector& particle, Window& window) { // update :) // if (clock() >= NextUpdate) // { double x,y; int w = window.getWidth(); int h = window.getHeight(); double Left = 20; double Right = w-20; double up = 20; double down = h-20; for (int i=0; i < MAX_PARTICLES; i++) { // each one if (!(particle[i]->Dead())) { // dont change if its dead Play = clock() - LastUpdate; if (clock() >= NextUpdate) { // this is for.. the amount of time, to get the distance perfect particle[i]->ChangeXi(GravX); // change its motion with gravity particle[i]->ChangeYi((GravY*(particle[i]->GetMass()/2))); // ^^ same } //cout << "\nxi = " << particle[i]->GetXi(); //cout << "\nyi = " << particle[i]->GetYi(); x = particle[i]->GetX() + Play*particle[i]->GetXi();// + or -? y = particle[i]->GetY() + Play*particle[i]->GetYi();// play around with this a lot. +/- // not sure what this is right now.. ohh for motion.. this is good //cout << "\nclock = " << clock(); //cout << "\nlastupdate = " << LastUpdate; //cout << "\nplay = " << Play; //Play /= 100; // dunno why, 1000 ms in 1 second. //cout << "\nx = " << x; //cout << "\ny = " << y; // x = x + Play*x; // y = y + Play*y; particle[i]->Move(x,y); // change its location // cout << "\nx = " << x; // cout << "\ny = " << y; ///////////////////////////////////////////// // OUT OF AREA CHECK // ///////////////////////////////////////////// // check to see if it can die. if (particle[i]->GetX() <= Left || particle[i]->GetX() >= Right) particle[i]->Kill(); // yup if (particle[i]->GetY() >= down )//|| particle[i]->GetY() <= up) particle[i]->Kill(); /* if (partocle[i].GetAge() >= DeathAge) particle[i].Kill(); */ } } //cout << "\nnextup = " << NextUpdate; LastUpdate = clock(); // SET last updatzor //cout << "\nlast = " << LastUpdate; if (clock() >= NextUpdate) { // change colors at right time green-= 10; if (green <= 0) { green = 0; red -= 20; if (red <= 0) red = 0; } NextUpdate = clock() + WaitTime; } // } } void main() { NextUpdate = clock(); srand(time(NULL)); RBG colors; colors.blue = 0; colors.green = 0; colors.red = 254; const char *rocket = "rocket.jpg";//leave Image imgRocket(rocket,Image::JPEG); double random_integer; double random_integer2; int random_mass; // gets all the cariables astuff cout << "Commands, are. \n'y' = blast at mouse point.\n'b' = shoots a rocket at mouse point\n'v' = detonates rocket, explosion\n"; cout << "Max amount of particles: "; cin >> MAX_PARTICLES; vector particle(MAX_PARTICLES); cout << "Enter wind, negative is left, positive is right: "; cin >> GravX; cout << "Enter Gravity, negative is up, positive is dowm: "; cin >> GravY; cout << "Enter time for each update, in ms: "; // bahahahahaha stay cin >> WaitTime; cout << "Enter max mass for each particle(0-max): "; cin >> MaxMass; cout << "Enter explosion size: "; cin >> ExplosionSize; cout << "Enter 1 for explosions-up, and 2 for all around: "; cin >> Direction; Window window(640,480,"Thingy"); // mass is now random. Speed it falls is now random. particle[0] = new Object(320, 400, imgRocket, 1); particle[0]->ChangeYi((-.5)); //set up DA rocket for (int m = 1; m < MAX_PARTICLES; m++) { // set up initial BLAST directions random_integer = ((rand()%5) + (rand()%10)*ExplosionSize)/WaitTime;///10; // 10 random_integer2 = ((rand()%5) + (rand()%10)*ExplosionSize)/WaitTime;///10; if ((rand()%2) == 0) random_integer *= -1; // cannot be all down, and to right :) left too if ((rand()%2) == 1 || Direction == 1) // up random_integer2 *= -1; random_mass = 2 + rand()%MaxMass; // DA MASS //cout << "\n\nrad 1 = " << random_integer; //cout << "\nrad 2 = " << random_integer2; particle[m] = new Particle(320, 50, colors, random_mass); // MADE particle[m]->Alive(); // not needed at all. particle[m]->ChangeXi(random_integer); // change its motion with gravity particle[m]->ChangeYi(random_integer2); // ^^ same } int i = 0; double x = 150; double y = 150; int w = 300; int h = 400; Style THICK_GREEN = Style(Color::GREEN, 3); window.disableAutoPageFlip(); window.autoFlushKeyboardQueue(false); window.autoFlushMouseQueue(false); window.autoFlushTimerQueue(false); Style linestyle(Color::GREEN,3); while(!Done) { // the game loop Update(particle, window); // hmm update Draw(particle, window); // wow draw? if(window.isKeyDown('y') && clock() >= NextKeyP) { // launch... nothing, blow.. up stuff at mouse area x = window.getMouseX(); y = window.getMouseY(); resetParticles(particle, x, y); NextKeyP = clock() + KeyTime; } // y = blast at mouse point :) very nice if(window.isKeyDown('b') && clock() >= NextKeyP) { // blast rocket at this time:) x = window.getMouseX(); y = window.getMouseY(); //KillParticles(particle); // particles, not objects (which is 0) particle[0]->MakeYi(-.5); particle[0]->MakeXi(0); particle[0]->Alive(); particle[0]->Move(x,y); NextKeyP = clock() + KeyTime; } // b = launch rocket at block area. at 30, speed ( good, gets to the top) if(window.isKeyDown('v') && clock() >= NextKeyP) { // BLOw UP RIOCKET... KABOOM x = particle[0]->GetX(); // rockets x y = particle[0]->GetY(); // rockets y resetParticles(particle, x, y); // blast them der. and kill rocket particle[0]->Kill(); NextKeyP = clock() + KeyTime; } // b = blast at rocket point :) very nice // cout << "\nParticle 1 | " << particle[0]->GetY(); } } void resetParticles(vector& particle, double X, double Y) { // restets the particles.. this is in main... just sets it up double random_integer = 0; double random_integer2 = 0; int random_mass = 0; red = 255;//CurrentColor.red; green = 255;//CurrentColor.green; blue = 0;//CurrentColor.blue; for (int i = 1; i < MAX_PARTICLES; i++) { random_integer = ((rand()%5) + (rand()%10)*ExplosionSize)/WaitTime;//*10; // for smaller random_integer2 = ((rand()%5) + (rand()%10)*ExplosionSize)/WaitTime;//*10; // smaller if ((rand()%2) == 0) random_integer *= -1; if ((rand()%2) == 1 || Direction == 1) random_integer2 *= -1; random_mass = 1 + rand()%MaxMass; particle[i]->ChangeAll(random_integer, random_integer2, Y, X, random_mass); //ChangeAll(int newXi, int newYi, int newY, int newX, int newMass) particle[i]->Alive(); // not needed at all. } } void KillParticles(vector& particle) { // kill al but the rocket thuis 1 for (int i = 1; i < MAX_PARTICLES; i++) { particle[i]->Kill(); } }