Exemplo n.º 1
0
        public Point GetAnimalNextWaypoint(Point startPoint, Point destinationPoint, MovingType movingType)
        {
            int    resultX = 0, resultY = 0, speed;
            double distance;

            speed = _field.Animals[startPoint.Y, startPoint.X].Speed;

            distance = _distanceHandler.GetDistance(startPoint, destinationPoint);

            if (movingType == MovingType.Pursuit)
            {
                resultX = startPoint.X + CountPositionDelta(startPoint.X, destinationPoint.X, speed, distance);
                resultY = startPoint.Y + CountPositionDelta(startPoint.Y, destinationPoint.Y, speed, distance);
            }
            else if (movingType == MovingType.Runaway)
            {
                resultX = startPoint.X - CountPositionDelta(startPoint.X, destinationPoint.X, speed, distance);
                resultY = startPoint.Y - CountPositionDelta(startPoint.Y, destinationPoint.Y, speed, distance);
            }

            int CountPositionDelta(int from, int to, int animalSpeed, double distanceToPoint)
            {
                return((int)Math.Round((to - from) * animalSpeed / distanceToPoint));
            }

            return(new Point(resultX, resultY));
        }
Exemplo n.º 2
0
        public BlockMoving(int x, int y, int Distance, MovingType T, Boolean Start)
        {
            //ImageCount = 4;
            MaxDistance = Distance;
            Type        = T;
            this.x      = x;
            this.y      = y;
            OT          = ObjectType.OT_MovingBlock;
            SetWidthHeight();
            width = 50;
            Dir   = 2.0;
            if (Start)
            {
                Dir *= -1;
            }

            if (Type == MovingType.MT_UpDown)
            {
                StartPosition = newy;
            }
            else
            {
                StartPosition = newx;
            }

            MarioOn = false;

            TimerGenerator.AddTimerEventHandler(TimerType.TT_50, OnMove);
        }
Exemplo n.º 3
0
    void Move(MovingType mt)
    {
        Vector3 moveAmount;

        if (mt == MovingType.MoveForward)
        {
            moveAmount = Vector3.forward;
        }
        else if (mt == MovingType.MoveBackward)
        {
            moveAmount = Vector3.back;
        }
        else if (mt == MovingType.MoveLeft)
        {
            moveAmount = Vector3.left;
        }
        else if (mt == MovingType.MoveRight)
        {
            moveAmount = Vector3.right;
        }
        else if (mt == MovingType.MoveUp)
        {
            moveAmount = Vector3.up;
        }
        else
        {
            moveAmount = Vector3.down;
        }
        moveAmount = MoveUnit * moveAmount;
        this.transform.localPosition += moveAmount;
    }
Exemplo n.º 4
0
        public void startMoving(MovingType movingType,
                                float dstX, float dstY, int dstW, int dstH, int frame)
        {
            bool noMoving = true;

            startMoving();

            if (setMovingPos(dstX, dstY))
            {
                noMoving = false;
            }
            if (setMovingSize(dstW, dstH))
            {
                noMoving = false;
            }
            if (!noMoving)
            {
                isMovingPos     = true;
                isMovingSize    = true;
                this.movingType = movingType;
                movingFrame     = 0;
                movingFrameMax  = frame;
                isMoving        = true;
            }
        }
Exemplo n.º 5
0
 public bool Move(MovingType direction)
 {
     if (batteryLife <= 0)
     {
         System.Console.WriteLine("BATTERY EMPTY");
         return(false);
     }
     if (position.CanMoveToDirection(direction))
     {
         this.position = position.GetFieldInDirection(direction);
         Scan();
         LoadPackage();
         UnloadPackage();
         batteryLife -= BATTERY_DRAIN;
         ChargeBattery();
         if (!visitedFields.Contains(position))
         {
             visitedFields.Add(position);
         }
         return(true);
     }
     else
     {
         System.Console.WriteLine("CANT MOVE TO DIRECTION");
         return(false);
     }
 }
