Ejemplo n.º 1
0
    private void InitialzeStateManager()
    {
        _stateManager = new StateManager(_muffinAnimator);

        IdleState 		idle = new IdleState(_stateManager, transform);
        MoveState 		move = new MoveState(_stateManager, transform);
        TrapState 		trap = new TrapState(_stateManager, transform);
        DieState 		die	= new DieState(_stateManager, transform);
        SpinState		spin = new SpinState(_stateManager, transform);
        BlastState		blast = new BlastState(_stateManager, transform);
        ChocoRushState	chocoRush = new ChocoRushState(_stateManager, transform);

        PauseState		pause = new PauseState(_stateManager, transform);

        _stateManager.AddCharacterState(idle);
        _stateManager.AddCharacterState(move);
        _stateManager.AddCharacterState(trap);
        _stateManager.AddCharacterState(die);
        _stateManager.AddCharacterState(spin);
        _stateManager.AddCharacterState(blast);
        _stateManager.AddCharacterState(chocoRush);

        _stateManager.AddCharacterState(pause);

        _stateManager.SetDefaultState("Pause");
    }
Ejemplo n.º 2
0
    void Update()
    {
        switch (spinState)
        {
        case SpinState.Waiting:
            waitTime  -= Time.deltaTime;
            spinTime   = tempSpinTime;
            isSpinning = false;

            SetThemInactive(particleEffects);

            if (waitTime <= 0)
            {
                spinState = SpinState.Spinning;
            }
            break;

        case SpinState.Spinning:
            spinTime  -= Time.deltaTime;
            waitTime   = tempWaitTime;
            isSpinning = true;
            SetThemActive(particleEffects);
            gameObject.transform.Rotate(0, 0, spinSpeed * Time.deltaTime);

            if (spinTime <= 0)
            {
                spinState = SpinState.Waiting;
            }
            break;
        }
    }
Ejemplo n.º 3
0
    void Start()
    {
        tempSpinTime = spinTime;
        tempWaitTime = waitTime;

        spinState = SpinState.Spinning;

        circleCol = gameObject.GetComponent <CircleCollider2D>();
    }
Ejemplo n.º 4
0
        public void ThreeJRacahSymmetry()
        {
            foreach (ThreeJSymbol symbol in GenerateRandomThreeJSymbols(50.0, 10))
            {
                // compute the 3j symbol
                SpinState s1 = symbol.Column1;
                SpinState s2 = symbol.Column2;
                SpinState s3 = symbol.Column3;
                double    C  = SpinMath.ThreeJ(s1, s2, s3);

                // form other 3j symbols related by Racah symmetry

                double    k1, k2, k3, n1, n2, n3;
                SpinState t1, t2, t3;

                // rows 1->2->3

                k1 = (s2.J + s2.M + s3.J + s3.M) / 2.0;
                k2 = (s1.J + s1.M + s3.J + s3.M) / 2.0;
                k3 = (s1.J + s1.M + s2.J + s2.M) / 2.0;
                n1 = s1.J - s1.M - k1;
                n2 = s2.J - s2.M - k2;
                n3 = s3.J - s3.M - k3;

                t1 = new SpinState(k1, n1);
                t2 = new SpinState(k2, n2);
                t3 = new SpinState(k3, n3);
                double CC = SpinMath.ThreeJ(t1, t2, t3);

                Assert.IsTrue(TestUtilities.IsNearlyEqual(C, CC));

                // transpose rows and columns

                /*
                 * k1 = s1.J;
                 * k2 = (s2.J + s3.J + s1.M) / 2.0;
                 * k3 = (s2.J + s3.J - s1.M) / 2.0;
                 * n1 = s2.J - s3.J;
                 * n2 = s3.J - s3.M - k2;
                 * n3 = s3.J + s3.M - k2;
                 *
                 * t1 = new SpinState(k1, n1);
                 * t2 = new SpinState(k2, n2);
                 * t3 = new SpinState(k3, n3);
                 * double CT = SpinMath.ThreeJ(t1, t2, t3);
                 *
                 * Assert.IsTrue(TestUtilities.IsNearlyEqual(C, CT));
                 */
            }
        }
Ejemplo n.º 5
0
    public void StartSpin(float spinDelay)
    {
        if(isSpinning) {
            return;
        }

        this.delay = spinDelay;
        delaySpent = 0.0f;
        velocity = 0;
        spinningFor = 0;
        haveTarget = false;
        state = SpinState.Delay;
        isSpinning = true;
    }
Ejemplo n.º 6
0
        private static SpinState[] GenerateRandomSpinStates(Spin j, int n)
        {
            int tj = (int)(2.0 * j.J);

            SpinState[] result = new SpinState[n];
            Random      rng    = new Random(1);

            for (int i = 0; i < n; i++)
            {
                int tm = -tj + 2 * rng.Next(tj + 1);
                result[i] = new SpinState(j, tm / 2.0);
            }

            return(result);
        }
