コード例 #1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var mapEntity = this.mapQuery.GetSingletonEntity();
            var map       = this.EntityManager.GetMap(mapEntity);

            int2 move = this.GetSingleton <Move>();

            var max = new int2(map.Width - 1, map.Height - 1);
            var min = int2.zero;

            this.Entities.WithAll <Player>()
            .ForEach((ref Position position, ref ViewshedData viewshedData) =>
            {
                var destination    = position.Value + move;
                var destinationIdx = map.xy_idx(destination.x, destination.y);
                if (map.Tiles[destinationIdx] != TileType.Wall)
                {
                    position.Value     = clamp(destination, min, max);
                    viewshedData.Dirty = true;

                    this.SetSingleton <PlayerPosition>(position.Value);
                }
            })
            .WithoutBurst()
            .Run();

            return(default);
コード例 #2
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var mapEntity = this.mapQuery.GetSingletonEntity();
            var map       = this.EntityManager.GetMap(mapEntity);

            int2 move = default;

            if (Input.GetKeyDown(KeyCode.LeftArrow) ||
                Input.GetKeyDown(KeyCode.Keypad4) ||
                Input.GetKeyDown(KeyCode.H))
            {
                move.x = -1;
            }

            if (Input.GetKeyDown(KeyCode.RightArrow) ||
                Input.GetKeyDown(KeyCode.Keypad6) ||
                Input.GetKeyDown(KeyCode.L))
            {
                move.x = 1;
            }

            if (Input.GetKeyDown(KeyCode.UpArrow) ||
                Input.GetKeyDown(KeyCode.Keypad8) ||
                Input.GetKeyDown(KeyCode.K))
            {
                move.y = 1;
            }

            if (Input.GetKeyDown(KeyCode.DownArrow) ||
                Input.GetKeyDown(KeyCode.Keypad2) ||
                Input.GetKeyDown(KeyCode.J))
            {
                move.y = -1;
            }

            var max = new int2(map.Width - 1, map.Height - 1);
            var min = int2.zero;

            this.Entities.WithAll <Player>()
            .ForEach((ref Position position, ref ViewshedData viewshedData) =>
            {
                var destination    = position.Value + move;
                var destinationIdx = map.xy_idx(destination.x, destination.y);
                if (map.Tiles[destinationIdx] != TileType.Wall)
                {
                    position.Value     = clamp(destination, min, max);
                    viewshedData.Dirty = true;
                }
            })
            .Run();

            return(default);
コード例 #3
0
ファイル: PlayerMoveSystem.cs プロジェクト: Hengle/RogueDOTS
        protected override void OnUpdate()
        {
            var runState = this.GetSingleton<RunState>();

            if(runState != RunState.State.PlayerTurn)
            {
                return;
            }
            
            var mapEntity = this.mapQuery.GetSingletonEntity();
            var map = this.EntityManager.GetMap(mapEntity);

            int2 move = this.GetSingleton<Move>();
            
            var max = int2(map.Width - 1, map.Height - 1);
            var min = int2.zero;

            var combatStats = this.GetComponentDataFromEntity<CombatStats>();
            var ecb = new EntityCommandBuffer(Allocator.TempJob);

            this.Entities.WithAll<Player>()
                .ForEach((Entity entity, ref Position position, ref ViewshedData viewshedData) =>
                {
                    var destination = position + move;
                    var destinationIdx = map.xy_idx(destination.x, destination.y);
                    
                    var potentialTargets = map.TileContents[destinationIdx];

                    for(int i = 0; i < potentialTargets.Length; i++)
                    {
                        var potentialTarget = potentialTargets[i];

                        if(combatStats.HasComponent(potentialTarget))
                        {
                            ecb.AddComponent(entity, new WantsToMelee { Target = potentialTarget });
                            return;
                        }
                    }
                    
                    if(map.Tiles[destinationIdx] != TileType.Wall)
                    {
                        position = clamp(destination, min, max);
                        
                        this.SetSingleton(new PlayerPosition { Entity = entity, Value = position });
                    }
                })
                .WithoutBurst()
                .Run();
            
            ecb.Playback(this.EntityManager);
            ecb.Dispose();
        }
コード例 #4
0
ファイル: Map.cs プロジェクト: r2d2m/RogueDOTS
 public static void Deconstruct(this int2 value, out int x, out int y)
 {
     x = value.x;
     y = value.y;
 }