예제 #1
0
    public void Teleport(s_charactermanager returning_system)
    {
        positon = grid.VectorPositionFromWorld(transform.position);
        Queue <o_node> di = new Queue <o_node>();

        foreach (o_node n in directions)
        {
            di.Enqueue(n);
        }
        Vector2Int newpos = new Vector2Int();

        while (di.Count != 1)
        {
            di.Dequeue();
        }
        transform.position = di.Peek().position;
        newpos             = grid.VectorPositionFromWorld(transform.position);
        grid.character_layer[positon.x, positon.y] = null;
        grid.character_layer[newpos.x, newpos.y]   = this;
        grid.UnpaintAllNodes();
        di.Clear();

        returning_system.LooseFocus();
    }
예제 #2
0
    public List <o_node> RetracePath(o_node current, o_node start)
    {
        Grid.UnpaintAllNodes();
        List <o_node> path = new List <o_node>();

        o_node currentnode = current;

        while (currentnode != start)
        {
            path.Add(currentnode);
            {
                Vector2Int nodepos = Grid.VectorPositionFromWorld(currentnode.position);

                //Grid.PaintNode(nodepos, Color.white);
                HashSet <o_node> neigh = Grid.CheckAroundNode(current);

                //print(currentnode.DIR);
            }
            currentnode = currentnode.parent;
        }
        path.Reverse();

        /*
         * print(Grid.ObjectFromWorld(path[0]));
         * print(Grid.ObjectFromWorld(path[path.Count - 1]));
         *
         * if (Grid.ObjectFromWorld(path[path.Count - 1]) != null)
         * {
         *  s_object obj = Grid.ObjectFromWorld(path[path.Count - 1]);
         *  while (path.Count != 0 &&
         *      obj != null &&
         *      obj.GetType() == typeof(o_character))
         *  {
         *      path.Remove(path[path.Count - 1]);
         *      if (path.Count > 0)
         *          if (Grid.ObjectFromWorld(path[path.Count - 1]) != null)
         *              obj = Grid.ObjectFromWorld(path[path.Count - 1]);
         *      else
         *          break;
         *  }
         * }*/
        //path.Add(start);
        return(path);
    }
    private void Update()
    {
        if (Grid.gridworldsize.y > 0 && Grid.gridworldsize.x > 0)
        {
            Vector3  mousePositon = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            s_object selectedObj  = Grid.ObjectFromWorld(mousePositon);

            if (Input.GetKeyDown(KeyCode.W))
            {
                spritenum++;
            }
            if (Input.GetKeyDown(KeyCode.S))
            {
                spritenum--;
            }


            if (Input.GetKeyDown(KeyCode.E))
            {
                angle += 90;
            }

            if (angle > 360)
            {
                angle = 0;
            }

            examplerend.gameObject.transform.localRotation = Quaternion.Euler(0, 0, angle);

            spritenum = Mathf.Clamp(spritenum, 0, spriteArray.Length - 1);

            examplerend.sprite = spriteArray[spritenum];

            if (Grid.NodeFromWorld(mousePositon) != null)
            {
                Vector2 snap = Grid.SnapToGrid(mousePositon);
                if (Input.GetMouseButton(0))
                {
                    if (selectedObj != null)
                    {
                        if (selectedObj.GetComponent <s_object>().GetType() == typeof(o_tile))
                        {
                            SpriteRenderer ren = selectedObj.GetComponent <SpriteRenderer>();
                            ren.sprite = spriteArray[spritenum];
                            ren.gameObject.transform.localRotation = examplerend.gameObject.transform.localRotation;
                        }
                    }
                    //target.transform.position = mousePositon;
                    if (Grid.ObjectFromWorld(mousePositon) == null)
                    {
                        Vector2Int vecint = Grid.VectorPositionFromWorld(mousePositon);

                        if (selected_object != null)
                        {
                            s_object obj = Grid.SpawnObject(selected_object.name, snap);
                        }
                    }
                }
                if (Input.GetMouseButton(1))
                {
                    if (Grid.ObjectFromWorld(mousePositon) != null)
                    {
                        Vector2Int vecint = Grid.VectorPositionFromWorld(mousePositon);
                        if (selected_object != null)
                        {
                            Grid.DespawnObject(snap);
                        }
                    }
                }
            }
        }

        if (Grid.nodes != null)
        {
            for (int x = 0; x < Grid.gridworldsize.x; x++)
            {
                for (int y = 0; y < Grid.gridworldsize.y; y++)
                {
                    /*
                     * SpriteRenderer colourRender = Grid.nodegameobjects[x, y].GetComponent<SpriteRenderer>();
                     * colourRender.color = Color.white;
                     * if (Grid.CheckForNodeOnGrid(mousePositon, x, y))
                     * {
                     *  colourRender.color = Color.blue;
                     * }
                     */
                }
            }
        }
    }