Пример #1
0
        public override void Update()
        {
            // add dust particles effect when motion direction is changed
            if (ObstacleAt(Side.Down))
            {
                if (PreviousVelocity.X > 0 && !(Velocity.X > 0))
                {
                    Engine.Core.Game.Instance.AddEntity(new Decal(SpriteCache.Get(PlayerDecals.DustParticlesRight.ToString()),
                                                                  new Vector2f(Position.X + BoundingBox.Right, Position.Y)));
                }

                else if (PreviousVelocity.X < 0 && !(Velocity.X < 0))
                {
                    Engine.Core.Game.Instance.AddEntity(new Decal(SpriteCache.Get(PlayerDecals.DustParticlesLeft.ToString()),
                                                                  new Vector2f(Position.X + BoundingBox.Left, Position.Y)));
                }
            }

            base.Update();

            if (Alive)
            {
                Action.Current?.Update(this);
            }

            Movement.Current?.Update(this);
        }
Пример #2
0
        public void Render(AABB view, double interpolation)
        {
            var position = InterpolatedPosition(interpolation);

            // animation not found, use default sprite
            Renderer.Instance.RenderSprite(view, SpriteCache.Get(SpriteId), position);
        }
Пример #3
0
        private static ScreenBuffer DirectLighting(AABB view, Layer layer, Light[] lights, AABB[] obstacles)
        {
            var data  = SpriteCache.Get(layer.DataMapId);
            var color = SpriteCache.Get(layer.ColorMapId);

            var viewMin  = view.Min.Round();
            var viewSize = view.Size.Round();

            var sdl2Renderer = Renderer.Instance as SDL2Renderer;
            var result       = sdl2Renderer.CreateScreenBuffer(BufferEnum.DirectIllumination, viewSize);

            //for (var i = 0; i < result.Data.Length / 4; i++)
            Parallel.For(0, result.Data.Length / 4, (i, loopState) =>
            {
                var screen = new Vector2i(i % viewSize.X, i / viewSize.X);
                var wIndex = (viewMin.Y + screen.Y) * data.Size.X + viewMin.X + screen.X;
                var sIndex = ((viewSize.Y - screen.Y - 1) * viewSize.X + screen.X) * 4;

                if ((data.Data[wIndex] & Level.ShadeMask) == Level.ShadeMask)
                {
                    var tmpColor = new Color4f(color.Data[wIndex]);
                    if (tmpColor.A > 0)
                    {
                        tmpColor += RayTracing.DirectLight(screen + viewMin, lights, obstacles) * 0.5;
                    }

                    var finalColor          = new Color4b(tmpColor);
                    result.Data[sIndex + 0] = finalColor.A;
                    result.Data[sIndex + 1] = finalColor.B;
                    result.Data[sIndex + 2] = finalColor.G;
                    result.Data[sIndex + 3] = finalColor.R;
                }
                else
                {
                    // just alpha channel
                    result.Data[sIndex] = 0;
                }
            }
                         );

            return(result);
        }
Пример #4
0
    //------------------------------------------------------------------------------------------------------------------------
    //                                                  Initialize()
    //------------------------------------------------------------------------------------------------------------------------
    public void Initialize(Item item, bool isSelected)
    {
        //store item
        this.item = item;

        //set checkmark visibility
        if (isSelected)
        {
            checkMark.SetActive(true);
        }

        //set button image
        Image  image  = GetComponentInChildren <Image>();
        Sprite sprite = SpriteCache.Get(item.iconName);

        if (sprite != null)
        {
            image.sprite = sprite;
        }
    }
    public void Initialize(Item item, bool isSelected)
    {
        // Store item
        this.item = item;

        // Set checkmark visibility
        checkMark.SetActive(isSelected);

        // Set button image
        Image  image  = GetComponentInChildren <Image>();
        Sprite sprite = SpriteCache.Get(item.GetComponent <DrawableComponent>().IconName);

        nameText.text     = item.Name;
        costText.text     = '$' + item.Cost.ToString();
        quantityText.text = item.Quantity.ToString() + 'x';

        if (sprite != null)
        {
            image.sprite = sprite;
        }
    }
Пример #6
0
        private static ScreenBuffer PerPixelShading(AABB view, Layer layer, Light[] lights, AABB[] obstacles)
        {
            var colorLayer = SpriteCache.Get(layer.ColorMapId);

            var viewMin  = view.Min.Round();
            var viewSize = view.Size.Round();

            var sdl2Renderer = Renderer.Instance as SDL2Renderer;
            var buffer       = sdl2Renderer.CreateScreenBuffer(BufferEnum.PerPixelShading, viewSize);
            var bufferLength = buffer.Data.Length / 4;

            //for (var i = 0; i < bufferLength; i++)
            Parallel.For(0, bufferLength, (i, loopState) =>
            {
                var bufferPixel = new Vector2i(i % viewSize.X, i / viewSize.X);
                var layerIndex  = (viewMin.Y + bufferPixel.Y) * colorLayer.Size.X + viewMin.X + bufferPixel.X;
                var bufferIndex = ((viewSize.Y - bufferPixel.Y - 1) * viewSize.X + bufferPixel.X) * 4;

                var color = new Color4f(colorLayer.Data[layerIndex]);
                if (color.A > 0)
                {
                    // TODO per pixel shading
                    color.A *= 0.5;

                    var finalColor = new Color4b(color);
                    buffer.Data[bufferIndex + 0] = finalColor.A;
                    buffer.Data[bufferIndex + 1] = finalColor.B;
                    buffer.Data[bufferIndex + 2] = finalColor.G;
                    buffer.Data[bufferIndex + 3] = finalColor.R;
                }
                else
                {
                    // just alpha channel
                    buffer.Data[bufferIndex] = 0;
                }
            }
                         );

            return(buffer);
        }
