Exemple #1
0
    private void HandleBallHitEvent(GameEvent eve)
    {
        Debug.LogError("HandleBallHitEvent");
        GameEventModuel eventModuel = GameStart.GetInstance().EventModuel;

        eventModuel.SendEvent(GameEventID.AI_SWITCH_STATE, true, 0f, EAIStateType.GotoHitTarget);
    }
Exemple #2
0
    public override void ExitState()
    {
        GameEventModuel eventModuel = GameStart.GetInstance().EventModuel;

        eventModuel.UnRegisterEventListener(GameEventID.Reset_Game_State, HandleResetStateEvent);
        eventModuel.UnRegisterEventListener(GameEventID.ENTITY_HIT_BALL, HandleEntityHitBall);
    }
Exemple #3
0
    public override void UnRegisterEvent()
    {
        base.UnRegisterEvent();
        GameEventModuel eveModuel = GameStart.GetInstance().EventModuel;

        eveModuel.UnRegisterEventListener(GameEventID.PLAYER_HIT_BALL, HandlePlayerHitBallEvent);
    }
Exemple #4
0
    private void OnDisable()
    {
        GameEventModuel eventModuel = GameStart.GetInstance().EventModuel;

        eventModuel.UnRegisterEventListener(GameEventID.ENTITY_HIT_BALL, HandleEntityHitBallMessage);
        eventModuel.UnRegisterEventListener(GameEventID.AI_HIT_BALL, HandleAIHitBallMessage);
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        m_trigger = true;
        GameEventModuel eveModuel = GameStart.GetInstance().EventModuel;

        eveModuel.SendEvent(GameEventID.TRIGGER_GAME_EVENT, true, 0f);
        gameObject.SetActive(false);
    }
Exemple #6
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        GameEventModuel eveModuel = GameStart.GetInstance().EventModuel;

        if (eveModuel != null)
        {
            eveModuel.SendEvent(GameEventID.PLAYER_HIT_BALL, true, 0f);
        }
    }
Exemple #7
0
    private void OnBackClick()
    {
        GameAudioModuel moduel = GameStart.GetInstance().AudioModuel;

        moduel.PlayAudio("click_01");
        GameEventModuel eveModuel = GameStart.GetInstance().EventModuel;

        eveModuel.SendEvent(GameEventID.SWITCH_GAME_STATE, true, 0f, EGameStateType.GameMenuState);
    }
    private void HitBallDelegate(Player player, Vector2 direction, float force, int id)
    {
        if (m_gameBall == null)
        {
            return;
        }

        bool checkIsHitArea = PlayerCollider.CheckInHitBallArea(m_gameBall.GetBallInstance().transform, player.Transform,
                                                                player.PlayerData.m_radius, player.PlayerData.m_angle, player.BoxCollider);

        if (checkIsHitArea)
        {
            CameraControl.GetInstance().Trigger();
            CameraControl.GetInstance().TriggerMask();

            GameAudioModuel audioModuel = GameStart.GetInstance().AudioModuel;
            if (id == m_player.ID)
            {
                GameEventModuel meoduel = GameStart.GetInstance().EventModuel;
                meoduel.SendEvent(GameEventID.PLAYER_HIT_BALL, true, 0f);

                m_side = ESide.Player;
                m_contestData.AddIndex();

                m_contestUI.FreshUI(m_contestData.m_heart, m_contestData.m_index);
                if (m_contestData != null && m_contestData.m_changeAudio && !m_change)
                {
                    List <string> list = new List <string>
                    {
                        "lerp",
                        "BGM_002",
                    };
                    audioModuel.PlayBgAudio(list);
                    m_change = true;
                }

                m_playerIndex++;
                m_playerIndex = Mathf.Clamp(m_playerIndex, 0, m_audioNameList.Count - 1);
                audioModuel.PlayAudio(m_audioNameList[m_playerIndex]);
            }
            else
            {
                m_side = ESide.AI;
                m_aiIndex++;
                m_aiIndex = Mathf.Clamp(m_aiIndex, 0, m_audioNameList.Count - 1);
                audioModuel.PlayAudio(m_audioNameList[m_aiIndex]);
            }

            if (m_gameBall != null)
            {
                ESide side = (id == m_player.ID) ? ESide.Player : ESide.AI;
                m_gameBall.SetVelocity(direction, force, side);
                m_gameBall.ChangeEffectDir(side);
            }
        }
    }
