示例#1
0
    //Vector3 theLastMovingFormingStartingPlaceOnFloor_ = Vector3.zero;
    //Vector3 theOriginalCurrentTargetPoint_ = Vector3.zero;
    //Vector3 theCurrentTargetPoint_ = Vector3.zero;

    private List <MovingScheduleElement> buildMovingScheduleToPoint(Vector2 inPoint)
    {
        List <MovingScheduleElement> theResult = new List <MovingScheduleElement>();

        //Debug.Log("~~~~~~~~~~~{{{");
        Vector2 theCurrentPointOnFloor = getPointOnFloor(transform.position);
        //Debug.Log("~~~~~~~~~~~}}}");

        Vector2 theTargetPointOnFloor = getPointOnFloor(inPoint);

        //theLastMovingFormingStartingPlaceOnFloor_ = theCurrentPointOnFloor;
        //theOriginalCurrentTargetPoint_ = inPoint;
        //theCurrentTargetPoint_ = theTargetPointOnFloor;

        int theIterationsGuard = 10;

        while (true)
        {
            FloorDirection theDirection = getFloorDirectionToAchievePosition(theCurrentPointOnFloor.y, theTargetPointOnFloor.y);
            if (FloorDirection.None == theDirection)
            {
                break;
            }

            Stairs theRightNearestStairs = getNearestStairs(theCurrentPointOnFloor, true, theDirection);
            Stairs theLeftNearestStairs  = getNearestStairs(theCurrentPointOnFloor, false, theDirection);

            if (!theRightNearestStairs && !theLeftNearestStairs)
            {
                throw new System.Exception("Cannot find any stairs");
            }

            MovingScheduleElement theStairsScheduleElement = new MovingScheduleElement();
            theStairsScheduleElement.movingDirection = theRightNearestStairs ? MovingDirection.Right : MovingDirection.Left;
            theStairsScheduleElement.movingTarget    = MovingTarget.MoveUntilStairs;
            theStairsScheduleElement.targetStairs    = theRightNearestStairs ? theRightNearestStairs : theLeftNearestStairs;
            theResult.Add(theStairsScheduleElement);

            theCurrentPointOnFloor = getPointOnFloor(theStairsScheduleElement.targetStairs.endPointPosition);

            if (--theIterationsGuard < 0)
            {
                throw new System.Exception("Too many pathfind iterationis");
            }
        }

        MovingScheduleElement theScheduleElement = new MovingScheduleElement();

        theScheduleElement.movingDirection = (theTargetPointOnFloor.x > theCurrentPointOnFloor.x) ? MovingDirection.Right : MovingDirection.Left;
        theScheduleElement.movingTarget    = MovingTarget.MoveUntilPoint;
        theScheduleElement.targetPoint     = theTargetPointOnFloor;
        theResult.Add(theScheduleElement);

        //Debug.Log("PATH REQUEST [" + gameObject.name + "] {{{");
        //foreach (MovingScheduleElement theElement in theResult)
        //    Debug.Log("[" + theElement.movingDirection + "|" + theElement.movingTarget + "|" + theElement.targetPoint + "|" + theElement.targetStairs + "]");
        //Debug.Log("}}}");

        return(theResult);
    }
示例#2
0
    Stairs getNearestStairs(Vector2 inPointToFindFrom, bool inFindRight, FloorDirection inDirection)
    {
        float theCastingRadius   = 1f;
        float theCastingDistance = 100f;

        float   theCastingVectorSign     = inFindRight ? 1f : -1f;
        Vector2 theCastingDistanceVector = Vector2.right * theCastingDistance * theCastingVectorSign;

        RaycastHit2D[] theHits = Physics2D.CircleCastAll(
            inPointToFindFrom, theCastingRadius, theCastingDistanceVector);
        Boxed <RaycastHit2D> theNearestHit = getNearestHitByType <Stairs>(inPointToFindFrom, theHits,
                                                                          (Stairs inStairs) =>
        {
            return((FloorDirection.Down == inDirection && !inStairs.isForMovingUp) ||
                   (FloorDirection.Up == inDirection && inStairs.isForMovingUp));
        });

        return((null != theNearestHit) ? theNearestHit.value.collider.GetComponent <Stairs>() : null);
    }
示例#3
0
 public void ResetPlayerFloor()
 {
     if (SetGravityDirection.gDirection == SetGravityDirection.GDirection.DOWN)
     {
         floorDirection = PlayerController.FloorDirection.DOWN;
     }
     else if (SetGravityDirection.gDirection == SetGravityDirection.GDirection.UP)
     {
         floorDirection = PlayerController.FloorDirection.UP;
     }
     else if (SetGravityDirection.gDirection == SetGravityDirection.GDirection.LEFT)
     {
         floorDirection = PlayerController.FloorDirection.LEFT;
     }
     else if (SetGravityDirection.gDirection == SetGravityDirection.GDirection.RIGHT)
     {
         floorDirection = PlayerController.FloorDirection.RIGHT;
     }
 }