Пример #7
0
        public override void Render(AABB view, double interpolation)
        {
            var position = InterpolatedPosition(interpolation);

            if (Alive)
            {
                var animation = SpriteCache.Get(Movement.Current.Animation.ToString());
                if (animation != null)
                {
                    Renderer.Instance.RenderSpriteFrame(view, animation, position,
                                                        Movement.Current.AnimationFrame % (animation.Size.X / animation.Size.Y));
                }
                else
                {
                    // animation not found, use default sprite
                    Renderer.Instance.RenderSprite(view, SpriteCache.Get(DefaultSpriteId), position);
                }
            }
            else
            {
                // TODO render death animation
                Renderer.Instance.RenderSprite(view, SpriteCache.Get(DefaultSpriteId), position);
            }
        }
Пример #8
0
        private static ScreenBuffer AmbientOcclusion(AABB view, Layer layer, Light[] lights, AABB[] obstacles, int pixelSize)
        {
            var data  = SpriteCache.Get(layer.DataMapId);
            var color = SpriteCache.Get(layer.ColorMapId);

            var viewMin  = view.Min.Round();
            var viewSize = view.Size.Round();

            var sdl2Renderer = Renderer.Instance as SDL2Renderer;

            // ambient occlusion
            var aoSize         = viewSize / pixelSize;
            var aoBuffer       = sdl2Renderer.CreateScreenBuffer(BufferEnum.AmbientOcclusion1, aoSize);
            var aoBufferLength = aoBuffer.Data.Length / 4;

            Parallel.For(0, aoBufferLength, (i, loopState) =>
            {
                var aoPixel     = new Vector2i(i % aoSize.X, i / aoSize.X);
                var aoIndex     = ((aoSize.Y - aoPixel.Y - 1) * aoSize.X + aoPixel.X) * 4;
                var screenPixel = aoPixel * pixelSize + new Vector2i(pixelSize / 2);

                var pixelColor = RayTracing.AmbientOcclusion(viewMin + screenPixel, obstacles,
                                                             probeDistance: 128, rayCount: 4);

                var finalColor             = new Color4b(pixelColor);
                aoBuffer.Data[aoIndex + 0] = finalColor.A;
                aoBuffer.Data[aoIndex + 1] = finalColor.B;
                aoBuffer.Data[aoIndex + 2] = finalColor.G;
                aoBuffer.Data[aoIndex + 3] = finalColor.R;
            });

            // ambient occlusion & color
            var viewBuffer       = sdl2Renderer.CreateScreenBuffer(BufferEnum.AmbientOcclusion1, viewSize);
            var viewBufferLength = viewBuffer.Data.Length / 4;

            Parallel.For(0, viewBufferLength, (i, loopState) =>
            {
                var viewPixel = new Vector2i(i % viewSize.X, i / viewSize.X);
                var viewIndex = ((viewSize.Y - viewPixel.Y - 1) * viewSize.X + viewPixel.X) * 4;

                var colorIndex = (viewMin.Y + viewPixel.Y) * data.Size.X + viewMin.X + viewPixel.X;
                if (color.Data[colorIndex + 0] > 0)
                {
                    var aoPixel = viewPixel / pixelSize;
                    var aoIndex = ((aoSize.Y - aoPixel.Y - 1) * aoSize.X + aoPixel.X) * 4;

                    var pixelColor = new Color4f(color.Data[colorIndex]);
                    var aoColor    = new Color4f(new Color4b(
                                                     aoBuffer.Data[aoIndex + 3],
                                                     aoBuffer.Data[aoIndex + 2],
                                                     aoBuffer.Data[aoIndex + 1],
                                                     aoBuffer.Data[aoIndex + 0]).AsUint);

                    var finalColor = new Color4b(pixelColor * aoColor);
                    viewBuffer.Data[viewIndex + 0] = finalColor.A;
                    viewBuffer.Data[viewIndex + 1] = finalColor.B;
                    viewBuffer.Data[viewIndex + 2] = finalColor.G;
                    viewBuffer.Data[viewIndex + 3] = finalColor.R;
                }
                else
                {
                    // just alpha channel
                    viewBuffer.Data[viewIndex] = 0;
                }
            });

            return(viewBuffer);
        }