Ejemplo n.º 1
0
    private void Start()
    {
        sp = GetComponent <SpriteRenderer>();
        actionController = GetComponent <ActionController>();
        hitableObj       = GetComponent <HitableObj>();
        audioSource      = GetComponent <AudioSource>();

        filter.SetLayerMask(detect_layermask);
        filter.useTriggers = true;

        actionController.eOnActionComplete   += SetDefaultAction;
        actionController.eActionQueueCleared += delegate { actionController.AddAction(Idle_act); };

        move_act.action.AddListener(delegate { Move(); });


        //First default action
        actionController.AddAction(Idle_act);

        shoot_act.gap_time = weapon.weaponData.shoot_gap_time;

        //generate move goal
        move_goal = new GameObject().transform;

        hitableObj.gotHit_event += OnHurt;
        hitableObj.Die_event    += Die;
    }
Ejemplo n.º 2
0
    public override void CollisionDetect()
    {
        int num = collider.OverlapCollider(filter2D, res);

        for (int i = 0; i < num; i++)
        {
            HitableObj.Hit_event_c(res[i].gameObject, ammoData.damage);
            Debug.Log("hit " + res[i].gameObject.name);
            turns--;
        }
        if (turns > 0 && num > 0)
        {
            //Vector2 _normal = vec.x > res[0].transform.position.x ? Vector2.right : Vector2.left;
            Vector2 _normal = (res[0].transform.position - transform.position).magnitude > 0.3f ? vec.rotate(-45 * Mathf.Deg2Rad) : -vec;
            vec = Vector2.Reflect(vec, _normal);
            //Vector3 _in = vec.normalized;
            //Vector3 _normal = GetSimpleNormal(res[0].gameObject);
            //vec = vec.rotate(90 * Vector3.Cross(vec, _normal).z);
            transform.position = (Vector2)transform.position + vec.normalized;
        }
        else if (turns < 0)
        {
            //Destory self:
            DoDestory();
        }
    }
Ejemplo n.º 3
0
 void Start()
 {
     hitable = gameObject.GetComponent <HitableObj>();
     MaxHP   = hitable.HP;
     hitable.gotHit_event += UpdateHPbar;
     hitable.Die_event    += Die;
 }
Ejemplo n.º 4
0
 private void Start()
 {
     hitable = gameObject.GetComponent <HitableObj>();
     if (hitable != null)
     {
         hitable.Die_event += DoBreak;
     }
 }
Ejemplo n.º 5
0
    public void SetHitable(HitableObj _hitable)
    {
        hitable = _hitable;
        maxHP   = hitable.HP;
        hitable.gotHit_event += UpdateHPBar;
        hitable.Die_event    += DestorySelfOnDie;

        height_offset = (float)_hitable.gameObject.GetComponent <SpriteRenderer>()?.bounds.size.y;
    }
Ejemplo n.º 6
0
    private void Start()
    {
        actionController = GetComponent <ActionController>();
        hitableObj       = gameObject.GetComponent <HitableObj>();
        basicEnemy       = GetComponent <BasicEnemy>();

        cDrawSkill = StartCoroutine(DrawASkill());

        hitableObj.Die_event += Die;
    }
Ejemplo n.º 7
0
    private void Start()
    {
        actionController = GetComponent <ActionController>();
        rigidbody        = GetComponent <Rigidbody2D>();
        animator         = GetComponent <Animator>();
        hitable          = GetComponent <HitableObj>();
        audioSource      = GetComponent <AudioSource>();

        EquipWeapon(weapon.weaponData);

        hitable.Die_event    += Die;
        hitable.gotHit_event += Hurt;
    }
Ejemplo n.º 8
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        Vector2 inDirection = dir;
        Vector2 inNormal    = collision.contacts[0].normal.normalized;
        Vector2 newVelocity = Vector2.Reflect(inDirection, inNormal);

        Debug.DrawLine(collision.transform.position, (Vector2)collision.transform.position + inNormal * 5, Color.green, 1);
        Debug.DrawLine(collision.transform.position, (Vector2)collision.transform.position + newVelocity * 5, Color.cyan, 1);

        rigid.velocity = newVelocity * reflectSpeed;
        //rigid.AddForce(newVelocity * reflectSpeed);

        Debug.DrawLine(transform.position, (Vector2)transform.position + rigid.velocity, Color.gray, 1);

        HitableObj.Hit_event_c(collision.gameObject, damage);
    }
