//-------------------------------------------------------------- void testApp::update(){ // Update the control text based on the player's choice on the title screen. if ( gameState == 0 ) fWriteControls(); // Don't update anything else if not on the game screen. if ( gameState != 1 ) return; // Reset essential conditionals. myPlayer.onSurface = false; if ( getThisOne < 0 ) getThisOne = objectList.size() - 1; if ( getThisOne > objectList.size() - 1 ) getThisOne = 0; // Apply gravity to the player. // Come back to this. Use it to fake analog sensitivity with jump height proportional to how long the button is held. Gravity only applies sometimes. myPlayer.applyForce( ofVec2f( 0.0, 0.3 ) ); // Run collision detection. playerCollidesWithObject(); // Update the player (duh). myPlayer.update(); // Update the notes. updateObjectList(); // Following up the boolean function we created above, this oF function sorts the vector according to the values of the booleans and then removes any with a 'true' value: ofRemove( objectList, bShouldIErase ); ofRemove( recordedList, bShouldIErase ); }
//-------------------------------------------------------------- void testApp::update() { ofRemove(circles, ofxBox2dBaseShape::shouldRemoveOffScreen); ofRemove(boxes, ofxBox2dBaseShape::shouldRemoveOffScreen); box2d.update(); ground.clear(); ground.addVertexes(groundLine); ground.create(box2d.getWorld()); }
void BeatPulser::update(){ for (int i=0; i<partyBirthRate; i++) { party.push_back(PartiCircle(loc, tertiaryColor)); } ofRemove(party, deathTest); ofRemove(pulses, deathTest); for (int i=0;i<party.size();i++){ party[i].update(); } for (int i=0;i<pulses.size();i++){ pulses[i].update(); } }
void testApp::update(){ ken.update(); ryu.update(); Projectile::gravity = panel.getValueF("gravity"); Projectile::friction = panel.getValueF("friction"); Projectile::explosionTime = panel.getValueF("explosionTime"); if(panel.getValueB("manualMode")) { if(panel.getValueB("fire0")) { panel.setValueB("fire0", false); fire(getId(0)); } if(panel.getValueB("fire1")) { panel.setValueB("fire1", false); fire(getId(1)); } if(panel.hasValueChanged(variadic("playerCount"))) { setPlayerCount(panel.getValueI("playerCount")); panel.clearAllChanged(); } updatePosition(0, panel.getValueF("player0x"), panel.getValueF("player0y")); updatePosition(1, panel.getValueF("player1x"), panel.getValueF("player1y")); } while(receiver.hasWaitingMessages()) { ofxOscMessage msg; receiver.getNextMessage(&msg); if (msg.getAddress() == "/pew/playerPosition") { updatePosition(getId(msg.getArgAsInt32(0)), msg.getArgAsFloat(1), msg.getArgAsFloat(2)); } else if(msg.getAddress() == "/pew/fire") { fire(getId(msg.getArgAsInt32(0))); } else if (msg.getAddress() == "/pew/players") { setPlayerCount(msg.getArgAsInt32(0)); } } float explodeDistance = panel.getValueF("explodeDistance"); float dt = ofGetLastFrameTime(); for(int i = 0; i < projectiles.size(); i++) { projectiles[i].update(dt); for(int j = 0; j < players.size(); j++) { float distance = projectiles[i].position.distance(players[j].position); if(projectiles[i].source != j && distance < explodeDistance) { if(!projectiles[i].exploding) { projectiles[i].explode(); players[j].ouch(); } } } } ofRemove(projectiles, isOldProjectile); }
//-------------------------------------------------------------- void testApp::updateMovers(){ //ofVec2f wind(ofMap(mouseX, ofGetWidth()/2, ofGetWidth(), 0, 0.01), 0); ofVec2f windCartesian(-sin(ofDegToRad(wind.y)), cos(ofDegToRad(wind.y))); ofVec2f windForce(wind_speed * wind_speed * windCartesian/coefPixelToRealWorld); //ofVec2f gravity(0, 0.1); //generate balls here if (wind_speed > 2 && (ofRandomuf() < 0.00001 * wind_speed * cloudProbability || wind_speed - last_wind_speed > 4)){ //if (wind_speed > 2 && (ofRandomuf() < 0.00001 * 60 * cloudProbability || wind_speed - last_wind_speed > 4)){ movers.push_back(ofPtr<Mover>(new Mover())); movers.back().get()->setup(); //movers.back().get()->setMass(ofRandom(1.1, 4)); movers.back().get()->setMass(1); ofVec2f location; location.y = ofGetHeight()/2.; float width = 2/3.*ofGetHeight(); if (windCartesian.x > 0){ //location.x = 0-movers.back().get()->getDiameter(); location.x = -width; } else { //location.x = ofGetWidth(); location.x = ofGetWidth()+width; } //coefPixelToRealWorld = 1; movers.back().get()->setLocation(location.x, location.y); windCartesian.y = 0; windCartesian.normalize(); movers.back().get()->setVelocity(windCartesian*wind_speed/coefPixelToRealWorld); } last_wind_speed = wind_speed; // update balls for (unsigned int i = 0; i < movers.size(); i++){ //friction float c = frictionCoef; ofVec2f friction(movers[i].get()->getVelocity()); friction *= -1; friction.normalize(); friction *= c; movers[i].get()->applyForce(friction); //movers[i].applyForce(windForce); //movers[i].applyForce(gravity); movers[i].get()->update(); movers[i].get()->checkEdges(); } // delete balls ofRemove(movers, Mover::shouldRemoveOffScreen); }
//-------------------------------------------------------------- void ofApp::updateCircles() { for(auto &c : circles) { fields.affectCircle(c); } ofRemove(circles, ofxBox2dBaseShape::shouldRemoveOffScreen); if(circles.size() < gui->maxCircles) { newCircle(); } else if(circles.size() > gui->maxCircles) { circles.pop_back(); } }
//-------------------------------------------------------------- void ofApp::draw(){ for(int i=0; i<balls.size(); i++) { ofFill(); ofSetHexColor(0xe63b8b); balls[i].get()->draw(); } ofRemove(balls, ofxBox2dBaseShape::shouldRemoveOffScreen); string number = "Balls size = " + ofToString(balls.size()); ofDrawBitmapString(number,50,50); }
//-------------------------------------------------------------- void ofApp::update() { box2d.update(); if(bMouseForce) { float strength = 8.0f; float damping = 0.7f; float minDis = 100; for(int i=0; i<circles.size(); i++) { circles[i].get()->addAttractionPoint(mouseX, mouseY, strength); circles[i].get()->setDamping(damping, damping); } for(int i=0; i<customParticles.size(); i++) { customParticles[i].get()->addAttractionPoint(mouseX, mouseY, strength); customParticles[i].get()->setDamping(damping, damping); } } // remove shapes offscreen ofRemove(boxes, ofxBox2dBaseShape::shouldRemoveOffScreen); ofRemove(circles, ofxBox2dBaseShape::shouldRemoveOffScreen); ofRemove(customParticles, ofxBox2dBaseShape::shouldRemoveOffScreen); }
//-------------------------------------------------------------- void testApp::update() { ofRemove(circles, removeShapeOffScreen); ofRemove(boxes, removeShapeOffScreen); box2d.update(); float r = ofRandom(4, 20); circles.push_back(shared_ptr<ofxBox2dCircle>(new ofxBox2dCircle)); circles.back().get()->setPhysics(3.0, 0.53, 0.1); circles.back().get()->setup(box2d.getWorld(), ofGetWidth()/2+ofRandom(-100, 100), -200+ofRandom(30, 100), r); float w = ofRandom(4, 20); float h = ofRandom(4, 20); boxes.push_back(shared_ptr<ofxBox2dRect>(new ofxBox2dRect)); boxes.back().get()->setPhysics(3.0, 0.53, 0.1); boxes.back().get()->setup(box2d.getWorld(), ofGetWidth()/2+ofRandom(-100, 100), -200+ofRandom(30, 100), w, h); }
//-------------------------------------------------------------- void ofApp::update(){ ofSetWindowTitle(ofToString(ofGetFrameRate())); box2d.update(); if(ofGetElapsedTimeMillis()-timer>200){ timer = ofGetElapsedTimeMillis(); circles.push_back(ofPtr<ofxBox2dCircle>(new ofxBox2dCircle)); circles.back().get()->setPhysics(3.0, 0.3, 0.05); circles.back().get()->setup(box2d.getWorld(), 100, 100, 15); circles.back().get()->addForce(ofVec2f(10,5), 100); } ofRemove(circles, ofxBox2dBaseShape::shouldRemoveOffScreen); }
//-------------------------------------------------------------- void ofApp::update() { // add some circles every so often if((int)ofRandom(0, 10) == 0) { auto circle = std::make_shared<ofxBox2dCircle>(); circle->setPhysics(0.3, 0.5, 0.1); circle->setup(box2d.getWorld(), (ofGetWidth()/2)+ofRandom(-20, 20), -20, ofRandom(10, 20)); circles.push_back(circle); } // remove shapes offscreen ofRemove(circles, shouldRemove); // ofRemove(polyShapes, shouldRemove); box2d.update(); }
void threadedFunction() { while(isThreadRunning()) { for(int i = 0; i < backNotes.size(); i++) { MidiNote& cur = backNotes[i]; if(cur.finished()) { midi.sendNoteOff(cur.channel, cur.pitch, 0); } } ofRemove(backNotes, isFinished); lock(); swap(); unlock(); ofSleepMillis(1); } // silence remaining notes swap(); for(int i = 0; i < backNotes.size(); i++) { MidiNote& cur = backNotes[i]; midi.sendNoteOff(cur.channel, cur.pitch, 0); } }
//-------------------------------------------------------------- void testApp::update(){ angle++; rectTimer++; rad += radRate; // When the timer reaches the limit, make a new rect and reset the timer. if (rectTimer > rectRate) { makeNewRect(); } if (angle > 360) angle = 0; moveRects(); moveMouseRects(); whenRectsCollide(); // Following up the boolean function we created above, this oF function sorts the vector according to the values of the booleans and then removes any with a 'true' value: ofRemove(myRects,bShouldIErase); }
void Water::bubbleUpdate() { // 下から泡発生 if ( ofGetFrameNum()%10 == 0 ) { ofPtr<ofxBox2dCircle> circle = ofPtr<ofxBox2dCircle>(new ofxBox2dCircle); circle.get()->setPhysics(1, 0.5, 0.1); circle.get()->setup(bubbleWorld.getWorld(), ofRandom(0, waterWidth), waterHeight - 10, ofRandom(1, 5)); bubbles.push_back(circle); } // 泡の処理 for ( int i=0; i<bubbles.size(); i++ ) { // 浮力 float size = bubbles[i].get()->getRadius(); float frequency = (7.0/size) * sin(ofGetFrameNum()/(float)size * PI); ofVec2f pos = bubbles[i].get()->getPosition(); ofVec2f buoyancy = ofVec2f(bubbles[i].get()->getVelocity().x + frequency, -size * size); bubbles[i].get()->setVelocity(buoyancy); // ベクトル場に力があればボールに力を得る ofVec2f frc = VF.getForceFromPos(pos.x, pos.y); if ( frc.length() > 0 ) { bubbles[i].get()->addForce(ofVec2f(frc.x, frc.y), 1); } // 泡の削除のため画面外に泡を飛ばす for ( int j=0; j<borderCircles.size(); j++ ) { ofVec2f posBorder = borderCircles[j].get()->getPosition(); if ( pos.y < posBorder.y+size*2 && ofDist(posBorder.x, 0, pos.x, 0) <= 21 ) { bubbles[i].get()->setPosition(pos.x, -100); } } } // 泡の削除のために画面外に泡を飛ばす ofRemove(bubbles, ofxBox2dBaseShape::shouldRemoveOffScreen); }
void ofApp::onCopyingDone(CopyBridgeEventArgs& args) { sendCopyFinished(args.from, args.to); ofRemove(bridges, CopyBridge::shouldRemoveBridge); }
//-------------------------------------------------------------- void ofApp::update() { world.update(); ofRemove( rigidBodies, shouldRemoveRigidBody ); }
//-------------------------------------------------------------- void testApp::update(){ { // Repeated from setup. Allow controller to be switched on/off during play. Thanks to Michael Kahane for leading the way on this. if ( bUsingController == false ) { //CHECK IF THERE EVEN IS A GAMEPAD CONNECTED if(ofxGamepadHandler::get()->getNumPads()>0){ bUsingController = true; ofxGamepad* pad = ofxGamepadHandler::get()->getGamepad(0); ofAddListener(pad->onAxisChanged, this, &testApp::axisChanged); ofAddListener(pad->onButtonPressed, this, &testApp::buttonPressed); ofAddListener(pad->onButtonReleased, this, &testApp::buttonReleased); } else { bUsingController = false; } } } // End ofxGamepad stuff // Don't update anything else if not on the game screen. if ( gameState < 1 ) return; myStaff.update(); fCalcTrebleNotes(); // Reset essential conditionals. myPlayer.onSurface = false; myPlayer2.onSurface = false; if ( bHighlightNote ) { if ( getThisOne < 0 ) getThisOne = objectList.size() - 1; if ( getThisOne > objectList.size() - 1 ) getThisOne = 0; } fApplyGravity(); // Run collision detection. playerCollidesWithGroundOrSky(); playerCollidesWithObstacle(); playerCollidesWithObject(); objectCollidesWithObstacle(); // Calculate the player's success: iHitCounter = 0; // Reset this every frame. for ( int i = 0; i < objectList.size(); i++ ) { if ( objectList[ i ].bWasTouched == true ) { iHitCounter++; } } // Update the player (duh). myPlayer.update( gameState ); if ( gameState >= 3 ) { myPlayer2.update( gameState ); } // Update the notes. updateObjectList(); ofRemove( objectList, bShouldIErase ); ofRemove( recordedList, bShouldIErase ); }
//-------------------------------------------------------------- void testApp::update() { box2d.update(); switch(mode){ case START:{ } break; case WON:{ if(ofGetElapsedTimeMillis()-trans_time > 3000){ mode=START; customParticles.clear(); bullets.clear(); apples.clear(); level=0; } } break; case PLAY: if(ofGetElapsedTimeMillis()-sprite_timer >500){ sprite_timer= ofGetElapsedTimeMillis(); CustomParticle * p = customParticles[0].get(); p->cur.loadImage("hero.gif"); p->cur.resize(p->cur.getWidth()*0.05, p->cur.getHeight()*0.05); p->height= p->cur.getHeight(); p->width = p->cur.getWidth(); } //BOSS BATTLE if(level==4){ CustomParticle * p = customParticles[1].get(); if(p->getPosition().x > ofGetWidth()-20){ p->setVelocity(-p->getVelocity().x, p->getVelocity().y); } idx++; if(idx%(int)ofRandom(50, 100) == 0){ customParticles[1].get()->addAttractionPoint(movePt, -4.0f); movePt.x=(int)ofRandom(100,620); movePt.y=(int)ofRandom(10,400); customParticles[1].get()->addAttractionPoint(movePt, 10.0f); } } //BULLETS for(int i=0; i<bullets.size(); i++) { bullets[i].get()->age++; if(bullets[i].get()->age > 100){ bullets.erase(bullets.begin()+i); } } //BAD BULLETS if(level > 1){ int prob=20; if(level == 4) prob=30; if(ofRandom(1000)<prob){ ofLog()<<"SHOOOOOOOT"; // shoot.play(); apples.push_back(ofPtr<Bullet>(new Bullet(1))); Bullet * p = apples.back().get(); p->setPhysics(0.4, 0.5, 0.31); p->setup(box2d.getWorld(), customParticles[1]->getPosition().x, customParticles[1]->getPosition().y-10, p->width, p->height); p->addForce(customParticles[1]->getVelocity(), 80); p->addForce(ofVec2f(0,1), 60); if(level > 2){ p->addAttractionPoint(customParticles[0].get()->getPosition(), 50.0f); } SoundData * s = new SoundData(); p->setData(s); SoundData * sd = (SoundData*)p->getData(); sd->type = BADBULLET; sd->bHit = false; } } for(int i=0; i<apples.size(); i++) { apples[i].get()->age++; if(apples[i].get()->age > 100){ apples.erase(apples.begin()+i); } } for(int i=0; i<customParticles.size();i++){ CustomParticle * p = customParticles[i].get(); if(i==0){ if(p->getPosition().x > ofGetWidth()-50){ p->setVelocity(-p->getVelocity().x, p->getVelocity().y); } } SoundData * sd = (SoundData*)p->getData(); if(sd->bHit){ customParticles[i].get()->hurt(10); } if(p->hp < 0 && i!= 0){ p->addForce(ofVec2f(3,-5), 40); } if(customParticles[0].get()->hp < 0){ trans_time = ofGetElapsedTimeMillis(); //win.play(); ofLog()<<"LOST"; mode=LOST; } if((customParticles.size()< 2 || customParticles[1].get()->hp < 0) &&ofGetElapsedTimeMillis()-trans_time > 500){ if(level<4){ ofLog()<<"LVLUP"; level++; setLevel(level); trans_time=ofGetElapsedTimeMillis(); // }else{ // trans_time = ofGetElapsedTimeMillis(); // win.play(); // mode=WON; } } if(level==4 && customParticles[1].get()->hp<0){ trans_time = ofGetElapsedTimeMillis(); win.play(); ofLog()<<"WON"; mode=WON; } } break; } // remove shapes offscreen ofRemove(bullets, ofxBox2dBaseShape::shouldRemoveOffScreen); // ofRemove(bullets,bulletDies); ofRemove(customParticles, ofxBox2dBaseShape::shouldRemoveOffScreen); }
//-------------------------------------------------------------- void testApp::update() { if((int)ofRandom(0, 20)==10) { int randomHole = ofRandom(holes.size()); Bug newBug; newBug.pos = holes[randomHole]; newBug.vel.set(ofRandom(-1, 1), ofRandom(-1, 1)); bugs.push_back(newBug); } for(unsigned int i=0; i<bugs.size(); i++) { bugs[i].update(); // bug pos and size float size = bugs[i].size; ofVec2f pos = bugs[i].pos; // wrap the bugs around the screen if(pos.x > ofGetWidth()-size) bugs[i].pos.x = -size; if(pos.x < -size) bugs[i].pos.x = ofGetWidth()-size; if(pos.y > ofGetHeight()+size) bugs[i].pos.y = -size; if(pos.y < -size) bugs[i].pos.y = ofGetHeight()-size; } // check if we should remove any bugs ofRemove(bugs, shouldRemoveBug); // update the bullets for(unsigned int i=0; i<bullets.size(); i++) { bullets[i].update(); } // check if we want to remove the bullet ofRemove(bullets, shouldRemoveBullet); // did we hit a bug loop we are checking to see if a bullet // hits a bug. if so we are going to launch an event for the game for(unsigned int i=0; i<bullets.size(); i++) { for(unsigned int j=0; j<bugs.size(); j++) { ofVec2f a = bullets[i].pos; ofVec2f b = bugs[j].pos; float minSize = bugs[j].size; if(a.distance(b) < minSize) { static GameEvent newEvent; newEvent.message = "BUG HIT"; newEvent.bug = &bugs[j]; newEvent.bullet = &bullets[i]; ofNotifyEvent(GameEvent::events, newEvent); } } } }
// ---------------------------------------------------- void SpotsScene::draw() { drawBackground(); //just to update the background colour, sloppy ofColor peteBack = ofColor(255,242,240); ofSetColor(peteBack); ofFill(); ofRect(0, 0, CUBE_SCREEN_WIDTH, CUBE_SCREEN_HEIGHT); ofEnableAlphaBlending(); if((int)ofRandom(0, 300) == 30) { circleFrcFlip = !circleFrcFlip; } float n = ofGetElapsedTimef() * 0.2; if(circleFrcFlip) n *= -1; float r = 5 + ofNoise(n, circleFrc.x/3000.0) * 300; circleFrc.x = cos(n*TWO_PI) * r; circleFrc.y = sin(n*TWO_PI) * r; // ofSetColor(255, 0, 0); // ofCircle(circleFrc+getCentreCubeScreen(), 13); //don't draw red dot... ofSetColor(bgColor); for (vector<SpotShape>::iterator it=shapes.begin(); it!=shapes.end(); ++it) { ofVec2f p = it->getPosition(); float r = it->getRadius(); // it->tex->bind(); // glBegin(GL_QUADS); // // glVertex2f(p.x-r, p.y-r); glTexCoord2f(0, 0); // glVertex2f(p.x+r, p.y-r); glTexCoord2f(1, 0); // glVertex2f(p.x+r, p.y+r); glTexCoord2f(1, 1); // glVertex2f(p.x-r, p.y+r); glTexCoord2f(0, 1); // //ofSphere(p, 10); ofSetColor(it->colour); ofCircle(p, r); //draw the spot // glEnd(); // it->tex->unbind(); if(!isPointInScreen(p, r)) { it->destroy(); it->dead = true; } } ofRemove(shapes, ofxBox2dBaseShape::shouldRemove); ofFill(); ofSetColor(bgColor, 100); for (vector<ofVec2f>::iterator it=pts.begin(); it!=pts.end(); ++it) { ofCircle(*it, 2); } for (vector<TriangleShape>::iterator it=tris.begin(); it!=tris.end(); ++it) { ofSetColor(bgColor, 10); ofNoFill(); ofTriangle(it->a, it->b, it->c); // the triangle area float radius = GeometryUtils::getTriangleRadius(it->c, it->b, it->a); // center of the triangle ofVec2f center = GeometryUtils::getTriangleCenter(it->a, it->b, it->c); ofCircle(center, radius); /*ofSetColor(255); ofDrawBitmapString("a", it->a+10); ofDrawBitmapString("b", it->b+10); ofDrawBitmapString("c", it->c+10);*/ ofCircle(center, 3); } }
//-------------------------------------------------------------- void testApp::update(){ if (!titleScreen && !displayMsg1 && !displayMsg2 && !displayMsg3) { // If the player goes offscreen, reset to the default position: /*if (player.xPos < -player.wide || player.xPos > ofGetWidth()+player.wide) { player.xPos = xPosPlayerDefault; player.yPos = player.onGround; }*/ if (booYaCounter > 0) booYaCounter -= 1/framerate; if (dontPlayMeMsgCounter > 0) dontPlayMeMsgCounter -= 1/framerate; else dontPlayMeMsg = false; if (demo) { secondCounter ++; if (secondCounter >= framerate) { demoCounter--; secondCounter = 0; } if (demoCounter <= 0) demo = false; } if (slow) framerate = frameRateSlow; else framerate = framerateNormal; ofSetFrameRate(framerate); if (moveL) originX += moveSpeed; // Translate to the right on LEFT. if (moveR) originX -= moveSpeed; // Translate to the left on RIGHT. // Restore the player to default position where appropriate: if (player.yPos == player.onGround && !player.vanish && !player.kickAss){ if (player.xPos > xPosPlayerDefault) player.xPos--; if (player.xPos < xPosPlayerDefault) player.xPos++; } moveR = true; // Advance the screen automatically when the player's in the default pos: if ((player.xPos != xPosPlayerDefault && player.yPos != player.onGround && !collided) || player.vanish || player.kickAss) moveR = false; else if (collided && player.xPos < xPosPlayerDefault/2) moveR = false; // ...unless the player attacks: //else moveR = false; // Advance the enemy generation counter once per second: if (enemyRateCounter < enemyRate) enemyRateCounter += 1/framerateNormal; // Generate enemies automatically at the pace we set in setup(): if (enemyRateCounter >= enemyRate && enemies.size() < maxEnemies) { enemy_grunt enemy; // Position them just offscreen to the right, taking into account the changing position of the origin: enemy.setup(ofGetWidth()+fabs(originX)+100, groundY); enemies.push_back(enemy); enemyRateCounter = 0; } // Update everyone: for (int i = 0; i<enemies.size(); i++) enemies[i].update(originX); player.update(framerate); // Detect a collision between the player and an enemy: collided = false; // Set this to false by default, overwritten by collision: for (int i=0; i<enemies.size(); i++) { float enemyDistance = ofDist(player.xPos, player.yPos, enemies[i].xPos+originX, enemies[i].yPos); float attackDistance = (player.wide/2+enemies[i].rad)*4; float defeatDistance = player.wide/2+enemies[i].rad; if (enemyDistance < attackDistance && player.xPos < ofGetWidth()) { if (!player.vanish && !player.kickAss) storeI = i; // Record the value of the enemy in question. collided = true; // This cues jumping, vanishing, then kicking ass. if (enemyDistance < defeatDistance) { enemies[i].pwned = true; // The enemy is defeated. enemiesDefeated++; player.kickAss = false; // Occasionally play a message of condolence: if (rollForBooYa && ofRandom(1) <= 0.6) { booYaMsg = true; booYaCounter = booYaCounterLimit; rollForBooYa = false; } else rollForBooYa = false; } } else player.jump = false; } rollForBooYa = true; if (booYaCounter <= 0) booYaMsg = false; // Trigger effects on collision: if (collided && !player.kickAss) { player.jump = true; player.tall = 25; // Randomly activate slow motion: if (rollForSlow && ofRandom(1) < 0.2) { slow = true; rollForSlow = false; } else rollForSlow = false; } else { // Restore default values: rollForSlow = true; slow = false; player.tall = 50; } // Randomly comment on the vanishing act: if (player.vanish) { if (rollForNinja && ofRandom(1) < 0.5) { ninjaMsg = true; rollForNinja = false; } else rollForNinja = false; } else { // Restore default values: rollForNinja = true; ninjaMsg = false; } // The player reappears at a randomized point: if (player.changeX) { player.xPos += ofRandom(-xPosPlayerDefault, xPosPlayerDefault); player.yPos += ofRandom(-player.yPos, player.onGround-player.yPos-10); player.changeX = false; } // We use Xeno's Paradox to "animate" the player's movement toward the enemy's position to make an attack: if (player.kickAss) { if (player.xPos >= enemies[storeI].xPos+originX) { player.xPos -= xeno * ofDist(player.xPos, player.yPos, enemies[storeI].xPos+originX, player.yPos); } else { player.xPos += xeno * ofDist(player.xPos, player.yPos, enemies[storeI].xPos+originX, player.yPos); } player.yPos += xeno * ofDist(player.xPos, player.yPos, player.xPos, enemies[storeI].yPos); } // Update coordinates for writing messages: mouthX = player.xPos-player.wide/2-10; mouthY = player.yPos-player.tall/2-10; msgX = player.xPos-110; msgY = ofGetHeight()/2+10; textX = player.xPos-140; textY = ofGetHeight()/2; // Following up the boolean function we created above, this oF function sorts the vector according to the values of the booleans and then removes any with a 'true' value: ofRemove(enemies,bShouldIErase); // If the player defeats all the enemies, cue the win screen, then restart the game: if (enemiesDefeated >= totalToWin) youWonCounter += 1/framerate; if (youWonCounter >= youWonCounterLimit) { // Clear out the vector: for (int i=0; i<enemies.size(); i++) enemies.erase(enemies.begin(), enemies.end()); setup(); } } }
//-------------------------------------------------------------- void testApp::update(){ fingersFound.clear(); //here is a simple example of getting the hands and using them to draw trails from the fingertips. //the leap data is delivered in a threaded callback - so it can be easier to work with this copied hand data //if instead you want to get the data as it comes in then you can inherit ofxLeapMotion and implement the onFrame method. //there you can work with the frame data directly. //Option 1: Use the simple ofxLeapMotionSimpleHand - this gives you quick access to fingers and palms. simpleHands = leap.getSimpleHands(); if( leap.isFrameNew() && simpleHands.size() ){ leap.setMappingX(-230, 230, -ofGetWidth()/2, ofGetWidth()/2); leap.setMappingY(90, 490, -ofGetHeight()/2, ofGetHeight()/2); leap.setMappingZ(-150, 150, -200, 200); for(int i = 0; i < simpleHands.size(); i++){ for(int j = 0; j < simpleHands[i].fingers.size(); j++){ int id = simpleHands[i].fingers[j].id; ofPolyline & polyline = fingerTrails[id]; ofPoint pt = simpleHands[i].fingers[j].pos; //if the distance between the last point and the current point is too big - lets clear the line //this stops us connecting to an old drawing if( polyline.size() && (pt-polyline[polyline.size()-1] ).length() > 50 ){ polyline.clear(); } //add our point to our trail polyline.addVertex(pt); //store fingers seen this frame for drawing fingersFound.push_back(id); if (i % 2 == 0) { float w = ofRandom(4, 20); float h = ofRandom(4, 20); boxes.push_back(ofPtr<ofxBox2dRect>(new ofxBox2dRect)); boxes.back().get()->setPhysics(3.0, 0.53, 0.1); boxes.back().get()->setup(box2d.getWorld(), ofGetWidth()/2 + pt.x, ofGetHeight()/2 - pt.y, w, h); } else { float r = ofRandom(4, 20); // a random radius 4px - 20px circles.push_back(ofPtr<ofxBox2dCircle>(new ofxBox2dCircle)); circles.back().get()->setPhysics(3.0, 0.53, 0.1); circles.back().get()->setup(box2d.getWorld(), ofGetWidth()/2 + pt.x, ofGetHeight()/2 - pt.y, r); } } } } // Option 2: Work with the leap data / sdk directly - gives you access to more properties than the simple approach // uncomment code below and comment the code above to use this approach. You can also inhereit ofxLeapMotion and get the data directly via the onFrame callback. // vector <Hand> hands = leap.getLeapHands(); // if( leap.isFrameNew() && hands.size() ){ // // //leap returns data in mm - lets set a mapping to our world space. // //you can get back a mapped point by using ofxLeapMotion::getMappedofPoint with the Leap::Vector that tipPosition returns // leap.setMappingX(-230, 230, -ofGetWidth()/2, ofGetWidth()/2); // leap.setMappingY(90, 490, -ofGetHeight()/2, ofGetHeight()/2); // leap.setMappingZ(-150, 150, -200, 200); // // for(int i = 0; i < hands.size(); i++){ // for(int j = 0; j < hands[i].fingers().count(); j++){ // ofPoint pt; // // const Finger & finger = hands[i].fingers()[j]; // // //here we convert the Leap point to an ofPoint - with mapping of coordinates // //if you just want the raw point - use ofxLeapMotion::getofPoint // pt = leap.getMappedofPoint( finger.tipPosition() ); // // //lets get the correct trail (ofPolyline) out of our map - using the finger id as the key // ofPolyline & polyline = fingerTrails[finger.id()]; // // //if the distance between the last point and the current point is too big - lets clear the line // //this stops us connecting to an old drawing // if( polyline.size() && (pt-polyline[polyline.size()-1] ).length() > 50 ){ // polyline.clear(); // } // // //add our point to our trail // polyline.addVertex(pt); // // //store fingers seen this frame for drawing // fingersFound.push_back(finger.id()); // } // } // } // //IMPORTANT! - tell ofxLeapMotion that the frame is no longer new. leap.markFrameAsOld(); box2d.update(); if(bMouseForce) { float strength = 8.0f; float damping = 0.7f; float minDis = 100; for(int i=0; i<circles.size(); i++) { circles[i].get()->addAttractionPoint(mouseX, mouseY, strength); circles[i].get()->setDamping(damping, damping); } for(int i=0; i<customParticles.size(); i++) { customParticles[i].get()->addAttractionPoint(mouseX, mouseY, strength); customParticles[i].get()->setDamping(damping, damping); } } // remove shapes offscreen ofRemove(boxes, ofxBox2dBaseShape::shouldRemoveOffScreen); ofRemove(circles, ofxBox2dBaseShape::shouldRemoveOffScreen); ofRemove(customParticles, ofxBox2dBaseShape::shouldRemoveOffScreen); }
//-------------------------------------------------------------- void cyrilApp::update(){ // Disable all ofxPostProcessing effects so they only activate // if command is present in a running program _state.post[FX_KALEIDOSCOPE]->disable(); _state.post[FX_NOISE_WARP]->disable(); _state.post[FX_PIXELATE]->disable(); _state.post[FX_BLOOM]->disable(); for (int i = 0; i < 10; ++i) { if (running[i]) { if (prog[i]->valid) { prog[i]->update(_state); } } } if (doResetTimers) { (*_state.sym)[REG_FRAME] = 0; ofResetElapsedTimeCounter(); doResetTimers = false; } else { (*_state.sym)[REG_FRAME]++; } (*_state.sym)[REG_TIME] = ofGetElapsedTimeMillis(); (*_state.sym)[REG_SECS] = ofGetElapsedTimef(); (*_state.sym)[REG_FAST] = ofGetElapsedTimef() * 10; (*_state.sym)[REG_SLOW] = ofGetElapsedTimef() * 2; // For beat detection beat.update((*_state.sym)[REG_TIME]); (*_state.sym)[REG_BEAT_MAGNITUDE] = beat.getMagnitude(); (*_state.sym)[REG_BEAT_KICK] = beat.kick(); (*_state.sym)[REG_BEAT_SNARE] = beat.snare(); (*_state.sym)[REG_BEAT_HIHAT] = beat.hihat(); for (int i = REG_BEAT_FFT_START; i < REG_BEAT_FFT_MAX; ++i) { (*_state.sym)[i] = beat.getBand(i - REG_BEAT_FFT_START); } for(vector<Particle*>::iterator it = _state.ps->begin(); it != _state.ps->end(); ++it){ (*it)->update(); } ofRemove(*_state.ps, Particle::isDead); /* // check for waiting OSC messages while(receiver.hasWaitingMessages()){ // get the next message ofxOscMessage m; receiver.getNextMessage(&m); // check for mouse moved message if(m.getAddress() == "/buffer/0"){ string msg_string; msg_string = m.getAddress(); cout << msg_string << endl; } } */ }
// ---------------------------------------------------- void CellScene::update() { // reset the forces & remove deads for (vector<CellNode>::iterator it=cells.begin(); it!=cells.end(); ++it) { it->frc = 0; it->bRemove = isPointInScreen(it->pos, 100) == false; } ofRemove(cells, shouldRemove); float t = ofGetElapsedTimef()*0.02; ofVec2f dirVec = 0; for(int i=0; i<4; i++) { float amp = audioPtr->getVolume(i) * 10.0; if(i == AudioManager::TOP) { dirVec.y -= amp; } else if(i == AudioManager::BOTTOM) { dirVec.y += amp; } else if(i == AudioManager::LEFT) { dirVec.x -= amp; } else if(i == AudioManager::RIGHT) { dirVec.x += amp; } } dirVec *= 100; //printf("%f %f\n", dirVec.x, dirVec.y); for (vector<CellNode>::iterator itA=cells.begin(); itA!=cells.end(); ++itA) { ofVec2f pos = itA->pos; float frwX = ofNoise(pos.x * 0.003, pos.y * 0.006, ofGetElapsedTimef() * 0.6); ofVec2f noiseFrc; noiseFrc.x = ofSignedNoise(t, pos.y * 0.04) * 0.6; noiseFrc.y = ofSignedNoise(itA->uniquef, pos.x * 0.006, t); noiseFrc *= damping; ofVec2f sepFrc = 0; for (vector<CellNode>::iterator itB = itA; itB!=cells.end(); ++itB) { if (itA==itB) continue; ofVec2f v = itA->pos - itB->pos; float d = v.length(); float minRad = separationDistance + (itA->radius+itB->radius); if(d < minRad) { v.normalize(); sepFrc += v; } } sepFrc.normalize(); //sepFrc.limit(1.9); // add forces itA->frc += noiseFrc; itA->frc += sepFrc; itA->frc += dirVec; itA->frc.limit(maxParticleSpeed); // applu the forces itA->vel *= itA->drag; itA->vel += itA->frc; itA->pos += itA->vel; // wrap the screen //itA->wrapScreen(-200, -200, CUBE_SCREEN_WIDTH+400, CUBE_SCREEN_HEIGHT+400); } // voronoi up this scene if(cells.size() > 0) { voronoi.clear(); voronoi.put(0, 0, 0); voronoi.put(1, 1, 0); voronoi.put(2, 1, 1); voronoi.put(3, 0, 1); int inc = 4; for (vector<CellNode>::iterator it=cells.begin(); it!=cells.end(); ++it) { voronoi.put(inc, it->pos.x/(float)CUBE_SCREEN_WIDTH, it->pos.y/(float)CUBE_SCREEN_HEIGHT); inc ++; //cout << "i:" << inc << " x:" << it->pos.x << " y:" << it->pos.y << endl; } } // add some more int nRelease = MAX(1, 50 * releaseRate); for(int i=0; i<nRelease; i++) { addCells(); } }
//-------------------------------------------------------------- void testApp::update(){ if ( gameState == 0 ) { startScreenFade += startScreenFadeVel; if ( startScreenFade < 0 || startScreenFade > 255 ) { startScreenFadeVel *= -1; } return; } checkOsc(); //Matt { // Mauricio //ship1.update(); //secondBackground.update(); //Mauricio //After trying to coming up with a counter that goes up and down, Jennifer Presto provided this. withour her contribution it woudn't have been possible to achive it. frameNum = abs ( abs( 49 - counter) - 49); counter++; if( counter == 100){ counter = 0; } } collideSpaceshipsAndBullets(); collideSpaceshipsAndSpaceships(); collideEnemyAndBullets(); collideSpaceshipsAndEnemy(); { // Matt if ( !metroid.bDestroyMe ) metroid.update(shipList); for ( int i = 0; i < shipList.size(); i++ ) { shipList[ i ].update(); // Handle firing. if ( shipList[ i ].bFiring ) { if ( shipList[ i ].firePacer == 0 ) { float fireAng = shipList[ i ].rotAngle - PI; Bullet tmp( shipList[ i ].pos, fireAng ); bulletList.push_back( tmp ); shipList[ i ].firePacer = shipList[ i ].pacerMax; shipList[ i ].applyAngularForce( 0.5, fireAng ); } } } for ( int i = 0; i < bulletList.size(); i++ ) { bulletList[ i ].update(); } // AWESOME, come back to this later. // if ( shipList[ 0 ].shootBullet && shipList[ 0 ].allowAction ) { // float fireAng = shipList[ 0 ].rotAngle - PI; // Bullet tmp( shipList[ 0 ].pos, fireAng ); // bulletList.push_back( tmp ); // } } // Note from Matt: Following up the boolean function we created above, this oF function sorts the vector according to the values of the booleans and then removes any with a 'true' value: ofRemove( bulletList, bShouldIErase ); ofRemove( shipList, bShouldIErase2 ); if (metroid.bDestroyMe){ deque<Michael>::iterator it; for( it = kahane.begin(); it != kahane.end(); it++){ it->resetForces(); it->addDampingForce(); it->update(); } } }
//-------------------------------------------------------------- void ofApp::setup() { ofTrueTypeFont::setGlobalDpi(96); // load the font font.load("sans-serif", 11); sortTypeInfo = "no sort"; words.clear(); // load the txt document into a ofBuffer ofBuffer buffer = ofBufferFromFile("freshprince.txt"); string content = buffer.getText(); // take the content and split it up by spaces // we need to also turn new lines into spaces so we can seperate words on new lines as well ofStringReplace(content, "\r", " "); ofStringReplace(content, "\n", " "); vector <string> splitString = ofSplitString(content, " ", true, true); // copy over the words to our object for (unsigned int i=0; i<splitString.size(); i++) { LyricWord wrd; wrd.occurrences = 1; wrd.word = ofToLower( splitString[i] ); words.push_back(wrd); } // clean up the words removing any // characters that we do not want for (unsigned int i=0; i<words.size(); i++) { // run throught this ignore list and replace // that char with nothing char ignoreList[12] = {',', '.', '(', ')', '?', '!', '-', ':', '"', '\'', '\n', '\t'}; for(int j=0; j<12; j++) { // make string from char string removeStr; removeStr += ignoreList[j]; // remove and of the chars found ofStringReplace(words[i].word, removeStr, ""); } } // count the amount of times that we see a word for (unsigned int i=0; i<words.size(); i++) { int c = 1; for (unsigned int j=0; j<words.size(); j++) { if(words[i].word == words[j].word) c ++; } words[i].occurrences = c; } // remove duplicates of the words vector<LyricWord>tempWord; for (unsigned int i=0; i<words.size(); i++) { bool bAdd = true; for(unsigned int j=0; j<tempWord.size(); j++) { if(words[i].word == tempWord[j].word) bAdd = false; } if(bAdd) { tempWord.push_back(words[i]); } } words = tempWord; // remove word we do not want ofRemove(words, ofApp::removeWordIf); }
//-------------------------------------------------------------- void testApp::update(){ if ( getThisOne < 0 ) getThisOne = objectList.size() - 1; if ( getThisOne > objectList.size() - 1 ) getThisOne = 0; // Replay mode pauses movement and runs until all Objects have been replayed. if ( replay ) { myPlayer.allowMove = false; if ( recordedList.size() > 0 ) { float xDist; if ( replayedList.size() > 0 ) { xDist = replayedList[ replayedList.size() - 1 ].pos.x - myPlayer.pos.x; } else { xDist = 0; } if ( xDist >= recordedList[ 0 ].spacing ) { addReplayedObject( recordedList[ 0 ].whichNote, myPlayer.pos.x ); recordedList[ 0 ].destroyMe = true; } } else { replay = false; } } else { myPlayer.allowMove = true; } myPlayer.update(); // Update the notes. if ( objectList.size() != 0 ) { for ( int i = 0; i < objectList.size(); i++ ) { // Detect for collision with player's recorder, if the note is selected. if ( i == getThisOne ) { ofVec2f dist = myPlayer.pos - objectList[ i ].pos; if ( dist.lengthSquared() < ( 50 * 50 ) && myPlayer.record ) { // Check the spacing between the recorded note and the previous note. float xDist; if ( recordedList.size() == 0 ) { xDist = 0; } else { // FIND ME--I may need to adjust the below in case notes aren't captured linearly. xDist = objectList[ i ].pos.x - objectList[ i - 1 ].pos.x; } addRecordedObject( objectList[ i ].whichNote, xDist ); getThisOne++; } } // Highlight a specific Object. if ( i == getThisOne ) objectList[ i ].drawAttention = true; else objectList[ i ].drawAttention = false; objectList[ i ].update( myPlayer.pos ); } } if ( replayedList.size() != 0 ) { for ( int i = 0; i < replayedList.size(); i++ ) { replayedList[ i ].update( myPlayer.pos ); } } // Following up the boolean function we created above, this oF function sorts the vector according to the values of the booleans and then removes any with a 'true' value: ofRemove( objectList, bShouldIErase ); ofRemove( recordedList, bShouldIErase ); ofRemove( replayedList, bShouldIErase ); }