Exemplo n.º 1
0
 public void Stop()
 {
     resultNode = null;
     counter = 0;
     remainingDistance = 0f;
     walking = false;
 }
 public SCNode(Key key, Value value, SCNode next)
 {
     this.Key   = key;
     this.Value = value;
     this.Next  = next;
 }
Exemplo n.º 3
0
    void Update()
    {
        if(Input.GetKey(KeyCode.UpArrow)){
            Vector3 newPos = transform.position;
            newPos.y += 1f;
            transform.position = newPos;
        }

        if(Input.GetKey(KeyCode.DownArrow)){
            Vector3 newPos = transform.position;
            newPos.y -= 1f;
            transform.position = newPos;
        }

        if(Input.GetKey(KeyCode.LeftArrow)){
            Vector3 newPos = transform.position;
            newPos.x -= 1f;
            transform.position = newPos;
        }

        if(Input.GetKey(KeyCode.RightArrow)){
            Vector3 newPos = transform.position;
            newPos.x += 1f;
            transform.position = newPos;
        }

        if(resultNode != null && counter < resultNode.parentHistory.Count && !searching){
            if(this.transform.position != destination){
                MovePlayer();
            }

            else{
                //Vector2 playerTilePos = RecalculatePosition();
                counter++;
                t = 0f;
                GetDestination();
            }
        }

        else{
            resultNode = null;
            counter = 0;
            t = 0f;

        }
    }
Exemplo n.º 4
0
 private void MyPrint(SCNode result)
 {
     for(int i = 0; i < result.parentHistory.Count; i++){
         Debug.Log(result.parentHistory[i].tileLocation.row + "," + result.parentHistory[i].tileLocation.column);
     }
 }
Exemplo n.º 5
0
    void LateUpdate()
    {
        Vector2 playerTilePos;

        // Calculate the cell location on the map based on the player's location
        playerTilePos = RecalculatePosition();

        // if mouse down or mouse drag event occurred
        if (Input.GetMouseButtonUp(0) && !searching)
        {
            CalculateMousePosition();
            // if the mouse is positioned over the layer allow drawing actions to occur
            if(IsMouseOnMap()){
                searching = true;
                setPlayerDestination();
                t = 0f;
                resultNode = a_Star.PathFind(playerTilePos,destinationPos, Level1.levelArray);

                if(resultNode != null){
                    resultNode.parentHistory.Add(resultNode);
                    GetDestination();
                    //MyPrint(resultNode);
                }
                searching = false;
                //Debug.Log(resultNode.parentHistory[0].tileLocation.row);
                //Debug.Log(resultNode.parentHistory[0].tileLocation.column);

            }
        }
    }
Exemplo n.º 6
0
    private void SearchNewDestinationPosition(Vector2 playerPos)
    {
        searching = true;
        setPlayerDestination();
        resultNode = a_Star.PathFind(playerPos,destinationCell, Level1.levelArray);
        //		Debug.Log(playerPos);
        //		Debug.Log(destinationCell);

        if(resultNode != null){
            resultNode.parentHistory.Add(resultNode);
            GetDestination();
            walking = true;

            Vector3 cellPos = GetVectorFromTile(resultNode.tileLocation);
            scEventPosition = GetWorldPositionFromTile(cellPos);
            //MyPrint(resultNode);
        }
        else
            walking = false;

        searching = false;
        if (CalculateRemainingDistance() > runningDistance)
            speed = runningSpeed;
        else
            speed = walkingSpeed;

        //Debug.Log(resultNode.parentHistory[0].tileLocation.row);
        //Debug.Log(resultNode.parentHistory[0].tileLocation.column);
    }
Exemplo n.º 7
0
    private void MyPrint(SCNode result)
    {
        for(int i = 0; i < result.parentHistory.Count; i++){
            Vector3 cellPos = GetVectorFromTile(resultNode.parentHistory[i].tileLocation);

            Debug.Log(result.parentHistory[i].tileLocation.row + "," + result.parentHistory[i].tileLocation.column);
            Debug.Log("World: "+GetWorldPositionFromTile(cellPos));
        }
    }