Ejemplo n.º 1
0
Archivo: FSM.cs Proyecto: poup/ankagaja
    // Update is called once per frame
    void Update()
    {
        if (_nextState != null && _currentState != null && _currentState.Status == StateStatus.Running)
        {
            Debug.LogWarning(_currentState.GetType() + " OnLeave");
            _currentState.OnLeave();
        }

        if (_currentState != null && _currentState.Status == StateStatus.LeaveEnded)
        {
            _currentState = null;
        }

        if (_currentState == null && _nextState != null)
        {
            _currentState = _nextState;
            _nextState    = null;
            Debug.LogWarning(_currentState.GetType() + " OnStart");
            _currentState.OnEnter();
        }

        if (_currentState != null && _currentState.Status == StateStatus.Running)
        {
            _currentState.Update();
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        velocity = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
        if (velocity.magnitude > 1)
        {
            velocity.Normalize();
        }
        state.SetDirection();
        state.Update();

        // Attack
        if (Input.GetKey(attackKey) && releaseAttack)
        {
            releaseAttack = false;
            state.Attack();
        }
        else if (!Input.GetKey(attackKey))
        {
            releaseAttack = true;
        }

        // Interact
        if (Input.GetKey(interactKey) && releaseInteract)
        {
            releaseInteract = false;
            state.Interact();
        }
        else if (!Input.GetKey(interactKey))
        {
            releaseInteract = true;
        }
    }
Ejemplo n.º 3
0
 public void Update(float elapsedTime, float aspect)
 {
     if (_currentState == null)
     {
         return;
     }
     _currentState.Update(elapsedTime, aspect);
 }
Ejemplo n.º 4
0
    // Update is called once per frame
    void FixedUpdate()
    {
        // Handles AI actions
        // AI will perform an action periodically after inputTimer seconds
        // Shooting takes twice as much as other actions
        if (timer >= inputTimer)
        {
            transform.position = new Vector3(Mathf.Round(transform.position.x), Mathf.Round(transform.position.y), Mathf.Round(transform.position.z));

            currentNode = new GraphNode(transform.position.x, transform.position.y);

            if (graph.Contains(currentNode))
            {
                lastVisited = graph.FindLast(a => a.Equals(currentNode));
            }

            // If we are in node we haven't visited yet
            if (graph.Contains(currentNode) && !graph.Find(a => a.Equals(currentNode)).visited)
            {
                var newLists = GraphBuilder.ExploreGraph(transform.position, graph, unvisitedNodes, junctionNodes, holeNodes);
                graph          = newLists[0];
                unvisitedNodes = newLists[1];
                junctionNodes  = newLists[2];
                holeNodes      = newLists[3];

                graph.Find(a => a.Equals(new GraphNode(transform.position.x, transform.position.y))).visited = true;
                unvisitedNodes.Remove(new GraphNode(transform.position.x, transform.position.y));
            }

            // Every action update check enemies
            if (enemies.Count != 0)
            {
                CheckEnemies();
            }
            currentState.Update(this);

            switch (nextAction)
            {
            case 1:
                var desiredMovement = Direction.None;
                if (moveQueue.Count != 0)
                {
                    desiredMovement = moveQueue.Dequeue();
                }

                if (desiredMovement == Direction.Up)
                {
                    if (direction != Direction.Up)
                    {
                        newAngle  = new Vector3(0, 0, 90);
                        direction = Direction.Up;
                    }
                    else
                    {
                        moveXY = transform.position + new Vector3(0, 1f, 0);
                    }
                    timer = 0f;
                }
                else if (desiredMovement == Direction.Down)
                {
                    if (direction != Direction.Down)
                    {
                        newAngle  = new Vector3(0, 0, 270);
                        direction = Direction.Down;
                    }
                    else
                    {
                        moveXY = transform.position + new Vector3(0, -1f, 0);
                    }
                    timer = 0f;
                }
                else if (desiredMovement == Direction.Left)
                {
                    if (direction != Direction.Left)
                    {
                        newAngle  = new Vector3(0, 0, 180);
                        direction = Direction.Left;
                    }
                    else
                    {
                        moveXY = transform.position + new Vector3(-1f, 0, 0);
                    }
                    timer = 0f;
                }
                else if (desiredMovement == Direction.Right)
                {
                    if (direction != Direction.Right)
                    {
                        newAngle  = new Vector3(0, 0, 0);
                        direction = Direction.Right;
                    }
                    else
                    {
                        moveXY = transform.position + new Vector3(1f, 0, 0);
                    }
                    timer = 0f;
                }
                timer = 0f;
                break;

            case 2:
                Shoot();
                timer = -inputTimer;
                break;

            case 3:
                timer = 0f;
                break;
            }
        }

        timer += Time.deltaTime;
        transform.eulerAngles = AngleLerp(transform.eulerAngles, newAngle, timer / 1.6f);
        transform.position    = Vector3.Lerp(transform.position, moveXY, timer / 2f);
    }
Ejemplo n.º 5
0
 // Update is called once per frame
 void Update()
 {
     currentState.Update(this);
 }
Ejemplo n.º 6
0
 protected override void Update()
 {
     m_stateMachine.Update(LocalDeltaTime);
 }
Ejemplo n.º 7
0
 private void Update()
 {
     stateMachine.Update(CupheadTime.GlobalDelta);
 }
Ejemplo n.º 8
0
 void Update()
 {
     _state.Update(this);
 }