Ejemplo n.º 1
0
    void SetNewEvent(int id = 0)
    {
        controller.ClearActions(id);

        // How fast to perform actions?
        float actionTime = Random.Range(1, 2);

        if (currentAction < points.Length - 1)
        {
            controller.SetMouse(points[currentAction].position, actionTime, id);
            controller.PressMouse(actionTime, id);

            currentAction++;

            controller.MoveMouse(points[currentAction].position, actionTime, id);
            controller.ReleaseMouse(actionTime, id);

            controller.Play(id);
        }
    }
Ejemplo n.º 2
0
    void UpdateAI(int id)
    {
        if (controller.Playing(id))
        {
            return;
        }

        // Slicing the biggest object in the scene only
        Slicer2D biggestObject = GetSlicerInZone();

        if (biggestObject != null)
        {
            controller.ClearActions(id);

            Polygon2D poly = biggestObject.shape.GetWorld();

            // Predict rigidbody movement
            Rigidbody2D rb = biggestObject.GetComponent <Rigidbody2D>();

            Vector2 pos     = rb.position;
            Vector2 gravity = Physics2D.gravity;
            Vector2 force   = rb.velocity;

            // Get center of the object
            Vector2 centerOffset = poly.GetBounds().center - pos;

            float timer = 0;
            while (timer < 0.25f)
            {
                float delta = 0.1f;

                pos   += force * delta;
                force += gravity * delta;

                timer += delta;
            }

            centerOffset += pos;

            // Random slice rotation
            double sliceRotation = Random.Range(0f, Mathf.PI * 2);

            // Get bounds of an object to know the slice size
            Rect  bounds    = poly.GetBounds();
            float sliceSize = Mathf.Sqrt(bounds.width * bounds.width + bounds.height * bounds.height) * 1f;

            Vector2D firstPoint = new Vector2D(centerOffset);
            firstPoint.Push(sliceRotation, sliceSize);

            Vector2D secondPoint = new Vector2D(centerOffset);
            secondPoint.Push(sliceRotation, -sliceSize);

            // How fast to perform actions?
            float actionTime = 0.125f * 0.6f;

            controller.SetMouse(firstPoint.ToVector2(), actionTime, id);
            controller.PressMouse(actionTime, id);
            controller.MoveMouse(secondPoint.ToVector2(), actionTime, id);
            controller.ReleaseMouse(actionTime, id);
            controller.SetMouse(Vector2.zero, id);

            controller.Play(id);
        }
    }