Ejemplo n.º 7
0
        // generates only spinors of the same parity as j_min

        private static SpinState[] GenerateRandomSpinStates(double j_min, double j_max, int n)
        {
            int tj_min = (int)Math.Truncate(2.0 * j_min);
            int tj_max = (int)Math.Truncate(2.0 * j_max);

            SpinState[] states = new SpinState[n];
            Random      rng    = new Random(1);

            for (int i = 0; i < n; i++)
            {
                int tj = tj_min + 2 * rng.Next((tj_max - tj_min) / 2);
                int tm = -tj + 2 * rng.Next(tj);
                states[i] = new SpinState(tj / 2.0, tm / 2.0);
            }

            return(states);
        }
Ejemplo n.º 8
0
        public void ThreeJExchangeSymmetry()
        {
            foreach (ThreeJSymbol symbol in GenerateRandomThreeJSymbols(50.0, 10))
            {
                SpinState s1 = symbol.Column1;
                SpinState s2 = symbol.Column2;
                SpinState s3 = symbol.Column3;

                Console.WriteLine("( {0} {1} {2} )", s1.J, s2.J, s3.J);
                Console.WriteLine("( {0} {1} {2} )", s1.M, s2.M, s3.M);

                double s123 = SpinMath.ThreeJ(s1, s2, s3);
                double s231 = SpinMath.ThreeJ(s2, s3, s1);
                double s312 = SpinMath.ThreeJ(s3, s1, s2);

                Console.WriteLine("{0},{1},{2}", s123, s231, s312);

                Assert.IsTrue(TestUtilities.IsNearlyEqual(s123, s231));
                Assert.IsTrue(TestUtilities.IsNearlyEqual(s123, s312));

                int P;
                if (((int)(s1.J + s2.J + s3.J)) % 2 == 0)
                {
                    P = 1;
                }
                else
                {
                    P = -1;
                }

                double s132 = SpinMath.ThreeJ(s1, s3, s2);
                double s213 = SpinMath.ThreeJ(s2, s1, s3);
                double s321 = SpinMath.ThreeJ(s3, s2, s1);

                Console.WriteLine("{0},{1},{2}", s132, s213, s321);


                Assert.IsTrue(TestUtilities.IsNearlyEqual(s123, P * s132));
                Assert.IsTrue(TestUtilities.IsNearlyEqual(s123, P * s213));
                Assert.IsTrue(TestUtilities.IsNearlyEqual(s123, P * s321));
            }
        }
Ejemplo n.º 9
0
        public SpinningBoss()
            : base(new Vector2(Screen.X, 0))
        {
            Tesseract.Engine.GameWorld.GameState.InstantiateCurrent(new StoryElement(LevelManager.world.Reward));
            lastHit = -(float)Math.PI / 2;
            leftPieces = new List<Enemy>();
            rightPieces = new List<Enemy>();
            emitter = ParticleFactory.CreateStream(Color.Fuchsia, 4, 2, 64);

            for (int i = 0; i < 3; ++i)
            {
                EnemyMelee em = new EnemyMelee(Vector2.Zero, -1);
                em.radius *= 0.75f;
                leftPieces.Add(em);
            }
            for (int i = 0; i < 3; ++i)
            {
                EnemyMelee em = new EnemyMelee(Vector2.Zero, -1);
                em.radius *= 0.75f;
                rightPieces.Add(em);
            }
            leftOrb = new EnemyMelee(Vector2.Zero, -1);
            leftOrb.radius *= 1.5f;
            leftOrb.nBuild.PolyColor = Color.Fuchsia;
            leftOrb.Invulnerable = true;
            rightOrb = new EnemyMelee(Vector2.Zero, -1);
            rightOrb.radius *= 1.5f;
            rightOrb.nBuild.PolyColor = Color.Fuchsia;
            rightOrb.Invulnerable = true;

            spinTarget = Rotation + 1;
            Rotation = 0;
            state = SpinState.Spin;
            stateTime = 0;
            health = 8;
            nBuild.PolyColor = Color.Fuchsia;
            radius *= 1.5f;
            Invulnerable = true;
        }
        ///<summary>Transitions to the declerating state to stop the animation</summary>
        void DecelerateAndStopTheAnimation()
        {
            if ( theSpinState != SpinState.Decelerating ) {

                spinAnimation.From = SpinAngle;
                spinAnimation.To = (SpinAngle + (OneRotation / 8));
                spinAnimation.Duration = new Duration(TimeSpan.FromSeconds(SpinRate / 4));
                spinAnimation.DecelerationRatio = 1.0;
                spinAnimation.AccelerationRatio = 0.0;
                spinAnimation.RepeatBehavior = new RepeatBehavior(1.0); // default: repeat once.

                spinAnimation.Completed += RemoveAnimation;

                theSpinState = SpinState.Decelerating;

                this.BeginAnimation(SpinAngleProperty, spinAnimation);
            }
        }
