예제 #1
0
void PropColumnMenu::onTouchMoved(Touch *pTouch, Event *pEvent)
{
    Point point = pTouch->getLocation();
    
    m_editProp->setPosition(point);
    
    do
    {
        ControlButton* btn = GAME_UILAYER->getOperationMenu()->getDrugsBtn();
        
        Rect rect;
        rect.origin = btn->convertToWorldSpace(Point::ZERO);
        rect.size = btn->getContentSize();
        if (rect.containsPoint(point))
        {
            CC_BREAK_IF(m_editProp->getOpacity() == 255);
            m_editProp->setOpacity(255);
            btn->stopAllActions();
            ScaleTo* scaleTo = ScaleTo::create(0.1f, 1.1f);
            btn->runAction(scaleTo);
        }
        else
        {
            CC_BREAK_IF(m_editProp->getOpacity() == 127);
            m_editProp->setOpacity(127);
            btn->stopAllActions();
            ScaleTo* scaleTo = ScaleTo::create(0.1f, 1.0f);
            btn->runAction(scaleTo);
        }
    }
    while (0);
}
예제 #2
0
void PropColumnMenu::onTouchEnded(Touch *pTouch, Event *pEvent)
{
    Point point = pTouch->getLocation();
    
    Rect rect = Rect::ZERO;
    rect.origin = m_propColumn->convertToWorldSpace(Point::ZERO);
    rect.size = m_propColumn->getContentSize();
    
    if (rect.containsPoint(point))
    {
        point = m_propColumn->convertToNodeSpace(point);
        int x = (int)point.x / GRID_WIDTH;
        int y = (int)point.y / GRID_HEIGHT;
        y = ROW - y - 1;
        m_propVec[m_editProp->getTag()]->setVisible(true);
        this->swapProp(m_editProp->getTag(), y*COL+x);
    }
    else
    {
        if (m_editProp->getOpacity() == 255)
        {
            GAME_UILAYER->getOperationMenu()->addDrugs(2001);
            ControlButton* btn = GAME_UILAYER->getOperationMenu()->getDrugsBtn();
            btn->stopAllActions();
            ScaleTo* scaleTo = ScaleTo::create(0.1f, 1.0f);
            btn->runAction(scaleTo);
            m_propVec[m_editProp->getTag()]->removeFromParent();
            m_propVec[m_editProp->getTag()] = NULL;
        }
        else
        {
            float r = CCRANDOM_0_1();
            if (r ==1)
                r = 0;
            
            BgMap* bgMap = GAME_SCENE->getCurrBgMap();
            MapPoint playerPosition = MapPoint(Player::sharePlayer()->getPosition());
            
            MapPoint point = MapPointZero;
            std::vector<MapPoint> mapVec;
            M_INT lenght = 1;
            do
            {
                mapVec = playerPosition.getMapPointVectorForDistance(lenght);
                unsigned int index = 0;
                for (; index<mapVec.size(); index++)
                {
                    if (GAME_SCENE->getMapPointForProp(MapPoint(mapVec.at(index))) == NULL)
                    {
                        point = MapPoint(mapVec.at(index));
                    }
                }
                
                CC_BREAK_IF(!point.equals(MapPointZero));
                
                lenght++;
            }
            while (1);

            
            PropIconShow* show = m_propVec[m_editProp->getTag()];
            m_propVec[m_editProp->getTag()] = NULL;
            show->setVisible(true);
            show->retain();
            show->removeFromParent();
            show->setPosition(point.getCCPointValue());
            bgMap->addChild(show, BgMap::getZOrderZero(bgMap));
            show->release();
            show->setScale(0.8f);

            GAME_SCENE->insterMapPointForProp(show, point);
            
            show->setOpacity(0);
            FadeIn* fadeIn = FadeIn::create(0.1f);
            JumpBy* jumpBy = JumpBy::create(0.3f, Point::ZERO, 30, 1);
            Spawn* spawn = Spawn::create(fadeIn, jumpBy, NULL);
            show->runAction(spawn);
            
        }
    }
    m_editProp->removeFromParent();
    m_editProp = NULL;
}