Exemple #9
0
 private void Update()
 {
     if (m_start && Time.time > m_endTime)
     {
         m_start = false;
         HideEffect();
         GameEventModuel eveModuel = GameStart.GetInstance().EventModuel;
         eveModuel.SendEvent(GameEventID.END_GAME_EVENT, true, 0f);
     }
 }
Exemple #10
0
    public override void EnterState()
    {
        GameEventModuel eventModuel = GameStart.GetInstance().EventModuel;

        eventModuel.RegisterEventListener(GameEventID.ENTITY_HIT_BALL, HandleBallHitEvent);

        if (m_entity != null)
        {
            m_entity.Switch(EEntityState.Idle, Vector3.zero);
        }
    }
    public override void EnterState()
    {
        if (m_entity != null)
        {
            Vector2 dir      = m_entity.GetForwardDir();
            Vector2 position = new Vector2(Random.Range(m_fireRange.x, m_fireRange.y), dir.y);
            m_entity.Switch(EEntityState.Hit, position.normalized);

            GameEventModuel eventModuel = GameStart.GetInstance().EventModuel;
            eventModuel.SendEvent(GameEventID.AI_SWITCH_STATE, false, 0.3f, EAIStateType.GotoHitTarget);
        }
    }
Exemple #12
0
    private void Update()
    {
        if (m_start && Time.time > m_endTime)
        {
            m_start = false;
            if (m_ink != null)
            {
                m_ink.SetActive(false);

                GameEventModuel eveModuel = GameStart.GetInstance().EventModuel;
                eveModuel.SendEvent(GameEventID.END_GAME_EVENT, true, 0f);
            }
        }
    }
    public override void ExitState()
    {
        GameEventModuel eventModuel = GameStart.GetInstance().EventModuel;

        eventModuel.UnRegisterEventListener(GameEventID.TRIGGER_GAME_EVENT, OnTriggerEffectStart);
        eventModuel.UnRegisterEventListener(GameEventID.END_GAME_EVENT, OnTriggerEffectEnd);

        if (m_ground != null)
        {
            GameObject.Destroy(m_ground.gameObject);
            m_ground = null;
        }

        if (m_player != null)
        {
            m_player.Destroy();
            m_player = null;
        }

        if (m_playerController != null)
        {
            m_playerController.DestroyController();
            m_playerController = null;
        }

        if (m_gameBall != null)
        {
            m_gameBall.Destory();
            m_gameBall = null;
        }

        if (m_ai != null)
        {
            m_ai.Destroy();
            m_ai = null;
        }

        if (m_aiController != null)
        {
            m_aiController.DestroyController();
            m_aiController = null;
        }

        if (m_effect != null)
        {
            m_effect.Destory();
        }

        GameStart.GetInstance().UIModuel.UnLoadResUI(m_contestUI.gameObject);
    }
Exemple #14
0
    private void HitBall(Vector3 recordPos)
    {
        GameEventModuel eventModuel = GameStart.GetInstance().EventModuel;
        Vector2         dir         = CalculateHitBallDir(recordPos);

        if (m_characterControl != null)
        {
            eventModuel.SendEvent(GameEventID.ENTITY_HIT_BALL, true, 0f, EHitForceType.Middle, new Vector2(dir.x, dir.y));
        }
        else
        {
            EHitForceType type = (EHitForceType)Random.Range((int)EHitForceType.Soft, (int)EHitForceType.High);
            eventModuel.SendEvent(GameEventID.AI_HIT_BALL, true, 0f, type, new Vector2(dir.x, dir.y));
        }
    }
