예제 #1
0
void HelloWorld::ccTouchesEnded(cocos2d::CCSet *touches, cocos2d::CCEvent *event)
{
    m_pSprite->stopAllActions();
	
	
	CCTouch* touch=(CCTouch*)(touches->anyObject());
    //获取倒当前点击的坐标
    CCPoint location = touch ->getLocation();
    
    CCPoint mappt = TransformCoodrToMap(location);
    dirction=this->getDirectory((int)mappt.x,(int)mappt.y);
    if (dirction <0 ) return;
    //移动的时候的判定
    if((m_CurrentPos.x -8 < 0  )||((int)(m_CurrentPos.x + 8) >m_Mapsize.width))
    {
        MovePlayerTo(mappt);

    }
    else
    {
        MoveMapTo(mappt);
    }
    
    m_CurrentPos.x = mappt.x ;
    m_CurrentPos.y = mappt.y ;
    PlayerIsIdle = false;
    CCLOG("Currentpos.x = %f,Currentpos.y = %f",m_CurrentPos.x,m_CurrentPos.y);
    
    

}
예제 #2
0
void ZoneHandler::OnDrawingFinished()
{
    if(loading)
    {
        if(psengine->GetLoader()->GetLoadingCount() == 0 && csGetTicks() >= forcedLoadingEndTime)
        {
            // This is a bit of a hack. The problem is that we want to
            // stop movement while the loading screen is visible but not
            // restore the saved velocity if the player has changed movement
            // keys.
            if (celclient->GetMainPlayer() &&
                psengine->GetCharControl()->GetMovementManager()->MoveStateChanged(moveState))
            {
                newVel = celclient->GetMainPlayer()->GetVelocity();
            }

            // move player to new pos
            MovePlayerTo(newPos, newyrot, sectorToLoad, newVel);

            if(psengine->HasLoadedMap())
                loadWindow->Hide();

            loading = false;
            loadProgressBar->Completed();
            psengine->SetLoadedMap(true);

            // Move all entities which belong in these new sectors to them.
            psengine->GetCelClient()->OnMapsLoaded();

            // Reset camera clip distance.
            psCamera* cam = psengine->GetPSCamera();
            if(cam && !cam->GetDistanceCfg().adaptive)
                cam->UseFixedDistanceClipping(cam->GetFixedDistClip());
            psengine->GetPSCamera()->ResetCameraPositioning();

            // Update the lighting.
            psengine->GetModeHandler()->FinishLightFade();
            psengine->GetModeHandler()->DoneLoading(sectorToLoad);

            //Update delay data
            forcedBackgroundImg.Empty();
            forcedLoadingEndTime = 0;

            //restore the previous load window if any
            if(forcedWidgetName.Length())
                ForceLoadWindowWidget(false, forcedWidgetName);
        }
        else
        {
            float timeProgress = 1.0f;
            if(forcedLoadingEndTime)
            {
                timeProgress = (float)(csGetTicks() - forcedLoadingStartTime)/(forcedLoadingEndTime-forcedLoadingStartTime);
            }

            float loadProgress = 1.0f;
            if(loadCount)
            {
                loadProgress = (float)(loadCount-psengine->GetLoader()->GetLoadingCount())/loadCount;
                psengine->GetLoader()->ContinueLoading(false);
            }
            loadProgressBar->SetCurrentValue(csMin(loadProgress,timeProgress));
        }
    }
}
예제 #3
0
void ZoneHandler::LoadZone(csVector3 pos, float yrot, const char* sector, csVector3 vel, bool force)
{
    if((loading || !strcmp(sector, LOADING_SECTOR)) && !force)
        return;

    newPos = pos;
    newyrot = yrot;
    newVel = vel;
    csString sectorBackup = sectorToLoad; // cache old sector
    sectorToLoad = sector;
    bool connected = true;

    ZoneLoadInfo* zone = FindZone(sectorToLoad);
    if(zone == NULL)
    {
        Error1("Unable to find the sector you have entered in zoneinfo data.\nPlease check zoneinfo.xml");
        return;
    }

    // Save current movement state before stopping.
    psengine->GetCharControl()->GetMovementManager()->SaveMoveState(moveState);

    // Move player to the loading sector.
    MovePlayerTo(csVector3(0.0f), 0.0f, LOADING_SECTOR, csVector3(0.0f));

    // load target location
    if(!psengine->BackgroundWorldLoading())
    {
        // Load the world.
        if(!psengine->GetLoader()->LoadZones(zone->regions))
        {
            Error2("Unable to load zone '%s'\n", zone->inSector.GetData());
            return;
        }
    }
    else
    {
        // perform extra checks whether blocked loading is necessary
        if(sectorToLoad != sectorBackup)
        {
            iSector* newsector = psengine->GetEngine()->FindSector(sectorToLoad.GetDataSafe());
            iSector* oldsector = psengine->GetEngine()->FindSector(sectorBackup.GetDataSafe());

            if(oldsector && newsector && celclient->GetWorld())
            {
                celclient->GetWorld()->BuildWarpCache(); // we need an up-to-date warp cache here
                connected = celclient->GetWorld()->Connected(oldsector, newsector);
            }
            else
            {
                connected = false;
            }
        }

        psengine->GetLoader()->UpdatePosition(pos, sectorToLoad, true);
    }

    // Set load screen if required.
    loadCount = psengine->GetLoader()->GetLoadingCount();
    if(FindLoadWindow() && (loadCount != 0 || !psengine->HasLoadedMap() || !connected || forcedLoadingEndTime != 0))
    {
        loading = true;

        if(psengine->HasLoadedMap())
            loadWindow->Clear();

        loadWindow->AddText(PawsManager::GetSingleton().Translate("Loading world"));
        loadWindow->SetAlwaysOnTop(true);
        loadWindow->Show();

        //If a background is defined in script
        if(!forcedBackgroundImg.IsEmpty())
        {
            Debug2(LOG_LOAD, 0, "Setting background from script %s", forcedBackgroundImg.GetData());
            loadWindow->SetBackground(forcedBackgroundImg);
        }
        else
            // If the area has its own loading image, use it
            if(zone->loadImage)
            {
                Debug2(LOG_LOAD, 0, "Setting background %s", zone->loadImage.GetData());
                loadWindow->SetBackground(zone->loadImage.GetData());
            }

        loadProgressBar->SetTotalValue(1.0f);
        loadProgressBar->SetCurrentValue(0.0f);

        psengine->ForceRefresh();
    }
    else
        MovePlayerTo(newPos, newyrot, sectorToLoad, newVel);
}
예제 #4
0
void HelloWorld::MoveMapTo(CCPoint pos)
{
    
    CCPoint mappos = m_mapSprite->getPosition();
    if(dirction == 0)
    {
        MovePlayerTo(ccp(m_CurrentPos.x,m_CurrentPos.y +1));
        
    }else    if(dirction == 1)
    {
        MovePlayerTo(ccp(m_CurrentPos.x,m_CurrentPos.y +1));

        if ((m_CurrentMapStartPos.x+ScreenRowCount) <= m_Mapsize.width)
        {
            mappos.x -= 64;
            m_CurrentMapStartPos.x++;
        }
    }
    else  if(dirction ==2)
    {
        MovePlayerTo(ccp(m_CurrentPos.x,m_CurrentPos.y ));
        if ((m_CurrentMapStartPos.x+ScreenRowCount) <= m_Mapsize.width)
        {
            mappos.x -= 64;
            m_CurrentMapStartPos.x++;
        }
        
    }
    else if(dirction == 3)
    {
        MovePlayerTo(ccp(m_CurrentPos.x,m_CurrentPos.y-1 ));
        if ((m_CurrentMapStartPos.x+ScreenRowCount) <= m_Mapsize.width)
        {
            mappos.x -= 64;
            m_CurrentMapStartPos.x++;
        }
    }
    else if(dirction == 4)
    {
        MovePlayerTo(ccp(m_CurrentPos.x,m_CurrentPos.y-1 ));
//        if ((m_CurrentMapStartPos.x+ScreenRowCount) <= m_Mapsize.width)
//        {
//            mappos.x -= 64;
//            m_CurrentMapStartPos.x++;
//            MovePlayerTo(m_pSprite->getPosition());
//        }
    }
    else if(dirction == 5)
    {
        MovePlayerTo(ccp(m_CurrentPos.x,m_CurrentPos.y-1 ));
        if (m_CurrentMapStartPos.x>0)
        {
            mappos.x += 64;
            m_CurrentMapStartPos.x--;
            //MovePlayerTo(m_pSprite->getPosition());
        }
        
    }else if(dirction == 6)
    {
        
        if (m_CurrentMapStartPos.x>0)
        {
            MovePlayerTo(ccp(m_CurrentPos.x,m_CurrentPos.y ));
            mappos.x += 64;
            m_CurrentMapStartPos.x--;
            //MovePlayerTo(m_pSprite->getPosition());
        }
        else{
            MovePlayerTo(ccp(m_CurrentPos.x -1 ,m_CurrentPos.y));
        }
    }else if(dirction == 7)
    {
        MovePlayerTo(ccp(m_CurrentPos.x,m_CurrentPos.y+1 ));
        if (m_CurrentMapStartPos.x>0)
        {
            mappos.x += 64;
            m_CurrentMapStartPos.x--;
            //MovePlayerTo(m_pSprite->getPosition());
        }
    }
    
        
   
    CCActionInterval *actionTo=CCMoveTo::create(1.2f,mappos);
	CCAction *moveMapAction=CCSequence::create(
                                              actionTo,
                                              CCCallFunc::create(this,callfunc_selector(HelloWorld::MoveDone)),
                                              NULL
                                              );
    m_mapSprite->runAction(moveMapAction);
    
}