Exemplo n.º 6
0
        public void LinkFields(Field field, MovingType direction) // gegenseitige Verknüpfung von Feldern
        {
            switch (direction)
            {
            case MovingType.EAST:
                field.west = this;
                east       = field;
                break;

            case MovingType.NORTH:
                field.south = this;
                north       = field;
                break;

            case MovingType.SOUTH:
                field.north = this;
                south       = field;
                break;

            case MovingType.WEST:
                field.east = this;
                west       = field;
                break;
            }
        }
    private void ShowDice()
    {
        if (Input.GetKeyDown(KeyCode.Mouse0) && gameCycle == GameCycle.SecondStep)
        {
            AlternateInterface(1);
            activeCamera = ActiveCamera.DiceCamera;
            camMReference.TypesOfCameras(activeCamera);
            uIGameReference.ShowDiceMoves(1, diceNumber);
            AnimationScript.instance.TapAnimation(false);
            AnimationScript.instance.DiceAnimations(true);
            AudioScript.instance.DiceAudioState(0);
            diceNumber = Random.Range(1, 7);
            movingType = MovingType.Advancing;
            StartCoroutine(TimeToDiceAnimation());
        }
        IEnumerator TimeToDiceAnimation()
        {
            yield return(new WaitForSeconds(1));

            AudioScript.instance.DiceAudioState(1);
            uIGameReference.ShowDiceMoves(2, diceNumber);
            yield return(new WaitForSeconds(2));

            AudioScript.instance.DiceAudioState(2);
            AnimationScript.instance.DiceAnimations(false);
            emptyDiceTransform.eulerAngles = diceFaceRotation[diceNumber - 1];
            yield return(new WaitForSeconds(2));

            AudioScript.instance.DiceAudioState(3);
            gameCycle = GameCycle.ThirdStep;
        }
    }
