void HandleTouchOnMobile()
        {
            if (Input.touchCount <= 0)
            {
                return;
            }

            Touch   touch    = Input.GetTouch(0);
            Vector2 touchPos = touch.position;

            if (touch.phase == TouchPhase.Began)
            {
                _lastPosition = _startPosition = touchPos;
                EventHub.Emit(new EventTouchBegan(_startPosition));
            }
            else if (touch.phase == TouchPhase.Moved)
            {
                EventHub.Emit(new EventTouchMoved(touchPos, touchPos - _lastPosition, _startPosition));
                _lastPosition = touchPos;
            }
            else if (touch.phase == TouchPhase.Ended)
            {
                EventHub.Emit(new EventTouchEnded(touchPos, _startPosition));
            }
            else if (touch.phase == TouchPhase.Canceled)
            {
                EventHub.Emit(new EventTouchCanceled(touchPos));
            }
        }
Exemple #2
0
        void OnCharacterPassThoughLayer(PedestalLayer layer)
        {
            if (!HasPowerUp() && !layer.hasDestroyed)
            {
                _floorCombo += 1;
            }

            var eventPlayerPassLayer = new EventCharacterPassLayer(layer);

            eventPlayerPassLayer.hasCombo          = HasCombo();
            eventPlayerPassLayer.hasPowerup        = HasPowerUp();
            eventPlayerPassLayer.hasLayerDestroyed = layer.hasDestroyed;
            EventHub.Emit(eventPlayerPassLayer);

            // Special case, character has powerup and pass through the layer
            if (!layer.hasDestroyed && HasPowerUp())
            {
                UsePowerUp(null);
            }

            if (!layer.hasDestroyed)
            {
                _platform.DestroyLayer(layer, HasPowerUp());
            }

            _scoreCaculator.OnPassingLayer(HasPowerUp(), layer);
        }
        void HandleTouchOnEditor()
        {
            if (Input.GetMouseButtonDown(0))
            {
                _isMouseDown  = true;
                _lastPosition = _startPosition = Input.mousePosition;
                EventHub.Emit(new EventTouchBegan(_startPosition));
                return;
            }

            if (Input.GetMouseButtonUp(0))
            {
                _isMouseDown = false;
                Vector2 touchPos = Input.mousePosition;
                EventHub.Emit(new EventTouchEnded(touchPos, _startPosition));
                return;
            }

            if (_isMouseDown)
            {
                Vector2 touchPos = Input.mousePosition;
                EventHub.Emit(new EventTouchMoved(touchPos, touchPos - _lastPosition, _startPosition));
                _lastPosition = touchPos;
                return;
            }
        }
Exemple #4
0
 void ProcessEndGame(bool endGameByDead)
 {
     _gameState = endGameByDead ? GameState.EndByDead : GameState.EndByTimeout;
     _character.OnDie();
     _character.SetDieEffect(endGameByDead);
     _platform.CanInteract = false;
     EventHub.Emit <EventEndGame>(new EventEndGame(endGameByDead));
 }
Exemple #5
0
 public void OnRevived()
 {
     Sound2DManager.Instance.PlayBgm();
     PlayerPrefsHelper.CountWatchAdsTimes();
     Advertiser.AdvertisementSystem.HideEndGameBanner();
     EventHub.Emit(new EventRevive());
     DOTween.Kill(_watchAdDuration);
 }
Exemple #6
0
        private void OnRevive(EventRevive e)
        {
            if (_gameState == GameState.EndByDead)
            {
                _platform.ForceDestroyNextLayer(true);
            }

            _character.Revive();
            _character.Jump();

            _gameState            = GameState.Playing;
            _platform.CanInteract = true;
            _roundTime            = _gameSetting.reviveRoundDuration;
            EventHub.Emit(new EventGameTimeUpdate()
            {
                time = _roundTime
            });
        }
        private IEnumerator WaitAndStartGame()
        {
            _readyImage.SetActive(true);
            _labelCountdown.text = _gameSetting.roundDuration.ToString();
            _labelScore.text     = "0";

            yield return(new WaitForSeconds(2));


            _readyImage.SetActive(false);
            _goImage.SetActive(true);

            yield return(new WaitForSeconds(1));


            _goImage.SetActive(false);
            _hideGroup.SetActive(true);

            EventHub.Emit <EventStartGame>();
        }
