コード例 #1
0
ファイル: tree.c プロジェクト: FooBarrior/IMCS
//Cormen: 2a-2b
bool internalKeyDelete(TreeNodePtr node, int pos, int shift, FallDownBehave fb){
    int childNodePos = pos + shift;
    TreeNodePtr child = node->nodes[childNodePos];
    if(childNodePos >= node->childCount || child->keyCount < t) return false;

    free(node->items[pos]);
    node->items[pos] = fallDown(child, fb);
    
    LSQ_IntegerIndexT key = node->items[pos]->key;
    assert(deleteKey(child, key, getItemOrNext(child, key), false));
    node->subtreeKeyCount[childNodePos]--;

    return true;
}
コード例 #2
0
ファイル: dynamicgoo.cpp プロジェクト: twell/OpenGOO
void DynamicGoo::contactGround() {
    //Away to trapass body
    if (isDragging()) {
        //Change flag and reset normal status
        dragging=false;
        fallDown();
        //Emit a signal for the level class
        emit stopDragging();
        return;
    }
    else {

        if (!isSleeping() && qAbs(body->GetAngularVelocity())<body->GetLinearVelocity().Length() && prevTarget==NULL&&  (target==NULL ||(target!=NULL && (target->getVPosition()-body->GetPosition()).Length()<radius/10 ))) {

            ALbyte name[100]="resources/sounds/boing2.wav";
            QPair<unsigned int,unsigned int> source =sSystem->createSource(name);
            sSystem->setPitch(source.first,24.0/float(radius)*60.0/body->GetLinearVelocity().Length());
            sSystem->setVolume(source.first,2.0*body->GetLinearVelocity().Length()/80.0*radius/24.0);
            sSystem->setPosition(source.first,getPPosition());
            sSystem->playSource(source.first);
            sources.push_back(source);
        }
        onGround=true;
        groundPoint=this->getPPosition();

        //if has joint return;
        if (hasJoint()) {

            return;
        }
        if (sleeping) {
            body->SetGravityScale(1.0);
            return;
        }
        if(!hasJoint() && target==NULL) {
            emit this->nextTargetPlease(NULL);
        }
    }
}
コード例 #3
0
ファイル: dynamicgoo.cpp プロジェクト: seem-sky/epicwin3
void DynamicGoo::contactGround(QPoint p){

    //Away to trapass body
    if (isDragging()) {
        //Change flag and reset normal status
        dragging=false;
        fallDown();
        //Emit a signal for the level class
        emit stopDragging();
        return;
    }
    else {


        onGround=true;
        groundPoint=this->getPPosition();


        //if has joint and is not sticked on ground
        if (hasJoint()){
            if (!sticked && stickable){
                onGround=true;
                groundPoint=this->getPPosition();
                emit this->createSticky(p);
                sticked=true; //flag to true
            }
            return;
        }
        if (sleeping) {
            body->SetGravityScale(1.0);
            return;
        }
        if(!hasJoint() && target==NULL){
            emit this->nextTargetPlease(NULL);
        }
    }
}
コード例 #4
0
ファイル: dynamicgoo.cpp プロジェクト: seem-sky/epicwin3
void DynamicGoo::contactGround(){
    //Away to trapass body
    if (isDragging()) {
        //Change flag and reset normal status
        dragging=false;
        fallDown();
        //Emit a signal for the level class
        emit stopDragging();
        return;
    }
    else {

        if (!isSleeping() && qAbs(body->GetAngularVelocity())<body->GetLinearVelocity().Length() && prevTarget==NULL&&  (target==NULL ||(target!=NULL && (target->getVPosition()-body->GetPosition()).Length()<radius/10 )))
        {
            Goo::sSystem->SetPitch(boingSound, 24.0/float(radius)*60.0/body->GetLinearVelocity().Length());
            Goo::sSystem->SetVolume(boingSound, 2.0*body->GetLinearVelocity().Length()/80.0*radius/24.0);
            Goo::sSystem->SetPosition(boingSound, getPPosition());
            Goo::sSystem->Play(boingSound);
        }
        onGround=true;
        groundPoint=this->getPPosition();

        //if has joint return;
        if (hasJoint()){

            return;
        }
        if (sleeping) {
            body->SetGravityScale(1.0);
            return;
        }
        if(!hasJoint() && target==NULL){
            emit this->nextTargetPlease(NULL);
        }
    }
}
コード例 #5
0
ファイル: tree.c プロジェクト: FooBarrior/IMCS
void fallDownDelete(TreePtr tree, FallDownBehave fb){
    TreeItemPtr item = fallDown(tree->root, fb);
    if(NULL == item) return;
    LSQ_DeleteElement(tree, item->key);
}
コード例 #6
0
ファイル: dynamicgoo.cpp プロジェクト: seem-sky/epicwin3
void DynamicGoo::moveToTarget(){
    //Stop to follow if the goo is dragged for the use

    if (isDragging()) {
        stopFollow();
        return;
    }
    if (onGround && groundPoint!=getPPosition()) {
        onGround=false;
    }
    if (isFalling()) return;
    if (hasJoint()){

        return;


    }
    if (!hasJoint() && !isDragging() && isOnGround() && target==NULL ){
        emit this->nextTargetPlease(NULL);
    }
    if (following && !falling){
        if (prevTarget){
            if (!target->isLinked(prevTarget)){
                drop();
                return;
            }
            QPoint meTarget=target->getPPosition()-getPPosition();
            if (toVec(meTarget).Length()>15+radius/10) {
                stopFollow();
                fallDown();
                return;
            }

            //Compute mx and my for the position
            float mx,my;
            mx=(target->getVPosition().x-prevTarget->getVPosition().x);
            my=(target->getVPosition().y-prevTarget->getVPosition().y);
            float d=qSqrt(mx*mx+my*my);
            float md=qSqrt(qPow((target->getVPosition().x-getVPosition().x),2)+qPow((target->getVPosition().y-getVPosition().y),2));
            mx/=d;
            my/=d;
            float tx,ty;
            //Compute tehorical x and y
            tx=(getVPosition().x-prevTarget->getVPosition().x)/mx;
            ty=(getVPosition().y-prevTarget->getVPosition().y)/my;
            float yt=my*tx+prevTarget->getVPosition().y;
            float xt=mx*ty+prevTarget->getVPosition().x;

            //if my y position is different at least of 12 falldown and return
            if ((qAbs(getVPosition().y-yt)>getRadius() && qAbs(getVPosition().x-xt)>getRadius()) || (md>d+radius)){
                stopFollow();
                fallDown();
                return;
            }
        }
        //this is a work around for the very ugly bug of the "FLYING GOOS"
        //description of the bug if no prevTarget is setted but target is and the goo tower start to fall down the goo start to fly
        //for reach his target!
        //check if prevtarget is not setted and target is
        if (!prevTarget && target && !target->isOnGround()){
            //compute distance between target and me
            float d=(target->getVPosition()-getVPosition()).Length();
            //if that distance is more than 25 falldown and return
            //PS: remember that 30 is a single point contact between two goos
            if (d>=radius*0.2) {
                stopFollow();
                fallDown();
                return;
            }
            else if (d<radius*0.2){
                emit this->nextTargetPlease(target);
                body->SetLinearVelocity(b2Vec2(0,0));
                return;

            }

        }
        b2Vec2 dP;
        if (target!=NULL /*&& target->getBody()!=NULL*/)
            dP=target->getVPosition()-this->getVPosition();
        else {
            stopFollow();
            fallDown();
            return;
        }
        if (dP.Length()<=(radius-radius/4.0)/10.0){
            emit this->nextTargetPlease(target);
            body->SetLinearVelocity(b2Vec2(0,0));
            return;
        }
        if (!prevTarget){

            b2Vec2 dvec=(target->getVPosition()-getVPosition());
            float d=qSqrt(dvec.x*dvec.x+dvec.y*dvec.y);
            if (onGround && target->isOnGround() && d<distanceToJoint){
                double omega =(dP.x>0 ? speed*body->GetMass() : -speed*body->GetMass());
                body->SetAngularVelocity(omega);
                body->ApplyForceToCenter(body->GetMass()*body->GetWorld()->GetGravity());
            }
            else if (!onGround && d<radius*2) {
                emit this->nextTargetPlease(target);
                body->SetLinearVelocity(b2Vec2(0,0));
                return;
                dP.x=(dP.x>0 ? speed*2 : -speed*2);
                dP.y=body->GetMass()*body->GetWorld()->GetGravity().y;
                body->ApplyForceToCenter(dP);
            }
            else{
                body->SetGravityScale(1);
                stopFollow();
            }
        }
        else {
            dP.x=dP.x*speed/dP.Length();
            dP.y=dP.y*speed/dP.Length() ;
            body->SetLinearVelocity(dP);
        }
    }
}