bool Snapshot::load(string path) { mGalaxies.reserve(MAX_RESERVE); // Reserve memory bool success = true; // Open Snapshot file ifstream catalogue(path.c_str()); // Read file if (catalogue.is_open()) { printf("Loading Snapshot %s.\n", path.c_str()); // Success on opening files string element; getline(catalogue, element); //Skips first line with parameter names while (!catalogue.eof()) { // Stop at the end of the file // Array of parameters double values[PARAMETERS_TOTAL]; getline(catalogue, element, ','); // First Element is mass values[0] = atof(element.c_str()); // Skip the next element getline(catalogue, element, ','); // Three Position data for (int i = 1; i <= 3; i++) { getline(catalogue, element, ','); values[i] = atof(element.c_str()); } // Skip the next 4 (velocity and uband) getline(catalogue, element, ','); getline(catalogue, element, ','); getline(catalogue, element, ','); getline(catalogue, element, ','); // Load bBand getline(catalogue, element, ','); values[4] = atof(element.c_str()); // Skip to the end of the line getline(catalogue, element, '\n'); // Adding Galaxies mGalaxies.push_back( Galaxy(values[0], values[1], values[2], values[3], values[4])); } // close the catalogue catalogue.close(); printf("Note: Snapshot: Catalogues Reading Successful, %i galaxies.\n", (int) mGalaxies.size()); } else { printf("Warning: Snapshot failed to open file %s! \n", path.c_str()); } return success; }
void gameloop() //must be declared before main() so that main() can use it. { // This is here for testing purposes //Star sun = Star(50, 250, 250, sf::Color::Yellow); //sun.addPlanet(Planet(30, 100, 0, 90, sun, sf::Color::Blue)); //sun.addPlanet(Planet(40, 200, 0, 30, sun, sf::Color::Red)); //sun.addPlanet(Planet(20, 300, 0, 60, sun, sf::Color::Green)); Galaxy gal = Galaxy(); gal.generate(589418); while (Renderer::isOpen()) { Renderer::update(); //sun.update(); gal.update(); //Rest of loop here Renderer::render(); int fps = Renderer::getFPS(); if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){ Renderer::offset = sf::Vector2f(Renderer::offset.x + 10, Renderer::offset.y); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){ Renderer::offset = sf::Vector2f(Renderer::offset.x - 10, Renderer::offset.y); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){ Renderer::offset = sf::Vector2f(Renderer::offset.x, Renderer::offset.y + 10); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)){ Renderer::offset = sf::Vector2f(Renderer::offset.x, Renderer::offset.y - 10); } } }
#include "galaxy.h" #include <QMap> #include <QSharedData> #include <QStringList> #include <QTime> #include <QtMath> Galaxy Galaxy::instance = Galaxy(); class GalaxyData : public QSharedData { public: QMap<QString, SolarSystem> solarSystems; }; Galaxy::Galaxy() : data(new GalaxyData) { qsrand(QTime::currentTime().msec()); QStringList systemNames; systemNames.append(QStringLiteral("Earth616")); systemNames.append(QStringLiteral("Utopia")); systemNames.append(QStringLiteral("Omega")); systemNames.append(QStringLiteral("Tantalos")); systemNames.append(QStringLiteral("Carzon")); systemNames.append(QStringLiteral("Exo")); systemNames.append(QStringLiteral("Destiny")); systemNames.append(QStringLiteral("Frolix")); systemNames.append(QStringLiteral("Acamar")); systemNames.append(QStringLiteral("Adahn")); // The alternate personality for The Nameless One in "Planescape: Torment" systemNames.append(QStringLiteral("Aldea")); systemNames.append(QStringLiteral("Andevian"));
void Editor::check(double mousex, double mousey, int pixelx, int pixely, bool click, bool onSpace, bool leftButton) { unsigned int i; bool canRemove = false; bool wasRemoving = false; if(setGalaxy || setHole) { if(click) { if(setHole) { uni.holes.back().vx = -(uni.holes.back().x-mousex)*2e6; uni.holes.back().vy = -(uni.holes.back().y-mousey)*2e6; } else { uni.galaxies.back().vx = -(uni.galaxies.back().x-mousex)*2e6; uni.galaxies.back().vy = -(uni.galaxies.back().y-mousey)*2e6; } uni.calcStars(); setGalaxy = false; setHole = false; canPut = true; } } else { if(!onSpace) { canPut = false; } else { canPut = true; for(i = 0; i < uni.holes.size(); i++) { if( MPYTH(uni.holes[i].x, uni.holes[i].y, uni.holes[i].radius) ) { canPut = false; /* pruefen ob der ueberhaupt geloescht werden darf */ if(!uni.holes[i].inLevel() || all) { canRemove = true; if(click) { if(!all) { massreserve += uni.holes[i].mass; } uni.holes.erase(uni.holes.begin()+i); wasRemoving = true; } } } } if(!wasRemoving) { for(i = 0; i < uni.galaxies.size(); i++) { if( MPYTH(uni.galaxies[i].x, uni.galaxies[i].y, uni.galaxies[i].radius*4) ) { canPut = false; if(all) { canRemove = true; if(click) { uni.galaxies.erase(uni.galaxies.begin()+i); uni.calcStars(); wasRemoving = true; } } } } } if(!wasRemoving) { if( MPYTH(uni.goal.x, uni.goal.y, uni.goal.radius) ) { canPut = false; if(all) { canRemove = true; if(click) { uni.goal = Goal(); wasRemoving = true; } } } } if(canRemove && !wasRemoving) { SDL_SetCursor(scissors); } else { SDL_SetCursor(pointer); } if(canPut) { if(click) { if(!all) { if(massreserve >= getHoleWeight()) { massreserve -= getHoleWeight(); uni.holes.push_back(Blackhole(mousex,mousey,getHoleWeight())); canPut = false; canRemove = true; SDL_SetCursor(scissors); } } else { switch(type) { case hole: setHole = true; canPut = false; galaxyX = pixelx; galaxyY = pixely; uni.holes.push_back(Blackhole(mousex,mousey,getHoleWeight())); break; case bulge: setGalaxy = true; canPut = false; galaxyX = pixelx; galaxyY = pixely; srand(time(NULL)); uni.galaxies.push_back(Galaxy(mousex,mousey,getBulgeWeight(),!leftButton,(rand()%2))); uni.calcStars(); break; case goal: uni.goal.x = mousex; uni.goal.y = mousey; uni.goal.radius = getGoalRadius(); SDL_SetCursor(scissors); break; default: // nix setzen break; } } } } } } }