Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Help with Vectors

$
0
0

@jadie_p1 wrote:

Hi Guys,

I am making a game in OFW and I'm nearly there- I have a collision detection algorithm and also a points system and audio.

The game involves using gestures in Wekinator to control the left and right movements of a basket. The aim is to catch the different emoji's by moving.

However, now the vectors are playing up. I am trying to get them to offset randomly (and it was working before) but then I put the collision detection algorithm in and it stopped working. The images fall down, but they all fall down in the same pattern each frame (if that makes sense). Could someone please look at the code and tell me where I am going wrong? I need to finish this by tomorrow as I has to be in by Monday and I am working all week :open_mouth:

Thanks

    #include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
    // listen on the given port
    cout << "listening for osc messages on port " << PORT << "\n";
    receiver.setup(PORT);


   goodSound.load("/Users/jade/Desktop/of_v0.9.8_osx_release/apps/myApps/oscreceiveJade/bin/data/coin.wav");
   badSound.load("/Users/jade/Desktop/of_v0.9.8_osx_release/apps/myApps/oscreceiveJade/bin/data/blargg.wav");
   loopMusic.load("/Users/jade/Desktop/of_v0.9.8_osx_release/apps/myApps/oscreceiveJade/bin/data/music.mp3");
   loopMusic.setLoop(true);
   loopMusic.play();


   emojih.load("/Users/jade/Desktop/of_v0.9.8_osx_release/apps/myApps/oscreceiveJade/bin/data/happy.png");
   emojia.load("/Users/jade/Desktop/of_v0.9.8_osx_release/apps/myApps/oscreceiveJade/bin/data/angry.png");
   basket.load("/Users/jade/Desktop/of_v0.9.8_osx_release/apps/myApps/oscreceiveJade/bin/data/basket.png");


    score = 0;
    gesture = 0;
    x = 500;
    y = 650;
    basketWidth = 200;
    basketLength = 100;

    ofSetBackgroundAuto(true);
    //ofSetBackgroundColor(0);


    naemoji = ofRandom(2,5); // min is 2, max is 10 angry emojis
    nemoji = ofRandom(2,7); // min is 2, max is 7 happy emojis


    //HAPPY EMOJIS//

    for (int i = 0; i < nemoji; i++){

        emojil.push_back(ofRandom(0,5));


    }

    for (int i = 0; i < nemoji; i++){

        emojiX.push_back(ofRandom(0,1000));
        emojiY.push_back(ofRandom(-emojil[i], 40));
        emojiS.push_back(ofRandom(6,15));
    }

    ///ANGRY EMOJIS//


    for (int b = 0; b < naemoji; b++){ //adds 1 to the amount of rain each time

        emojiAl.push_back(ofRandom(0,10)); //length is random between 2 and 4


    }


    for (int b = 0; b < naemoji; b++){

        emojiAX.push_back(ofRandom(0,ofGetWidth())); //recalls the x axis rain
        emojiAY.push_back(ofRandom(-emojiAl[b], 40));
        emojiAS.push_back(ofRandom(10,16)); // random min and max speed
    }


}

//--------------------------------------------------------------
void ofApp::update(){


    if (messageBuffer.size()>maxBufferSize) messageBuffer.pop_back();

    // check for waiting messages
    while(receiver.hasWaitingMessages()){
        // get the next message
        ofxOscMessage m;
        receiver.getNextMessage(m);

        // check for face moved message
        if(m.getAddress() == "/wek/outputs"){

            gesture= m.getArgAsFloat(0);

        }



        basket.draw(100, 50,basketWidth,basketLength);

        if (gesture == 1.0){
            x= x+15;
        }else if(gesture == 2.0){
            x= x-15;
            }


        if (x >  ofGetWidth()-200){
            x = 500;
        }
        if (x < 0){

            x = 500;
        }

    }


}


//--------------------------------------------------------------
void ofApp::draw(){

    //gradient code
    glBegin(GL_QUADS);
    glColor3f( 1.0f, 0.5f, 0.2f );
    glVertex3f( 0.0f, 2.0f, 0.0f );
    glVertex3f( ofGetWidth(), 0.0f, 0.0f );
    glColor3f( 0.3f, 2, 1.0f );
    glVertex3f( ofGetWidth(), ofGetHeight(), 0.0f );
    glVertex3f( 0.0f, ofGetHeight(), 0.0f );
    glEnd();


    basket.draw(x, y, 200, 100);

        string buf;
        buf = "move left/right to catch all the happy faces!";
        ofDrawBitmapString(buf, 10, 20);
        ofSetColor(255);
        // read the buffer
        for(int j = 0; j < messageBuffer.size(); j++){
            ofDrawBitmapString(messageBuffer[j], 10, 40 + 15 * j);


        }

        for (int i = 0; i <nemoji; i++){
        emojih.draw(emojiX[i],emojiY[i],-emojil[i]);

            if(emojiY[i]>ofGetHeight()){


            emojiY[i] = - emojil[i];
            }

            emojiY[i] += emojiS[i];


            string points;
            points = "your score" + ofToString(score);
            ofDrawBitmapString(points, 700, 20);

           if(emojiX[i] + emojih.getWidth()/2 >= x  && emojiX[i] + emojih.getWidth()/2 <= x + basketWidth && emojiY[i] + emojih.getHeight()/2 > y){

                goodSound.play();
                //emojiX.pop_back();
                emojiY.pop_back();
                //emojiS.pop_back();
                score = score + 1;
                ofToString(score);




                }




 //ANGRY EMOJIS START//



    for (int b = 0; b <naemoji; b++){
        emojia.draw(emojiAX[b],emojiAY[b],-emojiAl[b]);
        if(emojiAY[b] > ofGetHeight()){


            emojiAY[b] = - emojiAl[b];
        }

            emojiAY[b] += emojiAl[b];

        if(emojiAX[b] + emojia.getWidth()/2 > x  && emojiAX[b] + emojia.getWidth()/2 < x + basketWidth && emojiAY[b] + emojia.getHeight()/2 > y){

            badSound.play();
            //emojiX.pop_back();
            emojiY.pop_back();
            //emojiS.pop_back();
            score = score - 1;
            ofToString(score);




            }

        }



    }
}



//---------------------------------------------------------------------

Posts: 4

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles