Exemplo n.º 1
0
    public void setRatings(Vector2 toAim)
    {
        topAttacks.Clear();

        int range = convertVectorToAbstractRange(ShitUtilities.getVectorLength(toAim)); // Get range

        for (int i = 0; i < attacks.Length; ++i)
        {
            AttackBase attack       = attacks[i];
            int[]      attackRanges = attack.getDesirableRange();

            foreach (int r in attackRanges)
            {
                if (r == range && isAttackCooldownZero(attack) && !topAttacks.Contains(attack))
                {
                    topAttacks.Add(attack);
                }
            }
        }

        /*Debug.Log("-");
        *  Debug.Log(range);
        *  Debug.Log(topAttacks.Count);
        *  Debug.Log("-");*/
        // calc range diff
        // calc cooldown
    }
Exemplo n.º 2
0
Arquivo: Brain.cs Projeto: NeoD1m/VH
    void calculateMovement()
    {
        float      minLen                     = float.MaxValue;
        Collider2D closestObstacle            = new Collider2D();
        Vector2    directionToClosestObstacle = new Vector2();

        // Moving towards the player
        Vector2 directionToPlayer = getVectorFromBossToPlayer().normalized;
        float   sizeToPlayer      = ShitUtilities.getVectorLength(directionToPlayer);


        float playerMovementM = (sizeToPlayer - ApproachThePlayer) * PathStraightforwardness;

        // Moving around obstacles
        foreach (Collider2D obstacle in totalCommander.obstacles)
        {
            if (obstacle != null)
            {
                Vector2            directionToObstacle;
                float              sizeToObstacle = myLegsCollider.Distance(obstacle).distance;
                ColliderDistance2D tmpCD          = myLegsCollider.Distance(obstacle);
                directionToObstacle = tmpCD.normal;

                if (sizeToObstacle < minLen)
                {
                    minLen                     = sizeToObstacle;
                    closestObstacle            = obstacle;
                    directionToClosestObstacle = directionToObstacle;
                }
                // Give to him who asks of you, and do not turn away from him who wants to borrow from you. MF 5:42
            }
        }


        if (minLen < 0.1f)
        {
            minLen = 0.1f;
        }

        float obstacleMovementM = (AvoidObstacles / minLen);

        float theDifference // Between An Amature And A Professional Is That You Write Your Own Compiler
            = Mathf.Abs((directionToPlayer + directionToClosestObstacle).x) + Mathf.Abs((directionToPlayer + directionToClosestObstacle).y);

        if (theDifference < 0.1f && aim == AIM_PLAYER && minLen < 2f)
        {
            //log("My aim has changed. I am moving towards PATH");

            int   mode   = 0;
            float shortX = directionToPlayer.x;
            float shortY = directionToPlayer.y;

            if (isCloseTo0(shortX + 1) && isCloseTo0(shortY))
            {
                mode = MovementPointsCalculator.CODE_RIGHT; // Right
            }
            if (isCloseTo0(shortX - 1) && isCloseTo0(shortY))
            {
                mode = MovementPointsCalculator.CODE_LEFT; // Left
            }
            if (isCloseTo0(shortX) && isCloseTo0(shortY - 1))
            {
                mode = MovementPointsCalculator.CODE_BOTTOM; // Bottom
            }
            if (isCloseTo0(shortX) && isCloseTo0(shortY + 1))
            {
                mode = MovementPointsCalculator.CODE_TOP; // Top
            }
            aim = AIM_POINT;
            List <Point> path = MovementPointsCalculator.GetRandomPathForOurSituation(mode, closestObstacle, myLegsCollider);
            foreach (Point p in path)
            {
                points.Add(p);
            }
        }

        if (aim == AIM_POINT)
        {
            Vector2 directionToAim = -(transform.position - points[0].getPosition());
            float   distToPoint    = ShitUtilities.getVectorLength(directionToAim);


            if (distToPoint < 0.05f)
            {
                //log("I've reached the POINT");
                points.RemoveAt(0);
                if (points.Count == 0)
                {
                    //log("My aim has changed. I am moving towards PLAYER");
                    aim = AIM_PLAYER;
                }
                else
                {
                    //log("New POINT is at: " + points[0].x + " " + points[0].y);
                }
            }

            if (attackChooser.isNoObstaclesToPlayer())
            {
                points.Clear();
                aim = AIM_PLAYER;
            }
        }

        Vector2 mainVector = new Vector2();

        switch (aim)
        {
        case AIM_PLAYER:
            mainVector  = directionToPlayer * playerMovementM;
            mainVector += directionToClosestObstacle * obstacleMovementM;
            break;

        case AIM_POINT:
            Vector2 directionToAim = -(transform.position - points[0].getPosition()).normalized;
            if (points.Count > 0)
            {
                mainVector = directionToAim * playerMovementM;
            }
            else
            {
                log("WARNING! I lost point to go.", true);
                aim = AIM_PLAYER;
            }
            break;
        }



        movementDirection = mainVector;
        //movementDirection += -perpDirection * obstacleMovementM;

        Vector2 difference = directionToClosestObstacle; //-directionToClosestObstacle;

        difference.Normalize();
        float rotationZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;

        if (rotationZ == 0f)
        {
            rotationZ = 0.000001f;
        }
        movementPointer.transform.rotation = Quaternion.Euler(0f, 0f, rotationZ);

        Vector2 difference2 = -mainVector;

        difference2.Normalize();
        float rotationZ2 = Mathf.Atan2(difference2.y, difference2.x) * Mathf.Rad2Deg;

        if (rotationZ2 == 0f)
        {
            rotationZ2 = 0.000001f;
        }
        movementPointer2.transform.rotation = Quaternion.Euler(0f, 0f, rotationZ2);
        //Debug.Log(closestObstacle.name.ToString() + " " + minLen.ToString());

        movementDirection = movementDirection.normalized;
    }