public virtual List <Vector2> TryRotate(List <Vector2> current, rotations currentRotation, rotationDirection direction)
        {
            Vector2 center = getCenter(current);

            if (direction == rotationDirection.clockwise)
            {
                List <Vector2> newcurrent = new List <Vector2>();
                foreach (Vector2 v in current)
                {
                    newcurrent.Add(RotatePointClockwise(v, center));
                }
                this.position = (this.position + 1) % 4;
                return(newcurrent);
            }

            if (direction == rotationDirection.counterclockwise)
            {
                List <Vector2> newcurrent = new List <Vector2>();
                foreach (Vector2 v in current)
                {
                    newcurrent.Add(RotatePointCounterClockwise(v, center));
                }
                this.position = (this.position + 3) % 4;
                return(newcurrent);
            }
            return(current);
        }
    // randomly adds the given parts within the budget
    void GenerateParts(int evoPointAllowance, List <Segment> segments)
    {
        List <Vector2> validBuildSpaces = ValidBuildSpaces();
        int            maxTries         = 10;

        while (evoPointAllowance > 0 && validBuildSpaces.Count > 0 && segments.Count > 0 && maxTries > 0)
        {
            // Get our random values together
            Segment   randomSegment    = segments[Random.Range(0, segments.Count)];
            Vector2   randomBuildSpace = validBuildSpaces[Random.Range(0, validBuildSpaces.Count)];
            rotations randomRotation   = 0;
            if (!randomSegment.multidirectional)
            {
                List <rotations> validRotations = ValidRotations(randomBuildSpace, randomSegment);
                if (validRotations.Count > 0)
                {
                    // hard code some priority here to improve symmetry, may revisit this later since we lose a lot of the random elements with this change
                    if (validRotations.Contains(rotations.UP))
                    {
                        randomRotation = rotations.UP;
                    }
                    else if (validRotations.Contains(rotations.DOWN))
                    {
                        randomRotation = rotations.DOWN;
                    }
                    else
                    {
                        randomRotation = validRotations[0];
                    }
                }
            }

            // See if we are building two items or one and make sure we can afford it
            if ((randomBuildSpace.x == 0 && evoPointAllowance > randomSegment.pointCost) ||
                (randomBuildSpace.x != 0 && evoPointAllowance > randomSegment.pointCost * 2))
            {
                AddSegmentYSymetrical(randomBuildSpace,
                                      randomRotation,
                                      randomSegment);
                if (randomBuildSpace.x == 0)
                {
                    evoPointAllowance -= randomSegment.pointCost;
                }
                else
                {
                    evoPointAllowance -= (randomSegment.pointCost * 2);
                }
                validBuildSpaces = ValidBuildSpaces();
            }
            maxTries--;
        }
    }
        public virtual List <Vector2> Rotate(List <Vector2> current, rotations currentRotation, rotationDirection direction, ref char?[,] array)
        {
            int            oldposition   = this.position;
            List <Vector2> afterrotation = TryRotate(current, currentRotation, direction);
            List <Vector2> mayberotated;

            foreach (Vector2 offset in this.kicks[oldposition][this.position])
            {
                mayberotated = MovePiece(afterrotation, offset);
                if (IsLegalPosition(mayberotated, ref array))
                {
                    return(mayberotated);
                }
            }
            this.position = oldposition;
            return(current);
        }
Exemple #4
0
    ///////////////////////
    // ROTATION UTLITIES //
    ///////////////////////

    // converts a rotation to world space degrees
    public static int RotationToInt(rotations currentRotation)
    {
        switch (currentRotation)
        {
        case rotations.UP:
            return(0);

        case rotations.DOWN:
            return(180);

        case rotations.LEFT:
            return(90);

        case rotations.RIGHT:
            return(270);

        default:
            return(0);
        }
    }
