예제 #1
0
        void processRotation(FBActor actor, FixVector2 moveDirection, bool tween, Fix64 maxAngle)
        {
            var speed = actor.m_particle.velocity.length;

            if (tween)
            {
                var cos     = FixVector2.dot(actor.m_direction, moveDirection);
                var cos_max = Fix64.Cos(maxAngle);

                if (cos >= cos_max)
                {
                    actor.m_direction = moveDirection;
                }
                else
                {
                    var sin_max =
                        FixVector2.cross(actor.m_direction, moveDirection) >= Fix64.Zero ?
                        Fix64.Sin(maxAngle) : Fix64.Sin(-maxAngle);

                    actor.m_direction = new FixVector2()
                    {
                        x = FixVector2.dot(actor.m_direction, new FixVector2(cos_max, -sin_max)),
                        y = FixVector2.dot(actor.m_direction, new FixVector2(sin_max, cos_max))
                    };
                }
            }
            else
            {
                actor.m_direction = moveDirection;
            }

            actor.m_particle.velocity = actor.m_direction * speed;
        }
예제 #2
0
        void _beforeFlyCatching(FBActor actor, Fix64 deltaTime)
        {
            actor.m_timer -= deltaTime;
            if (actor.m_timer <= Fix64.Zero)
            {
                //Debuger.Log("_beforeFlyCatching end begin move frameNumber:" + actor.world.world.frameCount);

                actor.m_timer = actor.m_cathingBallStateAniWaitTime;
                if (actor.m_stateBool && (actor.m_stateDataIndex == 3 || actor.m_stateDataIndex == 4))
                {
                    actor.m_stateInt = 0;//接不到球
                }
                else
                {
                    actor.m_stateInt = 1;//接到球
                }
                Fix64 verticleSpeed = _getActorVelocity(actor, actor.m_timer, out actor.m_cathingBallStateMovingVelocity);
                actor.particle.dampingAcceleration = Fix64.Zero;
                actor.m_stateSubState = (int)SubState.kFlyCatching;
                actor.m_cathingBallStateVerticleSpeed = verticleSpeed;
                //开始播放接球动画
                actor.world.onDoorKeeperCatchingBall(actor,
                                                     actor.m_stateDataIndex,
                                                     FixVector2.cross(actor.direction, actor.m_stateVector - actor.getPosition()) < Fix64.Zero);

                return;
            }
        }
예제 #3
0
        public override void enter(FBActor actor)
        {
            actor.m_stateSubState = (int)SubState.kBeforePassing;
            actor.m_timer         = actor.m_configuration.pb_beforePassingTime[actor.m_stateDataIndex];
            var   cos = FixVector2.dot(actor.m_direction, actor.m_stateVector);
            Fix64 ralativeDirection = Fix64.Zero;

            if (cos < Fix64.One)
            {
                var sin = Fix64.Sqrt(Fix64.One - cos * cos);

                ralativeDirection = FixVector2.cross(actor.m_direction, actor.m_stateVector);
                if (ralativeDirection >= Fix64.Zero)
                {
                    sin = -sin;
                }
                actor.m_stateValue = Fix64.Atan2(sin, cos);
            }
            else
            {
                actor.m_stateValue = Fix64.Zero;
            }

            int passBallFoot = actor.getKickBallFoot(actor.m_stateVector, actor.m_direction);

            actor.world.onPassBallBegin(actor, actor.m_stateDataIndex == 0, passBallFoot == 1);
        }
예제 #4
0
    DefendMoveDirection getMoveDirection()
    {
        Fix64 cosAngle = FixVector2.dot(direction, moveDirection);

        if (cosAngle > Fix64.Cos(configuration.dm1_angleA))
        {
            return(DefendMoveDirection.Forward);
        }
        else if (cosAngle < Fix64.Cos(configuration.dm1_angleB))
        {
            return(DefendMoveDirection.Back);
        }
        else
        {
            Fix64 cross = FixVector2.cross(direction, moveDirection);
            if (cross < Fix64.Zero)
            {
                return(DefendMoveDirection.Right);
            }
            else
            {
                return(DefendMoveDirection.Left);
            }
        }
    }
