Beispiel #1
0
        private void SetLightSourcesJob()
        {
            foreach (var info in _tempLightSourceInfos)
            {
                // Cells near light source are always visible;
                for (int x = info.X - 1; x <= info.X + 1; x++)
                {
                    for (int y = info.Y - 1; y <= info.Y + 1; y++)
                    {
                        VisionMask mask = GetMask(x, y);
                        if (mask != null)
                        {
                            float range     = Vector2Int.Distance(new Vector2Int(info.X, info.Y), new Vector2Int(x, y));
                            float intensity = info.CalculateIntensityRange(range);

                            if (intensity < 0)
                            {
                                intensity = 0;
                            }

                            float brightness = intensity;

                            _processedBrightness.Add(brightness);
                            _processedMasks.Add(mask);
                        }
                    }
                }

                for (int x = (int)Mathf.Round(info.X - info.Range); x <= info.X + info.Range; x++)
                {
                    for (int y = (int)Mathf.Round(info.Y - info.Range); y <= info.Y + info.Range; y++)
                    {
                        bool result = IsVisibleFrom(new Vector2Int(info.X, info.Y), new Vector2Int(x, y));

                        VisionMask mask = GetMask(x, y);
                        if (mask != null && result)
                        {
                            //float brightness = mask.GetBrightness() + info.CalculateIntensity(new Vector2Int(x, y));
                            float range     = Vector2Int.Distance(new Vector2Int(info.X, info.Y), new Vector2Int(x, y));
                            float intensity = info.CalculateIntensityRange(range);

                            if (intensity < 0)
                            {
                                intensity = 0;
                            }

                            float brightness = intensity;

                            _processedBrightness.Add(brightness);
                            _processedMasks.Add(mask);

                            //mask.SetLighting(brightness, mask.GetColor());
                        }
                    }
                }
            }

            _tempLightSourceInfos.Clear();
        }
Beispiel #2
0
        private void ProcessVisionBlockers()
        {
            // Cells near player are always visible;
            for (int x = _visionSourceCell.x - 1; x <= _visionSourceCell.x + 1; x++)
            {
                for (int y = _visionSourceCell.y - 1; y <= _visionSourceCell.y + 1; y++)
                {
                    VisionMask mask = GetMask(x, y);
                    if (mask != null)
                    {
                        mask.SetVisible();

                        if (_ignoreLight)
                        {
                            mask.SetLighting(1, Color.black);
                        }
                    }
                }
            }

            for (int x = _visionSourceCell.x - _sightRange; x <= _visionSourceCell.x + _sightRange; x++)
            {
                for (int y = _visionSourceCell.y - _sightRange; y <= _visionSourceCell.y + _sightRange; y++)
                {
                    bool result = IsVisibleFrom(_visionSourceCell, new Vector2Int(x, y));

                    if (!ServerController.IsCellInBounds(new Vector2Int(x, y)))
                    {
                        continue;
                    }

                    VisionMask mask = _masks[x, y];
                    if (mask != null && result)
                    {
                        mask.SetVisible();

                        if (_ignoreLight)
                        {
                            mask.SetLighting(1, Color.black);
                        }
                    }
                }
            }
        }