Exemple #8
0
        private void Update()
        {
            _character.CustomUpdate();
            _cameraFollower.CustomUpdate();

            _platform.UpdatePenguinPosition(_character.transform.position);
            _scoreCaculator.Update(Time.deltaTime);

            if (_gameState == GameState.Playing)
            {
                _roundTime -= Time.deltaTime;
                if (_roundTime <= 0)
                {
                    ProcessEndGame(false);
                }

                EventHub.Emit(new EventGameTimeUpdate()
                {
                    time = _roundTime
                });
            }
        }
Exemple #9
0
        // TODO: need to clean up
        private IEnumerator _Fall()
        {
            float   animationTime = 0.75f;
            Vector3 downward      = -transform.forward;

            downward = Quaternion.Euler(0f, 360f / 14f, 0) * downward;
            Vector3 deltaPos  = downward.normalized * 7;
            float   velocityY = 2;
            float   gravity   = 20;
            // floatdeltaPos.y = -8;

            Vector3 perpendicularAxis = Quaternion.Euler(0f, 90f, 0) * downward;

            deltaPos = deltaPos / animationTime;

            float time = 0f;

            while (time <= animationTime)
            {
                time      += Time.deltaTime;
                velocityY -= gravity * Time.deltaTime;

                // Update position
                Vector3 position = transform.position;
                position   += deltaPos * Time.deltaTime;
                position.y += velocityY * Time.deltaTime;

                transform.position = position;

                // Update rotation
                Vector3 centerPoint = _meshRenderer.bounds.center;
                transform.RotateAround(centerPoint, perpendicularAxis, -245 * Time.deltaTime);
                yield return(new WaitForEndOfFrame());
            }

            EventHub.Emit(new EventPedestalDestroy(this));
        }
Exemple #10
0
 private void OnScoreUpdate(long score, long increase)
 {
     EventHub.Emit <EventUpdateScore>(new EventUpdateScore(score, increase));
     PlayerPrefsHelper.AddToTotalScore((int)increase);
 }
Exemple #11
0
        private void OnCharacterCollideWithPedestal(Pedestal pedestal)
        {
            if (pedestal.type == PedestalType.Squid_01)
            {
                _roundTime += _gameSetting.squidBonusDuration;
                pedestal.Destroy();
                EventHub.Emit(new EventGameTimeUpdate()
                {
                    time = _roundTime
                });

                EventHub.Emit(new EventGetBonusTime()
                {
                    bonusTime = _gameSetting.squidBonusDuration,
                    squid     = pedestal
                });

                return;
            }
            else if (HasPowerUp())
            {
                if (pedestal.type == PedestalType.Pedestal_04_Powerup)
                {
                    _character.ActivePowerup();
                    _character.SetBoostEffect(true);
                    _remainPowerupBreakFloor = _gameSetting.powerUpBreakFloors;
                }
                UsePowerUp(pedestal);
                _floorCombo = 0;
                return;
            }
            else if (HasCombo())
            {
                Debug.LogError("Has combo");
                // Special case, should give player powerup.
                if (pedestal.type == PedestalType.Pedestal_04_Powerup)
                {
                    _character.ActivePowerup();
                    _character.SetBoostEffect(true);
                    _remainPowerupBreakFloor = _gameSetting.powerUpBreakFloors;
                }
                else
                {
                    _character.Jump();
                    _platform.ForceDestroyNextLayer();
                }

                _floorCombo += 1;
                _scoreCaculator.OnLandingLayer(HasCombo(), _floorCombo, pedestal);
                _scoreCaculator.PreventUpdateScoreOnNextLanding();
                _floorCombo = 0;
                return;
            }
            else
            {
                if (pedestal.type == PedestalType.Pedestal_01 ||
                    pedestal.type == PedestalType.Pedestal_01_1_Fish ||
                    pedestal.type == PedestalType.Pedestal_01_3_Fish)
                {
                    _character.Jump();
                }
                else if (pedestal.type == PedestalType.Pedestal_04_Powerup)
                {
                    _character.ActivePowerup();
                    _character.SetBoostEffect(true);
                    _remainPowerupBreakFloor = _gameSetting.powerUpBreakFloors;
                }
                else if (pedestal.type == PedestalType.DeadZone_01)
                {
                    Debug.Log("Dead by touching deadzone");
                    ProcessEndGame(true);
                }
                else if (pedestal.type == PedestalType.Wall_01)
                {
                    Debug.Log("Dead by touching wall");
                    ProcessEndGame(true);
                }
            }

            _scoreCaculator.OnLandingLayer(HasCombo(), _floorCombo, pedestal);
            _floorCombo = 0;
        }
Exemple #12
0
 public void Destroy()
 {
     _active = false;
     gameObject.SetActive(false);
     EventHub.Emit(new EventPedestalDestroy(this));
 }