Ejemplo n.º 1
0
    private void Move()
    {
        foreach (var connector in ConnectorList)
        {
            connector.transform.position += Vector3.down * 3;

            if (connector.transform.position.y < -5)
            {
                connector.SetAsAvailable();
            }
        }

        ConnectorList.RemoveAll(x => !x.gameObject.activeSelf);

        foreach (var connection in ConnectionList)
        {
            connection.transform.position += Vector3.down * 3;

            connection.name = connection.transform.position.ToString();

            if (connection.transform.position.y < -5)
            {
                connection.SetAsAvailable();
            }
        }

        ConnectionList.RemoveAll(x => !x.gameObject.activeSelf);

        player.gameObject.transform.position += Vector3.down * 3;

        if (player.gameObject.transform.position.y < -3)
        {
            GameOver();
        }
    }
Ejemplo n.º 2
0
    private void Update()
    {
        if (IsGameOver)
        {
            return;
        }

        if (_isInitiating)
        {
            if (middleSpawnPoint.position.y < 12)
            {
                if (_timeLeft <= 0)
                {
                    Spawn();

                    if (currentConnector == null)
                    {
                        currentConnector = ConnectorList.FirstOrDefault(x => x.Col == 0);
                    }

                    foreach (var spawnPoint in SpawnPoints)
                    {
                        spawnPoint.transform.position += Vector3.up * 3;
                    }

                    _timeLeft = Speed;
                }
                else
                {
                    _timeLeft -= Time.deltaTime;
                }
            }
            else
            {
                _isInitiating = false;
            }
        }
        else
        {
            if (_timeLeft <= 0)
            {
                Spawn();
                Move();

                Speed = Mathf.Clamp(Speed - 0.01f, 0.1f, 1f);

                _timeLeft = Speed;
            }
            else
            {
                _timeLeft -= Time.deltaTime;
            }
        }
    }
Ejemplo n.º 3
0
    private void Player_OnPlayerTryMove(Vector3 newPosition)
    {
        if (IsGameOver)
        {
            return;
        }

        int newCol = Mathf.RoundToInt(newPosition.x);
        int newRow = Mathf.RoundToInt(newPosition.y);

        var connector = ConnectorList.FirstOrDefault(x => x.Col == newCol && x.Row == newRow);

        if (connector != null)
        {
            Connect(connector);
        }
    }
Ejemplo n.º 4
0
 public Drawing()
 {
     this.Shapes = new ShapeList();
     this.Connectors = new ConnectorList();
 }
Ejemplo n.º 5
0
    private void Spawn()
    {
        HashSet <int> sss = new HashSet <int>();

        for (int i = 0; i < SpawnPoints.Length; i++)
        {
            if (Random.Range(0, 2) == 1)
            {
                sss.Add(i);
            }
        }

        if (!sss.Intersect(prevConnectors).Any())
        {
            sss.Add(prevConnectors.Where(x => x >= 0).ToArray().GetRandom());
        }

        for (int i = 0; i < SpawnPoints.Length - 2; i++)
        {
            if (!sss.Contains(i) || !sss.Any(x => x >= i + 2))
            {
                continue;
            }

            int k = sss.Where(x => x >= i + 2).Min();

            for (int j = i + 1; j <= k; j++)
            {
                sss.Add(j);
            }
        }

        prevConnectors.Clear();

        for (int i = 0; i < SpawnPoints.Length; i++)
        {
            bool spawnHere = sss.Contains(i);

            if (spawnHere)
            {
                var connector = ConnectorPool.GetConnector(Connectors.GetRandomGoodConnector());
                connector.transform.position = SpawnPoints[i].position;
                ConnectorList.Add(connector);

                connector.name = connector.ConnectorDef.Name;

                prevConnectors.Add(i);
            }
            else
            {
                if (Random.Range(0f, 1f) > 0.7f)
                {
                    var connector = ConnectorPool.GetConnector(Connectors.GetRandomBadConnector());
                    connector.transform.position = SpawnPoints[i].position;
                    ConnectorList.Add(connector);

                    connector.name = connector.ConnectorDef.Name;
                }
            }
        }
    }