Beispiel #1
0
//--------------------------------------------------------------
void TuioKinect::draw()
{
	float height = (float)ofGetHeight();
	float width = (float)ofGetWidth() ; 
	
	ofSetColor(0,0,0,200) ; 
	
	//Additive blend mode
	glBlendFunc(GL_SRC_COLOR, GL_ONE);
	
	ofSetColor(255, 255, 255) ; 
	ofEnableSmoothing();
	
	for(int i=0; i< customParticles.size(); i++) 
	{
		customParticles[i].draw(0);
	}
	
	box2d.draw();
	box2d.drawGround() ;

	ofSetColor(255, 255, 255);
	std::list<TuioCursor*> alive_cursor_list = tuioServer->getTuioCursors();
	std::list<TuioCursor*>::iterator alive_cursor;
	
	for (alive_cursor=alive_cursor_list.begin(); alive_cursor!= alive_cursor_list.end(); alive_cursor++) 
	{
		TuioCursor *ac = (*alive_cursor);
		
		float absXSpeed = ac->getXSpeed() ;
		float absYSpeed = ac->getYSpeed() ;
		float xpos = ac->getX() * (float)ofGetWidth() ; 
		float ypos = ac->getY() * (float)ofGetHeight() ; 
		
		absXSpeed = ( absXSpeed < 0 ) ? absXSpeed * -1 : absXSpeed ; 
		absYSpeed = ( absYSpeed < 0 ) ? absYSpeed * -1 : absYSpeed ; 
			
		if ( absXSpeed > .30 || absYSpeed > .30 ) 
		{	
			int _size  = customParticles.size() ;
			if ( _size < 20 ) 
			{
				CustomParticle p;
				
				if ( _size % 2 == 0 ) 
				{
					p.changeIsFire(true);
				}
				else {
					p.changeIsFire(false) ; 
				}

				float r = ofRandom(.25f, 1.0f); //normalized diff
				p.setPhysics(4.0 * r, .2 * r, .45 * r );
				p.setup(box2d.getWorld(), xpos, ypos, (r*30) );
				p.setVelocity( ac->getXSpeed()*10 , ac->getYSpeed()*10 ) ; 
				customParticles.push_back(p);
			}
		}
		
		//Draw that path!
		drawTuioPath( ac->getPath() ) ; 
	}
	
	//Debug Text
	ofSetColor(255, 255, 255);
	char reportStr[1024];
	sprintf(reportStr, "set near threshold %i (press: + -)\nset far threshold %i (press: < >)\nnum blobs found %i, fps: %i", nearThreshold, farThreshold, (int)contourFinder.blobs.size(), (int)ofGetFrameRate());
	ofDrawBitmapString(reportStr, 20, 650);
	ofEnableAlphaBlending() ; 

	ofSetColor ( 10 , 10 , 10 ); 
	ofFill() ; 
	ofSetLineWidth( 2 ) ;
	ofRect(0, 0, 40, 40 ) ; 
		
	ofSetColor(255, 255, 255 ) ; 
	ofFill() ;

	grayImage.draw(5, 5, 192, 144 );
	contourFinder.draw(5, 5, 192, 144 );
	ofFill() ;
	ofDisableAlphaBlending() ; 
}
Beispiel #2
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);
    
}