Beispiel #1
0
        public EyeRenderer(Actor actor, Player player, LevelTransition levelTransition) : base(actor)
        {
            this.player                        = player;
            this.levelTransition               = levelTransition;
            this.levelTransition.onWakeUp     += WakeUpAnimation;
            this.levelTransition.onFallAsleep += FallAsleepAnimation;

            this.openAmountAccessors = new TweenAccessors <float>(() => this.openPercent, val => this.openPercent = val);
            this.eyeTween            = new TweenChain();

            BuildEye(20);
        }
Beispiel #2
0
        public LureRenderer(Actor actor, Player player, EyeRenderer eye, Level currentLevel) : base(actor)
        {
            MachinaGame.Assets.GetSoundEffectInstance("frog_bass").Play();

            this.eye           = eye;
            this.player        = player;
            this.bubbleSpawner = RequireComponent <BubbleSpawner>();
            var targetLocalPos = transform.LocalPosition;

            this.lureTween = new TweenChain();
            var accessors = new TweenAccessors <float>(() => this.progress, val => this.progress = val);

            lureTween.AppendFloatTween(1f, 0.25f, EaseFuncs.QuadraticEaseOut, accessors);
            lureTween.AppendCallback(() =>
            {
                var caughtFish = false;

                if (currentLevel.HarnessVulnerable)
                {
                    foreach (var targetActor in actor.scene.GetAllActors())
                    {
                        var harness = targetActor.GetComponent <Harness>();
                        if (harness != null && harness.HarnessRect.Contains(EndPos))
                        {
                            harness.TakeDamage();
                        }
                    }
                }

                foreach (var targetActor in actor.scene.GetAllActors())
                {
                    var jellyfish = targetActor.GetComponent <Jellyfish>();
                    if (jellyfish != null)
                    {
                        if (jellyfish.IsHit(transform.Position, lureSize))
                        {
                            this.wasStunned = true;
                            jellyfish.Hit();
                        }
                    }
                }

                if (!wasStunned)
                {
                    foreach (var targetActor in actor.scene.GetAllActors())
                    {
                        var eatable = targetActor.GetComponent <Eatable>();
                        if (eatable != null)
                        {
                            if ((targetActor.transform.Position - transform.Position).Length() < this.lureSize + eatable.fish.HitRadius)
                            {
                                caughtFish          = true;
                                this.caughtFishSize = eatable.fish.Size;
                                eatable.actor.Destroy();
                                break;
                            }
                        }
                    }
                }


                if (!caughtFish)
                {
                    foreach (var targetActor in actor.scene.GetAllActors())
                    {
                        var plant = targetActor.GetComponent <Seaweed>();

                        if (plant != null)
                        {
                            var node = plant.NodeAt(transform.Position, this.lureSize);
                            if (node != null)
                            {
                                this.wasStunned = true;
                                plant.Hit();
                            }
                        }
                    }
                }

                if (caughtFish)
                {
                    MachinaGame.Assets.GetSoundEffectInstance("bass").Play();

                    bubbleSpawner.SpawnBubble(EndPos, Vector2.Zero, 0.1f);
                    bubbleSpawner.SpawnBubble(EndPos, Vector2.Zero, 0.2f);
                    bubbleSpawner.SpawnBubble(EndPos, Vector2.Zero, 0.3f);
                    bubbleSpawner.SpawnBubble(EndPos, Vector2.Zero, 0.4f);

                    this.currentPhase = Phase.Caught;
                    lureTween.AppendFloatTween(0f, 0.2f, EaseFuncs.QuadraticEaseOut, accessors);
                    lureTween.AppendCallback(() =>
                    {
                        this.currentPhase       = Phase.Feeding;
                        transform.LocalPosition = new Vector2(0, 0);
                    });
                    lureTween.AppendWaitTween(0.25f);
                    lureTween.AppendCallback(() =>
                    {
                        this.currentPhase = Phase.Retracting;
                        this.eye.ClearTween();
                        this.eye.TweenOpenAmountTo(2f, 0.1f);
                        this.eye.TweenPlaySound("cthulu-wins");
                        this.eye.TweenOpenAmountTo(0f, 0.15f);
                        this.eye.TweenOpenAmountTo(0f, 0.2f); // Stay closed
                        this.eye.TweenOpenAmountTo(1f, 0.25f);
                    });
                    lureTween.AppendCallback(() =>
                    {
                        var rand = MachinaGame.Random.DirtyRandom;
                        for (int i = 0; i < 10; i++)
                        {
                            bubbleSpawner.SpawnBubble(EndPos, new Vector2(rand.Next(-5, 5), rand.Next(5, 10)), 0f);
                        }
                    });
                    lureTween.AppendWaitTween(0.5f);
                    lureTween.AppendFloatTween(0f, 1f, EaseFuncs.QuadraticEaseOut, accessors);
                }
                else
                {
                    lureTween.AppendCallback(() =>
                    {
                        if (wasStunned)
                        {
                            var s   = MachinaGame.Assets.GetSoundEffectInstance("snare");
                            s.Pitch = -1f;
                            s.Play();
                        }
                        else
                        {
                            var s   = MachinaGame.Assets.GetSoundEffectInstance("snare");
                            s.Pitch = 1f;
                            s.Play();
                        }

                        this.currentPhase = Phase.Retracting;
                        var rand          = MachinaGame.Random.DirtyRandom;
                        for (int i = 0; i < 3; i++)
                        {
                            bubbleSpawner.SpawnBubble(EndPos, new Vector2(rand.Next(-5, 5), rand.Next(-5, 5)), 0f);
                        }
                    });

                    var retractDuration = 0.5f;
                    if (this.wasStunned)
                    {
                        retractDuration = 2.5f;
                    }

                    lureTween.AppendFloatTween(0f, retractDuration, EaseFuncs.QuadraticEaseOut, accessors);
                }
            });
        }
Beispiel #3
0
 public void AddVectorTween(Vector2 targetVal, float duration, EaseFunc easeFunc,
                            TweenAccessors <Vector2> accessors)
 {
     this.chain.AppendVectorTween(targetVal, duration, easeFunc, accessors);
 }
Beispiel #4
0
 public void AddIntTween(int targetVal, int duration, EaseFunc easeFunc, TweenAccessors <int> accessors)
 {
     this.chain.AppendIntTween(targetVal, duration, easeFunc, accessors);
 }
Beispiel #5
0
 public TweenChainComponent AddFloatTween(float targetVal, float duration, EaseFunc easeFunc,
                                          TweenAccessors <float> accessors)
 {
     this.chain.AppendFloatTween(targetVal, duration, easeFunc, accessors);
     return(this);
 }
Beispiel #6
0
 public TweenChainComponent AddTween <T>(T target, float duration, EaseFunc easeFunc, TweenAccessors <T> accessors,
                                         LerpFunc <T> lerp) where T : struct
 {
     this.chain.Append(new TweenChain.ChainItem <T>(target, duration, easeFunc, accessors, lerp));
     return(this);
 }