예제 #5
0
        void _prepareShooting(FBActor actor, Fix64 deltaTime)
        {
            if (actor.shootBallEvent)
            {
                actor.m_stateSubState = (int)SubState.kBeforeShooting;
                actor.m_timer         = actor.m_configuration.sb_beforeShootingTime[actor.m_stateDataIndex];
                var cos = FixVector2.dot(actor.m_direction, actor.m_stateVector);
                if (cos < Fix64.One)
                {
                    var sin = Fix64.Sqrt(Fix64.One - cos * cos);
                    if (FixVector2.cross(actor.m_direction, actor.m_stateVector) >= Fix64.Zero)
                    {
                        sin = -sin;
                    }
                    actor.m_stateValue = Fix64.Atan2(sin, cos);
                }
                else
                {
                    actor.m_stateValue = Fix64.Zero;
                }

                if (actor.m_stateDataIndex == (int)(ShootType.Killer))
                {
                    actor.world.fbGame.logicTimeScale = (Fix64)0.01f;
                }

                //
                actor.world.onShootBallReady(actor);

                return;
            }

            actor.m_particle.dampingAcceleration = actor.m_configuration.m1_stopDampingAcceleration_ball;

            if (actor.m_direction != actor.m_stateVector)
            {
                var cos      = FixVector2.dot(actor.m_direction, actor.m_stateVector);
                var maxAngle = actor.m_configuration.sb_angularSpeed * deltaTime;
                var cos_max  = Fix64.Cos(maxAngle);
                var speed    = actor.m_particle.velocity.length;
                if (cos >= cos_max)
                {
                    actor.m_direction = actor.m_stateVector;
                }
                else
                {
                    var sin_max =
                        FixVector2.cross(actor.m_direction, actor.m_stateVector) >= Fix64.Zero ?
                        Fix64.Sin(maxAngle) : Fix64.Sin(-maxAngle);

                    actor.m_direction = new FixVector2()
                    {
                        x = FixVector2.dot(actor.m_direction, new FixVector2(cos_max, -sin_max)),
                        y = FixVector2.dot(actor.m_direction, new FixVector2(sin_max, cos_max))
                    };
                }
                actor.m_particle.velocity = actor.m_direction * speed;
            }
        }
예제 #6
0
    //右脚1 ,左脚0
    int getKickBallFoot(FixVector2 dest, FixVector2 cur)
    {
        int   defaultFoot = this.configuration.defautKickBallFoot;
        Fix64 cross       = FixVector2.cross(dest, this.direction);

        if (cross < Fix64.Zero)
        {
            defaultFoot = 1;
        }
        if (cross > Fix64.Zero)
        {
            defaultFoot = 0;
        }

        return(defaultFoot);
    }
예제 #7
0
        void _beforeCatching(FBActor actor, Fix64 deltaTime)
        {
            if (actor.world.ball.owner != null || !actor.world.ball.willBeCatched)
            {
                actor.setToMovementState();
                //actor.m_nextState = Movement.instance;
                return;
            }

            actor.m_timer -= deltaTime;

            if (actor.m_timer <= actor.configuration.scb_catchingAniTime[0] && !actor.m_stateBool)
            {
                actor.m_stateBool = true;
                bool  ccw = false;
                Fix64 va  = FixVector2.cross(actor.m_direction, actor.m_stateVector);
                if (va == Fix64.Zero)
                {
                    ccw = actor.configuration.defautKickBallFoot == 0 ? true : false;
                }
                else
                {
                    ccw = va > Fix64.Zero;
                }
                actor.world.onActorStandCatchingBall(actor, ccw);
            }

            if (actor.m_timer <= Fix64.Zero)
            {
                actor.m_direction = actor.m_stateVector;
                actor.world.ball.transferTarget = actor;

                actor.m_stateSubState = (int)SubState.kAfterCatching;
                actor.m_timer         = actor.m_configuration.scb_lockTimeAfterCatching[0];

                return;
            }

            var cos   = FixVector2.dot(actor.m_stateVector, actor.m_direction);
            var sin   = FixVector2.cross(actor.m_stateVector, actor.m_direction);
            var angle = Fix64.Atan2(sin, cos) * actor.m_timer / actor.m_stateValue;

            cos = Fix64.Cos(angle);
            sin = Fix64.Sin(angle);
            actor.m_direction.x = FixVector2.dot(actor.m_stateVector, new FixVector2(cos, -sin));
            actor.m_direction.y = FixVector2.dot(actor.m_stateVector, new FixVector2(sin, cos));
        }
