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; } }
/// <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"; }
/** 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; } }
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; } } }
public void AddState(PlatformState state, bool current = false) { States.Add (state.Name, state); if (current) CurrentStateKey = state.Name; }
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; } } }
//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);
// A timer that makes the platform rise once done private IEnumerator BeginRise() { yield return(new WaitForSeconds(timeToRest)); moveAcceleration = 0f; platformState = PlatformState.isRising; }
// ------------------- 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; }
void Start() { rotateFront = false; rotateBack = false; platform = GetComponentInParent <PlatformState>(); audio = GetComponent <AudioSource>(); }
/// <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; }
private void Fall() { _animator.SetTrigger(TRIGGER_ANIM); _platformState = PlatformState.Fallen; _rigidbody2D.velocity = new Vector2(0, -FallSpeed); }
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; }
private void Start() { _platformState = PlatformState.Idle; _initialPosition = transform.position; _fallTimer = 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)); }
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(); } } }
void CalculateNewState() { if (state == PlatformState.Dying && decay >= 1.0) { state = PlatformState.Dead; dyingSound.Stop(); deathSound.Play(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(); } }
public virtual void WaitForStop() { while (State == PlatformState.Started) { Update(); Thread.Sleep(1); } State = PlatformState.Exited; }
// 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; }
/// <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; }
IEnumerator PlatformBehavior() { float TimeUntilShake = Lifetime - ShakeTime; yield return(new WaitForSeconds(TimeUntilShake)); state = PlatformState.Shake; yield return(new WaitForSeconds(ShakeTime)); state = PlatformState.Drop; }
/// <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); }
internal void Clean() { for (int i = 0; i < Weapons.Length; i++) { Weapons[i] = null; } Parts.Clean(null); Structure = null; State = PlatformState.Fresh; Comp = null; }
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!"); } }
private void ChangeState(PlatformState platformState) { BeforeStateChange(this, platformState); CurrentState = platformState; StateChanged(this, platformState); }
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!"); } }
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(); } }
/// <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; } } }
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. }
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; } }