Ejemplo n.º 9
0
    public virtual void CollisionDetect()
    {
        //detect collision
        int num = collider.OverlapCollider(filter2D, res);

        for (int i = 0; i < num; i++)
        {
            HitableObj.Hit_event_c(res[i].gameObject, ammoData.damage);
            Debug.Log(gameObject.name + " GC obj hit " + res[i].gameObject.name);
        }
        if (num > 0)
        {
            //Destory self:
            DoDestory();
        }
    }
Ejemplo n.º 10
0
    int jump_count = 0; //跳躍次數 (for 2段跳)
    private void Start()
    {
        rigid        = gameObject.GetComponent <Rigidbody2D>();
        listeners    = gameObject.GetComponent <PhysicsControlListeners>();
        animator     = gameObject.GetComponent <Animator>();
        playerAttack = gameObject.GetComponent <PlayerAttackControl>();
        sp           = gameObject.GetComponent <SpriteRenderer>();

        hitable = gameObject.GetComponent <HitableObj>();
        if (hitable != null)
        {
            hitable.Die_event    += Die;
            hitable.gotHit_event += Hurt;
        }

        listeners.eOnTouchGround += ResetJumpCount;
    }
Ejemplo n.º 11
0
 private void SetUpLocalEvent()
 {
     hitable   = gameObject.GetComponent <HitableObj>();
     listeners = gameObject.GetComponent <PhysicsControlListeners>();
     if (actionController != null)
     {
         actionController.eActionQueueCleared += AddDefault;
     }
     if (hitable != null)
     {
         hitable.Die_event += AddDie;
         //hitable.gotHit_event += Hurt;
         //hitable.gotHit_event += OnHurt;
         hitable.HitBy_event += OnHurt;
         //hitable.HitBy_event += HurtDirectionCheck;
     }
     if (listeners != null)
     {
         listeners.eOnTouchGround += ResetJumpCount;
         listeners.eOnTouchGround += OnJumpEnd;
     }
 }
Ejemplo n.º 12
0
    public void SetUpOnline(int _playerIndex)
    {
        OnCreate?.Invoke(_playerIndex);
        _pv     = GetComponent <PhotonView>();
        hitable = gameObject.GetComponent <HitableObj>();
        if (_pv == null)
        {
            return;
        }
        _isOnline = true;
        dataIndex = _playerIndex;
        Debug.Log("player index " + dataIndex);

        if (!_pv.IsMine)
        {
            //Destroy(GetComponent<PhysicsControlListeners>());
            Destroy(GetComponent <Rigidbody2D>());
            Destroy(GetComponent <ActionController>());
            //Destroy(body.GetComponent<PlayerAttackControl>());
            //Destroy(this);
        }
        else
        {
            //if (_hasInited){return;}
            //_hasInited = true;

            rigid            = gameObject.GetComponent <Rigidbody2D>();
            listeners        = gameObject.GetComponent <PhysicsControlListeners>();
            actionController = gameObject.GetComponent <ActionController>();
            _otherPlayers    = GetOtherPlayer();
            SetUpLocalEvent();

            string _head_path = "Prefab/Online/Head/" + PlayerSlot.heads_res[(int)PhotonNetwork.LocalPlayer.CustomProperties[CustomPropertyCode.HEAD_CDOE]].name;
            string _body_path = "Prefab/Online/Body/" + PlayerSlot.body_res[(int)PhotonNetwork.LocalPlayer.CustomProperties[CustomPropertyCode.BODY_CODE]].name;
            Head   _newHead   =
                PhotonNetwork.Instantiate(
                    _head_path,
                    //Instantiate(
                    //Resources.Load<Head>(_head_path),
                    head.transform.position,
                    Quaternion.identity
                    ).GetComponent <Head>();
            Body _newBody =
                PhotonNetwork.Instantiate(
                    _body_path,
                    //Instantiate(
                    //Resources.Load<Body>(_body_path),
                    body.transform.position,
                    Quaternion.identity
                    ).GetComponent <Body>();

            //_newBody.transform.SetParent(body.transform.parent);
            _newBody.transform.SetParent(transform);
            _newHead.transform.SetParent(transform);
            //_newHead.transform.SetParent(head.transform.parent);
            Destroy(head.gameObject);
            Destroy(body.gameObject);

            head = _newHead;
            body = _newBody;
            RpcSetUPParent();
            _pv.RPC("RpcSetupTeam", RpcTarget.All,
                    (int)PhotonNetwork.LocalPlayer.CustomProperties[CustomPropertyCode.TEAM_CODE],
                    (int)PhotonNetwork.LocalPlayer.CustomProperties[CustomPropertyCode.TEAM_LAYER]);

            SetKey(0);

            SetupRpcFunction();
            //temp
            //AddLanding();
        }
    }