예제 #1
0
    //被 -攻击- 逻辑处理
    override public void beAttack(GameObject obj)
    {
        if (obj.tag.Equals("Bullet"))
        {
            bullet_property bulletProperty = obj.GetComponent <bullet_property>();

            enemy_property enemyProperty = gameObject.GetComponent <enemy_property>();
            if (enemyProperty.invincible == false)
            {
                getDamage(enemyProperty, bulletProperty);
            }

            //判断击退类型
            if (bulletProperty.bulletknock != 0)
            {
                //Debug.Log (gameObject.name + "被击退.武器类型为:");
                getKnockBack(enemyProperty.gameObject, bulletProperty);
            }

            //判断攻击特效附加效果
            checkBulletEffect(gameObject, obj);

            if (isDie())
            {
                GameObject.Destroy(this.gameObject);
                constant.getMapLogic().checkOpenDoor();
            }
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (mBoss == null)
        {
            GameObject[] objs = GameObject.FindGameObjectsWithTag(constant.TAG_ENEMY);
            foreach (GameObject obj in objs)
            {
                enemy_property pro = obj.GetComponent <enemy_property>();
                if (pro.mIsBoss)
                {
                    mBoss = obj;
                    break;
                }
            }
        }

        if (mBoss != null)
        {
            this.gameObject.SetActive(true);
            GameObject        bossHpObj = GameObject.FindGameObjectWithTag("BossHp");
            GameObject        hpObj     = constant.getChildGameObject(bossHpObj, "hp");
            tk2dClippedSprite spr       = hpObj.GetComponent <tk2dClippedSprite> ();

            enemy_property pro = mBoss.GetComponent <enemy_property> ();
            float          w   = ((float)pro.Hp) / pro.MaxHp;
            //Debug.Log ("hp:" + pro.Hp + "," + pro.MaxHp + "," + w);
            //spr.clipTopRight = new Vector2(0, w);
            spr.ClipRect = new Rect(0, 0, w, 1);
        }
        else
        {
            this.gameObject.SetActive(false);
        }
    }
예제 #3
0
 //enemy_logic里调用
 public void upgradeProperties(enemy_property property)
 {
     mbulletSpeed    = baseBulletSpeed + property.AttackSpeed;
     mbulletRate     = baseBulletRate - (baseBulletRate - 0.1f) * property.AttackRate / 10;
     mbulletDistance = baseBulletDistance + property.AttackDistance;
     mbulletDamage   = baseBulletDamage + property.Damage * 5;
 }
예제 #4
0
    // Use this for initialization
    void Awake()
    {
        //玩家的位置
        player    = constant.getPlayer();
        playerPos = player.transform.position;
        //自己的属性
        enemySelf = gameObject.GetComponent <enemy_property>();



        spaceSearcherPath = "Prefabs/logic/spaceSearch";


        //动画
        ani = transform.FindChild("ui").FindChild("AnimatedSprite").gameObject;
        //寻路工具

        //动画脚本
        enemyAni = ani.GetComponent <tk2dSpriteAnimator> ();
        //攻击射击
        shooter = gameObject.GetComponent <enemyShotBullet> ();
        shooter.upgradeProperties(enemySelf);
        //判断是否开始重复行动
        completeMove = true;


        attackTempTime = 0;
        lockTempTime   = 0;
    }
예제 #5
0
    public void checkAngry()
    {
        enemy_property pro    = this.gameObject.GetComponent <enemy_property>();
        float          curPer = ((float)pro.Hp) / pro.MaxHp;

        if (curPer <= mAngryPer)
        {
            changeToNextStatus(Status.Angry);
        }
    }
예제 #6
0
    //判断玩家是否死亡
    public bool isDie()
    {
        enemy_property enemyProperty = gameObject.GetComponent <enemy_property>();

        if (enemyProperty.Hp <= 0)
        {
            return(true);
        }
        return(false);
    }
예제 #7
0
    //判断恐惧效果
    public void getScared(enemy_property enemyProperty, ScaredBullet scaredBullet)
    {
        int num = Random.Range(1, 101);

        if (num <= scaredBullet.sacredPercent)
        {
            Debug.Log("敌人被恐惧");
            enemyProperty.scared = true;
        }
    }
예제 #8
0
    public void resetWalkDir()
    {
        mUseWalkTime = mInterWalkTime;
        enemy_property pro = this.gameObject.GetComponent <enemy_property>();

        pro.BaseMoveSpeed = this.mWalkMaxSpeed;

        float d = Mathf.Deg2Rad * Random.Range(0, 359);

        mAddX = mWalkAcc * Mathf.Cos(d);
        mAddY = mWalkAcc * Mathf.Sin(d);
    }
예제 #9
0
    public void setRestAI()
    {
        GameObject obj = constant.getChildGameObject(this.gameObject, "AnimatedSprite");

        tk2dSpriteAnimator ani = obj.GetComponent <tk2dSpriteAnimator>();

        ani.Play("rest");

        mUseTime = mRestTime;

        enemy_property pro = this.gameObject.GetComponent <enemy_property>();

        pro.BaseMoveSpeed = 0;
    }
예제 #10
0
    //检查子弹的特殊效果
    override public void checkBulletEffect(GameObject enemy, GameObject bullet)
    {
        bullet_property bulletProperty = bullet.GetComponent <bullet_property> ();
        enemy_property  enemyProperty  = enemy.GetComponent <enemy_property> ();

        if (bulletProperty)
        {
            //是否具有恐惧效果
            if (bulletProperty.bulletSpe.scaredBullet.scaredEffect)
            {
                ScaredBullet scaredBullet = bulletProperty.bulletSpe.scaredBullet;
                getScared(enemyProperty, scaredBullet);
            }
        }
    }
예제 #11
0
    public void setSprintAI()
    {
        GameObject player = constant.getPlayer();

        if (player == null)
        {
            return;
        }

        enemy_property pro = this.gameObject.GetComponent <enemy_property>();

        pro.BaseMoveSpeed = this.mSprintMaxSpeed;
        if (this.mHasAngry)
        {
            pro.BaseMoveSpeed = this.mAngrySprintMaxSpeed;
        }

        GameObject obj = constant.getChildGameObject(this.gameObject, "AnimatedSprite");

        tk2dSpriteAnimator ani = obj.GetComponent <tk2dSpriteAnimator>();

        //spr.SetSprite("boss1_01");
        ani.Play("sprint");

        float x = player.transform.position.x - this.transform.position.x;
        float y = player.transform.position.y - this.transform.position.y;

        SphereCollider collider = this.GetComponent <SphereCollider>();

        Debug.Log("collider.bounds.size:" + collider.bounds.size.x + "," + collider.bounds.size.y);
        Debug.Log("dis:" + x + "," + y);
        if (collider.bounds.size.x / 2 > Mathf.Abs(x))
        {
            x = 0;
        }
        if (collider.bounds.size.y / 2 > Mathf.Abs(y))
        {
            y = 0;
        }

        float d = Mathf.Atan2(y, x);

        //Debug.Log("X,Y,D:" + x + "," + y + "," + d);
        mAddX = mSprintAcc * Mathf.Cos(d);
        mAddY = mSprintAcc * Mathf.Sin(d);

        //Debug.Log("mAddX,mAddY:" + mAddX + "," + mAddY);
    }
예제 #12
0
    void Awake()
    {
        //玩家的位置
        player    = constant.getPlayer();
        playerPos = player.transform.position;
        //自己的属性
        enemySelf       = gameObject.GetComponent <enemy_property>();
        enemyAniManager = gameObject.GetComponent <enemyAniManager>();
        //动画
        ani = transform.FindChild("ui").FindChild("AnimatedSprite").gameObject;

        //动画脚本
        enemyAni = ani.GetComponent <tk2dSpriteAnimator> ();

        lockTempTime = 0;
    }
예제 #13
0
    // Use this for initialization
    void Awake()
    {
        //自己的属性
        enemySelf = gameObject.GetComponent <enemy_property>();
        //动画控制
        ani = transform.FindChild("ui").FindChild("AnimatedSprite").gameObject;
        //寻路工具
        spaceSearcherPath = "Prefabs/logic/spaceSearch";
        //动画脚本
        enemyAni = ani.GetComponent <tk2dSpriteAnimator> ();
        //攻击射击脚本
        shooter = gameObject.GetComponent <enemyShotBullet> ();
        //判断是否开始重复行动
        completeMove = true;

        shooter.upgradeProperties(enemySelf);
    }
예제 #14
0
    //判断解除恐惧效果
    override public void checkScaredRecover(float deltaTime)
    {
        enemy_property enemyProperty = gameObject.GetComponent <enemy_property> ();

        if (enemyProperty.scared == true)
        {
            float scaredRecoverTime = enemyProperty.scaredRecoverTime;
            if (deltaTime >= scaredRecoverTime)
            {
                //Debug.Log (deltaTime + "--" + scaredRecoverTime + ": " + this.name + "解除恐惧");
                enemyProperty.scared = false;
            }
        }
        else
        {
            deltaTime_scared = 0;
        }
    }
예제 #15
0
    override public void getKnockBack(GameObject enemy, bullet_property bulletProperty)
    {
        enemy_property enemyProperty = enemy.GetComponent <enemy_property> ();
        //子弹的类型
        //weaponType weapontype = bulletProperty.WeaponType;
        //Debug.Log("bulletProperty.weaponType: " +weapontype);
        //击退的力度
        int force = bulletProperty.bulletknock;

        //敌人是否有霸体
        if (enemyProperty.heavyBody)
        {
            return;
        }

        //击退的类型
        //击退效果分类
        //1:普通击退
        //2:爆炸击退
        //3:

        KnockType knockType = bulletProperty.bulletSpe.knockType;

        switch (knockType)
        {
        default:
            break;

        case KnockType.none:
            break;

        case KnockType.normal:
            normalKnockBack(bulletProperty, force);
            break;

        case KnockType.explode:
            explodeKnockBack(bulletProperty, force);
            break;
            break;
        }
    }
예제 #16
0
    void OnTriggerEnter(Collider other)
    {
        if (!bulletDie)
        {
            if (other.gameObject.layer == 8)
            {
                hitWall();
                return;
            }
            if (other.gameObject.tag == "Wall")
            {
                hitWall();
                return;
            }
            if (other.gameObject.tag == "Door")
            {
                hitWall();
                return;
            }

            if (bulletProperty.BattleType == constant.BattleType.Player)
            {
                enemy_property enemyPro = other.gameObject.GetComponent <enemy_property> ();
                if (enemyPro)
                {
                    //Debug.Log("子弹击中怪物.");
                    hitEnemies();
                }
            }
            if (bulletProperty.BattleType == constant.BattleType.Enemy)
            {
                char_property charPro = other.gameObject.GetComponent <char_property> ();
                if (charPro)
                {
                    Debug.Log("子弹击中玩家.");
                    hitEnemies();
                }
            }
        }
    }
예제 #17
0
    //player beattacked must edit in next 玩家收到伤害 将要修改
    override public void beAttack(GameObject obj)
    {
        Debug.Log("char beAttack");
        if (isWUDI())
        {
            return;
        }
        enemy_property enemyProperty = obj.GetComponent <enemy_property>();

        if (enemyProperty != null)
        {
            char_property charProperty = gameObject.GetComponent <char_property>();
            charProperty.Hp = charProperty.Hp - 1;

            if (isDie())
            {
                constant.getGameLogic().Die();
            }

            setWUDI();
        }
    }
예제 #18
0
    public void setFollowAI()
    {
        GameObject player = constant.getPlayer();

        if (player == null)
        {
            return;
        }

        enemy_property pro = this.gameObject.GetComponent <enemy_property>();

        pro.BaseMoveSpeed = this.mFollowMaxSpeed;

        GameObject obj = constant.getChildGameObject(this.gameObject, "AnimatedSprite");

        tk2dSpriteAnimator ani = obj.GetComponent <tk2dSpriteAnimator>();

        //spr.SetSprite("boss1_01");
        ani.Play("follow");
        updateFollowAcc();

        mUseTime = mFollowTime;
    }
예제 #19
0
    //获得伤害
    public void getDamage(enemy_property enemyProperty, bullet_property bulletProperty)
    {
        //Debug.Log("enemy get damage: " + bulletProperty.bulletDamage);
        enemyProperty.Hp = enemyProperty.Hp - bulletProperty.bulletDamage;

        Vector3 objectPos = this.transform.position;

        //伤害显示-------------

        //调整伤害输出的位置
        objectPos.y += 1;
        objectPos.z  = -5;

        string     showDamagePath  = "Prefabs/ui/UI_showDamage";
        GameObject showDamageClone = (GameObject)Instantiate(Resources.Load(showDamagePath), objectPos, Quaternion.identity);

        if (showDamageClone)
        {
            string damage = "-" + bulletProperty.bulletDamage.ToString();
            showDamageClone.GetComponent <enemy_showDamage>().showDamage(damage);
        }

        //伤害显示------------
    }
예제 #20
0
 // Use this for initialization
 void Awake()
 {
     enemySelf = gameObject.GetComponent <enemy_property>();
     GameObject obj = constant.getPlayer();
 }