示例#1
0
        public void TakeTurn(MoveOpt Opt)
        {
            float[] ret = new float[3];

            ret[0] = Wiskers[0].Update();
            ret[1] = Wiskers[1].Update();
            ret[2] = Wiskers[2].Update();
            List<Vector2> circleContent = CircleSensor.Update(this.Dir);
            int[] pieSliceContent = PieSliceSensor.Update(this.Dir);

            switch (Opt)
            {
                case MoveOpt.LEFT:
                    {
                        if (circle.AngularVelocity < 70)
                            circle.ApplyTorque((.5f) / 100f);
                        break;
                    }
                case MoveOpt.RIGHT:
                    {
                        if (circle.AngularVelocity > -70)
                            circle.ApplyTorque((-.5f) / 100f);
                        break;
                    }
                case MoveOpt.FORWARD:
                    {
                        circle.ApplyForce(circle.Rotation.GetVecFromAng() * speed * 2, circle.Position);
                        break;
                    }
                case MoveOpt.BACK:
                    {
                        circle.ApplyForce(circle.Rotation.GetVecFromAng() * -1 * speed, circle.Position);
                        break;
                    }
            }

            // Update player position and heading.
            this.Dir = circle.Rotation.GetVecFromAng();
            this.CurrentGridPos = circle.Position;

            // Update HUD for position/heading and each sensor type.
            // Update player info.
            HUD.UpdatePlayer(string.Format("Player Position: X={0:F2} Y={1:F2}; Heading: X={2:F2} Y={3:F2}", this.CurrentGridPos.X, this.CurrentGridPos.Y, this.Dir.X, this.Dir.Y));

            // Update whisker info.
            HUD.UpdateWhiskers(string.Format("{0:F2}", ret[2]), string.Format("{0:F2}", ret[0]), string.Format("{0:F2}", ret[1]));

            // Update circleSensor info.
            string adjacentInfo = "Agents: ";
            int i = 0;
            foreach(Vector2 otherAgent in circleContent)
            {
                i++;
                adjacentInfo += string.Format("{0}) dist: {1:F1}, angle: {2:F0}, ", i, otherAgent.X, otherAgent.Y);
            }
            HUD.UpdateAdjacents(adjacentInfo);

            // Update pieslice info.
            string pieSliceInfo = "PieSlices: ";
            pieSliceInfo += string.Format("Front: {0}, Left: {1}, Back: {2}, Right: {3}",
                pieSliceContent[0], pieSliceContent[1], pieSliceContent[2], pieSliceContent[3]);
            HUD.UpdatePieSlices(pieSliceInfo);
        }
        // Matches Android's Java API. Note, return (int)-1 for AT to
        // signal non-break because unsigned return type.
        public int getTextRunCursor(float advances, UInt16 buf, int start, int count, int offset, MoveOpt opt)
        {
            switch (opt)
            {
            case AFTER:
                if (offset < start + count)
                {
                    offset++;
                }

            // fall through
            //C++ TO C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
            case AT_OR_AFTER:
                while (!isGraphemeBreak(advances, buf, start, count, offset))
                {
                    offset++;
                }
                break;

            case BEFORE:
                if (offset > start)
                {
                    offset--;
                }

            // fall through
            //C++ TO C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
            case AT_OR_BEFORE:
                while (!isGraphemeBreak(advances, buf, start, count, offset))
                {
                    offset--;
                }
                break;

            case AT:
                if (!isGraphemeBreak(advances, buf, start, count, offset))
                {
                    //C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
                    //ORIGINAL LINE: offset = (int)-1;
                    offset.CopyFrom((int)-1);
                }
                break;
            }
            return(offset);
        }