Beispiel #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);
        }
Beispiel #2
0
        public void Draw(TCODConsole cons)
        {
            cons.setForegroundColor(TCODColor.white);
            for (int i = 0; i < MAP_WIDTH; i++)
            {
                for (int j = 0; j < MAP_HEIGHT; j++)
                {
                    cons.putChar(i, j, this[i, j] ? '#' : '.');
                }
            }

            _stair.Draw(cons);
            cons.putChar(StartPosX, StartPosY, '<');

            foreach (Item item in _items)
            {
                item.Draw(cons);
            }

            foreach (Monster mons in _monsters)
            {
                mons.Draw(cons);
            }

            Player.Draw(cons);

            for (int i = 0; i < MAP_WIDTH; i++)
            {
                for (int j = 0; j < MAP_HEIGHT; j++)
                {
                    /*int intens;
                     * Light light = LightAt(i, j);
                     *
                     * if (light == null)
                     *  intens = 0;
                     * else
                     * {
                     *  intens = light.IntensityAt(i, j);
                     *  color = color.Multiply(light.Color);
                     * }
                     * float value = (float)intens / 20 + (Game.ShowWall ? 0.05f : 0f);
                     * color.setValue(System.Math.Min(value, 1f));//*/

                    TCODColor color  = cons.getCharForeground(i, j);
                    TCODColor newCol = ColorAt(i, j);

                    if (newCol.NotEqual(TCODColor.black))
                    {
                        _known[i, j] = true;
                    }
                    color = color.Multiply(newCol);

                    cons.setCharForeground(i, j, color);
                }
            }
        }