예제 #8
0
    //获取调整后的方向
    FixVector2 getAjustedDirection(FixVector2 currentDirection, FixVector2 destDirection, Fix64 angleTolerance)
    {
        Fix64 cosAngle = Fix64.Cos(angleTolerance);

        //不需要旋转,足够了
        if (FixVector2.dot(currentDirection, destDirection) > cosAngle)
        {
            return(currentDirection);
        }

        Fix64 crossV = FixVector2.cross(destDirection, currentDirection);

        if (crossV != Fix64.Zero)
        {
            crossV        = crossV / Fix64.FastAbs(crossV);
            destDirection = FixVector2.rotate(destDirection, angleTolerance * crossV);
        }

        return(destDirection);
    }
예제 #9
0
        void _beforeCatching(FBActor actor, Fix64 deltaTime)
        {
            actor.m_timer -= deltaTime;
            if (actor.m_timer <= Fix64.Zero)
            {
                Debuger.Log("beforeCatching end begin move");
                actor.m_timer         = actor.configuration.dkcb_animationCathingTime[actor.m_stateDataIndex];
                actor.m_stateSubState = (int)SubState.kCatching;

                //移动球员位置到目标点
                _getActorVelocity(actor, actor.m_timer, out actor.m_cathingBallStateMovingVelocity);
                actor.particle.dampingAcceleration = Fix64.Zero;

                //开始播放接球动画
                actor.world.onDoorKeeperCatchingBall(actor,
                                                     actor.m_stateDataIndex,
                                                     FixVector2.cross(actor.direction, actor.m_stateVector - actor.getPosition()) < Fix64.Zero);

                return;
            }
        }
예제 #10
0
    static void processRotation(FBActor actor, FixVector2 moveDirection, Fix64 maxAngle)
    {
        var cos     = FixVector2.dot(actor.m_direction, moveDirection);
        var cos_max = Fix64.Cos(maxAngle);

        if (cos >= cos_max)
        {
            actor.m_direction = moveDirection;
        }
        else
        {
            var sin_max =
                FixVector2.cross(actor.m_direction, moveDirection) >= Fix64.Zero ?
                Fix64.Sin(maxAngle) : Fix64.Sin(-maxAngle);

            actor.m_direction = new FixVector2()
            {
                x = FixVector2.dot(actor.m_direction, new FixVector2(cos_max, -sin_max)),
                y = FixVector2.dot(actor.m_direction, new FixVector2(sin_max, cos_max))
            };
        }
    }
예제 #11
0
    FixVector2 getClampedDirection(FixVector2 direction, FixVector2 expectDirection, Fix64 clampAngle)
    {
        FixVector2 destDirection = expectDirection;
        Fix64      dif           = FixVector2.dot(expectDirection, direction);

        //角度过大
        if (dif < Fix64.Cos(clampAngle))
        {
            //旋转angleClamp
            Fix64 c = FixVector2.cross(expectDirection, direction);
            if (c < Fix64.Zero)//逆时针旋转为正
            {
                destDirection = FixVector2.rotate(expectDirection, -clampAngle);
            }
            else
            {
                destDirection = FixVector2.rotate(expectDirection, clampAngle);
            }
        }

        return(destDirection);
    }
예제 #12
0
        void _beforeCatching(FBActor actor, Fix64 deltaTime)
        {
            if (actor.world.ball.owner != null || !actor.world.ball.willBeCatched)
            {
                actor.setToMovementState();
                //actor.m_nextState = Movement.instance;
                return;
            }

            actor.m_timer -= deltaTime;

            if (actor.m_timer <= actor.configuration.scb_catchingAniTime[actor.m_stateDataIndex] && !actor.m_stateBool)
            {
                actor.m_stateBool = true;
                actor.world.onActorAirCatchingBall(actor, actor.m_stateDataIndex);
            }

            if (actor.m_timer <= Fix64.Zero)
            {
                actor.m_direction = actor.m_stateVector;
                actor.world.ball.transferTarget = actor;

                actor.m_stateSubState = (int)SubState.kAfterCatching;
                actor.m_timer         = actor.m_configuration.scb_lockTimeAfterCatching[actor.m_stateDataIndex];

                return;
            }

            var cos   = FixVector2.dot(actor.m_stateVector, actor.m_direction);
            var sin   = FixVector2.cross(actor.m_stateVector, actor.m_direction);
            var angle = Fix64.Atan2(sin, cos) * actor.m_timer / actor.m_stateValue;

            cos = Fix64.Cos(angle);
            sin = Fix64.Sin(angle);
            actor.m_direction.x = FixVector2.dot(actor.m_stateVector, new FixVector2(cos, -sin));
            actor.m_direction.y = FixVector2.dot(actor.m_stateVector, new FixVector2(sin, cos));
        }
