Esempio n. 1
0
    private IEnumerator CR_ExecuteMoves(GhostInformation _information)
    {
        int idx = 0;

        if (_information.Movement.Length >= 2)
        {
            Vector2 start  = _information.Movement[idx++];
            Vector2 target = _information.Movement[idx++];
            transform.position = start;

            while (idx < _information.Movement.Length)
            {
                for (float t = 0.0f; t < 0.5f; t += Time.deltaTime)
                {
                    Vector2 prevPosition = transform.position;
                    Vector2 newPosition  = Vector2.Lerp(start, target, t * 2);
                    Vector2 _moveDelta   = newPosition - prevPosition;

                    if (_moveDelta.x > 0)
                    {
                        _animator.Play("player_walking_right");
                    }
                    else if (_moveDelta.x < 0)
                    {
                        _animator.Play("player_walking_left");
                    }
                    else if (_moveDelta.y < 0)
                    {
                        _animator.Play("player_walking_frontal");
                    }
                    else if (_moveDelta.y > 0)
                    {
                        _animator.Play("player_walking_up");
                    }
                    else
                    {
                        _animator.Play("player_idle_frontal");
                    }

                    transform.position = newPosition;
                    yield return(null);
                }

                start  = target;
                target = _information.Movement[idx++];
            }
        }

        Destroy(gameObject);
    }
Esempio n. 2
0
    private IEnumerator CR_PlaybackGhosts()
    {
        while (true)
        {
            yield return(new WaitForSeconds(Random.Range(AverageInterval_s * 0.5f, AverageInterval_s * 1.5f)));

            if (_informations.Length > 0)
            {
                GhostInformation ghostInformation = _informations[Random.Range(0, _informations.Length - 1)];
                Ghost            ghost            = Instantiate(GhostPrefab, transform.position, Quaternion.identity);
                ghost.transform.parent = transform;
                ghost.ExecuteMoves(ghostInformation);
            }
        }
    }
Esempio n. 3
0
    public static GhostInformation FromPathObject(PathObject pathObject)
    {
        GhostInformation information = new GhostInformation();

        information.Room     = pathObject.room;
        information.Movement = pathObject.movement.Cast <JArray>().Select <JArray, Vector2>((JArray jarray) => {
            return(new Vector2(jarray[0].Value <float>(), jarray[1].Value <float>()));
        }).ToArray();
        information.Interactions = pathObject.interaction.Cast <JArray>().Select(jarray => {
            float x            = jarray[0].Value <float>();
            float y            = jarray[1].Value <float>();
            string interaction = jarray[2].Value <string>();
            return(new GhostInteraction(new Vector2(x, y), interaction));
        }).ToArray();

        return(information);
    }
Esempio n. 4
0
    private IEnumerator CR_GetPaths(int count = 50)
    {
        string url = APIClient.ServerURL + "api/paths/" + count;

        using (UnityWebRequest www = UnityWebRequest.Get(url)) {
            yield return(www.Send());

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
            }
            else
            {
                string data1           = www.downloadHandler.text;
                var    pathsFromServer = JsonConvert.DeserializeObject <List <PathObject> >(data1);
                _informations =
                    pathsFromServer.Select(pathObject => GhostInformation.FromPathObject(pathObject)).ToArray();
                Debug.Log("Got path informations");
            }
        }
    }
Esempio n. 5
0
 public void ExecuteMoves(GhostInformation information)
 {
     StartCoroutine(CR_ExecuteMoves(information));
 }