//-------------------------------------------------------------- void ofApp::keyPressed(int key) { switch(key) { // If pressed F change debug mode case 'f': case 'F': debug = !debug; break; case OF_KEY_LEFT_CONTROL: if (getSpaceShip(1)){ getSpaceShip(1)->createBullets(); shot.play(); } break; case OF_KEY_RIGHT_CONTROL: if (getSpaceShip(2)){ getSpaceShip(2)->createBullets(); shot.play(); } break; case OF_KEY_ESC: music.unloadSound(); explosion.unloadSound(); shot.unloadSound(); exit(); break; } }
//-------------------------------------------------------------- void ofApp::update() { ofBackground(255); if (werk) { bal.update(); if (keyup){ player.up(); } else if (keydown){ player.down(); } } if(bal.x < 0 ){ bal.x = 0; werk = false; } if (bal.x < player.x + (player.width)) { if (player.y > player.y - (player.height/2) && bal.y < player.y + (player.height / 2)) { bal.speedX = - bal.speedX; score ++; puts("score"); pling.play(); } } }
void ofApp::playSoundAtVolumeSpeed( ofSoundPlayer& SChgSize, float Vol, float Spd ) { SChgSize.setVolume(Vol); SChgSize.setSpeed(Spd); SChgSize.play(); }
void Bubble::update() { x += xVel; y += yVel; if ((x > ofGetWindowWidth()) || (x < 0)) { xVel *= (-1); sound.play(); } if ((y > ofGetWindowHeight()) || (y < 0)) { yVel *= (-1); sound.play(); } //collision with rectangle // for (<#initialization#>; <#condition#>; <#increment#>) { // <#statements#> // } }
//-------------------------------------------------------------- void testApp::keyPressed(int key){ cout << "fps: " << ofToString(ofGetFrameRate()) << endl; cout << "frame: " << ofToString(ofGetFrameNum()) << endl; if (key == 'f') drawFBO = !drawFBO; if (key == 'r') autoRotate = !autoRotate; if (key == 'p') player.play(); if (key == 'e') drawEQ = !drawEQ; }
void ofApp::splitAsteroid(int which) { int asteroidShape = 0; if(asteroids[which]->getSize() > 20) { for(int i = 0; i < (asteroids[which]->getSize()/40)+1; i++) { asteroidShape = ofRandom(asteroidsDefinitions.size()); Asteroid* newAsteroid = new Asteroid(); newAsteroid->setup(asteroidsDefinitions.at(asteroidShape), asteroids[which]->getSize()/2, asteroids[which]->getSpeed(), asteroids[which]->getRotation(), asteroids[which]->getPosition(), ofPoint(-(ofRandom(-1, 1)), ofRandom(-1, 1))); asteroids.push_back(newAsteroid); } } asteroids.erase(asteroids.begin() + which); if(asteroids.size() == 0) { generateAsteroids(ofRandom(4,6)); } //Play sound explosion explosion.play(); //GUI Data Update if(getSpaceShip(1)){ Player1Lifes = ofToString (getSpaceShip(1)->getLifes()); Player1Score = ofToString (getSpaceShip(1)->getPoints()); switch(getSpaceShip(1)->getLifes()) { case 0: serialConnection.writeByte('s'); break; case 1: serialConnection.writeByte('o'); break; case 2: serialConnection.writeByte('w'); break; case 3: serialConnection.writeByte('h'); break; } } if(getSpaceShip(2)){ Player2Lifes = ofToString (getSpaceShip(2)->getLifes()); Player2Score = ofToString (getSpaceShip(2)->getPoints()); switch(getSpaceShip(2)->getLifes()) { case 0: serialConnection.writeByte('f'); break; case 1: serialConnection.writeByte('u'); break; case 2: serialConnection.writeByte('d'); break; case 3: serialConnection.writeByte('t'); break; } } }
void update(){ Hands= ofPoint(x,y); //location of the hands in the air ( ir sensors) dir= ofPoint(Hands - location); dir.normalize(); dir *=0.01; accel= dir; velocity += accel; //speed location += velocity; // where is + the movement speed velocity.limit(maxspeed); //verctor doesnt get bigger then 3 //collision target if(ofDist(Target.x,Target.y, location.x, location.y)<rectSize){ points ++; Target=ofPoint(ofRandom(20,ofGetWidth()-20), ofRandom(20,ofGetHeight()-20)); hitsound.play(); } }
void ringButtonPressed() { ring.play(); }
//-------------------------------------------------------------- void testApp::setup(){ ofBackground(0); ofSetFrameRate(30); ofEnableAlphaBlending(); // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // glEnable(GL_DEPTH_TEST); glPointSize(1.0); drawFBO = false; autoRotate = true; drawEQ = false; //not really needed // glEnable(GL_ALPHA_TEST); // glAlphaFunc(GL_GREATER, 0.10f); //generate the mesh points buildSphereMesh(rad, res, vm); cout << "nverts: " << vm.getNumVertices() << endl; cout << "arb: " << ofGetUsingArbTex() << ", norm: " << ofGetUsingNormalizedTexCoords() << endl; //load the texture shader shader.load("tex.vert", "tex.frag"); //fft init fftSmoothed = new float[8192]; memset(fftSmoothed, 0x00, sizeof(float) * 8192); //map the frequencies to bark bands float freq_spc = FREQ_MAX / (float)SPECTRAL_BANDS; for (int i = 0; i < SPECTRAL_BANDS; i++) { int bidx = bark(i * freq_spc); barkmap[i] = bidx; } //load the position updating frag shader pos_shader.load("", "position.frag"); //for the sphere we set this to the resolution which = #of verts along each axis fbo_res = res; //init the fbo's with blank data vector<ofVec3f> fbo_init_data; fbo_init_data.assign(fbo_res * fbo_res, ofVec3f(0.0, 0.0, 0.0)); posbuf.allocate(fbo_res, fbo_res, GL_RGB32F); posbuf.src->getTextureReference().loadData((float *)&fbo_init_data[0], fbo_res, fbo_res, GL_RGB); posbuf.dst->getTextureReference().loadData((float *)&fbo_init_data[0], fbo_res, fbo_res, GL_RGB); //reuse fbo_init_data for no real reason, it just needs to be blank eq_tex.allocate(fbo_res, 1, GL_RGB32F_ARB); eq_tex.loadData((float *)&fbo_init_data[0], fbo_res, 1, GL_RGB); axis_loc = fbo_res; angincr = 180.0/(float)fbo_res; player.loadSound("jhfd.mp3"); player.play(); //go }