Beispiel #1
0
        public void OnNewPosition()
        {
            //tell the previous tileNode and current tileNode if we are solid.
            if (tileNode != null)
            {
                if (tileNode.itemsHere.Contains(this))
                {
                    tileNode.itemsHere.Remove(this);
                }
            }

            tileNode = tilemapManager.GetTileNode(position);
            if (tileNode != null)
            {
                if (!tileNode.itemsHere.Contains(this))
                {
                    tileNode.itemsHere.Add(this);
                }
                else
                {
                    Debug.LogWarning("tile node already had gridElement. This should never happen.");
                }
            }             //else: our object was moved where there isn't a tile.


            onNewPositionAction?.Invoke();
        }
Beispiel #2
0
        public Pathfind SetDestination(Vector3 worldSpacePos)
        {
            var destination = tilemapManager.GetTileNode(tilemapManager.WorldToCell(worldSpacePos));

            pathfind.pathStatus = 0;
            StartCoroutine(WaitForPathThenQueueMoves(destination));
            return(pathfind);
        }
Beispiel #3
0
        private void CheckForItem()
        {
            var pos       = _gridElement.position;
            var tile      = _tilemapManager.GetTileNode(pos);
            var collected = new List <GridElement>();

            for (int i = tile.itemsHere.Count; i > 0; i--)
            {
                GridElement ge = tile.itemsHere[i - 1];
                if (ge.item != null)
                {
                    AddItemToInventory(ge.item);
                    tile.itemsHere.Remove(ge);
                    if (ge.destroyOnItemPickup)
                    {
                        Destroy(ge.gameObject);
                    }
                }
            }
        }
Beispiel #4
0
        private void Stab()
        {
            var stabLocation = playerAgent.position + playerAgent.facingDirection;

            tilemapManager.SoundOneTile(stabLocation);
            //
            TileNode      stabNode = tilemapManager.GetTileNode(stabLocation);
            List <AIBase> killme   = new List <AIBase>();

            foreach (var ge in stabNode.itemsHere)
            {
                if (ge.GetComponent <AIBase>() != null)
                {
                    killme.Add(ge.GetComponent <AIBase>());
                }
            }

            foreach (var toDie in killme)
            {
                toDie.KillMe();
            }
        }
Beispiel #5
0
    // Update is called once per frame
    void Update()
    {
        if (_agent.status == AgentStatus.Dead)
        {
            return;
        }
        if (!handleInput.Value)
        {
            return;
        }
        if (!gfm.playerCanMove.Value)
        {
            return;
        }

        //keyboard Input
        if (UnityEngine.Input.GetKeyDown(KeyCode.RightArrow))
        {
            inputStack.Enqueue(Vector2Int.right);
        }
        else if (UnityEngine.Input.GetKeyDown(KeyCode.LeftArrow))
        {
            inputStack.Enqueue(Vector2Int.left);
        }
        else if (UnityEngine.Input.GetKeyDown(KeyCode.UpArrow))
        {
            inputStack.Enqueue(Vector2Int.up);
        }
        else if (UnityEngine.Input.GetKeyDown(KeyCode.DownArrow))
        {
            inputStack.Enqueue(Vector2Int.down);
        }

        // if (UnityEngine.Input.GetKeyDown(KeyCode.Space))
        // {
        //  _tilemapManager.Sound(_agent.position, 3);
        // }

        //pathfinding test.
        if (UnityEngine.Input.GetMouseButtonDown(1))
        {
            var clickPos  = _tilemapManager.WorldToCell(Camera.main.ScreenToWorldPoint(UnityEngine.Input.mousePosition));
            var clickNode = _tilemapManager.GetTileNode(clickPos);
            if (clickNode == null)
            {
                return;
            }

            StartCoroutine(WaitAndQueuePath(clickNode.position));
        }

        ///
        if (UnityEngine.Input.GetMouseButtonDown(0))
        {
            //if input for movement...
            var clickPos = _tilemapManager.WorldToCell(Camera.main.ScreenToWorldPoint(UnityEngine.Input.mousePosition));

            if (_agent.position == clickPos)
            {
                return;
            }                     //if we clicked ON the player. This how we show menu?

            if (_agent.position.x == clickPos.x)
            {
                inputStack.Enqueue(_agent.position.y < clickPos.y ? Vector2Int.up : Vector2Int.down);
            }
            else if (_agent.position.y == clickPos.y)
            {
                inputStack.Enqueue(_agent.position.x < clickPos.x ? Vector2Int.right : Vector2Int.left);
            }
        }                 //end mouse movement

        ///
        if (!_activeTurn.blockPlayerMovement && inputStack.Count > 0)
        {
            _activeTurn = _agent.Move(inputStack.Dequeue());
            if (_activeTurn.turnTaken)
            {
                _activeTurn.blockPlayerMovement = true;
            }
        }
    }