Ejemplo n.º 11
0
    void setMovingLeft()
    {
        float targetRotation = (targetLine / (float)totalLine);
        Quaternion target = Quaternion.Euler(0, 0, targetRotation * 360.0f);
        
        if (Mathf.Abs(transform.rotation.z - target.z) % Mathf.PI < 0.0001)
        {
            curLine = targetLine;
            spinState = SpinState.Stop;
            return;
        }

        transform.rotation = Quaternion.RotateTowards(transform.rotation, target, spinSpeed);
    }
        ///<summary>Begins, or re-begins the spin animation.</summary>
        void BeginSpinningAnimation()
        {
            switch (theSpinState)
            {
                case SpinState.NotSpinning:
                    SpinAngle = Angle;
                    spinAnimation = new DoubleAnimation();
                    break;

                case SpinState.Decelerating:
                    break;

                case SpinState.Accelerating:
                case SpinState.Running:
                    throw new InvalidOperationException("Should not be in the Acclerating or Running state.");
            }

            spinAnimation.From = SpinAngle;
            spinAnimation.To = (SpinAngle + (OneRotation / 8));
            spinAnimation.Duration = new Duration(TimeSpan.FromSeconds(SpinRate/4));
            spinAnimation.DecelerationRatio = 0.0;
            spinAnimation.AccelerationRatio = 1.0;

            spinAnimation.Completed += SpinContinuously;

            theSpinState = SpinState.Accelerating;

            this.BeginAnimation(SpinAngleProperty, spinAnimation);
        }
Ejemplo n.º 13
0
 public void SpinStateInvalid1()
 {
     // spin state indices are smaller than spin indices
     SpinState s = new SpinState(1.0, -2.0);
 }
Ejemplo n.º 14
0
    void keyDownStateCange(float key)
    {
        if (spinState != SpinState.Stop || player.isDodging())
        {
            return;
        }

        if ( key > 0 )
        {
            spinState = SpinState.Right;
			player.rightMove();
            targetLine = (curLine + 3) % 4;
        }
        else if ( key < 0)
        {
			spinState = SpinState.Left;
			player.leftMove();
            targetLine = (curLine + 1) % 4;
        }
    }
Ejemplo n.º 15
0
 public void SpinStateInvalid2()
 {
     // spin states indices match the parity of spin indices
     SpinState s = new SpinState(1.0, 0.5);
 }
Ejemplo n.º 16
0
    void UpdateStopping()
    {
        velocity -= deceleration * Time.deltaTime;
        if(velocity < minVelocity) {
            velocity = minVelocity;
        }

        foreach(var go in icons) {
            var localPos = go.transform.localPosition;
            localPos.y -= velocity;
            go.transform.localPosition = localPos;
        }
        for(var i = 0; i < icons.Count; i++) {
            var toUpdate = icons[i];
            var pos = toUpdate.transform.localPosition;
            if(pos.y < -50) {
                var idx = i - 1;
                if(idx < 0) {
                    idx += icons.Count;
                }
                var next = icons[idx];
                var nextPos = next.transform.localPosition;
                pos.y = nextPos.y + 100.0f;
                toUpdate.transform.localPosition = pos;
            }
        }

        var stopPos = icons[(int)target].transform.localPosition.y;
        if(Mathf.Abs(100.0f - stopPos) < minVelocity * 1.5f) {
            state = SpinState.Stopped;
        }
    }
Ejemplo n.º 17
0
 public void SpinStateInvalid3()
 {
     // spin state values are integer or half-integer
     SpinState s = new SpinState(3.0, 0.75);
 }
