Exemple #1
0
//--------------------------------------------------------------
void ofApp::update(){
    Bubble tempBubble;
    tempBubble.setup(ofGetMouseX(), ofGetMouseY());
    bubbles.push_back(tempBubble);
    for(int i=0; i<bubbles.size(); i++){
        //bubbles[i].vel = ofVec2f(ofRandom(-4, 4), ofRandom(-10, 10));
        bubbles[i].update();
        float distance = ofDist(bubbles[i].birth.x, bubbles[i].birth.y, bubbles[i].pos.x , bubbles[i].pos.y);
        //this equation erases bubble instances after they go off the screen so the program doesn't keep trying to draw them
        if (distance>500){
            bubbles.erase(bubbles.begin()+i);
            i--;  //if we don't do this here, we'll skip the next bubble in this update
        }
    }
    Box tempBox;
    tempBox.setup(ofGetWindowWidth()/2, ofGetWindowHeight());
    boxes.push_back(tempBox);
    for(int i=0; i<boxes.size(); i++){
        boxes[i].update();
        float distance = ofDist(boxes[i].birth.x, boxes[i].birth.y, boxes[i].pos.x , boxes[i].pos.y);
        if (distance>500){
            boxes.erase(boxes.begin()+i);
            i--;
        }

    }
}
Exemple #2
0
//--------------------------------------------------------------
void ofApp::update(){
    for( int i = 0; i < bubbles.size() ; i++) {
        bubbles[i].update() ;
        //Code to erase the bubbles once they reach a certain distance
        float distance = ofDist(bubbles[i].birth.x, bubbles[i].birth.y , bubbles[i].pos.x, bubbles[i].pos.y) ;
        if(distance > 300) {
            bubbles.erase(bubbles.begin() + i) ;
            i-- ;
        }
        //Code to erase a bubble if its underneath the mouse cursor
        if(mouseX >= bubbles[i].pos.x - 10 && mouseX <= bubbles[i].pos.x + 10
           && mouseY >= bubbles[i].pos.y - 10 && mouseY <= bubbles[i].pos.y +10) {
            bubbles.erase(bubbles.begin() + i) ;
            i-- ;
            
        }
//        if(bubbles[i].pos.x < 100 || bubbles[i].pos.x > 800) {
//            bubbles.erase(bubbles.begin() + i) ;
//            i-- ;
//        }
//        if(bubbles[i].pos.y < 100 || bubbles[i].pos.y > 600) {
//            bubbles.erase(bubbles.begin() + i) ;
//            i-- ;
//        }
    }
    //generates a bubble to be drawn
    Bubble tempBubble ;
    tempBubble.setup(ofGetWidth()/2, ofGetHeight()/2) ;
    bubbles.push_back(tempBubble) ;
}