Ejemplo n.º 1
0
        public static TCODConsole LoadImage(string fileName)
        {
            var         transparentColor = new TCODColor(255, 0, 255);
            TCODConsole image            = null;

            try {
                using (var file = File.Open(fileName, FileMode.Open)) {
                    var decrompressedStream = new GZipStream(file, CompressionMode.Decompress);
                    var reader      = new BinaryReader(decrompressedStream);
                    var fileVersion = reader.ReadInt32();
                    var layerCount  = reader.ReadInt32();

                    // Reserving space for these in advance, so I'm not doing memory
                    // allocations repeatedly in the loop.
                    int       layerWidth = 0;
                    int       layerHeight = 0;
                    int       x, y;
                    int       characterCode = 0;
                    TCODColor foreground    = new TCODColor();
                    TCODColor background    = new TCODColor();

                    for (int layerIndex = 0; layerIndex < layerCount; ++layerIndex)
                    {
                        layerWidth  = reader.ReadInt32();
                        layerHeight = reader.ReadInt32();
                        if (image == null)
                        {
                            image = new TCODConsole(layerWidth, layerHeight);
                            image.setBackgroundColor(transparentColor);
                            image.clear();
                            image.setKeyColor(transparentColor);
                        }

                        for (var charIndex = 0; charIndex < layerWidth * layerHeight; ++charIndex)
                        {
                            x                = charIndex / layerHeight;
                            y                = charIndex % layerHeight;
                            characterCode    = reader.ReadInt32();
                            foreground.Red   = reader.ReadByte();
                            foreground.Green = reader.ReadByte();
                            foreground.Blue  = reader.ReadByte();
                            background.Red   = reader.ReadByte();
                            background.Green = reader.ReadByte();
                            background.Blue  = reader.ReadByte();

                            // Check if the current cell is transparent.
                            if (background.NotEqual(transparentColor))
                            {
                                image.putCharEx(x, y, characterCode, foreground, background);
                            }
                        }
                    }
                }
            } catch (Exception e) {
                Logger.Error($"Error loading file '{fileName}': {e.Message}");
            }
            return(image);
        }
Ejemplo n.º 2
0
Archivo: Fov.cs Proyecto: dritory/Janus
        public Fov(Actor owner, params object[] args) : base(owner, args)
        {
            if (args.Length > 0)
            {
                if (args[0].GetType() == typeof(string))
                {
                    fovRadius = int.Parse((string)args[0]);
                }
                else
                {
                    fovRadius = (int)args[0];
                }
            }
            if (args.Length > 1)
            {
                if (args[1].GetType() == typeof(string))
                {
                    strenght = byte.Parse((string)args[1]);
                }
                else
                {
                    strenght = (byte)(int)args[1];
                }
            }
            if (args.Length > 2)
            {
                try
                {
                    System.Reflection.PropertyInfo property = typeof(libtcod.TCODColor).GetProperty(args[2].ToString().ToLower());
                    if (property != null)
                    {
                        color = (libtcod.TCODColor)property.GetValue(color, null);
                    }
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc.Message);
                }
            }
            mapx   = (fovRadius);
            mapy   = (fovRadius);
            height = mapx;
            width  = mapy;

            fovMaps    = new TCODMap[2];
            fovMaps[0] = new TCODMap(width * 2, height * 2);
            fovMaps[1] = new TCODMap(width * 2, height * 2);

            calculatedMaps = new byte[width * 2, height * 2, fovMaps.Length];
            lightmap       = new TCODConsole(map.renderWidth, map.renderHeight);
            lightmap.setBackgroundColor(TCODColor.black);
            lightmap.setKeyColor(TCODColor.black);
            update();
        }
Ejemplo n.º 3
0
        public LibtcodScreen(int width, int height, TCODConsole tcodConsole)
        {
            Width = width;
            Height = height;

            TCODConsoleInst = tcodConsole;

            TCODConsoleInst.setBackgroundFlag(TCODBackgroundFlag.Overlay);
            BackgroundColor = ConsoleRGB.Black;
            ForegroundColor = ConsoleRGB.White;
            TCODConsoleInst.setKeyColor(TCODColor.red);
        }
Ejemplo n.º 4
0
Archivo: Fov.cs Proyecto: dritory/Janus
        public override void load(Actor owner)
        {
            base.load(owner);
            lightmap = new TCODConsole(map.renderWidth, map.renderHeight);
            lightmap.setBackgroundColor(TCODColor.black);
            lightmap.setKeyColor(TCODColor.black);
            fovMaps    = new TCODMap[2];
            fovMaps[0] = new TCODMap(width * 2, height * 2);
            fovMaps[1] = new TCODMap(width * 2, height * 2);

            calculatedMaps = new byte[width * 2, height * 2, fovMaps.Length];
            initializeFov  = true;
        }
Ejemplo n.º 5
0
        public DynamicFov() : base()
        {
            mapx   = 0;
            mapy   = 0;
            height = map.renderHeight + (mapy);
            width  = map.renderWidth + (mapx);

            fovMaps    = new TCODMap[1];
            fovMaps[0] = new TCODMap(width, height);
            lightmap   = new TCODConsole(map.renderWidth, map.renderHeight);
            lightmap.setBackgroundColor(TCODColor.black);
            lightmap.setKeyColor(TCODColor.black);
            update();
        }
Ejemplo n.º 6
0
        public void initialize(bool restarting, int levelnr, Type mapGenerator)
        {
            this._levelnr             = levelnr;
            Program.engine.gameStatus = GameStatus.LOADING;
            map             = new Map(this, 4, 4, 100, 50);
            lightMapConsole = new TCODConsole(map.renderWidth, map.renderHeight);

            lightMapConsole.setKeyColor(TCODColor.white);
            actorHandler = new ActorHandler();
            actorHandler.initialize(restarting, this);

            Console.WriteLine("Generating Map...");
            map.generate(mapGenerator);

            Program.engine.gameStatus = GameStatus.IDLE;
        }
Ejemplo n.º 7
0
        public override void load(Actor owner)
        {
            base.load(owner);
            mapx   = 0;
            mapy   = 0;
            height = map.renderHeight + (mapy);
            width  = map.renderWidth + (mapx);

            fovMaps    = new TCODMap[1];
            fovMaps[0] = new TCODMap(width, height);
            lightmap   = new TCODConsole(map.renderWidth, map.renderHeight);
            lightmap.setBackgroundColor(TCODColor.black);
            lightmap.setKeyColor(TCODColor.black);
            initializeFov = true;
            update();
        }