Beispiel #1
0
    Vector3 GetGridWall(Vector2 gridPosition, Vector2 direction, float height = 0)
    {
        Vector3 toReturn = GridF.TransformGridToPoint(gridPosition) + GridF.Direction2ToDirection3(direction * 0.5f * LabyrinthGenerator.instance.scale);

        toReturn.y = height;
        return(toReturn);
    }
Beispiel #2
0
    void Update()
    {
        float   y           = transform.position.y;
        Vector3 newPosition = GridF.TransformGridToPoint(GridF.TransformPointToGrid(transform.parent.transform.position));

        newPosition.y      = y;
        transform.position = newPosition;
        transform.rotation = rotation;
    }
Beispiel #3
0
    void Draw(float radius = 0.8f, float sinOffset = 0, float sinOffsetMultiplicator = 1, float amplitude = 0.5f)
    {
        //float refScale = 0.1f;
        List <int[]> rings = new List <int[]>();


        Vector3 gridOffset = GridF.TransformGridToPoint(positionInGrid) - transform.position;

        gridOffset.y = 0;

        foreach (List <Vector2> thread in walls)
        {
            foreach (Vector2 point in thread)
            {
                int pointX = (int)point.x;
                int pointY = (int)point.y;

                Vector2 transformOffset = ((point + Vector2.one) / 2 - Vector2.one * 1.5f);
                Vector3 offset          = new Vector3(transformOffset.x, 0, transformOffset.y);
                float   y = Mathf.Sin((offset.x + sinOffset * sinOffsetMultiplicator + positionInGrid.x) * 2) * amplitude
                            + Mathf.Cos((offset.z - sinOffset * sinOffsetMultiplicator + positionInGrid.y) * 2) * amplitude;

                Vector3 position = offset * scale + gridOffset + Vector3.up * y;
                float   distance = (transform.position - transform.TransformPoint(position)).magnitude;
                distance = Mathf.Clamp((scale - 0.15f * scale) - distance, 0, scale);

                rings.Add(mesh.AddArray(CreateRing(radius * distance, position, Quaternion.Euler(0, 45 * (pointsGrid[pointX, pointY] - 1), 0))));

                //GameObject newObj = GameObject.CreatePrimitive(PrimitiveType.Capsule);
                //newObj.transform.position = transform.position + offset;
                //newObj.transform.rotation = Quaternion.Euler(0, 45 * (pointsGrid[pointX, pointY] - 1), 90);
                //newObj.transform.localScale = Vector3.one * refScale;
                //refScale += 0.1f;
            }
            for (int i = 1; i < rings.Count; i++)
            {
                mesh.ConectRings(rings[i], rings[i - 1]);
            }
            mesh.Cap(rings[0]);
            mesh.Cap(rings[rings.Count - 1], true);

            rings.Clear();
        }

        mesh.UpdateMesh();
    }
    void Start()
    {
        TextureToMap();

        GetGroundFromMap();
        GetWallsFromMap();

        groundMeshObject = new MeshObject((grounds.Count * 4), grounds.Count * 2 * 3);
        wallMeshObject   = new MeshObject(walls.Count * 4, walls.Count * 2 * 3);

        DrawGround();
        DrawWalls();
        DrawCeil();

        CombineInstance[] combineMesh = new CombineInstance[3];
        combineMesh[0].mesh = groundMeshObject.GenerateMesh();
        combineMesh[1].mesh = wallMeshObject.GenerateMesh();
        combineMesh[2].mesh = ceilMeshObject.GenerateMesh();

        Mesh generatedMesh = new Mesh();

        generatedMesh.CombineMeshes(combineMesh, false, false);

        GetComponent <MeshFilter>().sharedMesh   = generatedMesh;
        GetComponent <MeshCollider>().sharedMesh = generatedMesh;

        player.transform.position = new Vector3(((origin.x * 2) + 1) * scale, height * scale / 2, ((origin.y * 2) + 1) * scale);
        float angle = Mathf.Atan2(originDirection.x, originDirection.y) * Mathf.Rad2Deg;

        player.transform.eulerAngles = new Vector3(0, angle, 0);

        goal.transform.position = new Vector3(((end.x * 2) + 1) * scale, 0, ((end.y * 2) + 1) * scale);
        //endDirection = new Vector2(1,1);
        angle = Mathf.Atan2(endDirection.x, endDirection.y) * Mathf.Rad2Deg;
        goal.transform.eulerAngles = new Vector3(0, angle, 0);

        if (Game.enemies)
        {
            GameObject enemy = Instantiate(enemyType);
            enemy.transform.position    = GridF.TransformGridToPoint(end * 2 + Vector2.one + endDirection / 2);
            enemy.transform.eulerAngles = new Vector3(0, angle, 0);
        }
    }