Exemplo n.º 8
0
        public bool Move(MovingType direction)
        {
            Field fieldInMovingDirection = currentPosition.GetFieldInDirection(direction);

            if (fieldInMovingDirection != null)
            {
                if (fieldInMovingDirection is OpenWater)
                {
                    LifeDrain();
                }
                if (fieldInMovingDirection is Door)
                {
                    this.OpenDoor(fieldInMovingDirection as Door);
                }

                Field fieldToMoveTo = (fieldInMovingDirection as IEnter).Enter();
                if (fieldToMoveTo != null)
                {
                    this.currentPosition = fieldToMoveTo;
                    if (fieldInMovingDirection is BonFire)
                    {
                        (this.currentPosition as BonFire).Levelup(this);
                    }

                    isFighting = false;
                    ScanForEnemy();
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 9
0
 // Use this for initialization
 void Start()
 {
     _move    = false;
     _rotate  = false;
     Move     = false;
     MoveType = MovingType.Teleport;
     Target   = TargetColor.Blue;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Baiskonstrukto,
 /// </summary>
 public MovingAbility()
 {
     Moving = MovingType.OneWay;
     Ending = EndingType.Standing;
     Start = Vector2.Zero;
     End = Vector2.Zero;
     Center = Vector2.Zero;
     Radius = Vector2.Zero;
 }
Exemplo n.º 11
0
 public void ValueCopy(MovingMapObject moving)
 {
     points           = moving.points;
     playOneShot      = moving.playOneShot;
     movingType       = moving.movingType;
     movingTime       = moving.movingTime;
     waitTime         = moving.waitTime;
     isMoveWithPlayer = moving.isMoveWithPlayer;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Perform a linear move
 /// </summary>
 /// <param name="startPos">Start position</param>
 /// <param name="endPos">End Position</param>
 public void LinearMove(Vector2 startPos, Vector2 endPos)
 {
     mMovingStatus        = MovingType.Linear;
     mTime                = 0.0f;
     mPositionStart       = startPos;
     mPositionDestination = endPos;
     Vector2.Distance(ref mPositionStart, ref mPositionDestination, out mMoveDistance);
     mDirection = (float)Math.Atan2(endPos.Y - startPos.Y, endPos.X - startPos.X);
 }
Exemplo n.º 13
0
 public virtual void Move(Vector3 destPos, MovingType movingType, float delayTime)
 {
     IsMoving        = true;
     DestPos         = destPos;
     TimeMoving      = delayTime;
     TimerMoving     = 0;
     StartPos        = transform.localPosition;
     this.movingType = movingType;
 }
Exemplo n.º 14
0
 public void AdjustEnemy(float health, float speed, float damage, MovingType type, float money)
 {
     maxHealth       = health;
     health          = maxHealth;
     movementSpeed   = speed;
     givenDamage     = damage;
     moneyForKilling = money;
     movingType      = type;
 }
Exemplo n.º 15
0
 public virtual void Move(Vector3 destPos, MovingType movingType, float delayTime)
 {
     IsMoving = true;
     DestPos = destPos;
     TimeMoving = delayTime;
     TimerMoving = 0;
     StartPos = transform.localPosition;
     this.movingType = movingType;
 }
Exemplo n.º 16
0
    public override void Reset()
    {
        base.Reset();


        mInvalidState = true;
        lastState     = IdleStateDef.Count;
        lastIsMove    = false;
        lastTrans     = false;
        lastMoveType  = MovingType.MoveType_Name;
    }
Exemplo n.º 17
0
        /**
         * 自動移動(座標)
         * @param dstX  目的x
         * @param dstY  目的y
         * @param frame  移動にかかるフレーム数
         */
        public void startMoving(MovingType movingType, float dstX, float dstY, int frame)
        {
            if (!setMovingPos(dstX, dstY))
            {
                // 移動不要
                return;
            }
            startMoving();

            isMoving        = true;
            isMovingPos     = true;
            isMovingSize    = false;
            this.movingType = movingType;
            movingFrame     = 0;
            movingFrameMax  = frame;
        }
Exemplo n.º 18
0
        /**
         * 自動移動(サイズ)
         * @param dstW
         * @param dstH
         * @param frame
         */
        public void startMovingSize(int dstW, int dstH, int frame)
        {
            if (!setMovingSize(dstW, dstH))
            {
                // 移動不要
                return;
            }
            startMoving();

            movingType     = MovingType.UniformMotion;
            isMoving       = true;
            isMovingPos    = false;
            isMovingSize   = true;
            movingFrame    = 0;
            movingFrameMax = frame;
        }
Exemplo n.º 19
0
 public Field GetFieldInDirection(MovingType direction) // Verknüpfung der Attribute east, north, west und south des Datentyp "Field" und vom Datentyp Enum Moving Type
 {
     if (direction == MovingType.NORTH)
     {
         return(north);
     }
     if (direction == MovingType.EAST)
     {
         return(east);
     }
     if (direction == MovingType.SOUTH)
     {
         return(south);
     }
     return(west);
 }
    public void ShowMovingText(MovingType movingType, int diceNumber, int currentTarget)
    {
        if (diceNumber > 1)
        {
            switch ((int)movingType)
            {
            case 0:
                moveSpacesText.text = "Advance " + (diceNumber--);; break;

            case 1:
                moveSpacesText.text = "Reverse " + (diceNumber--); break;

            case 2:
                moveSpacesText.text = "Teleporting  to \n" + currentTarget + " point"; break;
            }
        }
    }
Exemplo n.º 21
0
        public static Type ResolveAI(MovingType type)
        {
            switch (type)
            {
            case MovingType.OrbitAroundPoint: return(typeof(OrbitCombatAI));

            case MovingType.Patrol: return(typeof(PatrolBetweenAreasCombatAI));

            case MovingType.None: return(typeof(StayCombatAI));

            case MovingType.FreeFlyAtBox: return(typeof(WanderCombatAI));

            case MovingType.FreeFlyNearPoint: return(typeof(WanderAroundPointCombatAI));

            case MovingType.FollowPathCombat: return(typeof(FollowPathCombatAI));

            case MovingType.FollowPathNonCombat: return(typeof(FollowPathAI));

            default:
                throw new Exception(string.Format("Unsupported AI type = {0}", type));
            }
        }
Exemplo n.º 22
0
    public void Enable(MovingType type)
    {
        _currentMoving?.Disable();

        switch (type)
        {
        case MovingType.Charmode:
            _charmodeMoving.Enable();
            _currentMoving = _charmodeMoving;
            break;

        case MovingType.Panorama:
            _panoramaMoving.Enable();
            _currentMoving = _panoramaMoving;
            break;

        case MovingType.Orbital:
            _orbitalMoving.Enable();
            _currentMoving = _orbitalMoving;
            break;
        }
    }
Exemplo n.º 23
0
        public BlockMoving(int x, int y, int Distance, MovingType T, Boolean Start)
        {
            //ImageCount = 4;
            MaxDistance = Distance;
            Type = T;
            this.x = x;
            this.y = y;
            OT = ObjectType.OT_MovingBlock;
            SetWidthHeight();
            width = 50;
            Dir = 2.0;
            if (Start)
                Dir *= -1;

            if (Type == MovingType.MT_UpDown)
                StartPosition = newy;
            else
                StartPosition = newx;

            MarioOn = false;

            TimerGenerator.AddTimerEventHandler(TimerType.TT_50, OnMove);
        }
Exemplo n.º 24
0
        /// <summary>
        /// 设置透明度的对话框
        /// </summary>
        //private Transparency transparency = new Transparency();
        public FormClock(string text)
        {
            InitializeComponent();

            if (text == "撒花")
            {
                movingType = MovingType.Flower;

                labelTime.Width = text.Length * 50;
                this.Size = labelTime.Size;
                this.Width = text.Length * 50;
                labelTime.Text = text;
                labelTime.ForeColor = clist[ra.Next() % 20];

                this.Top = ra.Next() % (Screen.GetWorkingArea(this).Bottom / 4) + Screen.GetWorkingArea(this).Bottom / 2 + this.Height;
                this.Left = Screen.GetWorkingArea(this).Right + ra.Next() % (Screen.GetWorkingArea(this).Right / 2);

                vVertical = - 4 - ra.Next() % 7 ;
                vHorizonal = 7;
            }
            else
            {
                movingType = MovingType.Common;

                labelTime.Width = text.Length * 50;
                this.Size = labelTime.Size;
                this.Width = text.Length * 50;
                labelTime.Text = text;
                labelTime.ForeColor = clist[ra.Next() % 20];

                this.Top = ra.Next() % (Screen.GetWorkingArea(this).Bottom / 4) + this.Height;
                this.Left = Screen.GetWorkingArea(this).Right;

                vHorizonal = 5;
            }
        }
Exemplo n.º 25
0
 /// <summary>
 /// Perform a linear move
 /// </summary>
 /// <param name="startPos">Start position</param>
 /// <param name="endPos">End Position</param>
 public void LinearMove(Vector2 startPos, Vector2 endPos)
 {
     movingStatus = MovingType.Linear;
     time = 0.0f;
     positionStart = startPos;
     positionDestination = endPos;
     Vector2.Distance(ref positionStart, ref positionDestination, out MoveDistance);
     direction = (float)Math.Atan2(endPos.Y - startPos.Y,endPos.X - startPos.X);
 }
Exemplo n.º 26
0
        public bool CanMoveToDirection(MovingType direction) // Funktion ob man sich in die Richtung bewegen kann
        {
            Field fieldToMoveTo = GetFieldInDirection(direction);

            return(fieldToMoveTo != null);                           // return true, wenn es nicht null ist. Die Variable "fieldToMoveTo" vom Typ "Field" wird true dh. Robot kann auf dieses Feld.
        }
Exemplo n.º 27
0
		/// <summary>
		/// Stop moving and reset times
		/// </summary>
		public void StopMoving() {
			mMovingStatus = MovingType.None;
			mTime = 0.0f;
			mTotalTime = 0.0f;
		}
Exemplo n.º 28
0
 public void EnableMoving(MovingType type)
 {
     _movingController.Enable(type);
 }
    private void ShowTVQuestions()
    {
        if (gameCycle == GameCycle.FourthStep)
        {
            AlternateInterface(3);
            RandomTestSelection();
            activeCamera = ActiveCamera.TVCamera;
            camMReference.TypesOfCameras(activeCamera);
            animReference.TVAnimations(true);

            timerToLooseQuestion = 20f;
            while (timerToLooseQuestion > 0)
            {
                if (questionState == QuestionState.Answered)
                {
                    AnswerResult(buttonsGame.SendAnswerResult());
                    break;
                }
                else if (questionState == QuestionState.NotAnswered)
                {
                    timerToLooseQuestion -= Time.time;
                    if (timerToLooseQuestion <= 0)
                    {
                        StartCoroutine(TimeToEndTurn(4f));
                    }
                }
            }
        }
        void RandomTestSelection()
        {
            randomQuestion = Random.Range(0, generalCultureQuestions.Length);
            buttonsGame.ReceiveRandomValue(randomQuestion);
            uIGameReference.QuestionAssignation(randomQuestion, 0);
            randomAnswerList  = new List <int>(3);
            randomWrongAnswer = new List <int>(2);
            for (int i = 0; i < randomAnswerList.Capacity; i++)
            {
                randomSelections      = Random.Range(0, randomAnswerList.Capacity);
                randomWrongSelections = Random.Range(0, randomWrongAnswer.Capacity);
                if (randomAnswerList.Capacity != 1)
                {
                    if (randomWrongAnswer.Capacity != 1)
                    {
                        uIGameReference.AnswerAssignations(1, randomSelections, randomQuestion);
                    }
                    else
                    {
                        uIGameReference.AnswerAssignations(2, randomSelections, randomQuestion);
                    }
                    randomAnswerList.Remove(randomSelections);
                    randomWrongAnswer.Remove(randomWrongSelections);
                }
                else
                {
                    uIGameReference.AnswerAssignations(3, randomSelections, randomQuestion);
                }
            }
        }

        void AnswerResult(bool isAcerted)
        {
            platformScript.SendCurrentPlatform(wayPoints[currentTarget].position, platformType);
            if (isAcerted && platformType != PlatformType.Neutral)
            {
                MovingTypeAssignation(true);
                gameCycle = GameCycle.ThirdStep;
            }
            else if (isAcerted == false && platformType != PlatformType.Neutral)
            {
                MovingTypeAssignation(false);
            }

            uIGameReference.QuestionAssignation(randomQuestion, 1);
            if (platformType == PlatformType.Neutral)
            {
                StartCoroutine(TimeToEndTurn(4f));
            }
        }

        void MovingTypeAssignation(bool isAcerted)
        {
            if (isAcerted)
            {
                switch ((int)platformType)
                {
                case 0: movingType = MovingType.Waiting; break;

                case 1: movingType = MovingType.Advancing; break;

                case 2: movingType = MovingType.Waiting; break;

                case 3: movingType = MovingType.Teleporting; break;
                }
            }
            else
            {
                switch ((int)platformType)
                {
                case 0: movingType = MovingType.Waiting; break;

                case 1: movingType = MovingType.Waiting; break;

                case 2: movingType = MovingType.Reversing; break;

                case 3: movingType = MovingType.Teleporting; break;
                }
            }
        }

        void EventLimiter() // funcion que cumple el proposito de limitar el maximo de movimiento
        {
            //if (intAdvanceLimit >= 2)
            //    isLimAdvanceOver = true;
            //else if (intReverseLimit >= 2)
            //    isLimReverseOver = true;
            //else if (intMisteryLimit >= 2)
            //    isLimMisteryOver = true;
            //else
            //{
            //    isLimAdvanceOver = false;
            //    isLimReverseOver = false;
            //    isLimMisteryOver = false;
            //}
        }
    }
Exemplo n.º 30
0
        public Point GetNewPositionByBehavior(IAnimal animal, Point nearestAnimal, Point oldPosition, MovingType movingType)
        {
            _animalSpeed = _field.Animals[oldPosition.Y, oldPosition.X].Speed;
            Point           newPosition     = oldPosition;
            DistanceHandler distanceHandler = new DistanceHandler();

            if ((nearestAnimal.X != -1) && (distanceHandler.GetDistance(oldPosition, nearestAnimal) <= animal.VisionRange))
            {
                if ((distanceHandler.GetDistance(oldPosition, nearestAnimal) <= animal.Speed) && (animal.Type == AnimalType.Carnivore))
                {
                    newPosition = nearestAnimal;
                }
                else
                {
                    Point desiredPosition = _pathHandler.GetAnimalNextWaypoint(oldPosition, nearestAnimal, movingType);
                    newPosition = GetSuitableNewPosition(oldPosition, desiredPosition, animal.Type);
                }
            }
            else
            {
                newPosition = GetRandomNewPosition(oldPosition);
            }

            return(newPosition);
        }
Exemplo n.º 31
0
        private static AIType LoadAIType(XElement element)
        {
            MovingType movingType = (MovingType)Enum.Parse(typeof(MovingType), element.GetString("name"));

            AttackMovingType attackMovingType = AttackMovingType.AttackIdle;

            if (element.HasAttribute("attack_moving_type"))
            {
                attackMovingType = (AttackMovingType)Enum.Parse(typeof(AttackMovingType), element.GetString("attack_moving_type"));
            }
            //bool chase = element.GetBool("chase");
            switch (movingType)
            {
            case MovingType.FreeFlyAtBox:
            {
                Vector3 min = element.GetFloatArray("min").ToVector3();
                Vector3 max = element.GetFloatArray("max").ToVector3();

                return(new FreeFlyAtBoxAIType {
                        corners = new MinMax {
                            min = min, max = max
                        },
                        battleMovingType = attackMovingType
                    });
            }

            case MovingType.FreeFlyNearPoint:
            {
                float radius = element.GetFloat("radius");
                return(new FreeFlyNearPointAIType {
                        battleMovingType = attackMovingType, radius = radius
                    });
            }

            case MovingType.OrbitAroundPoint:
            {
                float phiSpeed   = element.GetFloat("phi_speed");
                float thetaSpeed = element.GetFloat("theta_speed");
                float radius     = element.GetFloat("radius");
                return(new OrbitAroundPointAIType {
                        battleMovingType = attackMovingType, phiSpeed = phiSpeed, thetaSpeed = thetaSpeed, radius = radius
                    });
            }

            case MovingType.Patrol:
            {
                Vector3 first  = element.GetFloatArray("first").ToVector3();
                Vector3 second = element.GetFloatArray("second").ToVector3();
                return(new PatrolAIType {
                        battleMovingType = attackMovingType, firstPoint = first, secondPoint = second
                    });
            }

            case MovingType.None:
            {
                return(new NoneAIType {
                        battleMovingType = attackMovingType
                    });
            }

            case MovingType.FollowPathCombat:
            {
                Vector3[] path = element.ToVector3List("path").ToArray();
                return(new FollowPathAIType {
                        battleMovingType = attackMovingType, path = path
                    });
            }

            case MovingType.FollowPathNonCombat:
            {
                Vector3[] path = element.ToVector3List("path").ToArray();
                return(new FollowPathNonCombatAIType {
                        path = path
                    });
            }
            break;

            default:
                throw new Exception("undefined ai type: " + movingType);
            }
        }
Exemplo n.º 32
0
 /// <summary>
 /// Stop moving and reset times
 /// </summary>
 public void StopMoving()
 {
     movingStatus = MovingType.None;
     time = 0.0f;
     totalTime = 0.0f;
 }
Exemplo n.º 33
0
		/// <summary>
		/// Perform move on found path
		/// </summary>
		/// <param name="Nodes">List of found path nodes</param>
		/// <param name="StartPosition">Point from where to start moving</param>
		/// <param name="EndPosition">Moving end point</param>
		public void PathMove(ref List<PathReturnNode> Nodes, Vector2 StartPosition, Vector2 EndPosition) {
			mMovingStatus = MovingType.PathSmooth;

			mCurveX.Keys.Clear();
			mCurveY.Keys.Clear();

			mNodePos = Nodes.Count - 1;

			//This needed to get directions
			mStartPosOnPath = new Point(Nodes[mNodePos].PosX, Nodes[mNodePos].PosY);
			mPrevPosOnPath = mStartPosOnPath;
			mCurrentPosOnPath = mStartPosOnPath;
			mEndPosOnPath = new Point(Nodes[0].PosX, Nodes[0].PosY);

			mDirFrom = GetDirection(mNodePos, ref Nodes);

			CurveKey key;

			//Loop throught all nodes
			for (int n = mNodePos - 1; n >= 0; n -= 1) {
				//Prew direction
				mDirTo = mDirFrom;
				//Get new direction
				mDirFrom = GetDirection(n, ref Nodes);

				//Add nodes in curves, LinearMoves array and DirTo are used to get the rigt spot
				key = new CurveKey((mNodePos - n) * mGridWidth, mCurrentPosOnPath.X * mGridWidth + mLinearMoves[mDirTo].X);

				mCurveX.Keys.Add(key);

				key = new CurveKey((mNodePos - n) * mGridWidth, mCurrentPosOnPath.Y * mGridWidth + mLinearMoves[mDirTo].Y);

				mCurveY.Keys.Add(key);

				mPrevPosOnPath = mCurrentPosOnPath;
				mCurrentPosOnPath = new Point(Nodes[n].PosX, Nodes[n].PosY);
			}


			//First and last nodes are inserted and are not path node based
			//We should get distance form first to second node to insert in in right time
			float firstDist = mGridWidth - Vector2.Distance(StartPosition, new Vector2(mCurveX.Keys[0].Value, mCurveY.Keys[0].Value));

			key = new CurveKey(firstDist, StartPosition.X);
			mCurveX.Keys.Add(key);
			key = new CurveKey(firstDist, StartPosition.Y);
			mCurveY.Keys.Add(key);

			float secondDist = Vector2.Distance(EndPosition, new Vector2(mCurveX.Keys[mCurveX.Keys.Count - 1].Value, mCurveY.Keys[mCurveY.Keys.Count - 1].Value)) - mGridWidth;

			key = new CurveKey(Nodes.Count * mGridWidth + secondDist, EndPosition.X);
			mCurveX.Keys.Add(key);
			key = new CurveKey(Nodes.Count * mGridWidth + secondDist, EndPosition.Y);
			mCurveY.Keys.Add(key);

			if (mNodePos > 2) {
				mCurveX.Keys.RemoveAt(1);
				mCurveX.Keys.RemoveAt(mCurveX.Keys.Count - 2);
				mCurveY.Keys.RemoveAt(1);
				mCurveY.Keys.RemoveAt(mCurveY.Keys.Count - 2);
			}

			//Compute tangents for both curves
			mCurveX.ComputeTangents(CurveTangent.Smooth);
			mCurveY.ComputeTangents(CurveTangent.Smooth);

			//Set start and end positions on curve, used in Update
			mTime = firstDist;
			mTotalTime = Nodes.Count * mGridWidth + secondDist;
		}
Exemplo n.º 34
0
    private void PlayIdleAnim()
    {
        /*
         * //  * 播放空闲动作
         * //  */
        if (Owner.IdleIndex >= IdleStateDef.Count)
        {
            Owner.IdleIndex = IdleStateDef.Rest;
        }


        string statename = null;

        BattleUnit battleUnit = Owner as BattleUnit;


        if (battleUnit != null)
        {
            if (Owner.IdleIndex == lastState &&
                lastMoveType == Owner.GetMovingType() &&
                lastIsMove == battleUnit.IsMoveing() &&
                lastTrans == battleUnit.IsInviolable() &&
                lastweaponid == battleUnit.GetMainWeaponID() &&
                !mInvalidState)
            {
                return;
            }
            lastState    = Owner.IdleIndex;
            lastMoveType = Owner.GetMovingType();
            lastTrans    = battleUnit.IsInviolable();
            lastIsMove   = battleUnit.IsMoveing();
            lastweaponid = battleUnit.GetMainWeaponID();
        }
        else
        {
            if (Owner.IdleIndex == lastState && mInvalidState)
            {
                lastState = Owner.IdleIndex;
            }
        }

        mInvalidState = false;

        if (Owner.IdleIndex == IdleStateDef.Rest && battleUnit != null && !battleUnit.IsInviolable())
        {
            bool lowerMove = Owner.GetMovingType() == MovingType.MoveType_Lowwer;
            // 能不能移动
            if (lowerMove && !battleUnit.IsMoveing())
            {
                statename = Owner.CombineAnimname(AnimationNameDef.PrefixZhanliXiuxi);
            }
        }

        if (string.IsNullOrEmpty(statename) || !mAnimator.Property.IsStateExist(statename))
        {
            statename = IdleStateAnimationDef.GetAnimationNameByState(Owner.IdleIndex);
            statename = Owner.CombineAnimname(statename);
        }

        int statehash = mAnimator.Property.GetStateHash(statename);

        if (statehash == 0)
        {
            mInvalidState = true;
            return;
        }
        SetTransition(statehash);
    }
Exemplo n.º 35
0
 /// <summary>
 /// Stop moving and reset times
 /// </summary>
 public void StopMoving()
 {
     mMovingStatus = MovingType.None;
     mTime         = 0.0f;
     mTotalTime    = 0.0f;
 }
Exemplo n.º 36
0
        private void GetMovmentInput(out float speed)
        {
            // Read input
            float horizontal = Input.GetAxis("Horizontal");
            float vertical   = Input.GetAxis("Vertical");

            bool waswalking = m_IsWalking;

            // keep track of whether or not the character is walking or running
            //Can only run while standing
            if (m_standing && Input.GetKey(KeyCode.LeftControl))
            {
                m_MovingType = MovingType.RUN;
            }
            else
            {
                m_IsWalking  = true;
                m_MovingType = MovingType.WALK;
            }

            if (Input.GetKey(KeyCode.LeftShift))
            {
                m_MovingType = MovingType.SLOWWALK;
            }

            // set the desired speed to be slow walking, walking, or running
            switch (m_MovingType)
            {
            case MovingType.SLOWWALK:
                speed = m_SlowWalkSpeed;
                break;

            case MovingType.WALK:
                speed = m_WalkSpeed;
                break;

            case MovingType.RUN:
                speed = m_RunSpeed;
                break;

            default:
                speed = 1;
                break;
            }

            //if we are crouched modify speed
            if (!m_standing)
            {
                speed *= 0.5f;
            }

            m_Input = new Vector2(horizontal, vertical);

            // normalize input if it exceeds 1 in combined length:
            if (m_Input.sqrMagnitude > 1)
            {
                m_Input.Normalize();
            }

            // handle speed change to give an fov kick
            // only if the player is going to a run, is running and the fovkick is to be used
            if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0)
            {
                StopAllCoroutines();
                StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown());
            }
        }
Exemplo n.º 37
0
        /// <summary>
        /// Perform move on found path
        /// </summary>
        /// <param name="Nodes">List of found path nodes</param>
        /// <param name="StartPosition">Point from where to start moving</param>
        /// <param name="EndPosition">Moving end point</param>
        public void PathMove(ref List <PathReturnNode> Nodes, Vector2 StartPosition, Vector2 EndPosition)
        {
            mMovingStatus = MovingType.PathSmooth;

            mCurveX.Keys.Clear();
            mCurveY.Keys.Clear();

            mNodePos = Nodes.Count - 1;

            //This needed to get directions
            mStartPosOnPath   = new Point(Nodes[mNodePos].PosX, Nodes[mNodePos].PosY);
            mPrevPosOnPath    = mStartPosOnPath;
            mCurrentPosOnPath = mStartPosOnPath;
            mEndPosOnPath     = new Point(Nodes[0].PosX, Nodes[0].PosY);

            mDirFrom = GetDirection(mNodePos, ref Nodes);

            CurveKey key;

            //Loop throught all nodes
            for (int n = mNodePos - 1; n >= 0; n -= 1)
            {
                //Prew direction
                mDirTo = mDirFrom;
                //Get new direction
                mDirFrom = GetDirection(n, ref Nodes);

                //Add nodes in curves, LinearMoves array and DirTo are used to get the rigt spot
                key = new CurveKey((mNodePos - n) * mGridWidth, mCurrentPosOnPath.X * mGridWidth + mLinearMoves[mDirTo].X);

                mCurveX.Keys.Add(key);

                key = new CurveKey((mNodePos - n) * mGridWidth, mCurrentPosOnPath.Y * mGridWidth + mLinearMoves[mDirTo].Y);

                mCurveY.Keys.Add(key);

                mPrevPosOnPath    = mCurrentPosOnPath;
                mCurrentPosOnPath = new Point(Nodes[n].PosX, Nodes[n].PosY);
            }


            //First and last nodes are inserted and are not path node based
            //We should get distance form first to second node to insert in in right time
            float firstDist = mGridWidth - Vector2.Distance(StartPosition, new Vector2(mCurveX.Keys[0].Value, mCurveY.Keys[0].Value));

            key = new CurveKey(firstDist, StartPosition.X);
            mCurveX.Keys.Add(key);
            key = new CurveKey(firstDist, StartPosition.Y);
            mCurveY.Keys.Add(key);

            float secondDist = Vector2.Distance(EndPosition, new Vector2(mCurveX.Keys[mCurveX.Keys.Count - 1].Value, mCurveY.Keys[mCurveY.Keys.Count - 1].Value)) - mGridWidth;

            key = new CurveKey(Nodes.Count * mGridWidth + secondDist, EndPosition.X);
            mCurveX.Keys.Add(key);
            key = new CurveKey(Nodes.Count * mGridWidth + secondDist, EndPosition.Y);
            mCurveY.Keys.Add(key);

            if (mNodePos > 2)
            {
                mCurveX.Keys.RemoveAt(1);
                mCurveX.Keys.RemoveAt(mCurveX.Keys.Count - 2);
                mCurveY.Keys.RemoveAt(1);
                mCurveY.Keys.RemoveAt(mCurveY.Keys.Count - 2);
            }

            //Compute tangents for both curves
            mCurveX.ComputeTangents(CurveTangent.Smooth);
            mCurveY.ComputeTangents(CurveTangent.Smooth);

            //Set start and end positions on curve, used in Update
            mTime      = firstDist;
            mTotalTime = Nodes.Count * mGridWidth + secondDist;
        }
Exemplo n.º 38
0
        public static void Move(MovingType moveTo, EventHandler secondAnimation = null,
                                bool err = false, bool menu = false, bool detail = false, double height = -1)
        {
            Thickness newPosition = new Thickness(0, 0, 0, 0);

            main.ResizeMode = (detail ? ResizeMode.NoResize : ResizeMode.CanResizeWithGrip);

            if (menu)
            {
                Interface.Mod.View(canvasToShow: main.mainMenu, top: true);
            }

            if (err)
            {
                Interface.Mod.View(canvasToShow: main.errorDetail, top: true);
            }

            if (moveTo == MovingType.ToLeft)
            {
                Interface.Mod.View(left: true);
                newPosition = new Thickness(main.ActualWidth, 0, 0, 0);
            }

            if (moveTo == MovingType.ToRight)
            {
                Interface.Mod.View(right: true);
                newPosition = new Thickness((main.ActualWidth * -1), 0, 0, 0);
            }

            if (moveTo == MovingType.ToTop)
            {
                newPosition = new Thickness(0, main.errorDetail.Height, 0, 0);
            }

            if (moveTo == MovingType.ToMainMenu)
            {
                newPosition = new Thickness(0, height, 0, 0);
            }

            if ((moveTo == MovingType.ToMain) && unitTestIsOpen)
            {
                Interface.Mod.UnitTestClose();
            }

            bool mainCanvasMoving = (err || menu);

            ThicknessAnimation move = new ThicknessAnimation
            {
                Duration = TimeSpan.FromSeconds(0.2),
                From     = (mainCanvasMoving ? main.mainPlaceCanvas.Margin : main.mainGrid.Margin),
                To       = newPosition
            };

            if (secondAnimation != null)
            {
                move.Completed += secondAnimation;
            }

            if (mainCanvasMoving)
            {
                main.mainPlaceCanvas.BeginAnimation(FrameworkElement.MarginProperty, move);
            }
            else
            {
                main.mainGrid.BeginAnimation(FrameworkElement.MarginProperty, move);
            }

            if (menu && (moveTo == MovingType.ToMainMenu))
            {
                mainMenuIsOpen = true;
            }
            else if (menu)
            {
                mainMenuIsOpen = false;
            }
        }