Exemplo n.º 1
0
//--------------------------------------------------------------
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);
    
}
Exemplo n.º 2
0
void testApp::setLevel(int lvl){
  ofLog()<<"NEW LEVEL" +ofToString(level)+" "+ofToString(lvl);
  switch(lvl){
    case 0:{
      customParticles.push_back(ofPtr<CustomParticle>(new CustomParticle(1, 0, 100)));
      CustomParticle * p = customParticles.back().get();
      
      float r = ofRandom(3, 10);		// a random radius 4px - 20px
      p->setPhysics(0.4, 0.53, 0.31);
      p->setup(box2d.getWorld(), (int)ofRandom(100,600), 400, p->width, p->height);
      
      
      SoundData * s = new SoundData();
      p->setData(s);
      SoundData * sd = (SoundData*)p->getData();
      sd->type = GUY;
      sd->bHit	= false;
      
      
    }
      break;
    case 1:{
      bullets.clear();
      apples.clear();
      customParticles.push_back(ofPtr<CustomParticle>(new CustomParticle(1, 1, 150)));
      CustomParticle * p = customParticles.back().get();
      
      float r = ofRandom(3, 10);		// a random radius 4px - 20px
      p->setPhysics(0.4, 0.53, 0.31);
      p->setup(box2d.getWorld(), (int)ofRandom(100,600), 300, p->width, p->height);
      
      
      SoundData * s = new SoundData();
      p->setData(s);
      SoundData * sd = (SoundData*)p->getData();
      sd->type = GUY;
      sd->bHit	= false;
    }
      
      break;
    case 2:{
      bullets.clear();
      apples.clear();
      customParticles.push_back(ofPtr<CustomParticle>(new CustomParticle(1, 2, 200)));
      CustomParticle * p = customParticles.back().get();
      
      float r = ofRandom(3, 10);		// a random radius 4px - 20px
      p->setPhysics(0.4, 0.53, 0.31);
      p->setup(box2d.getWorld(),(int)ofRandom(100,600), 400, p->width, p->height);
      
      
      SoundData * s = new SoundData();
     
      p->setData(s);
      SoundData * sd = (SoundData*)p->getData();
      sd->type = GUY;
      sd->bHit	= false;
    }
      
      break;
    case 3:{
      bullets.clear();
      apples.clear();
      customParticles.push_back(ofPtr<CustomParticle>(new CustomParticle(1, 3, 300)));
      CustomParticle * p = customParticles.back().get();
      
      float r = ofRandom(3, 10);		// a random radius 4px - 20px
      p->setPhysics(0.4, 0.53, 0.31);
      p->setup(box2d.getWorld(), mouseX, mouseY, p->width, p->height);
      
      
      SoundData * s = new SoundData();
     
      p->setData(s);
      
      SoundData * sd = (SoundData*)p->getData();
      sd->type = GUY;
      sd->bHit	= false;
    }
      break;
    case 4:{
      bullets.clear();
      apples.clear();
      edgeLine.addVertex(ofGetWidth(), 0);
      edgeLine.addVertex(ofGetWidth(), ofGetHeight()-30);
      
      
      
      edgeLine.setPhysics(0.0, 0.5, 0.5);
      edgeLine.create(box2d.getWorld());
      
      customParticles.push_back(ofPtr<CustomParticle>(new CustomParticle(1, 4, 350)));
      CustomParticle * p = customParticles.back().get();
      movePt.x=(int)ofRandom(100,600);
      movePt.y=(int)ofRandom(10,400);
      
      float r = ofRandom(3, 10);		// a random radius 4px - 20px
      p->setPhysics(0.1, 0.53, 0.31);
      p->setup(box2d.getWorld(), movePt.x, movePt.y, p->width, p->height);
      
      
      SoundData * s = new SoundData();
            p->setData(s);
   
      SoundData * sd = (SoundData*)p->getData();
      sd->type = BIGGUY;
      sd->bHit	= false;
    }
      break;

      
  }

  
}
Exemplo n.º 3
0
//--------------------------------------------------------------
void testApp::draw(){

// MARK: DRAW KINECT POINT CLOUD    
//    int inc = 20;
//    for (int i = 0; i < kinect.pointCloud.size(); i+=inc) {
//        
//        float z = (kinect.pointCloud[i].z < 0.001) ? 1 : kinect.pointCloud[i].z;
//
//        float prox = (1.0 - z);
//        float sz = pow(prox, 3) * inc;
//        ofCircle(kinect.pointCloud[i].x * (float)ofGetWidth(), kinect.pointCloud[i].y * (float)ofGetHeight(), sz);
//
//        int limit_w = kinect.getOutputWidth();
//        if(i % limit_w == 0) {
//            i += inc * limit_w;
//        }
//    }
    
    
// MARK: DRAW BOX2D PARTICLES TO FBO
    fbo.begin();
    ofClear(0, 0, 0, 255);
    
    if(isFilterActive) {
        shader.begin();
        shader.setUniform1i("u_ratio", ledRatio);
    }
    
    for(int i = 0; i < b2dParticles.size(); i++) {
        CustomParticle p = b2dParticles[i];
        Data * customData = (Data*)p.getData();        
        
        
        if(kinect.pointCloud.size() > 0) {
//            int relativeX = ofMap(p.getPosition().x, 0, FBO_W, 0, kinect.getOutputWidth());            
            int relativeX = ofMap(p.getPosition().x, 0, FBO_W, 0, OUTPUT_SCREEN_W);
            relativeX = ofMap(relativeX, 0, OUTPUT_SCREEN_W, 0, kinect.getOutputWidth());
            int relativeY = ofMap(p.getPosition().y, 0, FBO_H, 0, kinect.getOutputHeight());
            
            int relativeKinectIndex = relativeX + (kinect.getOutputWidth() * relativeY);
            
            if(relativeKinectIndex < kinect.pointCloud.size()) {
                ofPoint kinectPoint = kinect.pointCloud[relativeKinectIndex];
                float z = (kinectPoint.z < 0.001) ? 1 : kinectPoint.z;
                float prox = 1.2 - z;
                
                float sz = 0;
                switch(customData->scope) {
                    case PERSONAL:
                        sz += personalMinParticleSize;
                        break;
                    case NEIGHBORHOOD:
                        sz += neighborhoodMinParticleSize;
                        break;
                    case CITY:
                        sz += cityMinParticleSize;
                        break;
                }                
                sz += prox * 80.0;

                float r = p.getRadius();
                
                // property = (target - property) / speed
                r += (sz - r) / 4.0f;
                
                p.setRadius(r);
            }
        }    

        p.draw();
    }
    
    if(isDebugingBox2d) { 
        ofEnableAlphaBlending();
        
        // DRAW JOINTS
        for(int j = 0; j < b2dJoints.size(); j++) {
            ofSetColor(255, 70);
            b2dJoints[j].draw();        
        }
        
        // DRAW ANCHORS
        ofSetColor(70);
        ofCircle(personalAnchorBottom.getPosition(), 4);
        ofCircle(personalAnchorTop.getPosition(), 4);
        ofCircle(personalAnchorLeft.getPosition(), 4);
        ofCircle(personalAnchorRight.getPosition(), 4);
        ofCircle(neighborhoodAnchorBottom.getPosition(), 4);
        ofCircle(neighborhoodAnchorTop.getPosition(), 4);
        ofCircle(neighborhoodAnchorLeft.getPosition(), 4);
        ofCircle(neighborhoodAnchorRight.getPosition(), 4);
        ofCircle(cityAnchorBottom.getPosition(), 4);
        ofCircle(cityAnchorTop.getPosition(), 4);
        ofCircle(cityAnchorLeft.getPosition(), 4);
        ofCircle(cityAnchorRight.getPosition(), 4);
    }

    if(isFilterActive) {        
        shader.end();
    }
    
    fbo.end();
    
    ofSetColor(255);
    fbo.draw(0,0);
// --------------------------------------------
    
// CHEAT: PILLARS MASK
    ofSetColor(25, 255);
    ofFill();
    ofRect(OUTPUT_SCREEN_W/3.0, 0, (FBO_W-OUTPUT_SCREEN_W)/2.0, FBO_H);
    ofRect(FBO_W - (OUTPUT_SCREEN_W/3.0) - (FBO_W-OUTPUT_SCREEN_W)/2.0, 0, (FBO_W-OUTPUT_SCREEN_W)/2.0, FBO_H);
// --------------------------------------------
    
    if(isGUIActive) {
        drawGUI();
    }
    
}