public static Vector3 Inside(this IRandomProvider random, AABox box)
 => new Vector3
 (
     x: box.Min.x + box.Size.x * random.GetNext(),
     y: box.Min.y + box.Size.y * random.GetNext(),
     z: box.Min.z + box.Size.z * random.GetNext()
 );
        public static Vector2 Direction(this IRandomProvider random)
        {
            Vector2 dir = new Vector2(random.GetNext() - .5f, random.GetNext() - .5f);

            if (dir == Vector2.zero)            //Should be very rare
            {
                return(Vector2.up);
            }
            return(MathUtils.FastNormalize(dir));
        }
        public static Vector2 Direction2D(this IRandomProvider random)
        {
            var dir = new Vector2
                      (
                x: random.GetNext() - .5f,
                y: random.GetNext() - .5f
                      );

            if (dir == Vector2.zero) //Should be very rare
            {
                return(Vector2.up);
            }
            return(FastNormalize(dir));
        }
        protected override void ExecuteSubtask(int execID, int index)
        {
            Vector3 position = random.Inside(spawnArea);

            var entity = context.CreateEntity();

            context.SetComponent(entity, new TransformComponent(Float3x4.FromPosition(position)));
            context.SetComponent(entity, new GraphicComponent(graphicID: 1));
            context.SetComponent(entity, new ProjectileSpawnerComponent(cooldown: random.GetNext() * 5f));
        }
Exemple #5
0
        public void StartMove(ref Pacman pacman, CheckPosition startPosition, Checker checker, int index)
        {
            var currentPosition = startPosition;

            for (var i = 0; i < (int)GameRules.NumberOfOneGameMove; i++)
            {
                var allSituation = checker.Checks[currentPosition];
                var action       = (Actions)pacman.Strategy.Lines.FirstOrDefault(x => x.Key == string.Join("", allSituation)).Value;
                var rnd          = new Random();
                while (action == Actions.Random || action == Actions.Freeze)
                {
                    action = (Actions)_randomPro.GetNext(rnd, 7);
                }

                switch (action)
                {
                case Actions.Freeze:
                    continue;

                case Actions.Up:
                case Actions.Right:
                case Actions.Down:
                case Actions.Left:
                    var nextCheck = (Situations)allSituation[(int)action];
                    if (nextCheck == Situations.Wall)
                    {
                        pacman.Points[index] = pacman.Points[index] + (int)Points.HitWall;
                    }
                    else
                    {
                        currentPosition      = GetNextPosition(currentPosition, action);
                        pacman.Points[index] = pacman.Points[index] + (int)Points.Move;
                    }
                    break;

                case Actions.Eat:
                    if ((Situations)allSituation[(int)Check.Me] == Situations.Bean)
                    {
                        pacman.Points[index] = pacman.Points[index] + (int)Points.EatBean;
                        CheckerChange(ref checker, currentPosition);
                    }
                    else
                    {
                        pacman.Points[index] = pacman.Points[index] + (int)Points.EatEmpty;
                    }
                    break;
                }
            }
        }
 public static float Between(this IRandomProvider random, float minValue, float maxValue)
 {
     return(minValue + (maxValue - minValue) * random.GetNext());
 }
        protected void Update()
        {
            if (taskManager == null)
            {
                return;
            }

            //---> Update target info based on the linked-in transform
            UpdateTargetInfo(target1Trans, ref target1Position, ref target1Velocity);
            UpdateTargetInfo(target2Trans, ref target2Position, ref target2Velocity);

            //---> Render the data from the previous tasks
            if (completeDependency != null)
            {
                completeProfilerTrack.LogStartWork();
                {
                    //Wait for (and help out with) completing the tasks from the previous frame
                    completeDependency.Complete();
                }
                completeProfilerTrack.LogEndWork();

                //Render the results from the previous tasks
                renderProfilerTrack.LogStartWork();
                {
                    renderSet.Render();
                    renderSet.Clear();
                }
                renderProfilerTrack.LogEndWork();
            }

            //---> Update the tasks with info from the inspector
            avoidanceHasher.CellSize             = avoidanceCellSize;
            avoidanceHasher.Fuzz                 = random.GetNext(); //Apply random fuzz to make the grid less noticable
            moveCubeTask.CubeRadius              = cubeRadius;
            moveCubeTask.CubeSeperationForce     = cubeSeperationForce;
            moveCubeTask.CubeVeloInheritance     = cubeVeloInheritance;
            moveCubeTask.TargetRadius            = targetRadius;
            moveCubeTask.TargetSeperationForce   = targetSeperationForce;
            moveCubeTask.TargetVeloInheritance   = targetVeloInheritance;
            moveCubeTask.DeltaTime               = Time.deltaTime;
            moveCubeTask.Target1Position         = target1Position;
            moveCubeTask.Target1Velocity         = target1Velocity;
            moveCubeTask.Target2Position         = target2Position;
            moveCubeTask.Target2Velocity         = target2Velocity;
            respawnCubeTask.MaxDistance          = maxDistanceBeforeRespawn;
            respawnCubeTask.RespawnArea          = MathUtils.FromCenterAndSize(Vector2.zero, respawnAreaSize);
            respawnCubeTask.RespawnForce         = respawnForce;
            addToRenderSetTask.HitByTarget1Color = hitByTarget1Color;
            addToRenderSetTask.HitByTarget2Color = hitByTarget2Color;

            //---> Clear some data from the previous frame
            bucketedCubes.Clear();

            //---> Schedule tasks for this frame
            //NOTE: there is no safety yet, so you manually need to check what resources the taska are
            //using and setup dependencies between the tasks accordingly
            IDependency startDep = taskManager.ScheduleSingle
                                   (
                task: startTask
                                   );
            IDependency bucketCubesDep = taskManager.ScheduleArray
                                         (
                data: cubeData,
                task: bucketCubeTask,
                batchSize: batchSize,
                dependency: startDep,
                tracker: bucketCubesProfilerTrack
                                         );
            IDependency updateCubeDep = taskManager.ScheduleArray
                                        (
                data: cubeData,
                task: moveCubeTask,
                batchSize: batchSize,
                dependency: bucketCubesDep,
                tracker: moveCubesProfilerTrack
                                        );
            IDependency respawnCubesDep = taskManager.ScheduleArray
                                          (
                data: cubeData,
                task: respawnCubeTask,
                batchSize: batchSize,
                dependency: updateCubeDep,
                tracker: respawnCubesProfilerTrack
                                          );
            IDependency addToRenderSetDep = taskManager.ScheduleArray
                                            (
                data: cubeData,
                task: addToRenderSetTask,
                batchSize: RenderSet.BATCH_SIZE,
                dependency: respawnCubesDep,
                tracker: addToRenderSetProfilerTrack
                                            );

            //---> Setup the finish dependency
            completeDependency = addToRenderSetDep;
        }