Beispiel #5
0
    void PositionateFlowers()
    {
        Vector3 position = transform.position;

        position.y = 0;

        float distance = (position - GridF.TransformGridToPoint(transform.parent.GetComponent <EnemyBase>().currentPositionInGrid)).magnitude;

        distance = (scale - Mathf.Clamp(distance, 0, scale)) / scale;

        //if (positionInGrid != GridF.TransformPointToGrid(transform.position)) flowerGrowing = true;
        if (transform.parent.GetComponent <EnemyBase>().currentPositionInGrid != transform.parent.GetComponent <EnemyBase>().prevPositionInGrid)
        {
            flowerGrowing = true;
        }
        else if (prevFlowerGrowingDistance > distance)
        {
            flowerGrowing = false;
        }

        prevFlowerGrowingDistance = distance;

        if (!flowerGrowing)
        {
            distance = unGrowRate.Evaluate(distance);
        }
        else
        {
            distance = growRate.Evaluate(distance);
        }

        flower.transform.position   = GridF.TransformGridToPoint(transform.parent.GetComponent <EnemyBase>().currentPositionInGrid) /*+ Vector3.up * transform.position.y*/;
        flower.transform.localScale = Vector3.one * distance;

        distance = (position - GridF.TransformGridToPoint(transform.parent.GetComponent <EnemyBase>().currentPositionInGrid + transform.parent.GetComponent <EnemyBase>().direction)).magnitude;
        distance = (scale - Mathf.Clamp(distance, 0, scale)) / scale;
        distance = growRate.Evaluate(distance);

        nextFlower.transform.position   = GridF.TransformGridToPoint(transform.parent.GetComponent <EnemyBase>().currentPositionInGrid + transform.parent.GetComponent <EnemyBase>().direction) /*+ Vector3.up * transform.position.y*/;
        nextFlower.transform.localScale = Vector3.one * distance;
    }