Exemple #5
0
 // Adds a new segment to the given location and also adds a new segment mirrored along the y axis
 public void AddSegmentYSymetrical(Vector2 buildUnits, rotations currentRotation, Segment segment)
 {
     if (buildUnits.x == 0)
     {
         AddSegment(buildUnits, currentRotation, segment);
     }
     else
     {
         AddSegment(buildUnits, currentRotation, segment);
         rotations _altRot = currentRotation;
         if (currentRotation == rotations.LEFT)
         {
             _altRot = rotations.RIGHT;
         }
         else if (currentRotation == rotations.RIGHT)
         {
             _altRot = rotations.LEFT;
         }
         AddSegment(new Vector2(-buildUnits.x, buildUnits.y), _altRot, segment);
     }
 }
Exemple #6
0
    //////////////////////////////////
    // SEGMENT CREATION AND REMOVAL //
    //////////////////////////////////

    // adds a new segment to a location (if possible), adjusts the placeable chart and adjusts stats
    public void AddSegment(Vector2 buildUnits, rotations currentRotation, Segment segment)
    {
        if (CheckPlace(buildUnits))
        {
            if (segment &&
                evoPoints >= segment.pointCost &&
                (segment.multidirectional || CheckRot(buildUnits, currentRotation)))
            {
                Segment newSegment = ((GameObject)Instantiate(segment.gameObject,
                                                              (buildUnits + new Vector2(this.transform.position.x, this.transform.position.y)),
                                                              Quaternion.Euler(new Vector3(0, 0, RotationToInt(currentRotation) + transform.rotation.eulerAngles.z)))).GetComponent <Segment>();

                // set location
                newSegment.transform.parent        = this.transform;
                newSegment.creature                = this;
                newSegment.transform.localPosition = new Vector2(buildUnits.x, buildUnits.y);

                // add segment to the array
                SetSegmentAt(buildUnits, newSegment);

                // set placeable locations
                RecalculatePlace(buildUnits);
                RecalculateNeighborPlaces(buildUnits);

                // set color
                newSegment.GetComponent <SpriteRenderer>().color = color;

                // set stats
                UpdateEvoPoints(evoPoints - segment.pointCost);
                totalHealth += segment.healthBonus;
                totalEnergy += segment.energyBonus;
                totalSpeed  += segment.speedBonus;
                weight      += segment.weightBonus;

                stimulus.worth  += segment.pointCost / 2;
                stimulus.threat += segment.threat;
            }
        }
    }
