コード例 #1
0
ファイル: Play.cs プロジェクト: aenemenate/Landlord
        public static void RenderMap(Player player, SadConsole.Console console, Window window)
        {
            Point worldIndex = player.WorldIndex;
            Point startPoint = window.CalculateMapStartPoint();

            for (int i = startPoint.X; i - startPoint.X < GUI.MapWidth; i++)
            {
                for (int j = startPoint.Y; j - startPoint.Y < window.Height; j++)
                {
                    Program.WorldMap[worldIndex.X, worldIndex.Y].DrawCell(i, j, player, console, window);
                }
            }
        }
コード例 #2
0
ファイル: MapTile.cs プロジェクト: aenemenate/Landlord
        public void DrawCell(int x, int y, Player player, SadConsole.Console console, Window window)
        {
            Point startPoint = window.CalculateMapStartPoint();

            int currentFloor = player.CurrentFloor;

            Block[]           blocks      = currentFloor >= 0 ? Dungeon.Floors[currentFloor].Blocks : map;
            Tile[]            tiles       = currentFloor >= 0 ? Dungeon.Floors[currentFloor].Floor : floor;
            List <Projectile> projectiles = currentFloor >= 0 ? Program.WorldMap[worldIndex.X, worldIndex.Y].Dungeon.Floors[currentFloor].Projectiles : Program.WorldMap[worldIndex.X, worldIndex.Y].Projectiles;
            Projectile        p           = projectiles.Find(pr => pr.Position.Equals(new Point(x, y)));
            int width = Program.WorldMap.TileWidth;

            float nonVisibleMultiplierFore, nonVisibleMultiplierBack, visibleMultiplierFore, visibleMultiplierBack, heightMultiplierFore, heightMultiplierBack;

            if (player.CurrentFloor >= 0 == true)
            {
                heightMultiplierFore = 0F;
                heightMultiplierBack = 0F;
            }
            else
            {
                float cellHeight = Program.WorldMap.HeightMap[x + 100 * player.WorldIndex.X, y + 100 * player.WorldIndex.Y];
                heightMultiplierFore = ((90F - cellHeight) / 128F) * 0.25F;
                heightMultiplierBack = ((90F - cellHeight) / 128F) * 0.1F;
            }

            nonVisibleMultiplierFore = 0.78F - heightMultiplierFore;
            nonVisibleMultiplierBack = 0.89F - heightMultiplierBack;
            visibleMultiplierFore    = 0.96F - heightMultiplierFore;
            visibleMultiplierBack    = 1.02F - heightMultiplierBack;

            Color floorForeColor = tiles[x * width + y].Splattered ? Color.DarkRed : tiles[x * width + y].ForeColor;
            Color floorBackColor = tiles[x * width + y].BackColor;

            Color blockForeColor = blocks[x * width + y].Splattered ? Color.DarkRed : blocks[x * width + y].ForeColor;
            Color blockBackColor = blocks[x * width + y].BackColor;

            void RenderFloorTile()
            {
                if (!tiles[x * width + y].Explored)
                {
                    console.SetGlyph(x - startPoint.X, y - startPoint.Y, tiles[x * width + y].Graphic, Color.Black, Color.Black);
                }
                else
                {
                    switch (tiles[x * width + y].Visible)
                    {
                    case (false):
                        console.SetGlyph(x - startPoint.X, y - startPoint.Y, tiles[x * width + y].Graphic, floorForeColor * nonVisibleMultiplierFore, floorBackColor * nonVisibleMultiplierBack);
                        break;

                    case (true):
                        console.SetGlyph(x - startPoint.X, y - startPoint.Y, tiles[x * width + y].Graphic, floorForeColor * visibleMultiplierFore, floorBackColor * visibleMultiplierBack);
                        break;
                    }
                }
            }

            void RenderBlock()
            {
                Block block = blocks[x * width + y];
                bool  blockIsUnseenCreature = block is Creature && block.Visible == false;

                if (blockIsUnseenCreature)
                {
                    Creature creature = (Creature)block;
                    if (creature.Alive)
                    {
                        bool creatureIsInEmptySpace = creature.CurrentBlock.Type == BlockType.Empty;
                        if (creatureIsInEmptySpace)
                        {
                            RenderFloorTile();
                            return;
                        }
                        else
                        {
                            block = creature.CurrentBlock;
                        }
                    }
                }



                if (block.BackColor == Color.Pink)
                {
                    if (block.Type == BlockType.Creature)
                    {
                        Creature creature = (Creature)block;
                        bool     creatureIsOnColoredBlock = creature != null && creature.CurrentBlock.Type != BlockType.Empty && creature.CurrentBlock.BackColor != Color.Pink;
                        blockBackColor = creatureIsOnColoredBlock ? creature.CurrentBlock.BackColor : floorBackColor;
                    }
                    else
                    {
                        blockBackColor = floorBackColor;
                    }
                }

                if (block.Explored == false)
                {
                    console.SetGlyph(x - startPoint.X, y - startPoint.Y, block.Graphic, Color.Black, Color.Black);
                }
                else
                {
                    switch (block.Visible)
                    {
                    case (false):
                        console.SetGlyph(x - startPoint.X, y - startPoint.Y, block.Graphic, blockForeColor * nonVisibleMultiplierFore, blockBackColor * nonVisibleMultiplierBack);
                        break;

                    case (true):
                        console.SetGlyph(x - startPoint.X, y - startPoint.Y, block.Graphic, blockForeColor * visibleMultiplierFore, blockBackColor * visibleMultiplierBack);
                        break;
                    }
                }
            }

            void RenderProjectile()
            {
                console.SetGlyph(x - startPoint.X, y - startPoint.Y, p.Item.Graphic, p.Item.ForeColor * visibleMultiplierFore, floorBackColor * visibleMultiplierBack);
            }

            if (tiles[x * width + y].Visible && p != null)
            {
                RenderProjectile();
            }
            else if (blocks[x * width + y].Type == BlockType.Empty)
            {
                RenderFloorTile();
            }
            else
            {
                RenderBlock();
            }
        }