Player::Player() : baseClimingSpeed(-7), baseFallingSpeed(10.5) { crashDebris.clear(); crashDebrisSpeed.clear(); damageParticle.clear(); damageParticleSpeed.clear(); crashDebris2.clear(); crashDebrisSpeed2.clear(); damageParticle2.clear(); damageParticleSpeed2.clear(); flameAnim = 0; flameScale = 0.5; animSteps = 10; animAscend = true; drawCollisionShapes = false; playerRotation = 0; playerSpeed = 0; if (!playerTexture.loadFromFile("Resources/Graphics/rocket.png")){ setExitState(true); MessageBox(NULL, L"Failed to load player texture!", L"Error", MB_OK); } if (!flameTexture.loadFromFile("Resources/Graphics/flame_1.png")){ setExitState(true); MessageBox(NULL, L"Failed to load player flame texture!", L"Error", MB_OK); } }
OtherObjects::OtherObjects() { if (!debrisTextureTop.loadFromFile("Resources/Graphics/debrisfield_top.png")){ setExitState(true); MessageBox(NULL, L"Failed to load the top debris texture!", L"Error", MB_OK ); } if (!debrisTextureBottom.loadFromFile("Resources/Graphics/debrisfield_bottom.png")){ setExitState(true); MessageBox(NULL, L"Failed to load the bottom debris texture!", L"Error", MB_OK ); } if (!starTexture.loadFromFile("Resources/Graphics/star.png")){ setExitState(true); MessageBox(NULL, L"Failed to load star object texture!", L"Error", MB_OK ); } if (!healthIconTexture.loadFromFile("Resources/Graphics/healthicon.png")){ setExitState(true); MessageBox(NULL, L"Failed to load health icon texture!", L"Error", MB_OK ); } if (!fuelIconTexture.loadFromFile("Resources/Graphics/fuelicon.png")){ setExitState(true); MessageBox(NULL, L"Failed to load fuel icon texture!", L"Error", MB_OK ); } }
int QA::finally(int xCode) { setExitState(xCode); // write pending results to qa-file.nc. Modes are considered there for( size_t i=0 ; i < qaExp.varMeDa.size() ; ++i ) setExitState( qaExp.varMeDa[i].finally() ); if( xCode == 63 || ( nc == 0 && xCode ) || (currQARec == 0 && pIn->isTime ) ) { // qa is up-to-date or a forced exit right from the start; // no data to write if( xCode == 63 ) xCode=0 ; is_exit=true; if(nc) { nc->close(); nc=0; } } if( nc ) { if( qaTime.isTime ) qaTime.finally( nc ); // post-processing xCode = finally_data(xCode) ; if(isRequiredGlobal) { Variable& glob = pIn->variable[pIn->varSz] ; if( glob.isValidAtt("creation_date") ) std::cout << "CREATE-BEG" << glob.getAttValue("creation_date") << "CREATE-END"; if( glob.isValidAtt("tracking_id") ) std::cout << "TRACK-BEG" << glob.getAttValue("tracking_id") << "TRACK-END"; } nc->close(); nc=0; } setExitState(xCode); // distinguish from a sytem crash (segmentation error) std::cout << "STATUS-BEG" << xCode << "STATUS-END"; std::cout << std::flush; return getExitState() ; }
void AGOSEngine_Elvira2::oe2_setExitLocked() { // 169: set exit locked Item *i = getNextItemPtr(); uint16 n = getVarOrWord(); uint16 d = getVarOrByte(); setExitState(i, n, d, 3); }
void AGOSEngine_Elvira2::oe2_setExitClosed() { // 168: set exit closed Item *i = getNextItemPtr(); uint16 n = getVarOrWord(); uint16 d = getVarOrByte(); setExitState(i, n, d, 2); }
void AGOSEngine_Elvira2::oe2_setExitOpen() { // 167: set exit open Item *i = getNextItemPtr(); uint16 n = getVarOrWord(); uint16 d = getVarOrByte(); setExitState(i, n, d, 1); }
int QA::finally_data(int xCode) { // post processing, but not for conditions which indicate // incomplete checking. if( getExitState() < 3 ) { // 3 or 4 interrupted any checking if( enablePostProc ) { if( postProc() ) { if( getExitState() == 63 ) setExitState(1); // this is considered a change notes->setCheckStatus(n_data, n_fail); } } } // read history from the qa-file.nc and append new entries appendToHistory(); if( isCheckData ) { // check for flags concerning the total data set, // but exclude the case of no record if( pIn->currRec > 0 ) for( size_t j=0 ; j < qaExp.varMeDa.size() ; ++j ) qaExp.varMeDa[j].qaData.checkFinally(qaExp.varMeDa[j].var); for( size_t j=0 ; j < qaExp.varMeDa.size() ; ++j ) { // write qa-results attributes about statistics qaExp.varMeDa[j].qaData.setStatisticsAttribute(nc); // plausibility range checks about units qaExp.varMeDa[j].verifyPercent(); } } return getExitState() ; }
bool QA::checkConsistency(InFile &in, std::vector<std::string> &opt, std::string& tPath) { defaultPrjTableName() ; // Read or write the project table. Consistency consistency(this, &in, opt, tPath); if( !consistency.isEnabled() ) return true; // for running qaExp.run() consistency.setAnnotation(notes); consistency.setExcludedAttributes( excludedAttribute ); bool is_1st = consistency.check(); // inquire whether the meta-data checks passed int ev; if( (ev = notes->getExitState()) > 1 ) setExitState( ev ); return is_1st; }
void QA::openQA_Nc(InFile &in) { // Generates a new nc file for QA results or // opens an existing one for appending data. // Copies time variable from input-nc file. // name of the result file was set before if ( !qaFile.is() ) { std::string key("00"); if( notes->inq( key) ) { std::string capt("openQA_Nc(): undefined file.") ; (void) notes->operate(capt) ; notes->setCheckStatus("QA_open", n_fail); setExitState( notes->getExitState() ) ; return; } } nc = new NcAPI; if( notes ) nc->setNotes(notes); if( nc->open(qaFile.getFile(), "NC_WRITE", false) ) { // continue a previous session importedRecFromPrevQA=nc->getNumOfRecords(); currQARec += importedRecFromPrevQA; if( currQARec ) isNotFirstRecord = true; initDataOutputBuffer(); initResumeSession(); isResumeSession=true; return; } // So, we have to generate a netCDF file from almost scratch; isFirstFile=true; if( currQARec == 0 && in.nc.getNumOfRecords() == 1 ) qaTime.isSingleTimeValue = true; // open new netcdf file if( qaNcfileFlags.size() ) nc->create(qaFile.getFile(), qaNcfileFlags); else nc->create(qaFile.getFile(), "NC_NETCDF4"); if( isCheckTimeValues) { if( qaTime.time_ix > -1 ) qaTime.openQA_NcContrib(nc); else { // dimensions qaTime.name="fixed"; nc->defineDim("fixed", 1); } } // create variable for the data statistics etc. for( size_t m=0 ; m < qaExp.varMeDa.size() ; ++m ) qaExp.varMeDa[m].qaData.openQA_NcContrib(nc, qaExp.varMeDa[m].var); // global atts at creation. initGlobalAtts(in); initDataOutputBuffer(); return; }
bool QA::init(void) { // Open the qa-result.nc file, when available or create // it from scratch. Meta data checks are performed. // Initialisation of time and time boundary testing. // Eventually, entry() is called to test the data of fields. notes->init(); // safe qaExp.setParent(this); qaTime.setParent(this); // default for the qaFile setFilename( pIn->file ); // apply parsed command-line args applyOptions(); std::string vName(qaExp.getVarnameFromFilename()); if(isRequiredVariable) pIn->pullMetaData('V', vName); if(isRequiredTime && !isRequiredVariable) pIn->pullMetaData('T'); if(isRequiredGlobal) pIn->pullMetaData('G'); initCheckStatus(); // check for CF Convention. if(isCheckCF) { cF->setDataVarName(vName); cF->setFilename(pIn->file); (void) cF->run(); } // exclude user-defined data variables from any checking pIn->excludeVars(); qaTime.init(optStr); qaExp.init(optStr); // DRS specifications if(isCheckDRS_F || isCheckDRS_P) { drs_cv_table.setParent(this); drs_cv_table.setPath(tablePath); drs_cv_table.applyOptions(optStr); drs_cv_table.read(); } // experiment specific obj: set parent, pass over options // check consistency between sub-sequent files or experiments if(isCheckCNSTY && (fileSequenceState == 's' || fileSequenceState == 'x') ) { // return true for a) no previous check available, // b) deviation from a privous check are found if( checkConsistency(*pIn, optStr, tablePath) ) qaExp.run(); } else qaExp.run(); // check existence of any data at all if( pIn->ncRecBeg == 0 && pIn->ncRecEnd == 0 ) { isCheckData=false; std::string key("6_15"); if( notes->inq( key, fileStr) ) { std::string capt("No records in the file") ; if( notes->operate(capt) ) { notes->setCheckStatus(n_data, n_fail ); setExitState( notes->getExitState() ) ; } } } if( isCheckData ) { if( !checkDataBody() ) { isCheckData = false; notes->setCheckStatus(n_data, n_fail); setExitState(2); // return true; } } if(isCheckTimeValues && !qaTime.isTime) notes->setCheckStatus(n_time, "FIXED"); if(isCheckTimeValues) { if( qaTime.isTime) { if( !checkDataBody(qaTime.name) ) { // time is defined, but there is no data qaTime.isTime = false; notes->setCheckStatus(n_time, n_fail); setExitState(2); } } } if(isCheckData || isCheckTimeValues) { notes->setConstraintFreq( qaExp.getFrequency() ); // enable detection of outlier and replicated records setProcessing(); // open netCDF for creating, continuation or resuming qa_<varname>.nc. // note that this must happen before checkMetaData which uses currQARec openQA_Nc(*pIn); if( isExit() || qaExp.isUseStrict || qaTime.isNoProgress ) { isCheckData=false; return true; } } if( isCheckData || isCheckTimeValues ) { // set pointer to function for operating tests // execPtr = &IObj::entry ; (void) entry(); } return true; // only meta-data check }
void Player::updatePlayer() { //Animation logic stuff if (flameAnim > animSteps){ animAscend = false; } else if (flameAnim < -animSteps){ animAscend = true; } //Collision checks //Borders if (!getExplosionState()){ if (playerSprite.getPosition().y <= (playerSprite.getGlobalBounds().height / 2) || playerSprite.getPosition().y + (playerSprite.getGlobalBounds().height / 2) >= VideoMode::getDesktopMode().height){ for (int i = 0; i < 2; i++){ decreaseHealth(difficulty); if (getPlayerHealth() < 0){ short num = -(getPlayerHealth()); increaseHealth(num); } if (hardcore) setExplosionState(true); updateCrashSound(); if (showParticles){ crashDebrisSpeed.push_back(Vector2f(-(getObstacleBaseSpeed() / 2), getRandom(-2, 2))); crashDebris.push_back(RectangleShape()); short ramNum = getRandom(5, 8); crashDebris.back().setSize(Vector2f(ramNum, ramNum)); crashDebris.back().setOrigin(ramNum / 2, ramNum / 2); ramNum = getRandom(50, 160); crashDebris.back().setFillColor(Color::Color(ramNum, ramNum, ramNum)); crashDebris.back().setPosition(collisionCircle[0].getPosition().x + getRandom(-5, 5), collisionCircle[0].getPosition().y + getRandom(-5, 5)); } } } //Obstacles for (int i=0; i<getNumberOfObstacles(); i++){ if (playerCollision(&collisionCircle[0], &getObstacleObject(i))){ if (getPlayerHealth() > 0) decreaseHealth(difficulty); if (getPlayerHealth() < 0){ short num = -(getPlayerHealth()); increaseHealth(num); } if (hardcore) setExplosionState(true); updateCrashSound(); if (showParticles){ crashDebrisSpeed.push_back(Vector2f(-(getObstacleBaseSpeed() / 2), getRandom(-2, 2))); crashDebris.push_back(RectangleShape()); short ramNum = getRandom(5, 8); crashDebris.back().setSize(Vector2f(ramNum, ramNum)); crashDebris.back().setOrigin(ramNum / 2, ramNum / 2); ramNum = getRandom(50, 160); crashDebris.back().setFillColor(Color::Color(ramNum, ramNum, ramNum)); crashDebris.back().setPosition(collisionCircle[0].getPosition().x + getRandom(-5, 5), collisionCircle[0].getPosition().y + (getRandom(-5, 5))); } } if (playerCollision(&collisionCircle[1], &getObstacleObject(i))){ if (getPlayerHealth() > 0) decreaseHealth(difficulty); if (getPlayerHealth() < 0){ short num = -(getPlayerHealth()); increaseHealth(num); } if (hardcore) setExplosionState(true); updateCrashSound(); if (showParticles){ crashDebrisSpeed.push_back(Vector2f(-(getObstacleBaseSpeed() / 2), getRandom(-2, 2))); crashDebris.push_back(RectangleShape()); short ramNum = getRandom(4, 7); crashDebris.back().setSize(Vector2f(ramNum, ramNum)); crashDebris.back().setOrigin(ramNum / 2, ramNum / 2); ramNum = getRandom(50, 160); crashDebris.back().setFillColor(Color::Color(ramNum, ramNum, ramNum)); crashDebris.back().setPosition(collisionCircle[1].getPosition().x + getRandom(-3, 3), collisionCircle[1].getPosition().y + (getRandom(-3, 3))); } } if (playerCollision(&collisionCircle[2], &getObstacleObject(i))){ if (getPlayerHealth() > 0) decreaseHealth(difficulty); if (getPlayerHealth() < 0){ short num = -(getPlayerHealth()); increaseHealth(num); } if (hardcore) setExplosionState(true); updateCrashSound(); if (showParticles){ crashDebrisSpeed.push_back(Vector2f(-(getObstacleBaseSpeed() / 2), getRandom(-2, 2))); crashDebris.push_back(RectangleShape()); short ramNum = getRandom(4, 7); crashDebris.back().setSize(Vector2f(ramNum, ramNum)); crashDebris.back().setOrigin(ramNum / 2.0f, ramNum / 2.0f); ramNum = getRandom(50, 160); crashDebris.back().setFillColor(Color::Color(ramNum, ramNum, ramNum)); crashDebris.back().setPosition(collisionCircle[2].getPosition().x + getRandom(-3, 3), collisionCircle[2].getPosition().y + (getRandom(-3, 3))); } } } } //Explosion if (getPlayerHealth() <= 0 || getExplosionState()){ setExplosionState(true); decreaseFuel(getPlayerFuel()); updateExplosionText(); stopRocketSound(); stopAlarmSound(); stopCrashSound(); if (initExplosion){ for (int i = 0; i < 200; i++){ crashDebrisSpeed2.push_back(Vector2f(getRandom(-2, 2), getRandom(-2, 2))); crashDebris2.push_back(RectangleShape()); short ramNum = getRandom(4, 7); crashDebris2.back().setSize(Vector2f(ramNum, ramNum)); crashDebris2.back().setOrigin(ramNum / 2.0f, ramNum / 2.0f); ramNum = getRandom(50, 160); crashDebris2.back().setFillColor(Color::Color(ramNum, ramNum, ramNum)); crashDebris2.back().setPosition(collisionCircle[0].getPosition().x + getRandom(-3, 3), collisionCircle[0].getPosition().y + (getRandom(-3, 3))); damageParticleSpeed2.push_back(Vector2f(getRandom(-3, 3), getRandom(-3, 3))); damageParticle2.push_back(CircleShape()); damageParticle2.back().setRadius(getRandom(1, 2)); damageParticle2.back().setFillColor(Color::Color(255, 153, 51)); int j = getRandom(0, 2); damageParticle2.back().setPosition(collisionCircle[0].getPosition().x + getRandom(-3, 3), collisionCircle[0].getPosition().y + (getRandom(-3, 3))); } playExplosionSound(); } for (int i = 0; i < crashDebris2.size(); i++){ crashDebris2[i].move(crashDebrisSpeed2[i].x - explosionSpeedCounter, crashDebrisSpeed2[i].y); if (i % 2 == 0){ crashDebris2[i].rotate(2); } else crashDebris2[i].rotate(-2); crashDebrisSpeed2[i].x = crashDebrisSpeed2[i].x * 0.985; crashDebrisSpeed2[i].y = crashDebrisSpeed2[i].y * 0.985; if (crashDebris2[i].getPosition().x < -10){ crashDebris2.erase(crashDebris2.begin() + i); crashDebrisSpeed2.erase(crashDebrisSpeed2.begin() + i); } } for (int i = 0; i < damageParticleSpeed2.size(); i++){ damageParticle2[i].move(damageParticleSpeed2[i].x - explosionSpeedCounter, damageParticleSpeed2[i].y); damageParticleSpeed2[i].x = damageParticleSpeed2[i].x * 0.985; damageParticleSpeed2[i].y = damageParticleSpeed2[i].y * 0.985; if (damageParticle2[i].getPosition().x < -10){ damageParticle2.erase(damageParticle2.begin() + i); damageParticleSpeed2.erase(damageParticleSpeed2.begin() + i); } } if (explosionSpeedCounter <= 10.0){ explosionSpeedCounter *= 1.03; } initExplosion = false; if (Keyboard::isKeyPressed(Keyboard::R)){ setCrashState(true); setExplosionState(false); } else if (Keyboard::isKeyPressed(Keyboard::Escape)) setExitState(true); } //Updates //Crash debris if (showParticles){ for (int i = 0; i < crashDebris.size(); i++){ crashDebris[i].move(crashDebrisSpeed[i].x, crashDebrisSpeed[i].y); if (i % 2 == 0) crashDebris[i].rotate(10); else crashDebris[i].rotate(-10); if (crashDebris[i].getPosition().x < -20){ crashDebris.erase(crashDebris.begin() + i); crashDebrisSpeed.erase(crashDebrisSpeed.begin() + i); } } //Damage particles if (getPlayerHealth() > 0 && getPlayerHealth() <= 75){ if (1 >= getRandom(0, 10)){ damageParticleSpeed.push_back(Vector2f(-(getObstacleBaseSpeed()), 0)); damageParticle.push_back(CircleShape()); damageParticle.back().setRadius(1); damageParticle.back().setFillColor(Color::Color(255, 153, 51)); int i = getRandom(0, 2); damageParticle.back().setPosition(collisionCircle[i].getPosition().x + getRandom(-3, 3), collisionCircle[i].getPosition().y + (getRandom(-3, 3))); } } if (getPlayerHealth() > 0 && getPlayerHealth() <= 50){ if (1 >= getRandom(0, 5)){ damageParticleSpeed.push_back(Vector2f(-(getObstacleBaseSpeed()), 0)); damageParticle.push_back(CircleShape()); damageParticle.back().setRadius(1); damageParticle.back().setFillColor(Color::Color(255, 153, 51)); int i = getRandom(0, 2); damageParticle.back().setPosition(collisionCircle[i].getPosition().x + getRandom(-3, 3), collisionCircle[i].getPosition().y + (getRandom(-3, 3))); } } if (getPlayerHealth() > 0 && getPlayerHealth() <= 25){ if (1 >= getRandom(0, 2)){ damageParticleSpeed.push_back(Vector2f(-(getObstacleBaseSpeed()), 0)); damageParticle.push_back(CircleShape()); damageParticle.back().setRadius(1); damageParticle.back().setFillColor(Color::Color(255, 153, 51)); int i = getRandom(0, 2); damageParticle.back().setPosition(collisionCircle[i].getPosition().x + getRandom(-3, 3), collisionCircle[i].getPosition().y + (getRandom(-3, 3))); } if (1 >= getRandom(0, 50)){ } } for (int i = 0; i < damageParticle.size(); i++){ damageParticle[i].move(damageParticleSpeed[i].x, damageParticleSpeed[i].y); if (damageParticle[i].getPosition().x < -10){ damageParticle.erase(damageParticle.begin() + i); damageParticleSpeed.erase(damageParticleSpeed.begin() + i); } } } if (getPlayerFuel() > 0 && getPlayerHealth() > 0){ if (controlScheme == 1){ if (Keyboard::isKeyPressed(Keyboard::Space)){ if (playerRotation >= -30){ playerRotation -= 15; if (playerRotation < -30) playerRotation = playerRotation - (playerRotation + 30); playerSprite.setRotation(playerRotation); } playerSprite.move(0, baseClimingSpeed); //Climing speed is always constant playerSpeed = -(baseFallingSpeed +3); //Set speed value so that transition from climing to falling feels smooth } else { if (playerRotation <= 20){ playerRotation += 5; playerSprite.setRotation(playerRotation); } playerSprite.move(0, baseFallingSpeed + playerSpeed); if (playerSpeed <= 0) playerSpeed = playerSpeed + 1; else if ((playerSpeed <= baseFallingSpeed) && (playerSpeed > 0)) playerSpeed = playerSpeed * 1.02; } } else if (controlScheme == 2){ if (Keyboard::isKeyPressed(Keyboard::Left) && playerRotation >= -30){ playerRotation -= 3; } else if (Keyboard::isKeyPressed(Keyboard::Right) && playerRotation <= 30){ playerRotation += 3; } else if (Keyboard::isKeyPressed(Keyboard::Space)){ playerRotation = 0; } playerSprite.setRotation(playerRotation); playerSprite.move(0, playerRotation / 3); } else if (controlScheme == 3){ if (Keyboard::isKeyPressed(Keyboard::Left)){ if (playerRotation >= -30) playerRotation -= 5; } else if (Keyboard::isKeyPressed(Keyboard::Right)){ if (playerRotation <= 30) playerRotation += 5; } else { if (playerRotation < 0){ playerRotation += 5; } else if (playerRotation > 0) playerRotation -= 5; } playerSprite.setRotation(playerRotation); playerSprite.move(0, playerRotation / 3); } if (getPlayerHealth() > 0) updateRocketSound(); } else if (getPlayerFuel() <= 0){ if (!playedShutdownSound){ playShutdownSound(); playedShutdownSound = true; } stopRocketSound(); if (playerRotation < 0) playerSprite.move(0, playerRotation / 6); else if (playerRotation > 0) playerSprite.move(0, playerRotation / 3); if (playerRotation < 0) playerSprite.rotate(-1); else if (playerRotation > 0) playerSprite.rotate(1); } //Flame Sprite Bottom flameSpriteBottom.setPosition((playerSprite.getPosition().x - 45) - (playerRotation / 2.4), (playerSprite.getPosition().y + 28) + -(playerRotation / 1.05)); flameSpriteBottom.setRotation(playerSprite.getRotation()); if (animAscend){ flameScale += 0.012; flameSpriteBottom.setScale(flameScale, flameSpriteBottom.getScale().y); flameAnim++; } else if (!animAscend){ flameScale -= 0.012; flameSpriteBottom.setScale(flameScale, flameSpriteBottom.getScale().y); flameAnim--; } //Flame Sprite Top flameSpriteTop.setPosition(playerSprite.getPosition().x - 45, (playerSprite.getPosition().y - 7) + -(playerRotation / 1.05)); flameSpriteTop.setRotation(playerSprite.getRotation()); if (animAscend){ flameScale += 0.012; flameSpriteTop.setScale(flameScale, flameSpriteBottom.getScale().y); flameAnim++; } else if (!animAscend){ flameScale -= 0.012; flameSpriteTop.setScale(flameScale, flameSpriteBottom.getScale().y); flameAnim--; } collisionCircle[0].setPosition(playerSprite.getPosition().x + 20, playerSprite.getPosition().y + ((playerRotation / 3) + 2)); collisionCircle[1].setPosition(playerSprite.getPosition().x - (24 - (playerRotation / 5)), playerSprite.getPosition().y - ((playerRotation / 2) + 12)); collisionCircle[2].setPosition(playerSprite.getPosition().x - (24 + (playerRotation / 5)), playerSprite.getPosition().y - ((playerRotation / 2) - 14)); }