예제 #13
0
        public override void enter(FBActor actor)
        {
            Fix64 animationTime = actor.configuration.dkcb_animationCathingTime[actor.m_stateDataIndex];

            //足球飞行时间
            Fix64 ballFlyTime = actor.m_stateValue;

            Debuger.Log("DoorKeeperCathingBall Begin zoneIndex:" + actor.m_stateDataIndex);
            //a\b区的情况
            if (actor.m_stateDataIndex == 0 || actor.m_stateDataIndex == 1)
            {
                actor.m_stateInt = 1;//能拿到球
                if (animationTime < ballFlyTime)
                {
                    Debuger.Log("ab区 begin kBeforeCatching");
                    actor.m_stateSubState = (int)SubState.kBeforeCatching;
                    actor.m_timer         = ballFlyTime - animationTime;
                }
                else
                {
                    Debuger.Log("ab区 begin kCatching");

                    //在BallFlyTime时间内移动到目标
                    _getActorVelocity(actor, ballFlyTime, out actor.m_cathingBallStateMovingVelocity);
                    actor.particle.dampingAcceleration = Fix64.Zero;

                    actor.m_stateSubState = (int)SubState.kCatching;
                    actor.m_timer         = ballFlyTime;

                    //开始播放接球动画
                    actor.world.onDoorKeeperCatchingBall(actor,
                                                         actor.m_stateDataIndex,
                                                         FixVector2.cross(actor.direction, actor.m_stateVector - actor.getPosition()) < Fix64.Zero);
                }
            }
            else
            {
                Fix64      heightOffset     = Fix64.Zero;
                FixVector2 moveTargetOffset = getMoveTargetOffset(actor, out heightOffset);
                Fix64      moveDistance     = moveTargetOffset.length;

                Fix64 actorMoveTime = Fix64.Zero;
                if (actor.configuration.dkcb_cathingBallMovingVolocity[actor.m_stateDataIndex].x != Fix64.Zero)
                {
                    actorMoveTime = moveDistance / actor.configuration.dkcb_cathingBallMovingVolocity[actor.m_stateDataIndex].x;
                }

                Fix64 actorMoveTimeVerticle = Fix64.Zero;
                if (actor.configuration.dkcb_cathingBallMovingVolocity[actor.m_stateDataIndex].y != Fix64.Zero)
                {
                    actorMoveTimeVerticle = heightOffset / actor.configuration.dkcb_cathingBallMovingVolocity[actor.m_stateDataIndex].y;
                }

                Fix64 actorMoveTimeAjusted = actorMoveTime > actorMoveTimeVerticle ? actorMoveTime : actorMoveTimeVerticle;

                //不能拿到球
                if (actorMoveTimeAjusted > ballFlyTime)
                {
                    //直接移动
                    Fix64 verticleSpeed = _getActorVelocity(actor, actorMoveTimeAjusted, out actor.m_cathingBallStateMovingVelocity);
                    actor.particle.dampingAcceleration = Fix64.Zero;

                    actor.m_stateSubState = (int)SubState.kFlyCatching;
                    //腾空时垂直方向上的速度
                    actor.m_cathingBallStateVerticleSpeed = verticleSpeed;
                    actor.m_stateInt = 0;//不能拿到球
                    actor.m_timer    = actorMoveTimeAjusted;

                    //拿球动画
                    actor.world.onDoorKeeperCatchingBall(
                        actor,
                        actor.m_stateDataIndex,
                        FixVector2.cross(actor.direction, actor.m_stateVector - actor.getPosition()) < Fix64.Zero);

                    Debuger.Log(" can not get ball begin kFlyCatching");
                }
                else
                {
                    //动画时间比较长,直接开始做动画,并且开始移动,把球弹开
                    if (animationTime > ballFlyTime)
                    {
                        Fix64 verticleSpeed = _getActorVelocity(actor, ballFlyTime, out actor.m_cathingBallStateMovingVelocity);
                        actor.particle.dampingAcceleration = Fix64.Zero;

                        actor.m_stateSubState = (int)SubState.kFlyCatching;
                        actor.m_cathingBallStateVerticleSpeed = verticleSpeed;
                        actor.m_stateInt = 2;//把球弹开
                        actor.m_timer    = ballFlyTime;

                        //拿球动画
                        actor.world.onDoorKeeperCatchingBall(
                            actor,
                            actor.m_stateDataIndex,
                            FixVector2.cross(actor.direction, actor.m_stateVector - actor.getPosition()) < Fix64.Zero);


                        //Debuger.Log(" can colide ball begin kFlyCatching frameNumber: " + actor.world.world.frameCount);
                    }
                    else//动画时间比较短,接住球,先等待一段时间,然后播动画,做位移
                    {
                        //
                        Fix64 animationWaitTime = animationTime > actorMoveTimeAjusted ? animationTime : actorMoveTimeAjusted;
                        actor.m_stateSubState = (int)SubState.kBeforeFlyCathing;
                        actor.m_timer         = ballFlyTime - animationWaitTime;
                        actor.m_cathingBallStateAniWaitTime = animationWaitTime;
                        Debuger.Log(" can get ball kBeforeFlyCathing");
                    }
                }
            }

            actor.world.onDoorKeeperCatchingBallReady(actor, actor.m_stateInt == 1);
        }
