예제 #1
0
bool GameLayer::isCollisionArea(COLL_STATE state, CCRect roleBox, CCRect collisionBox) {
    bool bFlag = false;
    
    switch (state) {
        case COLL_STATE_LEFT: {
            bFlag = isCollisionLeft(roleBox, collisionBox);
            break;
        }
        case COLL_STATE_RIGHT: {
            bFlag = isCollisionRight(roleBox, collisionBox);
            break;
        }
        case COLL_STATE_TOP: {
            bFlag = isCollisionTop(roleBox, collisionBox);
            break;
        }
        case COLL_STATE_BOTTOM: {
            bFlag = isCollisionBottom(roleBox, collisionBox);
            break;
        }
        default:
            break;
    }
    
    if (bFlag) {
        fixCollision(state, mRole, collisionBox);
    }
    
    return bFlag;
}
예제 #2
0
파일: Runner.cpp 프로젝트: whtoo/RunCPP
bool RunnerSprite::isCollisionWithBarriers(CollisionFace face){
    
    bool bFlag = false;
    CCLOG("face %d",face);
    switch (face) {
        case kTOP:
            for(unsigned int i = 0;i<barriers.size(); i++){
                Rect box = barriers[i];
                bFlag = this->isCollisionWithTop(box);
                if(bFlag) {
                    fixCollision(face,box);
                    break;
                };
            }
            break;
       case kRTOP:
            for(unsigned int i = 0;i<barriers.size(); i++){
                Rect box = barriers[i];
                bFlag = this->isCollisionWithRTop(box);
                if(bFlag) {
                    fixCollision(face,box);
                    break;
                };
            }
            
            break;
        case kBOTTON:
            for(unsigned int i = 0;i<barriers.size(); i++){
                Rect box = barriers[i];
                bFlag = this->isCollisionWithBottom(box);
                if(bFlag) {
                    fixCollision(face,box);
                    break;
                };
            }
             break;
        case kRBOTTON:
            for(unsigned int i = 0;i<barriers.size(); i++){
                Rect box = barriers[i];
                bFlag = this->isCollisionWithRBottom(box);
                if(bFlag) {
                    fixCollision(face,box);
                    break;
                };
            }
            break;
        case kRIGHT:
            for(unsigned int i = 0;i<barriers.size(); i++){
                Rect box = barriers[i];
                bFlag = this->isCollisionWithRight(box);
                if(bFlag) {
                    fixCollision(face,box);
                    break;
                };
            }
             break;
        case kLEFT:
            for(unsigned int i = 0;i<barriers.size(); i++){
                Rect box = barriers[i];
                bFlag = this->isCollisionWithLeft(box);
                if(bFlag) {
                    fixCollision(face,box);
                    break;
                };
            }
             break;
        default:
            CCLOG("invalid face");
            break;
    }
    
    if(bFlag)CCLOG("collisions at %d",face);
    return bFlag;
}