Exemple #15
0
    public override void EnterState()
    {
        GameEventModuel eventModuel = GameStart.GetInstance().EventModuel;

        eventModuel.RegisterEventListener(GameEventID.Reset_Game_State, HandleResetStateEvent);
        eventModuel.RegisterEventListener(GameEventID.ENTITY_HIT_BALL, HandleEntityHitBall);

        GameObject ball = GameObject.Find("Ball");

        if (ball != null)
        {
            m_ball = CommonFunc.AddSingleComponent <Ball>(ball);
            m_ball.Reset();
        }

        GameObject chracter = GameObject.Find("Character");

        if (chracter != null)
        {
            m_entityInstance = chracter.GetComponent <EntityInstance>();

            Vector4 moveRange = new Vector4(-1.73f, -0.81f, 3.15f, -5.4f);
            m_entityInstance.SetMoveRange(moveRange);
        }


        GameObject ai = GameObject.Find("AI");

        if (ai != null)
        {
            m_aiInstance = ai.GetComponent <EntityInstance>();
            Vector4 moveRange = new Vector4(-2.09f, 9.3f, 2.61f, 4.61f);
            m_aiInstance.SetMoveRange(moveRange);
            ai.AddComponent <AIStateController>();
        }

        GameDataModuel dataModuel = GameStart.GetInstance().DataModuel;

        dataModuel.SetGameData(3, 0);

        m_ui = GameObject.FindObjectOfType <GameTestStateUI>();
        if (m_ui != null)
        {
            m_ui.Init();
        }
    }
Exemple #16
0
    private void Start()
    {
        EntityInstance instance = gameObject.GetComponent <EntityInstance>();

        m_aiStateDic = new Dictionary <int, AIStateBase>();
        m_aiStateDic.Add((int)EAIStateType.Idle, new AIIdleState(instance));
        m_aiStateDic.Add((int)EAIStateType.FireBall, new AIFireBallState(instance));
        m_aiStateDic.Add((int)EAIStateType.GotoHitTarget, new AIGoHitTargetState(instance));
        m_aiStateDic.Add((int)EAIStateType.Hit, new AIHitState(instance));
        m_aiStateDic.Add((int)EAIStateType.Prepare, new AIPrepareState(instance));

        m_curAIStateType = EAIStateType.None;
        SwitchState(EAIStateType.Idle);

        GameEventModuel eventModuel = GameStart.GetInstance().EventModuel;

        eventModuel.RegisterEventListener(GameEventID.AI_SWITCH_STATE, HandleSwitchState);
    }
    public void Init()
    {
        if (m_heartParent != null)
        {
            int childCount = m_heartParent.transform.childCount;
            m_hearts = new GameObject[childCount];
            for (int i = 0; i < childCount; i++)
            {
                m_hearts[i] = m_heartParent.transform.GetChild(i).gameObject;
            }
        }

        GameEventModuel eventModuel = GameStart.GetInstance().EventModuel;

        eventModuel.RegisterEventListener(GameEventID.GAME_DATA_CHANGE, OnDataChange);

        FreshUI();
    }
Exemple #18
0
    public override void Init()
    {
        m_stateDic = new Dictionary <int, GameStateBase>();
        m_stateDic.Add((int)EGameStateType.GameTestState, new GameTestState(EGameStateType.GameTestState));
        m_stateDic.Add((int)EGameStateType.GameExerciseState, new GameExerciseState(EGameStateType.GameExerciseState));
        m_stateDic.Add((int)EGameStateType.GameContestState, new GameContestState(EGameStateType.GameContestState));
        m_stateDic.Add((int)EGameStateType.GameMenuState, new GameMenuState(EGameStateType.GameMenuState));
        m_stateDic.Add((int)EGameStateType.BombState, new GameBombState(EGameStateType.BombState));

        foreach (int id in m_stateDic.Keys)
        {
            m_stateDic[id].SwitchStateAction = SwitchState;
        }

        SwitchState(EGameStateType.GameMenuState);

        GameEventModuel eveModuel = GameStart.GetInstance().EventModuel;

        eveModuel.RegisterEventListener(GameEventID.SWITCH_GAME_STATE, SwitchState);
    }