Ejemplo n.º 18
0
 private void SetState(SpinState state)
 {
     this.lastHit = 0;
     this.state = state;
     this.stateTime = 0;
 }
        /// <summary>Called when the animation has slowed to a stop.  Removes the animation</summary>
        /// <remarks>This should only be called from the spinAnimationCompleted event.</remarks>
        void RemoveAnimation(object sender, EventArgs e)
        {
            spinAnimation.Completed -= RemoveAnimation;

            //
            // We have to remember the current spin angle becuase the animation will
            // reset the SpinAngleProperty back to its base value when it is removed
            // from the SpinAngleProperty.  The SpinAngleProperty base value is the
            // animations from value.
            //
            double tmp = SpinAngle % OneRotation;

            this.BeginAnimation(SpinAngleProperty, null);

            Angle = tmp;
            SpinAngle = tmp;

            SetValue(SpinningPropertyKey, false);

            //
            // We have to 'forget' the spin animation here because once set, it never
            // forget's the SpinAngleProperty base value so we will get jerks when
            // spin is renabled.  Said another way, simply removing the animation
            // from the property does not cause it to forget its state.  So, we must
            // throw away the current animation and create a new one next time
            // spinning is re-enabled.
            //
            spinAnimation = null;

            theSpinState = SpinState.NotSpinning;

            if (!IsEnabled)
            {
                SetDisabledBrushes();
            }
        }
        /// <summary>Updates the animation to spin continuously</summary>
        void SpinContinuously(object sender, EventArgs e)
        {
            spinAnimation.Completed -= SpinContinuously;

            spinAnimation.From = SpinAngle;
            spinAnimation.To = SpinAngle + OneRotation;
            spinAnimation.Duration = new Duration(TimeSpan.FromSeconds(SpinRate));
            spinAnimation.DecelerationRatio = 0.0;
            spinAnimation.AccelerationRatio = 0.0;
            spinAnimation.RepeatBehavior = RepeatBehavior.Forever;

            theSpinState = SpinState.Running;

            this.BeginAnimation(SpinAngleProperty, spinAnimation);
        }
Ejemplo n.º 21
0
 void UpdateDelay()
 {
     delaySpent += Time.deltaTime;
     if(delaySpent > delay) {
         audio.clip = startSound;
         audio.Play ();
         state = SpinState.Spinning;
     }
 }
Ejemplo n.º 22
0
    void UpdateSpinning()
    {
        velocity += acceleration * Time.deltaTime;
        if(velocity > maxVelocity) {
            velocity = maxVelocity;
        }

        foreach(var go in icons) {
            var localPos = go.transform.localPosition;
            localPos.y -= velocity;
            go.transform.localPosition = localPos;
        }
        for(var i = 0; i < icons.Count; i++) {
            var toUpdate = icons[i];
            var pos = toUpdate.transform.localPosition;
            if(pos.y < -100) {
                var idx = i - 1;
                if(idx < 0) {
                    idx += icons.Count;
                }
                var next = icons[idx];
                var nextPos = next.transform.localPosition;
                pos.y = nextPos.y + 100.0f;
                toUpdate.transform.localPosition = pos;
            }
        }

        spinningFor += Time.deltaTime;
        if(haveTarget && spinningFor >= spinTime) {
            state = SpinState.Stopping;
        }
    }
Ejemplo n.º 23
0
        public void SixJThreeJRelation()
        {
            SixJSymbol[] symbols = GenerateRandomSixJSymbols(50.0, 5);
            foreach (SixJSymbol symbol in symbols)
            {
                Spin a = symbol.J1;
                Spin b = symbol.J2;
                Spin c = symbol.J3;
                Spin d = symbol.J4;
                Spin e = symbol.J5;
                Spin f = symbol.J6;

                SpinState[] ams = GenerateRandomSpinStates(a, 2);
                SpinState[] bms = GenerateRandomSpinStates(b, 2);
                foreach (SpinState am in ams)
                {
                    foreach (SpinState bm in bms)
                    {
                        if (Math.Abs(am.M + bm.M) > c.J)
                        {
                            continue;
                        }
                        SpinState cm = new SpinState(c, -(am.M + bm.M));

                        double g1 = SpinMath.ThreeJ(am, bm, cm);
                        double g2 = SpinMath.SixJ(a, b, c, d, e, f);
                        double p  = g1 * g2;

                        double        q   = 0.0;
                        List <double> ts  = new List <double>();
                        SpinState[]   dms = d.States();
                        foreach (SpinState dm in dms)
                        {
                            if (Math.Abs(dm.M + cm.M) > e.J)
                            {
                                continue;
                            }
                            SpinState em  = new SpinState(e, dm.M + cm.M);
                            SpinState mem = new SpinState(e, -em.M);
                            double    f1  = SpinMath.ThreeJ(dm, mem, cm);

                            if (Math.Abs(em.M + am.M) > f.J)
                            {
                                continue;
                            }
                            SpinState fm  = new SpinState(f, em.M + am.M);
                            SpinState mfm = new SpinState(f, -fm.M);
                            double    f2  = SpinMath.ThreeJ(em, mfm, am);

                            SpinState mdm = new SpinState(d, -dm.M);
                            double    f3  = SpinMath.ThreeJ(fm, mdm, bm);

                            double t = f1 * f2 * f3;

                            int s = (int)Math.Round(dm.J + dm.M + em.J + em.M + fm.J + fm.M);
                            if (s % 2 != 0)
                            {
                                t = -t;
                            }

                            q += t;
                            ts.Add(t);
                        }

                        Console.WriteLine("{0} v. {1}", p, q);
                        //Assert.IsTrue(TestUtilities.IsNearlyEqual(p, q));
                        Assert.IsTrue(TestUtilities.IsSumNearlyEqual(ts, p));
                    }
                }
            }
        }