Beispiel #6
0
    void Draw()
    {
        //Update head
        {
            Vector3 headPosition = head.position;
            headPosition.y = CalculateHeight(head.position);
            head.position  = headPosition;
        }

        mesh.Clear();
        if (controlPoints.Count > 0)
        {
            float addedDistance = 0;

            if (moved)
            {
                addedDistance = ((head.transform.position - prevWall).magnitude / betweenWallsDistance);
                if (turning && enemy.state != EnemySmooth.State.Turning)
                {
                    turning = false; ChangeTile();
                }
            }

            List <int[]> rings = new List <int[]>();

            if (controlPoints.Count == maxControlPoints)
            {
                {
                    Point2  point = controlPoints[0];
                    Vector3 realPointLocalPosition = (GridF.TransformGridToPoint(point.position) + GridF.Direction2ToDirection3(point.direction) * addedDistance * LabyrinthGenerator.instance.scale);
                    realPointLocalPosition += CalculateHeight(realPointLocalPosition) * Vector3.up - transform.position;

                    float width = widthCurve.Evaluate(0);
                    rings.Add(mesh.AddArray(CreateRing(width, realPointLocalPosition, point.angle), 0));

                    if (addedDistance < 0.5f)
                    {
                        Point2 point2         = controlPoints[1];
                        float  distanceToHead = 0.5f - addedDistance;
                        realPointLocalPosition = (GridF.TransformGridToPoint(point.position) + CalculateHeight(GridF.TransformGridToPoint(point.position)) * Vector3.up) - transform.position;
                        Vector3 realPointLocalPosition2 = (GridF.TransformGridToPoint(point2.position) + Vector3.up * CalculateHeight(GridF.TransformGridToPoint(point2.position))) - transform.position;

                        width = widthCurve.Evaluate(distanceToHead / (controlPoints.Count - 0.5f));
                        rings.Add(mesh.AddArray(CreateRing(width, (realPointLocalPosition + realPointLocalPosition2) / 2, (point.angle + point2.angle) / 2), distanceToHead));
                    }
                }

                for (int i = 1; i < controlPoints.Count; i++)
                {
                    Point2  point                  = controlPoints[i];
                    float   distanceToHead         = i - addedDistance;
                    Vector3 realPointLocalPosition = (GridF.TransformGridToPoint(point.position) + CalculateHeight(GridF.TransformGridToPoint(point.position)) * Vector3.up) - transform.position;

                    float width = widthCurve.Evaluate(distanceToHead / (controlPoints.Count - 0.5f));
                    rings.Add(mesh.AddArray(CreateRing(width, realPointLocalPosition, point.angle), distanceToHead));
                    //rings.Add(mesh.AddArray(CreateRing(1, realPointLocalPosition + (new Vector3(point.direction.x, 0, point.direction.y) * addedDistance), point.angle)));

                    if (i == controlPoints.Count - 1)
                    {
                        distanceToHead = i + 0.5f - addedDistance;

                        /*Quaternion headAngle = head.rotation * Quaternion.Euler(0,point.angle,0);
                         * while (Mathf.Abs(headAngle - point.angle) > 360)
                         * {
                         *  if (headAngle < point.angle) headAngle += 360;
                         *  else headAngle -= 360;
                         * }
                         * Debug.Log(headAngle.eulerAngles.y);*/
                        width = widthCurve.Evaluate(distanceToHead / (controlPoints.Count - 0.5f));
                        realPointLocalPosition = (realPointLocalPosition + transform.InverseTransformPoint(head.position)) / 2;
                        rings.Add(mesh.AddArray(CreateRing(width, realPointLocalPosition, point.angle), distanceToHead));

                        distanceToHead -= 0.25f;
                        width           = widthCurve.Evaluate(distanceToHead / (controlPoints.Count - 0.5f));
                        rings.Add(mesh.AddArray(CreateRing(width, ((realPointLocalPosition + transform.InverseTransformPoint(head.position)) / 2), head.rotation), distanceToHead));
                    }

                    else
                    {
                        distanceToHead = i + 0.5f - addedDistance;
                        Point2  point2 = controlPoints[i + 1];
                        Vector3 realPointLocalPosition2 = (GridF.TransformGridToPoint(point2.position) + CalculateHeight(GridF.TransformGridToPoint(point2.position)) * Vector3.up) - transform.position;
                        width = widthCurve.Evaluate(distanceToHead / (controlPoints.Count - 0.5f));
                        rings.Add(mesh.AddArray(CreateRing(width, (realPointLocalPosition + realPointLocalPosition2) / 2, point.angle), distanceToHead));
                    }
                }
            }
            //rings.Add(mesh.AddArray(CreateRing(widthCurve.Evaluate(1), transform.InverseTransformPoint(head.position), head.rotation), maxControlPoints - 0.5f));

            for (int i = 1; i < rings.Count; i++)
            {
                mesh.ConectRings(rings[i], rings[i - 1]);
            }

            mesh.Cap(rings[0]);
            mesh.Cap(rings[rings.Count - 1], true);

            mesh.UpdateMesh();
        }
    }