コード例 #1
0
void FSingleTileEditorViewportClient::OnTileSelectionRegionChanged(const FIntPoint& TopLeft, const FIntPoint& Dimensions)
{
	const int32 TopLeftIndex = (TileSet->GetTileCountX() * TopLeft.Y) + TopLeft.X;
	const int32 SelectionArea = Dimensions.X * Dimensions.Y;

	if (SelectionArea > 0)
	{
		const int32 NewIndex = (SelectionArea == 1) ? TopLeftIndex : INDEX_NONE;
		SetTileIndex(NewIndex);
	}
}
コード例 #2
0
TiledSprite::TiledSprite(const std::string &filename, unsigned nCols, unsigned nRows){
	// pide al TextureManager una referencia a la textura especificada
	const sf::Image &tex = TextureManager::GetInstance().GetTexture(filename);
	// asigna la textura al sprite
	SetImage(tex);
	// guarda la cantidad de filas y columnas (se van a necesitar más tarde para calcular el subrectángulo)
	this->nCols=nCols;
	this->nRows=nRows;
	// calcula el ancho y alto del tile
	tileW=tex.GetWidth()/nCols;
	tileH=tex.GetHeight()/nRows;
	// se pone mCurrentTileIndex en -1 para que al llamar a SetTileIndex() en la linea siguiente,
	// este valor se altere (debe inicializarse en otro valor != 0)
	mCurrentTileIndex=-1; 
	// asigna al sprite el primer tile del spritesheet
	SetTileIndex(0);
}
コード例 #3
0
ファイル: Unit.cpp プロジェクト: 1step6thswmaestro/16
//현재 Path.front에 저장되어 있는 타일 인덱스로 이동한다. 만약 Path가 비어있으면 false를 반환한다.
bool Unit::MoveToPathFront(int CurrentPacket) {
    //해당 유닛의 패스를 가져온다.
    auto& Path = GetPathPlanner()->GetPath();
    auto pMap = m_pGameWorld->GetMap();
    auto& Graph = pMap->GetNavGraph();

    LogMgr->Log("Path Size : %d",Path.size());

    if(Path.empty()) {
        LogMgr->Log("취소");
        m_pFSM->ChangeState(State_Idle::Instance());
        return false;
    }

    //움직일 다음 칸 인덱스를 가져온다.
    int MoveIndex = Path.front();
    Path.pop_front();

    //MoveIndex의 타일이 비어있는지 확인한다.
    //비어 있지 않으면 새로 AStar알고리즘을 실행하여 움직인다.
    //TODO : 나중에 최적화 할 것
    if(!Graph.GetNode(MoveIndex).IsEmpty()) {
        m_pPathPlanner->CreatePathToPosition(m_pPathPlanner->GetDestination());

        if(Path.empty()) {
            GetFSM()->ChangeState(State_Idle::Instance());
            return false;
        }

        MoveIndex = Path.front();
        Path.pop_front();
    }

    //이동시킨다.
    int PrevIndex = GetTileIndex();
    SetTileIndex(MoveIndex);
    Vec2 MyPosition = m_pGameWorld->GetMap()->GetNavGraph().GetNode(PrevIndex).getPosition();
    Vec2 PathFrontPosition = m_pGameWorld->GetMap()->GetNavGraph().GetNode(MoveIndex).getPosition();

    //Heading 설정
    SetHeading(PathFrontPosition - getPosition());

    //Move 액션 생성 과정 : 타일 간의 거리와 유닛의 이동속도를 고려하여 만든다.

    //다음 AutoTask를 먼저 등록한다.
    //본래 속도보다 TweakPacket 정도 더 빠르게 실행시킨다.

    float Distance = Vec2Distance(PathFrontPosition, MyPosition) / (DIVIDE_NODE ? 32.0f : 64.0f);
    float Duration = Distance / GetSpeed();

    int TweakPacket = 1;
    int NextPacket = (int)(NETWORK_FPS * Duration) - TweakPacket;
    printf("NextPacket : %d\n",NextPacket);
    //만일 NextPacket이 0보다 작거나 같다면 다음 타일을 가져온다.
    if(NextPacket <= 0) {
        printf("AAaaaaaaaaaaaa\n");
        return MoveToPathFront(CurrentPacket);
    }

    NetMgr->PushAutoTask(new AutoTaskMove(CurrentPacket + NextPacket, m_iID));
    SetAutoTaskPacket(CurrentPacket+NextPacket);

    auto pMove = MoveTo::create(Duration,PathFrontPosition);

    //액션을 실행한다.
    stopAllActions();
    runAction(pMove);

    return true;
}