void OnCollisionExit2D(Collision2D other)
 {
     if (other.gameObject.CompareTag("Player"))
     {
         platformState = PlatformState.Return;
     }
 }
    void RpcOnPlatformMoving()
    {
        if (platformState == PlatformState.Return && Vector3.Distance(transform.localPosition, startPosition) < 0.5f)
        {
            platformState     = PlatformState.Idle;
            rb2d.gravityScale = 0;
        }

        // Do nothing if idle
        if (platformState == PlatformState.Idle)
        {
            return;
        }

        Vector3 targetLocation = startPosition;

        // If active move towards target Location based on the gravity platform state
        if (platformState == PlatformState.Active)
        {
            if (gravityPlatformState == GravityPlatformState.Up)
            {
                targetLocation = startPosition + Vector3.up * distance;
            }
            else if (gravityPlatformState == GravityPlatformState.Down)
            {
                targetLocation = startPosition + Vector3.down * distance;
            }
        }

        float step = speed * Time.deltaTime;

        transform.localPosition = Vector3.MoveTowards(transform.localPosition, targetLocation, step);
    }
 void OnCollisionEnter2D(Collision2D other)
 {
     if (other.gameObject.CompareTag("Player"))
     {
         platformState = PlatformState.Active;
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructor for platform
        /// </summary>
        /// <param name="a_world"></param>World in which the platform is created and drawn
        /// <param name="a_leftPoint"></param>Left end point of the platform
        /// <param name="a_rightPoint"></param>Right end point of the platform
        /// <param name="a_texture"></param>Platform texture
        public Platform(World a_world, Vector2 a_leftPoint, Vector2 a_rightPoint, Texture2D a_texture)
        {
            m_world = a_world;

            m_leftPoint  = a_leftPoint;
            m_rightPoint = a_rightPoint;

            // Initializing platform position and dimensions
            float   width    = MathX.LineLength(a_leftPoint, a_rightPoint);
            Vector2 midPoint = MathX.Midpoint(a_leftPoint, a_rightPoint);

            m_sprite   = new Sprite(a_world, a_texture, new Vector2(width, 10), 0.0f, midPoint);
            m_rotation = MathX.GetAngleBetween(a_leftPoint, a_rightPoint) * (float)(Math.PI / 180);
            m_sprite.m_body.Rotation = m_rotation;
            m_sprite.m_body.BodyType = BodyType.Static;
            m_sprite.m_body.UserData = "platform";
            m_currentState           = PlatformState.ROOF;

            // Initializing normal vector
            Vector2 difference = a_leftPoint - a_rightPoint;

            m_normalVector = new Vector2(-difference.Y, difference.X);
            m_normalVector.Normalize();

            m_connection = new Sprite(a_world, ContentLibrary.circleTexture, 5, 0.0f, a_leftPoint);
            m_connection.m_body.BodyType = BodyType.Static;
            m_connection2 = new Sprite(a_world, ContentLibrary.circleTexture, 5, 0.0f, a_rightPoint);
            m_connection2.m_body.BodyType = BodyType.Static;
            //m_connection.m_body.UserData = "platform";
        }
Ejemplo n.º 5
0
    /** Switch - Iggy Azalea */
    public void Switch(PlatformState state)
    {
        switch (state)
        {
        case PlatformState.Enabled:
            MakeMeVisible(true);
            Collide(true);
            break;

        case PlatformState.Disabled:
            MakeMeVisible(false);
            Collide(false);
            break;

        case PlatformState.Invisible:
            MakeMeVisible(false);
            Collide(true);
            break;

        default:
            MakeMeVisible(false);
            Collide(false);
            break;
        }
    }
Ejemplo n.º 6
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        if (currentState == PlatformState.Neutral && !CompareTag("StartPlatform") && !CompareTag("FinishPlatform"))
        {
            if (other.gameObject.CompareTag("Player1"))
            {
                sprite.material  = manager.pinkPlatform;
                currentState     = PlatformState.Pink;
                gameObject.layer = 8;
            }
            else if (other.gameObject.CompareTag("Player2"))
            {
                sprite.material  = manager.bluePlatform;
                currentState     = PlatformState.Blue;
                gameObject.layer = 9;
            }
        }

        if (currentState == PlatformState.Neutral && CompareTag("FinishPlatform"))
        {
            if (other.gameObject.CompareTag("Player1"))
            {
                manager.isPlayer1OnFinish = true;
            }
            else if (other.gameObject.CompareTag("Player2"))
            {
                manager.isPlayer2OnFinish = true;
            }
        }
    }
Ejemplo n.º 7
0
        /// <summary>
        /// Constructor for platform
        /// </summary>
        /// <param name="a_world"></param>World in which the platform is created and drawn
        /// <param name="a_leftPoint"></param>Left end point of the platform
        /// <param name="a_rightPoint"></param>Right end point of the platform
        /// <param name="a_texture"></param>Platform texture
        public Platform(World a_world, Vector2 a_leftPoint, Vector2 a_rightPoint, Texture2D a_texture)
        {
            m_world = a_world;

            m_leftPoint = a_leftPoint;
            m_rightPoint = a_rightPoint;

            // Initializing platform position and dimensions
            float width = MathX.LineLength(a_leftPoint, a_rightPoint);
            Vector2 midPoint = MathX.Midpoint(a_leftPoint, a_rightPoint);
            m_sprite = new Sprite(a_world, a_texture, new Vector2(width, 10), 0.0f, midPoint);
            m_rotation = MathX.GetAngleBetween(a_leftPoint, a_rightPoint) * (float)(Math.PI / 180);
            m_sprite.m_body.Rotation = m_rotation;
            m_sprite.m_body.BodyType = BodyType.Static;
            m_sprite.m_body.UserData = "platform";
            m_currentState = PlatformState.ROOF;

            // Initializing normal vector
            Vector2 difference = a_leftPoint - a_rightPoint;
            m_normalVector = new Vector2(-difference.Y, difference.X);
            m_normalVector.Normalize();

            m_connection = new Sprite(a_world, ContentLibrary.circleTexture, 5, 0.0f, a_leftPoint);
            m_connection.m_body.BodyType = BodyType.Static;
            m_connection2 = new Sprite(a_world, ContentLibrary.circleTexture, 5, 0.0f, a_rightPoint);
            m_connection2.m_body.BodyType = BodyType.Static;
            //m_connection.m_body.UserData = "platform";
        }
    public void AddState(PlatformState state, bool current = false)
    {
        States.Add (state.Name, state);

        if (current)
            CurrentStateKey = state.Name;
    }
Ejemplo n.º 9
0
    void FixedUpdate()
    {
        if (m_state == PlatformState.Normal)
        {
            return;
        }

        Animation platAnim = gameObject.GetComponent <Animation>();

        if (platAnim == null || platAnim["Take 001"] == null)
        {
            //Debug.Log("No animation on falling platform!");
            return;
        }
        if (m_state == PlatformState.Shaking)
        {
            if (platAnim["Take 001"].normalizedTime >= 0.39f)
            {
                platAnim["Take 001"].normalizedTime = 0.10f;
            }
            if (m_timeTriggered + timeToFall < Time.time)
            {
                m_state = PlatformState.Falling;
                platAnim["Take 001"].normalizedTime = 0.40f;
                if (m_audio != null)
                {
                    m_audio.Play();
                }
            }
        }
        else if (m_state == PlatformState.Falling)
        {
            if (platAnim["Take 001"].normalizedTime >= 0.5f)
            {
                platAnim.Stop();
                m_state    = PlatformState.Down;
                m_timeDown = Time.time;
            }
        }
        else if (m_state == PlatformState.Down)
        {
            if (automaticReset)
            {
                if (m_timeDown + resetTime < Time.time)
                {
                    m_state = PlatformState.Resetting;
                    platAnim["Take 001"].normalizedTime = 0.70f;
                    platAnim.Play();
                }
            }
        }
        else if (m_state == PlatformState.Resetting)
        {
            if (platAnim["Take 001"].normalizedTime >= 0.97f)
            {
                m_state = PlatformState.Normal;
                platAnim.Stop();
            }
        }
    }
    void RpcOnPlatformMoving()
    {
        if (platformState == PlatformState.Idle)
        {
            return;
        }

        if (platformState == PlatformState.Active)
        {
            float angle = transform.localEulerAngles.z < 90 ? transform.localEulerAngles.z : 360 - transform.localEulerAngles.z;
            if (angle >= maxTurnAngle)
            {
                rb2d.constraints = RigidbodyConstraints2D.FreezeRotation | RigidbodyConstraints2D.FreezePosition;
                platformState    = PlatformState.Return;
            }
        }
        else if (platformState == PlatformState.Return)
        {
            transform.Rotate((transform.localEulerAngles.z < 90 ? Vector3.back : Vector3.forward) * rotateSpeed * Time.deltaTime);
            if (transform.localEulerAngles.z < 1)
            {
                platformState    = PlatformState.Idle;
                rb2d.constraints = RigidbodyConstraints2D.FreezePosition;
            }
        }
    }
Ejemplo n.º 11
0
        //https://docs.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Application?view=winrt-19041
        public IObservable <PlatformState> WhenStateChanged() => Observable
        .Create <PlatformState>(ob =>
        {
            var fgHandler = new LeavingBackgroundEventHandler((sender, target) => ob.OnNext(PlatformState.Foreground));
            var bgHandler = new EnteredBackgroundEventHandler((sender, target) => ob.OnNext(PlatformState.Background));

            if (this.app == null)
            {
                ob.OnNext(PlatformState.Background);
            }
            else
            {
                this.app.LeavingBackground += fgHandler;
                this.app.EnteredBackground += bgHandler;
            }
            return(() =>
            {
                if (this.app != null)
                {
                    this.app.LeavingBackground -= fgHandler;
                    this.app.EnteredBackground -= bgHandler;
                }
            });
        })
        .Do(x => this.Status = x);
Ejemplo n.º 12
0
        // A timer that makes the platform rise once done
        private IEnumerator BeginRise()
        {
            yield return(new WaitForSeconds(timeToRest));

            moveAcceleration = 0f;
            platformState    = PlatformState.isRising;
        }
Ejemplo n.º 13
0
            // -------------------
            public void Refresh()
            {
                this.platformList.Clear();

                BuildTargetGroup[] platformIds = (BuildTargetGroup[])System.Enum.GetValues(typeof(BuildTargetGroup));
                for (int i = 0; i < platformIds.Length; ++i)
                {
                    if (!ConfigManager.IsBuildTargetGroupSupported(platformIds[i]))
                    {
                        continue;
                    }
                    if (this.FindPlatform(platformIds[i]) != null)
                    {
                        continue;
                    }

                    PlatformState s = new PlatformState(this);

                    s.platform        = platformIds[i];
                    s.forceMobileMode = ConfigManager.IsSymbolDefined(ConfigManager.CF_FORCE_MOBILE_MODE, s.platform);

                    this.platformList.Add(s);
                }

                this.OnOptionChange();
            }
    public IEnumerator BecomeAmmo(Vector3 PlayerPosition)
    {
        StopCoroutine(StartDropTimer(sinkTime));

        // Set the target location
        playerPosition = PlayerPosition;
        // Start raising the platform
        var Floaters = GetComponentsInChildren <FloatingController>();

        foreach (var floater in Floaters)
        {
            StartCoroutine(floater.raiseUp(ammoTime));
        }
        // Set the material of the platform to the outline with a new color
        GetComponent <Renderer>().material.SetFloat("_Outline", outlineValue);
        playerPosition = PlayerPosition;
        // Wait for a just abit for the platform to raise from the tea
        yield return(new WaitForSeconds(ammoTime));

        // Set the new state
        state = PlatformState.ABSORBED;
        // Disable the floaters and rigidbody
        foreach (var floater in Floaters)
        {
            floater.enabled = false;
        }
        GetComponent <Rigidbody>().useGravity = false;
    }
Ejemplo n.º 15
0
 void Start()
 {
     rotateFront = false;
     rotateBack  = false;
     platform    = GetComponentInParent <PlatformState>();
     audio       = GetComponent <AudioSource>();
 }
Ejemplo n.º 16
0
    /// <summary>
    /// Color will change until player step on the platform and the platform is in any dangerous color
    /// </summary>
    IEnumerator ChangeColors()
    {
        _state = PlatformState.Stationary;

        m_fColorChangeIndex = 0;
        Tween t = DOTween.To(() => m_fColorChangeIndex, x => m_fColorChangeIndex = x, 1, m_fColorChangeDuration).SetLoops(-1, LoopType.Yoyo).ChangeStartValue(0).ChangeEndValue(1);



        while (true)
        {
            if (m_bHasCollide)
            {
                if (m_bWillLerp && m_fColorChangeIndex > 0.5)
                {
                    break;
                }
                else if (!m_bWillLerp)
                {
                    break;
                }
            }
            if (m_bWillLerp)
            {
                MaterialPropertyBlock property = new MaterialPropertyBlock();
                property.SetColor("_EmissionColor", m_GradientColor.Evaluate(m_fColorChangeIndex));
                m_Renderer.SetPropertyBlock(property);
            }

            yield return(null);
        }
        t.Kill();
    }
    IEnumerator MovePlatform(PlatformState direction)
    {
        _platformIsMoving = true;
        float elapsedTime = 0f;

        Vector3 startPoint = this.StartPoint.position;
        Vector3 endPoint   = this.EndPoint.position;

        if (direction == PlatformState.Down)
        {
            startPoint = this.EndPoint.position;
            endPoint   = this.StartPoint.position;
        }

        while (elapsedTime < TravelTimeinSeconds)
        {
            float fractionFromCurve = MovementCurve.Evaluate((elapsedTime / TravelTimeinSeconds));
            Platform.transform.position = Vector3.Lerp(startPoint, endPoint, fractionFromCurve);
            elapsedTime += Time.deltaTime;
            yield return(null);
        }

        Platform.transform.position = endPoint;

        _platformIsMoving = false;
    }
Ejemplo n.º 18
0
    private void Fall()
    {
        _animator.SetTrigger(TRIGGER_ANIM);

        _platformState        = PlatformState.Fallen;
        _rigidbody2D.velocity = new Vector2(0, -FallSpeed);
    }
Ejemplo n.º 19
0
    public IEnumerator BecomeAmmo(GameObject player)
    {
        StopCoroutine(StartDropTimer(sinkTime));

        // Set the target object
        playerObject = player;
        // Set the new state
        state = PlatformState.MOVING;
        // Set the material of the platform to the outline with a new color
        GetComponent <Renderer>().material.SetFloat("_Outline", outlineValue);

        // Wait for a just abit for the platform to be fully absorbed
        yield return(new WaitForSeconds(absorbTime));

        Player1 p = player.GetComponent <Player1>();

        state = PlatformState.ABSORBED;
        // Disable the floaters and rigid-body along with turning the collide into a trigger
        foreach (var floater in GetComponentsInChildren <FloatingController>())
        {
            floater.enabled = false;
        }
        GetComponent <Rigidbody>().useGravity  = false;
        GetComponent <BoxCollider>().isTrigger = true;
    }
Ejemplo n.º 20
0
    private void Start()
    {
        _platformState   = PlatformState.Idle;
        _initialPosition = transform.position;

        _fallTimer = 0;
    }
Ejemplo n.º 21
0
        internal PlatformState Init(WeaponComponent comp)
        {
            if (comp.MyCube.MarkedForClose)
            {
                return(PlatformCrash(comp, true, false, $"Your block subTypeId ({comp.MyCube.BlockDefinition.Id.SubtypeId.String}) markedForClose, init platform invalid, I am crashing now Dave."));
            }

            if (!comp.MyCube.IsFunctional)
            {
                State = PlatformState.Delay;
                return(State);
            }

            //Get or init Ai
            var newAi = false;

            if (!Comp.Session.GridTargetingAIs.TryGetValue(Comp.MyCube.CubeGrid, out Comp.Ai))
            {
                newAi   = true;
                Comp.Ai = Comp.Session.GridAiPool.Get();
                Comp.Ai.Init(Comp.MyCube.CubeGrid, Comp.Session);
                Comp.Session.GridTargetingAIs.TryAdd(Comp.MyCube.CubeGrid, Comp.Ai);
            }

            var blockDef = Comp.MyCube.BlockDefinition.Id.SubtypeId;

            if (!Comp.Ai.WeaponCounter.ContainsKey(blockDef))
            {
                Comp.Ai.WeaponCounter[blockDef] = Comp.Session.WeaponCountPool.Get();
            }

            var wCounter = comp.Ai.WeaponCounter[blockDef];

            wCounter.Max = Structure.GridWeaponCap;

            if (newAi)
            {
                Comp.SubGridInit();
                if (Comp.Ai.MarkedForClose)
                {
                    Log.Line($"PlatFormInit and AI MarkedForClose: CubeMarked:{Comp.MyCube.MarkedForClose}");
                }
            }

            if (wCounter.Max == 0 || Comp.Ai.Construct.GetWeaponCount(blockDef) + 1 <= wCounter.Max)
            {
                wCounter.Current++;
                GridAi.Constructs.UpdateWeaponCounters(Comp.Ai);
                State = PlatformState.Valid;
            }
            else
            {
                return(PlatformCrash(comp, true, false, $"{blockDef.String} over block limits: {wCounter.Current}."));
            }

            Parts.Entity = comp.Entity as MyEntity;

            return(GetParts(comp));
        }
Ejemplo n.º 22
0
    private void Start()
    {
        rendStipplesRight = transform.Find("DashPlatform_Visuals").transform.Find("Stipples_toRight").GetComponent <SpriteRenderer>();
        rendStipplesLeft  = transform.Find("DashPlatform_Visuals").transform.Find("Stipples_toLeft").GetComponent <SpriteRenderer>();

        plaftormState          = PlatformState.middle;
        currentPlayerDirection = 1;
    }
 private void OnCollisionExit2D(Collision2D other)
 {
     if (other.gameObject.CompareTag("Player"))
     {
         platformState    = PlatformState.Return;
         rb2d.constraints = RigidbodyConstraints2D.FreezePosition;
     }
 }
    private float m_timeTriggered; //!< time the platform stepped on

    #endregion Fields

    #region Methods

    void FixedUpdate()
    {
        if (m_state == PlatformState.Normal)
            return;

        Animation platAnim = gameObject.GetComponent<Animation>();
        if (platAnim == null || platAnim["Take 001"] == null)
        {
            //Debug.Log("No animation on falling platform!");
            return;
        }
        if(m_state == PlatformState.Shaking)
        {
            if(platAnim["Take 001"].normalizedTime >= 0.39f)
            {
                platAnim["Take 001"].normalizedTime = 0.10f;
            }
            if(m_timeTriggered+timeToFall < Time.time)
            {
                m_state = PlatformState.Falling;
                platAnim["Take 001"].normalizedTime = 0.40f;
                if (m_audio != null)
                {
                    m_audio.Play();
                }
            }
        }
        else if(m_state == PlatformState.Falling)
        {
            if(platAnim["Take 001"].normalizedTime >= 0.5f)
            {
                platAnim.Stop();
                m_state = PlatformState.Down;
                m_timeDown = Time.time;
            }
        }
        else if(m_state == PlatformState.Down)
        {
            if(automaticReset)
            {
                if(m_timeDown+resetTime < Time.time)
                {
                    m_state = PlatformState.Resetting;
                    platAnim["Take 001"].normalizedTime = 0.70f;
                    platAnim.Play();
                }
            }
        }
        else if(m_state == PlatformState.Resetting)
        {
            if(platAnim["Take 001"].normalizedTime >= 0.97f)
            {
                m_state = PlatformState.Normal;
                platAnim.Stop();
            }
        }
    }
Ejemplo n.º 25
0
 void CalculateNewState()
 {
     if (state == PlatformState.Dying && decay >= 1.0)
     {
         state = PlatformState.Dead;
         dyingSound.Stop();
         deathSound.Play(0);
     }
 }
Ejemplo n.º 26
0
 void OnTriggerEnter(Collider collider)
 {
     if (m_state == PlatformState.Normal)
     {
         m_state         = PlatformState.Shaking;
         m_timeTriggered = Time.time;
         m_platAnim["Take 001"].normalizedTime = 0.10f;
         m_platAnim.Play();
     }
 }
Ejemplo n.º 27
0
        public virtual void WaitForStop()
        {
            while (State == PlatformState.Started)
            {
                Update();
                Thread.Sleep(1);
            }

            State = PlatformState.Exited;
        }
Ejemplo n.º 28
0
 // Use this for initialization
 void Awake()
 {
     _spriteRenderer       = GetComponent <SpriteRenderer> ();
     _rigidbody            = GetComponent <Rigidbody2D>();
     platformHeight        = _spriteRenderer.bounds.size.y;
     platformWidth         = _spriteRenderer.bounds.size.x;
     _addPlatformComponent = false;
     _runScaleAnimation    = false;
     state     = PlatformState.Idle;
     prevState = PlatformState.Idle;
 }
Ejemplo n.º 29
0
    /// <summary>
    /// After a fill seconds the platform will respawn.
    /// </summary>
    IEnumerator Spawn()
    {
        _state             = PlatformState.Spawning;
        m_Renderer.enabled = false;
        col.enabled        = false;
        yield return(new WaitForSeconds(m_fSpawnDuration));

        transform.position = m_vInitialPosition;
        m_Renderer.enabled = true;
        col.enabled        = true;
    }
Ejemplo n.º 30
0
    IEnumerator PlatformBehavior()
    {
        float TimeUntilShake = Lifetime - ShakeTime;

        yield return(new WaitForSeconds(TimeUntilShake));

        state = PlatformState.Shake;
        yield return(new WaitForSeconds(ShakeTime));

        state = PlatformState.Drop;
    }
Ejemplo n.º 31
0
    /// <summary>
    /// returns true if selfstate is eaten by theirstate
    /// </summary>
    /// <param name="selfState"></param>
    /// <param name="theirState"></param>
    /// <returns></returns>
    public bool IsEatenBy(PlatformState selfState, PlatformState theirState)
    {
        if (selfState == PlatformState.FIRE && theirState == PlatformState.WATER ||
            selfState == PlatformState.GRASS && theirState == PlatformState.FIRE ||
            selfState == PlatformState.WATER && theirState == PlatformState.GRASS)
        {
            return(true);
        }

        return(false);
    }
Ejemplo n.º 32
0
 internal void Clean()
 {
     for (int i = 0; i < Weapons.Length; i++)
     {
         Weapons[i] = null;
     }
     Parts.Clean(null);
     Structure = null;
     State     = PlatformState.Fresh;
     Comp      = null;
 }
Ejemplo n.º 33
0
    private AudioSource m_audio;                                //!< The audio to play on fall

    // Use this for initialization
    void Start()
    {
        m_state         = PlatformState.Normal;
        m_timeDown      = 0.0f;
        m_timeTriggered = 0.0f;

        m_audio = this.GetComponentInChildren <AudioSource>();
        if (m_audio == null)
        {
            Debug.LogWarning("Falling platform missing audio source!");
        }
    }
    // Use this for initialization
    void Start()
    {
        m_state = PlatformState.Normal;
        m_timeDown = 0.0f;
        m_timeTriggered = 0.0f;

        m_audio = this.GetComponentInChildren<AudioSource>();
        if (m_audio == null)
        {
            Debug.LogWarning("Falling platform missing audio source!");
        }

        m_platAnim = gameObject.GetComponent<Animation>();
        if (m_platAnim == null || m_platAnim["Take 001"] == null)
        {
            Debug.LogError("Falling Platform '" + name + "' is missing required animations!");
        }
    }
Ejemplo n.º 35
0
		private void ChangeState(PlatformState platformState)
		{
			BeforeStateChange(this, platformState);
			CurrentState = platformState;
			StateChanged(this, platformState);
		}
Ejemplo n.º 36
0
		public void ChangeState(PlatformState state)
		{
			BeforeStateChange(this, state);
			CurrentState = state;
			StateChanged(this, state);
		}
 public void RemoveState(PlatformState state)
 {
     States.Remove (state.Name);
 }
 void OnTriggerEnter(Collider collider)
 {
     //Debug.Log("Collision entered");
     if(m_state == PlatformState.Normal)
     {
         m_state = PlatformState.Shaking;
         m_timeTriggered = Time.time;
         Animation platAnim = gameObject.GetComponent<Animation>();
         platAnim["Take 001"].normalizedTime = 0.10f;
         platAnim.Play();
     }
 }
    // Use this for initialization
    void Start()
    {
        m_state = PlatformState.Normal;
        m_timeDown = 0.0f;
        m_timeTriggered = 0.0f;

        m_audio = this.GetComponentInChildren<AudioSource>();
        if (m_audio == null)
        {
            Debug.LogWarning("Falling platform missing audio source!");
        }
    }
Ejemplo n.º 40
0
        private static void EventShouldBeCalledForStateDuringRegistration(Expression<Action<Game>> eventExpression, PlatformState state, bool changeStateFirst)
        {
            var eventCalled = false;
            var stateChanged = false;
            var platform = new FakePlatform();
            var objectFactoryMock = new Mock<IObjectFactory>();

            platform.StateChanged +=
                (p, s) =>
                {
                    if (s == state)
                    {
                        stateChanged = true;
                    }
                };

            var gameMock = new Mock<Game>();
            gameMock.Expect(g => g.OnInitialize());
            gameMock.Expect(g => g.OnBeforeInitialize());
            gameMock.Expect(g => g.OnLoadContent());
            gameMock.Expect(g => g.OnBeforeUpdate());
            gameMock.Expect(g => g.OnUpdate());
            gameMock.Expect(g => g.OnAfterUpdate());
            gameMock.Expect(g => g.OnStopped());
            gameMock.Expect(eventExpression).Callback(

                () =>
                {
                    Assert.That(stateChanged, Is.True);
                    eventCalled = true;
                });

            var assetLoaderServiceMock = new Mock<IAssetLoaderService>();
            var runtime = new Core.Runtime(platform, objectFactoryMock.Object, assetLoaderServiceMock.Object, null);

            if (changeStateFirst)
            {
                platform.ChangeState(state);
            }

            var displayMock = new Mock<IDisplay>();
            runtime.RegisterGame(displayMock.Object, gameMock.Object);

            if (!changeStateFirst)
            {
                platform.ChangeState(state);
            }

            Assert.That(eventCalled, Is.True);
        }
 void OnTriggerEnter(Collider collider)
 {
     if(m_state == PlatformState.Normal)
     {
         m_state = PlatformState.Shaking;
         m_timeTriggered = Time.time;
         m_platAnim["Take 001"].normalizedTime = 0.10f;
         m_platAnim.Play();
     }
 }
Ejemplo n.º 42
0
        /// <summary>
        /// Updates the platform's current state and makes sure it's rotated correctly
        /// </summary>
        public void Update()
        {
            m_sprite.m_body.Rotation = m_rotation;
            Vector2 grav = m_world.Gravity;
            grav.Normalize();

            float dotProduct = Vector2.Dot(m_normalVector, grav);

            if (dotProduct > 0)
            {
                m_currentState = PlatformState.ROOF;
            }
            else if (dotProduct < -0.8f)
            {
                m_currentState = PlatformState.GROUND;
            }
            else
            {
                m_currentState = PlatformState.SLOPE;
            }


        }
    private float m_timeTriggered; //!< time the platform stepped on

    #endregion Fields

    #region Methods

    void FixedUpdate()
    {
        if( m_platAnim == null || m_platAnim["Take 001"] == null )
        {
            return;
        }
        if (m_state == PlatformState.Normal)
        {
            m_platAnim["Take 001"].normalizedTime = 0.10f;
            m_platAnim.Stop();
            return;
        }

        if(m_state == PlatformState.Shaking)
        {
            if(m_platAnim["Take 001"].normalizedTime >= 0.39f)
            {
                m_platAnim["Take 001"].normalizedTime = 0.10f;
            }

            if(m_timeTriggered+timeToFall < Time.time)
            {
                m_state = PlatformState.Falling;
                m_platAnim["Take 001"].normalizedTime = 0.40f;
                if (m_audio != null)
                {
                    m_audio.Play();
                }
            }
        }
        else if(m_state == PlatformState.Falling)
        {
            if(m_platAnim["Take 001"].normalizedTime >= 0.5f)
            {
                m_platAnim.Stop();
                m_state = PlatformState.Down;
                m_timeDown = Time.time;
            }
        }
        else if(m_state == PlatformState.Down)
        {
            if(automaticReset)
            {
                if(m_timeDown+resetTime < Time.time)
                {
                    m_state = PlatformState.Resetting;
                    m_platAnim["Take 001"].normalizedTime = 0.70f;
                    m_platAnim.Play();
                }
            }
        }
        else if(m_state == PlatformState.Resetting)
        {
            if(m_platAnim["Take 001"].normalizedTime >= 0.97f)
            {
                m_state = PlatformState.Normal;
                m_platAnim["Take 001"].normalizedTime = 0.0f;
            }
            else if (m_timeDown + resetTime + 1 < Time.time)
            {
                m_state = PlatformState.Normal;
                m_platAnim["Take 001"].normalizedTime = 0.10f;
            }
        }
    }
Ejemplo n.º 44
0
        public bool BeginGameTransaction(ulong reserveAmount)
        {
            if (Meters.State != PlatformState.Idle)
            {
                Console.WriteLine("Platform is in state {0}, rejecting new transaction", Meters.State);
                return false;
            }
            if (reserveAmount > Meters.Balance)
            {
                Console.WriteLine("Not enough funds to begin transaction");
                return false;
            }

            Meters.StartBalance = Meters.Balance;
            Meters.AccumulatedPayout = 0;
            Meters.AccumulatedSecondaryPayout = 0;
            Meters.AccumulatedWager = 0;
            Meters.AccumulatedSecondaryWager = 0;
            Meters.CurrentCashoutAmount = 0;
            Meters.SecondaryGameCount = 0;
            // Meters.Balance // Do nothing with balance yet.

            nextGameState = PlatformState.Playing;

            return true; // Ok to start transaction.
        }
Ejemplo n.º 45
0
        public void EndGameTransaction()
        {
            var TotalPayout = Meters.AccumulatedPayout + Meters.AccumulatedSecondaryPayout;
            var TotalWager = Meters.AccumulatedWager + Meters.AccumulatedSecondaryWager;

            if (WinLimit == 0) // No Limits
            {
                nextGameState = PlatformState.Idle;

                Meters.Balance += TotalPayout - TotalWager; 
                Meters.StartBalance = 0;
                Meters.CurrentCashoutAmount = 0;
                Meters.AccumulatedPayout = 0;
                Meters.AccumulatedSecondaryPayout = 0;
                Meters.AccumulatedWager = 0;
                Meters.AccumulatedSecondaryWager = 0;
                Meters.SecondaryGameCount = 0;
            }
            
        }