Exemplo n.º 1
0
    public virtual void Init()
    {
        m_Scene = gameObject.GetComponentInParent(typeof(SubScene)) as SubScene;

        if (m_Scene == null)
        {
            throw new System.Exception("Object must be attached to a specific scene!");
        }

        float speed = m_Scene.GetWorldSpeed();

        SetWorldSpeed(speed);

        worldIndex = m_Scene.GetIndex();

        LocalPowerUpManager localPowerUpManager = m_Scene.GetLocalPowerUpManager();

        PowerUpManager.PowerUpEffect effect = m_Scene.GetLocalPowerUpManager().GetActivatedPowerUp();
        ActionParams actionParams           = localPowerUpManager.GetActionParams();

        if (effect.Equals(PowerUpManager.PowerUpEffect.Speed))
        {
            OnCollectedSpeed("", actionParams);
        }
        else if (effect.Equals(PowerUpManager.PowerUpEffect.Freeze))
        {
            //Nothing is supposed to be created during freeze but just in case
            OnCollectedFreeze("", actionParams);
        }

        //mPowerUpHandler = PowerUpHandlerBase.powerUpDefaultHandler;

        //Listen to events
        m_Scene.GetEventManager().ListenToEvent(ApplicationConstants.EVENT_PLAYER_DIE_BY_HIT, OnGameOver);
        m_Scene.GetEventManager().ListenToEvent(ApplicationConstants.EVENT_PLAYER_COLLECTED_SPEED, OnCollectedSpeed);
        m_Scene.GetEventManager().ListenToEvent(ApplicationConstants.EVENT_PLAYER_COLLECTED_FREEZE, OnCollectedFreeze);
    }
Exemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        _stateMachine = new StateMachine();

        mStandCollider    = transform.Find("Stand Collider").gameObject;
        mSlideCollider    = transform.Find("Slide Collider").gameObject;
        mPlatformCollider = transform.Find("Platform Collider").gameObject;

        //ColliderBridge cb = mPlatformCollider.AddComponent<ColliderBridge>();
        //cb.Initialize(this);

        //This supposed to fix the raycast issue
        Physics2D.queriesStartInColliders = false;
        collider = GetComponent <Collider2D>();

        run = new RunningState(this, _stateMachine);
        //charge = new ChargingState(this, _stateMachine);
        jump         = new JumpingState(this, _stateMachine);
        descend      = new DescendingState(this, _stateMachine);
        ultraJump    = new UltraJumpState(this, _stateMachine);
        powerDescend = new PowerDescendState(this, _stateMachine);
        slide        = new SlideState(this, _stateMachine);
        die          = new DyingState(this, _stateMachine);

        mRigidBody2D = GetComponent <Rigidbody2D>();

        //AudioManager.instance.PlayMusicInLoop("footsteps");

        worldIndex = m_Scene.GetIndex();

        mScore = m_Scene.GetScore();

        isShieldActive = false;
        mIsDead        = false;



        //PlayerMovementManager.SetInstance(worldIndex, this);

        mPlayerSprite = gameObject.GetComponentInChildren <PlayerSprite>();


        mAnimator = GetComponentInChildren <Animator>();

        //DontDestroyOnLoad(mAnimator);


        mAnimator.SetInteger("State", (int)PlayerAnimation.PlayerRunning);

        _stateMachine.Initialize(run);

        //--Sign as a listener to swipe down event
        m_Scene.GetEventManager().ListenToEvent(ApplicationConstants.EVENT_IO_SWIPE_DOWN, Instance_onSwipeDownEvent);
        m_Scene.GetEventManager().ListenToEvent(ApplicationConstants.EVENT_IO_TAP, Instance_onSwipeUpEvent);
        m_Scene.GetEventManager().ListenToEvent(ApplicationConstants.EVENT_PLAYER_COLLECTED_FREEZE, OnCollectedFreeze);
        m_Scene.GetEventManager().ListenToEvent(ApplicationConstants.EVENT_PLAYER_COLLECTED_SHIELD, OnCollectedShield);

        m_Scene.GetServiceManager().CallActionWhenServiceIsLive(ApplicationConstants.SERVICE_LOCAL_LEVEL_BUILDER, () =>
        {
            mLocalLevelBuilder = m_Scene.GetServiceManager().GetService <LocalLevelBuilder_v2>(ApplicationConstants.SERVICE_LOCAL_LEVEL_BUILDER);
        });
    }