Ejemplo n.º 1
0
        /// <summary>
        /// 是否警戒状态
        /// </summary>
        /// <returns></returns>
        public bool isCritical()
        {
            var closerPlayer = closerOpponent();

            if (!closerPlayer)
            {
                return(false);
            }

            var dist = (pos - closerPlayer.pos).magnitude;

            if (dist > enemy.criticalRange)
            {
                return(false);
            }

            Vector2 targetDirection = closerPlayer.transform.position - transform.position;
            Vector2 towardDirection = RuntimeCharacter.dir82Vec(direction);
            float   angle           = Vector2.Angle(targetDirection, towardDirection);

            if (angle > deteAngle)
            {
                return(false);
            }

            Ray2D ray2D = new Ray2D(pos, closerPlayer.pos);

            Debug.DrawLine(pos, closerPlayer.pos, Color.red);
            RaycastHit2D hit = Physics2D.Raycast(pos, closerPlayer.pos - pos, 100, (1 << 11 | 1 << 10));

            var mapPlayer = SceneUtils.get <MapPlayer>(hit.collider);

            return(hit && mapPlayer);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 绘制动画
        /// </summary>
        /// <param name="item"></param>
        void drawAnimation(RuntimeBattler item)
        {
            var dir = item.direction;

            if (RuntimeCharacter.isDir4(dir))
            {
                lastDir = RuntimeCharacter.dir2Index(dir);
            }

            switch ((RuntimeBattler.State)item.state)
            {
            case RuntimeBattler.State.Idle:
                drawIdle(item); break;

            case RuntimeBattler.State.Moving:
                drawCharacter(item); break;

            case RuntimeBattler.State.Using:
                drawAttackAction(item); break;

            //case RuntimeBattler.State.Dead:
            //	requestClear(true); break;
            default:
                drawIdle(item); break;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 配置旋转
        /// </summary>
        void setupRotation(RuntimeCharacter.Direction d)
        {
            var rot = transform.localEulerAngles;

            rot.z = RuntimeCharacter.dir82Angle(d);
            transform.localEulerAngles = rot;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 使用磁石
        /// </summary>
        void useMagnetite()
        {
            var dir = player.direction;
            var vec = RuntimeCharacter.dir82Vec(dir);
            //var resList = Physics2D.RaycastAll(pos, vec, magnetiteDist);

            Collider2D collider2d = Physics2D.OverlapBox(pos, collider.bounds.size, 0f, 1 << 8);

            for (int i = 1; i < magnetiteDist; i++)
            {
                collider2d = Physics2D.OverlapBox(pos + vec * i, collider.bounds.size, 0f, 1 << 8);
                debugLog(collider2d?.name);
                debugLog(collider?.bounds.size);
                var obj = collider2d?.gameObject;
                targetCol = SceneUtils.get <WaterColumn>(obj);
                if (targetCol == null)
                {
                    continue;
                }
                runtimeActor.addEnergy(-magnetiteEnergy);
                moveDirection(dir); break;
            }
            //foreach(var res in resList) {
            //	var obj = res.collider?.gameObject;

            //	targetCol = SceneUtils.get<WaterColumn>(obj);
            //	if (targetCol == null) continue;

            //	moveDirection(dir); break;
            //}
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 绘制攻击动画
        /// </summary>
        /// <param name="item"></param>
        void drawAttackAction(RuntimeBattler item)
        {
            var battler = item.battler;

            // 朝向左时候才会翻转
            sprite.flipX = battler.attackAniFlip &&
                           RuntimeCharacter.isLeftDir(item.direction);
            sprite.sprite = battler.getAttackAni(lastDir, aniRate);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 绘制角色
        /// </summary>
        /// <param name="item"></param>
        void drawCharacter(RuntimeBattler item)
        {
            var battler = item.battler;

            // 朝向左时候才会翻转
            sprite.flipX = battler.characterFlip &&
                           RuntimeCharacter.isLeftDir(item.direction);
            sprite.sprite = battler.getCharacter(lastDir, aniRate);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 更新朝向
        /// </summary>
        void updateDirection()
        {
            if (!directionController)
            {
                return;
            }
            var rot = directionController.localEulerAngles;

            rot.z = RuntimeCharacter.dir82Angle(direction);
            directionController.localEulerAngles = rot;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 计算闪烁位置
        /// </summary>
        public float calFlashDistance()
        {
            Vector2    flashVec     = RuntimeCharacter.dir82Vec(direction);                                                                        //闪烁方向
            Vector2    dropPos      = collCenter + flashVec * flashDistance;                                                                       //落点
            Vector2    colliderSize = new Vector2(collider.bounds.size.x - 0.02f, collider.bounds.size.y - 0.02f);                                 //微调碰撞盒
            Collider2D collHard     = Physics2D.OverlapCapsule(dropPos,
                                                               colliderSize, CapsuleDirection2D.Horizontal, 0f, (1 << 11) | (1 << 4) | (1 << 15)); //落点碰撞判断

            RaycastHit2D raycastHit2D = Physics2D.Raycast(pos, flashVec, flashDistance, (1 << 11) | (1 << 4) | (1 << 15));

            Collider2D collSoft = Physics2D.OverlapCapsule(dropPos,
                                                           colliderSize, CapsuleDirection2D.Horizontal, 0f, (1 << 8));//落点碰撞判断


            float flashDistStep = 0.05f;
            float flashDistRes  = 0.0f;

            if (raycastHit2D || collSoft)
            {
                //寻找最远落点
                while (flashDistStep <= flashDistance)
                {
                    collHard = Physics2D.OverlapCapsule(collCenter + flashVec * flashDistStep,
                                                        colliderSize, CapsuleDirection2D.Horizontal, 0f, (1 << 11) | (1 << 4) | (1 << 15));


                    collSoft = Physics2D.OverlapCapsule(collCenter + flashVec * flashDistStep,
                                                        colliderSize, CapsuleDirection2D.Horizontal, 0f, (1 << 8));//落点碰撞判断

                    debugLog(collHard?.name);
                    debugLog(collSoft?.name);
                    if (collHard)
                    {
                        break;
                    }
                    if (!collSoft || collSoft.isTrigger)
                    {
                        flashDistRes = flashDistStep;
                    }
                    flashDistStep += 0.05f;
                }
                return(flashDistRes);
            }
            //直接闪烁到最远距离
            else
            {
                return(flashDistance);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 更新移动
        /// </summary>
        bool updateMovement()
        {
            var speed = new Vector2(xDelta, yDelta);
            var flag  = (speed.x == 0 && speed.y == 0);

            if (flag)
            {
                stop();
            }
            else
            {
                moveDirection(RuntimeCharacter.vec2Dir8(speed));
            }

            return(!flag);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 将闪烁距离应用到闪烁
        /// </summary>
        /// <param name="distance"></param>
        public void applyFlashDistance(float distance)
        {
            Vector2 flashVec = RuntimeCharacter.dir82Vec(direction);//闪烁方向

            flashPos = pos + flashVec * distance;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 获取远离角色方向
        /// </summary>
        /// <returns></returns>
        RuntimeCharacter.Direction getFarDirection()
        {
            var delta = pos - player.pos;

            return(RuntimeCharacter.vec2Dir8(delta));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 获取靠近角色方向
        /// </summary>
        /// <returns></returns>
        RuntimeCharacter.Direction getCloseDirection()
        {
            var delta = closerOpponent().pos - pos;

            return(RuntimeCharacter.vec2Dir8(delta));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 配置速度
        /// </summary>
        void setupVelocity(RuntimeCharacter.Direction d)
        {
            var vec = RuntimeCharacter.dir82Vec(d);

            rigidbody.velocity = vec * speed;
        }