//---------------------------------------------- void ttChar::setup(ofxBox2d &characterWorld, ofxBox2d &dummyWorld, ttControl &ctrl, ofPoint SetPos, int iCharNum){ control = &ctrl; bFixedMove = false; setPos = SetPos; getPos = SetPos; charNum = iCharNum; mirrorLeft = false; character.setPhysics(1000.0f, 0.0f, 0.3f); character.setup(characterWorld.getWorld(), setPos.x, setPos.y, setWidth, setHeight); character.setData(new ttSetData); ttSetData* sd = (ttSetData*)character.getData(); if (charNum == 0) { sd->name = "char_A"; ofDirectory dir; int nFiles = dir.listDir("sprites/girl"); if (nFiles) { for (int i= 0; i<dir.numFiles(); i++) { string filePath = dir.getPath(i); sprite.push_back(ofImage()); sprite.back().loadImage(filePath); } } } else{ sd->name = "char_B"; ofDirectory dir; int nFiles = dir.listDir("sprites/boy"); if (nFiles) { for (int i= 0; i<dir.numFiles(); i++) { string filePath = dir.getPath(i); sprite.push_back(ofImage()); sprite.back().loadImage(filePath); } } } character.body->SetFixedRotation(true); character.body->SetLinearDamping(0.5); adjustedHeight = 85; }
//---------------------------------------------- void ttChar::setup(ofxBox2d &characterWorld, ofxBox2d &dummyWorld, ofPoint &Move, bool &smallLeft, bool &smallRight, bool &left, bool &right, bool &fixedMove, ofPoint SetPos, int iCharNum) { move = &Move; bSmallLeft = &smallLeft; bSmallRight = &smallRight; bLeft = &left; bRight = &right; bFixedMove = &fixedMove; setPos = SetPos; getPos = SetPos; charNum = iCharNum; character.setPhysics(0.50f, 0.0f, 0.3f); character.setup(characterWorld.getWorld(), setPos.x, setPos.y, setWidth, setHeight); character.setData(new ttSetData); b2Filter filter; ttSetData* sd = (ttSetData*)character.getData(); if (charNum == 0) { sd->name = "char_A"; filter.categoryBits = 0x0004; filter.maskBits = 0x0001|0x0002|0x0004; character.setFilterData(filter); } else { sd->name = "char_B"; filter.categoryBits = 0x0004; filter.maskBits = 0x0001|0x0002|0x0004; character.setFilterData(filter); } sd->bHit = false; sd->bHooked = false; character.body->SetFixedRotation(true); character.body->SetLinearDamping(0.5); }
void ttRope::setup(ofPoint CharPos, int Num_char, ofxBox2d&dummyWorld ){ charPos = CharPos; tempPos = CharPos; accXeno = CharPos; accFrc.set(0, 0); num_char = Num_char; ropeEnd.setPhysics(1, 0.1, 0.1); ropeEnd.setup(dummyWorld.getWorld(), charPos.x, charPos.y, 5); //for Xenoing data and catching up forces catchUpSpeed = 0.09f; strength = 8.0f; damping = 0.7f; }
//---------------------------------------------- void ttChar::setup(ofxBox2d &characterWorld, ofxBox2d &dummyWorld, ofPoint &Move, bool &smallLeft, bool &smallRight, bool &left, bool &right, bool &fixedMove, ofPoint SetPos, int iCharNum){ move = &Move; bSmallLeft = &smallLeft; bSmallRight = &smallRight; bLeft = &left; bRight = &right; bFixedMove = &fixedMove; setPos = SetPos; getPos = SetPos; charNum = iCharNum; character.setPhysics(5.0f, 0.0f, 1.0f); character.setup(characterWorld.getWorld(), setPos.x, setPos.y, setWidth, setHeight); b2FixtureDef fixture = character.fixture; fixture.filter.categoryBits = 1; cout<<character.fixture.shape->GetType() <<endl; character.setData(new ttSetData); ttSetData* sd = (ttSetData*)character.getData(); if (charNum == 0) { sd->name = "char_A"; }else{ sd->name = "char_B"; } sd->bHit = false; sd->bHooked = false; character.body->SetFixedRotation(true); character.body->SetLinearDamping(0.5); }
void FlyingObjectPhysics::setup(ofxBox2d& box2d, int x, int y, boost::property_tree::ptree& ptree, float lifetime) { ofxBox2dCircle* circle = new ofxBox2dCircle(); circle->setPhysics(ptree.get<float>("density", 1.0f), ptree.get<float>("bounce", 1.0f), ptree.get<float>("friction", 1.0f)); auto radius = ptree.get<float>("radius", 60.0f); circle->setup(box2d.getWorld(), x, y - radius, radius); circle->setDamping(ptree.get<float>("damping", 60.0f)); auto imageName = ptree.get<string>("image", ""); auto soundName = ptree.get<string>("sound", ""); auto hitSoundName = ptree.get<string>("hitsound", ""); circle->setVelocity(ofRandom(-2.0f, 2.0f), 10.0f + ofRandom(-2.0f, 2.0f)); if (imageName != "") { image = Resource::getInstance()->getImage(imageName); centerVector.x = ptree.get<float>("centerx", image->getWidth() * 0.5f); centerVector.y = ptree.get<float>("centery", image->getHeight() * 0.5f); } if (soundName != "") { Resource::getInstance()->getSound(soundName).play(); } shape = circle; setupTime = ofGetElapsedTimeMillis(); this->lifetime = lifetime; circle->setData(this); circle->body->SetBullet(true); if (hitSoundName != "") { hitSound = Resource::getInstance()->getSound(hitSoundName); } }
void Balloon::tieOff(ofxBox2d &physics){ ofVec3f pos = shape->getPosition(); shape->setup(physics.getWorld(),pos.x, pos.y, radius); shape->setPhysics(density, 0.53, .1); shape->setMassFromShape = true; }
void Balloon::init(float x, float y, float r, float density, ofxBox2d &physics){ shape = shared_ptr<ofxBox2dCircle>(new ofxBox2dCircle()); shape->setPhysics(density, 0.53, .1); shape->setMassFromShape = true; shape->setup(physics.getWorld(), x, y, r); }