Exemple #1
0
        private void Update()
        {
            var fovPos = WorldToConsolePos(transform.position);

            _testMap.visiblePoints.Clear();
            //var points = FOV.GetVisiblePoints(fovPos, _range, _testMap, Allocator.Temp).ToNativeArray();
            FOV.Compute(fovPos, _range, _testMap);

            _console.ClearScreen();

            foreach (var p in _testMap.visiblePoints)
            {
                char ch = _testMap.IsOpaque(p) ? '#' : '.';
                _console.Set(p.x, p.y, Color.white, Color.black, CodePage437.ToCP437(ch));
            }
        }
Exemple #2
0
    public void Print(int x, int y, string str)
    {
        _isDirty = true;

        _tileJobs.Complete();

        var bytes = CodePage437.StringToCP437(str, Allocator.TempJob);

        new WriteTileGlyphsJob
        {
            bytes = bytes,
            pos   = new int2(x, y),
            tiles = _tiles,
            width = Size.x,
        }.Run();
    }
Exemple #3
0
    public void PrintColor(int x, int y, string str, Color fgColor, Color bgColor)
    {
        _isDirty = true;
        _tileJobs.Complete();

        var bytes = CodePage437.StringToCP437(str, Allocator.TempJob);

        new WriteColoredTileGlyphsJob
        {
            bytes       = bytes,
            pos         = new int2(x, y),
            destination = _tiles,
            width       = Size.x,
            fgColor     = fgColor,
            bgColor     = bgColor
        }.Run();
    }
Exemple #4
0
        public JobHandle SchedulePrint(int x, int y, string str, JobHandle inputDeps = default)
        {
            _isDirty = true;

            _tileJobs = JobHandle.CombineDependencies(_tileJobs, inputDeps);

            var bytes = CodePage437.StringToCP437(str, Allocator.TempJob);

            _tileJobs = new WriteTileGlyphsJob
            {
                bytes = bytes,
                pos   = new int2(x, y),
                tiles = _tiles,
                width = Size.x
            }.Schedule(_tileJobs);


            return(_tileJobs);
        }
        void RenderView(
            DynamicBuffer <MapTiles> map,
            DynamicBuffer <TilesInView> view,
            NativeArray <Tile> consoleTiles,
            int2 mapSize)
        {
            Job.WithCode(() =>
            {
                Color fg = default;
                Color bg = Color.black;
                char ch  = default;
                for (int i = 0; i < map.Length; ++i)
                {
                    if (view[i])
                    {
                        var tileType = (TileType)map[i];

                        switch (tileType)
                        {
                        case TileType.Floor:
                            fg = new Color(0, .5f, .5f);
                            ch = '.';
                            break;

                        case TileType.Wall:
                            fg = new Color(0, 1, 0);
                            ch = '#';
                            break;
                        }

                        consoleTiles[i] = new Tile
                        {
                            fgColor = fg,
                            bgColor = bg,
                            glyph   = CodePage437.ToCP437(ch)
                        };
                    }
                }
            }).Run();

            RenderEntitiesInView(consoleTiles, view, mapSize);
        }
Exemple #6
0
 static byte Select(float v)
 {
     if (v >= .75f)
     {
         return(CodePage437.ToCP437('█'));
     }
     else if (v < .75f && v >= .55f)
     {
         return(CodePage437.ToCP437('▓'));
     }
     else if (v < .55f && v >= .35f)
     {
         return(CodePage437.ToCP437('▒'));
     }
     else if (v < .35f && v >= .15f)
     {
         return(CodePage437.ToCP437('░'));
     }
     return(0);
 }
Exemple #7
0
        public JobHandle SchedulePrintColor(int x, int y, string str, Color fgColor, Color bgColor, JobHandle inputDeps)
        {
            _isDirty = true;

            _tileJobs = JobHandle.CombineDependencies(_tileJobs, inputDeps);

            var bytes = CodePage437.StringToCP437(str, Allocator.TempJob);

            _tileJobs = new WriteColoredTileGlyphsJob
            {
                bytes       = bytes,
                pos         = new int2(x, y),
                destination = _tiles,
                width       = Size.x,
                fgColor     = fgColor,
                bgColor     = bgColor
            }.Schedule(_tileJobs);

            return(_tileJobs);
        }
        void RenderMemory(
            DynamicBuffer <MapTiles> map,
            DynamicBuffer <TilesInMemory> memory,
            NativeArray <Tile> consoleTiles,
            int2 mapSize)
        {
            Job.WithCode(() =>
            {
                Color fg = default;
                Color bg = Color.black;
                char ch  = default;
                for (int i = 0; i < map.Length; ++i)
                {
                    if (memory[i])
                    {
                        var tileType = (TileType)map[i];

                        fg = new Color(0.1f, .1f, 0.1f);
                        switch (tileType)
                        {
                        case TileType.Floor:
                            ch = '.';
                            break;

                        case TileType.Wall:
                            ch = '#';
                            break;
                        }

                        consoleTiles[i] = new Tile
                        {
                            fgColor = fg,
                            bgColor = bg,
                            glyph   = CodePage437.ToCP437(ch)
                        };
                    }
                }
            }).Run();
        }
Exemple #9
0
        public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
        {
            dstManager.AddComponent <Monster>(entity);
            dstManager.AddComponent <Position>(entity);
            dstManager.AddComponent <TilesInView>(entity);
            dstManager.AddComponent <Energy>(entity);
            dstManager.AddComponent <Prefab>(entity);
            dstManager.AddComponent <Actor>(entity);

            dstManager.AddComponent <Collidable>(entity);

            dstManager.AddComponentData <ViewRange>(entity, _viewRange);
            dstManager.AddComponentData <Speed>(entity, _speed);
            dstManager.AddComponentData <Name>(entity, name);
            dstManager.AddComponentData <Health>(entity, _health);

            dstManager.AddComponentData <Renderable>(entity, new Renderable
            {
                bgColor = Color.black,
                fgColor = _color,
                glyph   = CodePage437.ToCP437(_glyph)
            });
        }