Example #1
0
        private void Redraw()
        {
            var halfScreen        = new Point(ContentRct.Width, ContentRct.Height) / 2;
            var avatarScreenPoint = halfScreen + ContentRct.LeftTop;

            TileHelper.DrawHelper.ClearTiles(Rct, BackgroundColor);

            var worldLayer = World.TheWorld.Avatar.GeoInfo.Layer;

            var width  = ContentRct.Width;
            var height = ContentRct.Height;

            for (var x = 0; x < width; ++x)
            {
                for (var y = 0; y < height; ++y)
                {
                    var xy = new Point(x, y);

                    var liveCellCoords = LiveMap.WrapCellCoords(xy + World.TheWorld.DPoint);
                    var liveCell       = World.TheWorld.LiveMap.Cells[liveCellCoords.X, liveCellCoords.Y];
                    var screenPoint    = xy + ContentRct.LeftTop;
                    var visibilityA    = 1f;                 // liveCell.Visibility.A;
                    var finalLighted   = liveCell.FinalLighted;

                    if (liveCell.IsVisibleNow)
                    {
                        var eTerrains   = liveCell.Terrain;
                        var terrainTile = eTerrains.GetTile((int)Math.Abs((liveCell.LiveCoords.GetHashCode() * liveCell.Rnd)));
                        var tcolor      = terrainTile.Color.Multiply(finalLighted).Clamp().Lerp(terrainTile.Color.Multiply(0.7f), 1f - visibilityA);
                        terrainTile.Draw(screenPoint, tcolor);

                        foreach (var tileInfoProvider in liveCell.TileInfoProviders)
                        {
                            var tile  = tileInfoProvider.Tileset.GetTile(tileInfoProvider.TileIndex);
                            var color = tile.Color.LerpColorsOnly(tileInfoProvider.LerpColor, tileInfoProvider.LerpColor.A).Multiply(finalLighted).Clamp().UpdateAlfa(visibilityA);
                            tile.Draw(screenPoint, color, tileInfoProvider.Direction, tileInfoProvider.IsCorpse);
                        }
                    }
                    else if (liveCell.IsSeenBefore)
                    {
                        var fogColorMultiplier = worldLayer.GetFogColorMultiplier(liveCell);

                        var eTerrains   = liveCell.Terrain;
                        var terrainTile = eTerrains.GetTile((int)Math.Abs((liveCell.LiveCoords.GetHashCode() * liveCell.Rnd)));

                        var tcolor = terrainTile.Color.Multiply(fogColorMultiplier).ToGrayScale();
                        terrainTile.Draw(screenPoint, tcolor);
                        foreach (var tileInfoProvider in liveCell.FoggedTileInfoProviders)
                        {
                            var tile = tileInfoProvider.Tileset.GetTile(tileInfoProvider.TileIndex);
                            tile.Draw(screenPoint, tile.Color.LerpColorsOnly(tileInfoProvider.LerpColor, tileInfoProvider.LerpColor.A).ToGrayScale(), tileInfoProvider.Direction, tileInfoProvider.IsCorpse);
                        }
                        DrawHelper.FogTile(screenPoint);
                    }
                }
            }
            World.TheWorld.Avatar.Tileset.GetTile(World.TheWorld.Avatar.TileIndex).Draw(avatarScreenPoint, FColor.White);
        }
Example #2
0
        public void SetVisibleCelss(LiveMap _liveMap, Point _dPoint, FColor _startFrom)
        {
            unchecked
            {
                var cvisibles = new FColor[m_inOrder.Length];
                var visibles  = new float[m_inOrder.Length];

                cvisibles[0] = _startFrom;
                visibles[0]  = 1;

                for (var index = 0; index < m_inOrder.Length; index++)
                {
                    var visibilityCoeff = visibles[index];

                    if (visibilityCoeff < VISIBILITY_THRESHOLD)
                    {
                        continue;
                    }

                    var losCell = m_inOrder[index];
                    var myPnt   = LiveMap.WrapCellCoords(losCell.Point + _dPoint);

                    var liveCell   = _liveMap.Cells[myPnt.X, myPnt.Y];
                    var transColor = index == 0 ? FColor.White : liveCell.TransparentColor;

                    visibilityCoeff = transColor.A * visibilityCoeff;
                    var childsColor = cvisibles[index].Multiply(transColor);

                    if (visibilityCoeff < VISIBILITY_THRESHOLD)
                    {
                        continue;
                    }

                    foreach (var pair in losCell.CellIndexes)
                    {
                        visibles[pair.Key] += pair.Value * visibilityCoeff;
                        cvisibles[pair.Key] = cvisibles[pair.Key].ScreenColorsOnly(childsColor);
                    }
                }
                for (var index = 0; index < m_inOrder.Length; index++)
                {
                    var visibilityCoeff = visibles[index];
                    var color           = cvisibles[index];

                    if (visibilityCoeff < VISIBILITY_THRESHOLD)
                    {
                        continue;
                    }

                    var losCell = m_inOrder[index];
                    var myPnt   = LiveMap.WrapCellCoords(losCell.Point + _dPoint);

                    var liveCell = _liveMap.Cells[myPnt.X, myPnt.Y];
                    liveCell.Visibility = new FColor(Math.Min(1f, visibilityCoeff), color);
                }
            }
        }
Example #3
0
        public void LightCells(LiveMap _liveMap, Point _dPoint, FColor _fColor)
        {
            unchecked
            {
                var cvisibles       = new FColor[m_inOrder.Length];
                var power           = new float[m_inOrder.Length];
                var childVisibility = new float[m_inOrder.Length];

                power[0]           = _fColor.A;
                childVisibility[0] = 1;

                cvisibles[0] = new FColor(1f, _fColor);
                for (var index = 1; index < m_inOrder.Length; index++)
                {
                    cvisibles[index] = FColor.Empty;
                }
                for (var index = 0; index < m_inOrder.Length; index++)
                {
                    var losCell = m_inOrder[index];

                    var powerCoeff = power[index];

                    if (powerCoeff < LIGHT_THRESHOLD)
                    {
                        continue;
                    }

                    var myPnt = LiveMap.WrapCellCoords(losCell.Point + _dPoint);

                    var liveCell = _liveMap.Cells[myPnt.X, myPnt.Y];

                    var color = cvisibles[index].NormalColorOnly;

                    var transColor = index == 0 ? FColor.White : liveCell.TransparentColor;
                    if (childVisibility[index] > 0)
                    {
                        liveCell.Lighted = liveCell.Lighted.Screen(color.Multiply(powerCoeff));
                        powerCoeff      *= transColor.A;
                        if (powerCoeff < LIGHT_THRESHOLD)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        powerCoeff *= transColor.A;
                        if (powerCoeff < LIGHT_THRESHOLD)
                        {
                            continue;
                        }
                        liveCell.Lighted = liveCell.Lighted.Screen(color.Multiply(powerCoeff));
                    }

                    var childsColor = color.Multiply(transColor);

                    foreach (var pair in losCell.CellIndexes)
                    {
                        var i = pair.Key;

                        power[i] += pair.Value * powerCoeff;
                        cvisibles[i].AddColorOnly(childsColor);
                        childVisibility[i] = pair.Value * liveCell.Visibility.A;
                    }
                }
            }
        }