コード例 #1
0
        protected override void ClientInitialize(ClientInitializeData data)
        {
            base.ClientInitialize(data);

            var tilePosition = data.GameObject.TilePosition;
            var renderer     = data.ClientState.Renderer;

            if (ClientGroundExplosionAnimationHelper.IsGroundSpriteFlipped(tilePosition))
            {
                renderer.DrawMode = DrawMode.FlipHorizontally;
            }

            if (ClientGroundExplosionAnimationHelper.HasActiveExplosion(tilePosition))
            {
                // this is a fresh charred ground, animate the ground sprite
                var animationDuration      = ClientGroundExplosionAnimationHelper.ExplosionGroundDuration;
                var framesTextureResources = ClientComponentSpriteSheetAnimator.CreateAnimationFrames(
                    ClientGroundExplosionAnimationHelper.ExplosionGroundTextureAtlas);
                var componentAnimator = renderer.SceneObject.AddComponent <ClientComponentSpriteSheetAnimator>();
                componentAnimator.Setup(renderer,
                                        framesTextureResources,
                                        frameDurationSeconds: animationDuration / framesTextureResources.Length);

                componentAnimator.IsLooped = false;
                componentAnimator.Destroy(1.5 * animationDuration);
            }
        }
コード例 #2
0
        protected override void ClientInitialize(ClientInitializeData data)
        {
            base.ClientInitialize(data);

            var tilePosition = data.GameObject.TilePosition;
            var renderer     = data.ClientState.Renderer;

            if (ClientGroundExplosionAnimationHelper.IsGroundSpriteFlipped(tilePosition))
            {
                renderer.DrawMode = DrawMode.FlipHorizontally;
            }
        }
コード例 #3
0
        protected override void ClientUpdate(ClientUpdateData data)
        {
            base.ClientUpdate(data);

            // enable renderer when the explosion renderer has been finished
            var renderer = data.ClientState.Renderer;

            if (!renderer.IsEnabled &&
                !ClientGroundExplosionAnimationHelper.HasActiveExplosion(
                    data.GameObject.TilePosition))
            {
                renderer.IsEnabled = true;
            }
        }
コード例 #4
0
        public static void ClientExplode(
            Vector2D position,
            ExplosionPreset explosionPreset,
            float volume = 1.0f)
        {
            // add screen shakes
            ClientComponentCameraScreenShakes.AddRandomShakes(
                duration: explosionPreset.ScreenShakesDuration,
                worldDistanceMin: explosionPreset.ScreenShakesWorldDistanceMin,
                worldDistanceMax: explosionPreset.ScreenShakesWorldDistanceMax);

            // play sound
            var explosionSoundEmitter = Client.Audio.PlayOneShot(explosionPreset.SoundSet.GetSound(),
                                                                 worldPosition: position,
                                                                 volume: volume,
                                                                 pitch: RandomHelper.Range(0.95f, 1.05f));

            // extend explosion sound distance
            explosionSoundEmitter.CustomMinDistance = (float)explosionPreset.LightWorldSize / 3;
            explosionSoundEmitter.CustomMaxDistance = (float)explosionPreset.LightWorldSize;

            // create explosion renderer
            var explosionSpriteAnimationDuration = explosionPreset.SpriteAnimationDuration;
            var explosionSceneObject             = Client.Scene.CreateSceneObject("Temp explosion",
                                                                                  position);

            explosionSceneObject.Destroy(delay: explosionSpriteAnimationDuration);

            var explosionSpriteRenderer = Client.Rendering.CreateSpriteRenderer(
                explosionSceneObject,
                TextureResource.NoTexture,
                drawOrder: DrawOrder.Explosion,
                spritePivotPoint: (0.5, 0.5));

            explosionSpriteRenderer.Color = explosionPreset.SpriteColorMultiplicative;
            explosionSpriteRenderer.Size  = explosionPreset.SpriteSize;
            if (explosionPreset.SpriteColorAdditive.HasValue
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                || explosionPreset.SpriteBrightness != 1)
            {
                var renderingMaterial = RenderingMaterial.Create(EffectResourceAdditiveColorEffect);
                renderingMaterial.EffectParameters
                .Set("ColorAdditive", explosionPreset.SpriteColorAdditive ?? Colors.Black)
                .Set("Brightness", explosionPreset.SpriteBrightness);
                explosionSpriteRenderer.RenderingMaterial = renderingMaterial;
            }

            var isFlipped = 0
                            == PositionalRandom.Get(position.ToVector2Ushort(),
                                                    minInclusive: 0,
                                                    maxExclusive: 2,
                                                    seed: 893243289);

            if (isFlipped)
            {
                explosionSpriteRenderer.DrawMode = DrawMode.FlipHorizontally;
            }

            ClientComponentOneShotSpriteSheetAnimationHelper.Setup(
                explosionSpriteRenderer,
                explosionPreset.SpriteAtlasResources.TakeByRandom(),
                explosionSpriteAnimationDuration);

            // add light source for the explosion
            var explosionLight = ClientLighting.CreateLightSourceSpot(
                explosionSceneObject,
                explosionPreset.LightColor,
                size: explosionPreset.LightWorldSize,
                positionOffset: (0, 0),
                spritePivotPoint: (0.5, 0.5));

            ClientComponentOneShotLightAnimation.Setup(
                explosionLight,
                explosionPreset.LightDuration);

            // add blast wave
            var blastAnimationDuration = explosionPreset.BlastwaveAnimationDuration;

            if (blastAnimationDuration > 0)
            {
                ClientTimersSystem.AddAction(
                    explosionPreset.BlastwaveDelay,
                    () =>
                {
                    var blastSceneObject = Client.Scene.CreateSceneObject("Temp explosion",
                                                                          position);

                    blastSceneObject.Destroy(delay: blastAnimationDuration);

                    var blastSpriteRenderer = Client.Rendering.CreateSpriteRenderer(
                        blastSceneObject,
                        new TextureResource("FX/ExplosionBlast"),
                        drawOrder: DrawOrder.Explosion - 1,
                        spritePivotPoint: (0.5, 0.5));

                    // animate blast wave
                    ClientComponentGenericAnimationHelper.Setup(
                        blastSceneObject,
                        blastAnimationDuration,
                        updateCallback: alpha =>
                    {
                        var blastwaveAlpha        = (byte)(byte.MaxValue * (1 - alpha));
                        blastSpriteRenderer.Color = explosionPreset.BlastWaveColor
                                                    .WithAlpha(blastwaveAlpha);

                        var sizeX = MathHelper.Lerp(explosionPreset.BlastwaveSizeFrom.X,
                                                    explosionPreset.BlastwaveSizeTo.X,
                                                    alpha);
                        var sizeY = MathHelper.Lerp(explosionPreset.BlastwaveSizeFrom.Y,
                                                    explosionPreset.BlastwaveSizeTo.Y,
                                                    alpha);
                        blastSpriteRenderer.Size = new Size2F(sizeX, sizeY);
                    });
                });
            }

            ClientGroundExplosionAnimationHelper.OnExplode(
                delaySeconds: explosionSpriteAnimationDuration / 2,
                position: position);
        }