public void AddRipple(Vector2 _position, float _duration, float _size) { Ripple ripple; if (ripples.Count < rippleMaxCount || ripples.Count <= 0) { ripple = new Ripple(); ripples.Add(ripple); } else { ripple = ripples[0]; } ripple.position = _position; ripple.duration = _duration; ripple.progress = 0f; ripple.oneOverScale = 1f / Mathf.Clamp(_size, 0.2f, 1f); if (currentRippleCoroutine?.running != true) { currentRippleCoroutine = currentRippleCoroutine.StartCoroutine(this, UpdateRipplesCoroutine()); } }
// helper to go up public void Ascend() { // only if no action if (m_currentAction?.running == true) { return; } // cannot go up if depth is highest if (m_currentDepth == m_gameManager.TopCorridorDepth) { return; } // can only go up if there is hole Corridor topCorridor = m_gameManager.GetCorridor(m_currentDepth - 1); if (!topCorridor.m_cells[m_currentCell].m_hasHole) { return; } // play jump sound GameManager.s_gameSettings.jumpSFX.Play(m_sfxVolume); // ok climb up m_currentAction = m_currentAction.StartCoroutine(this, AscendAction(topCorridor)); }
// helper to move in corridor public void Move(int dx) { // only if no action if (m_currentAction?.running == true) { return; } // check if can move int result = m_currentCell + dx; if (result < 0 || result >= m_currentCorridor.Length) { return; } // if facing wrong direction, turn instead of move if (m_facingRight != dx > 0) { GameManager.s_gameSettings.moveSFX.Play(m_sfxVolume); m_currentAction = m_currentAction.StartCoroutine(this, FaceDirectionAction(dx > 0)); } else { // kill the guy there m_currentCorridor.DoToActors(this, result, result, x => x.HitByMelee(dx)); // move GameManager.s_gameSettings.moveSFX.Play(m_sfxVolume); m_currentAction = m_currentAction.StartCoroutine(this, MoveAction(result)); } }
// update call void Update() { // get delta time float dt = Time.deltaTime; // update black screen if (m_blackScreenProgress > 0f) { m_blackScreenProgress -= dt; SetBlackScreenPosition(); } // do game update if not retry if (m_isRetry) { // any key to retry if (Input.anyKeyDown && m_loseCoroutine?.running != true) { m_loseCoroutine = m_loseCoroutine.StartCoroutine(this, LoseCoroutine()); } } else { GameUpdate(dt); } }
// --- public static MCoroutine StartCoroutine(MonoBehaviour _caller, MCoroutine _mCoroutine, IEnumerator _coroutine) { if (_mCoroutine == null) { _mCoroutine = new MCoroutine(_caller); } _mCoroutine.Start(_coroutine); return(_mCoroutine); }
// helper to fire projectile public void FireProjectile() { // only if no action and cooldown if (m_currentAction?.running == true || m_gunCooldown > 0f) { return; } m_currentAction = m_currentAction.StartCoroutine(this, ProjectileFireAction()); }
// people die when they are killed public void Kill(float offset) { // cannot die if dead if (m_isDead) { return; } m_isDead = true; // slap GameManager.s_gameSettings.slapSFX.Play(m_sfxVolume); // force death action m_currentAction?.Stop(); m_transform.localEulerAngles = Vector3.zero; m_currentAction = m_currentAction.StartCoroutine(this, DeathAction(offset * m_deathOffsetStrength)); }
// initialize function public void Initialize(IActorController controller, GameManager gameManager, int depth, int cell, bool doFadeIn) { // reference controller m_controller = controller; // reference game manager m_gameManager = gameManager; // get components if (m_transform == null) { m_transform = GetComponent <Transform>(); m_renderer = GetComponent <SpriteRenderer>(); } // enter corridor m_currentDepth = depth; EnterCorridor(m_gameManager.GetCorridor(m_currentDepth), cell); // reset values m_gunCooldown = 0f; m_isDead = false; m_immuneToMelee = false; m_immuneToProjectile = false; // face random direction m_facingRight = Random.value > 0.5f; m_renderer.flipX = !m_facingRight; // initialize renderer m_renderer.color = doFadeIn ? Color.clear : m_color; m_renderer.sprite = doFadeIn ? GameManager.s_gameSettings.actorReadySprite : GameManager.s_gameSettings.actorAimSprite; m_renderer.enabled = true; // do fade in if (doFadeIn) { GameManager.s_gameSettings.appearSFX.Play(m_sfxVolume); m_currentAction = m_currentAction.StartCoroutine(this, FadeInAction()); } }
// helper to go deeper public void Descend() { // only if no action if (m_currentAction?.running == true) { return; } // get next corridor Corridor nextCorridor = m_gameManager.GetCorridor(m_currentDepth + 1); // do we need to break the floor if (m_currentCorridor.HasHole(m_currentCell)) { m_currentAction = m_currentAction.StartCoroutine(this, DescendAction(nextCorridor)); } else { m_currentAction = m_currentAction.StartCoroutine(this, FloorBreakAction()); } }
public static MCoroutine StartCoroutine(this MCoroutine _mCoroutine, MonoBehaviour _caller, IEnumerator _coroutine, bool _doEndAction = false) { return(MCoroutine.StartCoroutine(_caller, _mCoroutine, _coroutine, _doEndAction)); }
public static MCoroutine StartCoroutine(this MCoroutine _mCoroutine, MonoBehaviour _caller, IEnumerator _coroutine) { return(MCoroutine.StartCoroutine(_caller, _mCoroutine, _coroutine)); }