Exemple #19
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        if (other != null)
        {
            if (other.gameObject.layer == LayerMask.NameToLayer("Wall"))
            {
                ContactPoint2D contactPoint = other.contacts[0];
                Vector3        newDir       = Vector3.Reflect(m_dir, contactPoint.normal);
                newDir.z = 0f;
                //Quaternion rotation = Quaternion.FromToRotation(m_dir,  newDir);
                //transform.rotation = rotation;
                if (m_rigidBody != null)
                {
                    m_rigidBody.velocity = newDir.normalized * m_speed;
                }

                m_dir = newDir;
            }
            else if (other.gameObject.layer == LayerMask.NameToLayer("Boundary"))
            {
                GameDataModuel dataModuel = GameStart.GetInstance().DataModuel;
                if (gameObject.transform.localPosition.y > 0)
                {
                    dataModuel.AddHeart();
                }
                else
                {
                    dataModuel.ReduceHeart();
                }

                GameEventModuel eventModuel = GameStart.GetInstance().EventModuel;
                if (eventModuel != null)
                {
                    eventModuel.SendEvent(GameEventID.Reset_Game_State, true, 0f);
                }
            }
        }
    }
Exemple #20
0
    public void Update()
    {
        if (m_start)
        {
            if (Time.time > m_endTime)
            {
                m_start = false;

                if (m_ballInstance != null)
                {
                    m_ballInstance.SetOffsetDir(Vector2.zero);
                    m_ballInstance.SetNeedOffset(false);
                }

                GameEventModuel eveModuel = GameStart.GetInstance().EventModuel;
                eveModuel.SendEvent(GameEventID.END_GAME_EVENT, true, 0f);
            }
            else
            {
                m_ballInstance.SetNeedOffset(m_needOffset);
            }
        }
    }
    public override void EnterState()
    {
        GameEventModuel eventModuel = GameStart.GetInstance().EventModuel;

        eventModuel.RegisterEventListener(GameEventID.TRIGGER_GAME_EVENT, OnTriggerEffectStart);
        eventModuel.RegisterEventListener(GameEventID.END_GAME_EVENT, OnTriggerEffectEnd);

        m_contestData = new GameContestData();

        GameObject ground = GameStart.GetInstance().ResModuel.LoadResources <GameObject>(EResourceType.Ground, "Ground");

        ground   = CommonFunc.Instantiate(ground);
        m_ground = CommonFunc.AddSingleComponent <Ground>(ground);
        GroundData groundData = new GroundData();

        m_ground.InitGround(groundData);

        PlayerData playerData = new PlayerData();

        m_player = new Player(1, playerData);
        m_player.InitPlayerAction(HitBallDelegate);

        GameObject go = new GameObject("Controller");

        m_playerController = go.AddComponent <PlayerController>();
        m_playerController.InitController(m_player);

        BallData ballData = new BallData();

        m_gameBall = new GameBall(ballData, m_ground.BounceLine);
        m_gameBall.SetOutofRangeAction(GameBallOutofRange);
        m_gameBall.SetPosition(groundData.GetFireBallPoint(ESide.Player));

        AIPlayerData aiData = new AIPlayerData();

        m_ai = new Player(2, aiData);
        m_ai.Transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, 180f));
        m_ai.InitPlayerAction(HitBallDelegate);

        m_aiController = go.AddComponent <AIController>();
        m_aiController.SetGameBall(m_gameBall);
        m_aiController.InitController(m_ai);

        m_effect = new GameEffect();

        m_contestUI = GameStart.GetInstance().UIModuel.LoadResUI <GameContestUI>("ContestPrefab");
        CoroutineTool.GetInstance().StartCoroutine(SetUI());

        GameAudioModuel audioModuel = GameStart.GetInstance().AudioModuel;
        List <string>   list        = new List <string>
        {
            "BGM_001",
            "BGM_002",
            "lerp",
        };

        audioModuel.PreLoadAudio(list);
        audioModuel.StopAudio();

        m_player.Target = m_gameBall.GetBallInstance().transform;
        m_ai.Target     = m_gameBall.GetBallInstance().transform;
        m_change        = false;
    }
Exemple #22
0
    public override void ExitState()
    {
        GameEventModuel eventModuel = GameStart.GetInstance().EventModuel;

        eventModuel.UnRegisterEventListener(GameEventID.ENTITY_HIT_BALL, HandleBallHitEvent);
    }
Exemple #23
0
    private void SendEvent()
    {
        GameEventModuel moduel = GameStart.GetInstance().EventModuel;

        moduel.SendEvent(GameEventID.GAME_DATA_CHANGE, true, 0f);
    }