예제 #14
0
    void shootBallOut()
    {
        var        actor             = ball.owner;
        FixVector3 ballStartPosition = getActorShootOutPosition(actor, actor.shootingType);

        FixVector2 frontPosition = new FixVector2(ballStartPosition.x, ballStartPosition.z);
        Fix64      maxPassSpeed  = actor.configuration.maxGoalSpeed[(int)actor.shootingType];

        Fix64 rightDoorV = actor.team == FBTeam.kBlue ? new Fix64(1) : new Fix64(-1);

        GoalZone zone = config.getGoalZone((int)actor.shootingType, (int)actor.configuration.sb_ShootBallZone[(int)actor.shootingType]);

        //随机位置
        FixVector2 targetPosition = new FixVector2(config.worldSize.x * rightDoorV, zone.center.x * positiveDoorSide);

        targetPosition += new FixVector2
        {
            x = config.doorHalfSize.x * new Fix64(2) * randomUnit,
            y = zone.halfSize.x * (randomUnit - (Fix64)0.5f)
        };

        //Debuger.Log("targetPosition:" + targetPosition);
        FixVector2 kickBallDirection = (targetPosition - frontPosition).normalized;

        Fix64 needTime = Fix64.Zero;
        Fix64 angle    = Fix64.Zero;

        if (actor.shootingType == ShootType.Super)
        {
            Fix64 a = (targetPosition - frontPosition).length / new Fix64(2);
            Fix64 c = actor.configuration.curveBallRadius;
            if (c <= a)
            {
                angle = actor.configuration.curveBallMaxAngle;
            }
            else
            {
                Fix64 b = Fix64.Sqrt(c * c - a * a);
                angle = Fix64.Atan2(a, b);
                if (Fix64.FastAbs(angle) > actor.configuration.curveBallMaxAngle)
                {
                    angle = actor.configuration.curveBallMaxAngle;
                }
            }


            FixVector2 m        = FixVector2.kZero - new FixVector2(config.worldSize.x * rightDoorV, Fix64.Zero);
            FixVector2 n        = targetPosition - new FixVector2(config.worldSize.x * rightDoorV, Fix64.Zero);
            Fix64      cross_mn = FixVector2.cross(m, n);
            Fix64      angleDir = Fix64.Zero;
            if (cross_mn == Fix64.Zero)
            {
                angleDir = actor.configuration.defautKickBallFoot == 0 ? Fix64.One : -Fix64.One;
            }
            else if (cross_mn > Fix64.Zero)
            {
                angleDir = -Fix64.One;
            }
            else
            {
                angleDir = Fix64.One;
            }

            angle = angle * angleDir;
        }

        bool canShoot = BallParticle.calculateTime(frontPosition
                                                   , targetPosition
                                                   , maxPassSpeed
                                                   , ball.configuration.dampingAcceleration_air
                                                   , angle
                                                   , out needTime);
        Fix64 goalHeight = Fix64.Zero;

        if (!canShoot)
        {
            ball.freeByKick(ballStartPosition, kickBallDirection * maxPassSpeed, maxPassSpeed, false);
        }
        else
        {
            //随机高度
            goalHeight = zone.center.y + zone.halfSize.y * (randomUnit - (Fix64)0.5);
            ball.freeBySuperShoot(ballStartPosition, targetPosition, goalHeight, needTime, angle);
        }

        FBActor doorKeeper = getDoorKeeper(actor.team == FBTeam.kBlue ? FBTeam.kRed : FBTeam.kBlue);

        if (doorKeeper != null && doorKeeper != actor)
        {
            doorKeeperCathingBall(actor, doorKeeper);
        }
        onShootBallOut(actor, ball.get3DVelocity(), angle, new FixVector3 {
            x = targetPosition.x, y = goalHeight, z = targetPosition.y
        });
    }