Exemple #7
0
    // checks if the given piece is valid with its given rotation
    protected bool CheckRot(Vector2 buildUnits, rotations currentRotation)
    {
        Segment segment;

        switch (currentRotation)
        {
        case rotations.UP:
            segment = GetSegmentAt(buildUnits + Vector2.down);
            return(segment != null && segment.multidirectional);

        case rotations.DOWN:
            segment = GetSegmentAt(buildUnits + Vector2.up);
            return(segment != null && segment.multidirectional);

        case rotations.LEFT:
            segment = GetSegmentAt(buildUnits + Vector2.right);
            return(segment != null && segment.multidirectional);

        case rotations.RIGHT:
            segment = GetSegmentAt(buildUnits + Vector2.left);
            return(segment != null && segment.multidirectional);
        }
        return(false);
    }
        public override List <Vector2> TryRotate(List <Vector2> current, rotations currentRotation, rotationDirection direction)
        {
            if (direction == rotationDirection.clockwise)
            {
                this.position = (this.position + 1) % 4;
            }
            else
            {
                this.position = (this.position + 3) % 4;
            }

            int   maxX = 0;
            int   minX = 10;
            float centerX;
            int   maxY = -5;
            int   minY = 20;
            float centerY;

            foreach (Vector2 v in current)
            {
                if (v.X > maxX)
                {
                    maxX = (int)v.X;
                }
                if (v.X < minX)
                {
                    minX = (int)v.X;
                }
                if (v.Y > maxY)
                {
                    maxY = (int)v.Y;
                }
                if (v.Y < minY)
                {
                    minY = (int)v.Y;
                }
            }
            centerX = (minX + maxX) / 2;
            centerY = (minY + maxY) / 2;

            if (currentRotation == rotations.rotation1 && direction == rotationDirection.clockwise)
            {
                return(new List <Vector2> {
                    new Vector2(centerX + 1.5f, centerY + 2), new Vector2(centerX + 1.5f, centerY + 1), new Vector2(centerX + 1.5f, centerY), new Vector2(centerX + 1.5f, centerY - 1)
                });
            }
            if (currentRotation == rotations.rotation1 && direction == rotationDirection.counterclockwise)
            {
                return(new List <Vector2> {
                    new Vector2(centerX + 0.5f, centerY + 2), new Vector2(centerX + 0.5f, centerY + 1), new Vector2(centerX + 0.5f, centerY), new Vector2(centerX + 0.5f, centerY - 1)
                });
            }

            if (currentRotation == rotations.rotation2 && direction == rotationDirection.clockwise)
            {
                return(new List <Vector2> {
                    new Vector2(centerX + 1, centerY + 1.5f), new Vector2(centerX, centerY + 1.5f), new Vector2(centerX - 1, centerY + 1.5f), new Vector2(centerX - 2, centerY + 1.5f)
                });
            }
            if (currentRotation == rotations.rotation2 && direction == rotationDirection.counterclockwise)
            {
                return(new List <Vector2> {
                    new Vector2(centerX + 1, centerY + 0.5f), new Vector2(centerX, centerY + 0.5f), new Vector2(centerX - 1, centerY + 0.5f), new Vector2(centerX - 2, centerY + 0.5f)
                });
            }

            if (currentRotation == rotations.rotation3 && direction == rotationDirection.clockwise)
            {
                return(new List <Vector2> {
                    new Vector2(centerX + 0.5f, centerY + 1), new Vector2(centerX + 0.5f, centerY), new Vector2(centerX + 0.5f, centerY - 1), new Vector2(centerX + 0.5f, centerY - 2)
                });
            }
            if (currentRotation == rotations.rotation3 && direction == rotationDirection.counterclockwise)
            {
                return(new List <Vector2> {
                    new Vector2(centerX + 1.5f, centerY + 1), new Vector2(centerX + 1.5f, centerY), new Vector2(centerX + 1.5f, centerY - 1), new Vector2(centerX + 1.5f, centerY - 2)
                });
            }

            if (currentRotation == rotations.rotation4 && direction == rotationDirection.clockwise)
            {
                return(new List <Vector2> {
                    new Vector2(centerX + 2, centerY + 0.5f), new Vector2(centerX + 1, centerY + 0.5f), new Vector2(centerX, centerY + 0.5f), new Vector2(centerX - 1, centerY + 0.5f)
                });
            }
            if (currentRotation == rotations.rotation4 && direction == rotationDirection.counterclockwise)
            {
                return(new List <Vector2> {
                    new Vector2(centerX + 2, centerY + 1.5f), new Vector2(centerX + 1, centerY + 1.5f), new Vector2(centerX, centerY + 1.5f), new Vector2(centerX - 1, centerY + 1.5f)
                });
            }

            return(current);
        }
 public override List <Vector2> Rotate(List <Vector2> current, rotations currentRotation, rotationDirection direction, ref char?[,] array)
 {
     return(current);
 }
    /// <summary>
    /// Rotate left or right.
    /// </summary>
    /// <param name="dir">Negative is left, Positive is right.</param>
    public void Rotate(int dir)
    {
        if (rotation == false)
        {
            if (dir > 0)
            {
                if (endrot < 360)
                {
                    endrot = endrot + 90;
                }
                else
                {
                    endrot = 90;
                }
            }
            else if (dir < 0)
            {
                if (endrot > 0)
                {
                    endrot = endrot - 90;
                }
                else
                {
                    endrot = 270;
                }
            }

            rotation = true;
        }

        if (endrot == 0 || endrot == 360)
        {
            _curRotation = rotations.north;
        }
        else if (endrot == 90)
        {
            _curRotation = rotations.east;
        }
        else if (endrot == 180)
        {
            _curRotation = rotations.south;
        }
        else if (endrot == 270)
        {
            _curRotation = rotations.west;
        }
    }