示例#4
0
        private void frmGame_Load(object sender, EventArgs e)
        {
            Rand = new Random();

            // create the player.
            Player = new Player();

            // first, generate a name.
            // name generator's...names from: http://www.goodsandgoodies.com/wq/bashwe-dungeonnames.pdf
            switch (Rand.Pick<NameStructure>(new List<NameStructure>() { NameStructure.Prefix, NameStructure.Prefix2x, NameStructure.Suffix,
            NameStructure.PrefixAndSuffix, NameStructure.Prefix2xAndSuffix }))
            {
                case NameStructure.Prefix:
                    this.Name = "The {0} {1}".FormatBy(GeneratePrefix(Rand), GenerateLocation(Rand));
                    break;

                case NameStructure.Prefix2x:
                    this.Name = "The {0}-{1} {2}".FormatBy(GeneratePrefix(Rand), GeneratePrefix(Rand), GenerateLocation(Rand));
                    break;

                case NameStructure.Suffix:
                    this.Name = "The {0} of {1}".FormatBy(GenerateLocation(Rand), GenerateSuffix(Rand));
                    break;

                case NameStructure.PrefixAndSuffix:
                    this.Name = "The {0} {1} of {2}".FormatBy(GeneratePrefix(Rand), GenerateLocation(Rand), GenerateSuffix(Rand));
                    break;

                case NameStructure.Prefix2xAndSuffix:
                    this.Name = "The {0}-{1} {2} of {3}".FormatBy(GeneratePrefix(Rand), GeneratePrefix(Rand), GenerateLocation(Rand), GenerateSuffix(Rand));
                    break;
            }

            // pick whether the dungeon is ascending or descending.
            Direction = Rand.Pick<FloorDirection>(new List<FloorDirection>() { FloorDirection.Ascending, FloorDirection.Descending });
            SetFloor();
            SetPoints();

            // set the grid up.
            MapCells = new Cell[15, 10];
            for (int x = 0; x < 15; x++)
            {
                for (int y = 0; y < 10; y++)
                {
                    Label lbl = new Label();
                    lbl.Text = " ";
                    lbl.AutoSize = false;
                    lbl.Size = new System.Drawing.Size(46, 46);
                    lbl.Location = new Point(46 * x, 46 * y);
                    lbl.TextAlign = ContentAlignment.MiddleCenter;
                    lbl.Font = new System.Drawing.Font("Segoe UI", 16);
                    pnlGame.Controls.Add(lbl);
                    MapCells[x, y] = new Cell(lbl);
                }
            }

            // play a random song.
            PlayRandomSong();

            // generate a new map and display.
            GenerateNewMap();
            Update();
        }
示例#5
0
        private void frmGame_Load(object sender, EventArgs e)
        {
            Rand = new Random();

            // create the player.
            Player = new Player();

            // first, generate a name.
            // name generator's...names from: http://www.goodsandgoodies.com/wq/bashwe-dungeonnames.pdf
            switch (Rand.Pick <NameStructure>(new List <NameStructure>()
            {
                NameStructure.Prefix, NameStructure.Prefix2x, NameStructure.Suffix,
                NameStructure.PrefixAndSuffix, NameStructure.Prefix2xAndSuffix
            }))
            {
            case NameStructure.Prefix:
                this.Name = "The {0} {1}".FormatBy(GeneratePrefix(Rand), GenerateLocation(Rand));
                break;

            case NameStructure.Prefix2x:
                this.Name = "The {0}-{1} {2}".FormatBy(GeneratePrefix(Rand), GeneratePrefix(Rand), GenerateLocation(Rand));
                break;

            case NameStructure.Suffix:
                this.Name = "The {0} of {1}".FormatBy(GenerateLocation(Rand), GenerateSuffix(Rand));
                break;

            case NameStructure.PrefixAndSuffix:
                this.Name = "The {0} {1} of {2}".FormatBy(GeneratePrefix(Rand), GenerateLocation(Rand), GenerateSuffix(Rand));
                break;

            case NameStructure.Prefix2xAndSuffix:
                this.Name = "The {0}-{1} {2} of {3}".FormatBy(GeneratePrefix(Rand), GeneratePrefix(Rand), GenerateLocation(Rand), GenerateSuffix(Rand));
                break;
            }

            // pick whether the dungeon is ascending or descending.
            Direction = Rand.Pick <FloorDirection>(new List <FloorDirection>()
            {
                FloorDirection.Ascending, FloorDirection.Descending
            });
            SetFloor();
            SetPoints();

            // set the grid up.
            MapCells = new Cell[15, 10];
            for (int x = 0; x < 15; x++)
            {
                for (int y = 0; y < 10; y++)
                {
                    Label lbl = new Label();
                    lbl.Text      = " ";
                    lbl.AutoSize  = false;
                    lbl.Size      = new System.Drawing.Size(46, 46);
                    lbl.Location  = new Point(46 * x, 46 * y);
                    lbl.TextAlign = ContentAlignment.MiddleCenter;
                    lbl.Font      = new System.Drawing.Font("Segoe UI", 16);
                    pnlGame.Controls.Add(lbl);
                    MapCells[x, y] = new Cell(lbl);
                }
            }

            // play a random song.
            PlayRandomSong();

            // generate a new map and display.
            GenerateNewMap();
            Update();
        }