コード例 #1
0
// 计时器更新函数
void GameMain::update(float time){
    
    if(hero->state == 0){
        // 判断主角在奔跑的过程中,是否掉到没有路的位置了
        isherodrop();
    }
    
    if(1){
        // 判断是否顶到星星了
        Size size = Director::getInstance()->getVisibleSize();
        float fHeroWidth = hero->getContentSize().width;
        
        Point p1 = (map->getChildByTag(0))->getPosition();
        Point p2 = (map->getChildByTag(1))->getPosition();
        
        for(int i = 0;i < 5;i ++){
            if(p1.x <= fHeroWidth && (p1.x + size.width) >= fHeroWidth){
                // 主角在地图1范围内
                GameObjStar *obj = (GameObjStar *)(map->stars1).at(i);
                if(obj->get_visable() && isCollion(Point(200, hero->getPosition().y + 62.5), Point(p1.x + 86 + 96 * i, 460), 40, 35, 18.25, 17.75)){
                    obj->set_visable(false);
                    gamemark->addnumber(200);
                }
            }else{
                // 主角在地图2范围内
                GameObjStar *obj = (GameObjStar *)(map->stars2).at(i);
                if(obj->get_visable() && isCollion(Point(200, hero->getPosition().y + 62.5), Point(p2.x + 86 + 96 * i, 460), 40, 35, 18.25, 17.75)){
                    obj->set_visable(false);
                    gamemark->addnumber(200);
                }
            }
        }
    }
    
}
コード例 #2
0
ファイル: GameMainScene.cpp プロジェクト: rchen95/cocos2d-js
void GameMain::update(float time){
    if(hero->state == 0)
        isherodrop();
    Point p1 = (map->getChildByTag(0))->getPosition();
    Point p2 = (map->getChildByTag(1))->getPosition();
    for(int i = 0;i < 5;i ++){
        if(p1.x <= 100 && (p1.x + 480) >= 100){
            GameObjStar *obj = (GameObjStar *)(map->stars1).at(i);
            if(obj->get_visable() && isCollion(Point(100,hero->getPosition().y + 62.5),Point(p1.x + 86 + 96 * i,280),40,35,18.25,17.75)){
                obj->set_visable(false);
                gamemark->addnumber(200);
            }
        }else{
            GameObjStar *obj = (GameObjStar *)(map->stars2).at(i);
            if(obj->get_visable() && isCollion(Point(100,hero->getPosition().y + 62.5),Point(p2.x + 86 + 96 * i,280),40,35,18.25,17.75)){
                obj->set_visable(false);
                gamemark->addnumber(200);
            }
        }
    }
}