Пример #1
0
        // Action methods

        public void Walk()
        {
            if (this.movingState == MovingState.Idle)
            {
                this.movingState = MovingState.Walking;
            }
        }
Пример #2
0
 public void TakeOff()
 {
     if (this.movingState == MovingState.Jumping)
     {
         this.movingState = MovingState.InFlight;
     }
 }
Пример #3
0
 private void Start()
 {
     blackKnightAnimator = blackKnight.GetComponent <Animator>();
     health             = 18;
     blackKnightState   = new WalkingState(blackKnight, characterRobotBoy, blackKnightAnimator);
     isAttackOnCooldown = false;
 }
Пример #4
0
        public void Update(GameTime game_time, Controller controller)
        {
            if (controller.Up)
            {
                state = MovingState.Up;
            }

            else if (controller.Left)
            {
                state = MovingState.Left;
            }

            else if (controller.Down)
            {
                state = MovingState.Down;
            }

            else if (controller.Right)
            {
                state = MovingState.Right;
            }
            else
            {
                state = MovingState.Stopped;
            }
        }
Пример #5
0
    protected void Update()
    {
        switch (moving_state)
        {
        case MovingState.opening:
            if (Time.time - beginning_time >= time)
            {
                transform.position = max;
                moving_state       = MovingState.opened;
            }
            transform.Translate(speed * Time.deltaTime);
            break;

        case MovingState.closing:
            if (Time.time - beginning_time >= time)
            {
                transform.position = min;
                moving_state       = MovingState.closed;
            }
            transform.Translate(-speed * Time.deltaTime);
            break;

        case MovingState.opened:
        case MovingState.closed:
        default: break;
        }
    }
Пример #6
0
 public void MoveToLeft()
 {
     _direction = new Vector2(-4, 0);
     _effect    = SpriteEffects.FlipHorizontally;
     _moving    = MovingState.Walking;
     SoundManager.PlayWalking();
 }
Пример #7
0
 public void MoveToRight()
 {
     _direction = new Vector2(4, 0);
     _effect    = SpriteEffects.None;
     _moving    = MovingState.Walking;
     SoundManager.PlayWalking();
 }
Пример #8
0
        public IActionState GetState(string state)
        {
            IActionState actionState = null;

            if (_states.ContainsKey(state))
            {
                actionState = _states[state];
            }
            else
            {
                switch (state)
                {
                case "Moving":
                    actionState = new MovingState();
                    break;

                case "Idle":
                    actionState = new IdleState();
                    break;

                case "Shooting":
                    actionState = new ShootingState();
                    break;
                }
                _states.Add(state, actionState);
            }

            return(actionState);
        }
Пример #9
0
 public void Stop()
 {
     if (this.movingState == MovingState.Walking)
     {
         this.movingState = MovingState.Idle;
     }
 }
Пример #10
0
 public void StartNewCooldown(float duration, MovingState sender)
 {
     Task.Factory.StartNew(async() => {
         await Task.Delay((int)(duration * 1000));
         sender.IsShoveOffCooldown = true;
     });
 }
Пример #11
0
 public void Fall()
 {
     if (this.movingState == MovingState.InFlight)
     {
         this.movingState = MovingState.Falling;
     }
 }
    public void EnterState_MovingSelf(MovingState direction)
    {
        GameObject prevDestination = null;
        switch(direction)
        {
        case(MovingState.BeginForward):
            //if(_intDestinationIndex == checkpoints.Length-1)
                //return;
            _blnMovingForward = true;
            _intDestinationIndex = 1;
            prevDestination = checkpoints[0];
            break;
        case(MovingState.BeginReverse):
            //if(_intDestinationIndex == 0)
                //return;
            _blnMovingForward = false;
            _intDestinationIndex = checkpoints.Length-2;
            prevDestination = checkpoints[checkpoints.Length-1];
            break;
        case(MovingState.Continue):
            prevDestination = checkpoints[_intDestinationIndex];
            if (_blnMovingForward)
                _intDestinationIndex += 1;
            else
                _intDestinationIndex -= 1;
            break;
        }
        currentDestination = checkpoints[_intDestinationIndex];
        prevPosition = this.transform.position;
        if (blnTimedPlatform)
            fltSpeed = (currentDestination.transform.position - prevDestination.transform.position).magnitude / (fltTicksMoving * fltSecondsPerTick);

        currentState = States.MovingSelf;
    }
Пример #13
0
    // Update is called once per frame
    void Update()
    {
        //För testning och första ändring av MovingState. Kommer ersättas av nedräkningen sen.
        if (GameManager.instance.gameState == GameState.Running && GameManager.instance.oldGameState == GameState.Countdown)
        {
            ChangeState();
        }
        if (GameManager.instance.gameState == GameState.Menu && GameManager.instance.oldGameState == GameState.Running)
        {
            transform.position = startPosition;
            destination        = transform.position;
            timeElapsed        = 0;
            currentState       = MovingState.Idle;
        }


        if (GameManager.instance.gameState == GameState.Running)
        {
            RandomStateChange();

            if (transform.position.x < leftBoundary.x || transform.position.x > rightBoundary.x)
            {
                ChangeState();
                timeElapsed -= timeLimit;
            }

            ChangeDirection();

            transform.position = destination;
        }
    }
 public MovingEventArgs(bool facingRight, Vector2 position, Vector2 velocity, MovingState currentMovingState, MovingState lastMovingState)
 {
     this.facingRight        = facingRight;
     this.position           = position;
     this.velocity           = velocity;
     this.lastMovingState    = lastMovingState;
     this.currentMovingState = currentMovingState;
 }
Пример #15
0
 public void DisableSlammer()
 {
     StopAllCoroutines();
     myRend.gameObject.SetActive(false);
     myRend.enabled     = false;
     myCollider.enabled = false;
     currentState       = MovingState.None;
 }
Пример #16
0
 void _setMovingState(MovingState state)
 {
     if (movingState != state)
     {
         movingState = state;
         world.onActorMovingStateChanged(this);
     }
 }
Пример #17
0
 public void Stop()
 {
     _direction = Vector2.Zero;
     _moving    = MovingState.Stop;
     SoundManager.StopWalking();
     SoundManager.StopFalling();
     SoundManager.StopJumping();
 }
Пример #18
0
    /// <summary>
    /// Create an instance of this class function
    /// </summary>
    private MovingState()
    {
        if (_instance != null)
        {
            return;
        }

        _instance = this;
    }
Пример #19
0
 public override void onMouseDown(int x, int y)
 {
     this.selectedObject = this.drawingToolBox.GetCanvas().GetDrawingObjectAt(x, y, false);
     if (this.selectedObject != null)
     {
         this.selectedObject.SetState(MovingState.GetInstance());
         this.selectedObject.setMoveStart(x, y);
     }
 }
Пример #20
0
    private void ChangeStatus()
    {
        this.forward = Tank.NumberToMovingState(Random.Range(-1, 1));
        this.turnBody = Tank.NumberToMovingState(Random.Range(-1, 1));
        this.turnHead = Tank.NumberToMovingState(Random.Range(-1, 1));
        this.fire = Random.Range(0, 2) == 1;

        Invoke("ChangeStatus", this.changeStatusDelay);
    }
Пример #21
0
    private void ChangeStatus()
    {
        this.forward  = Tank.NumberToMovingState(Random.Range(-1, 1));
        this.turnBody = Tank.NumberToMovingState(Random.Range(-1, 1));
        this.turnHead = Tank.NumberToMovingState(Random.Range(-1, 1));
        this.fire     = Random.Range(0, 2) == 1;

        Invoke("ChangeStatus", this.changeStatusDelay);
    }
    void Start()
    {
        standingState = StandingState.CreateInstance(this);
        movingState   = MovingState.CreateInstance(this);
        turningState  = TurningState.CreateInstance(this);

        stateMachine = ScriptableObject.CreateInstance <StateMachine>();
        stateMachine.ChangeState(standingState);
    }
Пример #23
0
 void Start()
 {
     movingState   = MovingState.Waiting;
     direction     = new Vector3(-1.0f, 0.0f, 0.0f);
     preDirection  = direction;
     timer         = timerObject.GetComponent <GameTimer> ();
     maxMoveFrames = timer.GetMaxMoveFrames();
     scoreCount    = -1;
     AddAndUpdateScore();
 }
Пример #24
0
 public void StartJumpintRight()
 {
     _direction    = new Vector2(4, -6);
     _moving       = Sprite.MovingState.Jumping;
     _effect       = SpriteEffects.None;
     _jumpingStep  = 0;
     _jumpingSteps = longJumpSteps;
     _jumpingFase  = 0;
     SoundManager.PlayJumping();
 }
Пример #25
0
 public void StartJumpingLeft()
 {
     _direction    = new Vector2(-4, -6);
     _moving       = Sprite.MovingState.Jumping;
     _effect       = SpriteEffects.FlipHorizontally;
     _jumpingStep  = 0;
     _jumpingSteps = longJumpSteps;              // por defecto empezamos con un salto largo
     _jumpingFase  = 0;
     SoundManager.PlayJumping();
 }
Пример #26
0
 void Start()
 {
     cycle             = 0.7f;
     currentTime       = 0;
     currentMoveFrame  = 0;
     maxMoveFrames     = 12;
     movingState       = MovingState.Waiting;
     firstStepOfMoving = false;
     lastStepOfMoving  = false;
 }
Пример #27
0
        public IEnumerator Jump()
        {
            if (this.movingState == MovingState.Idle || this.movingState == MovingState.Walking)
            {
                this.movingState = MovingState.Jumping;
                yield return(new WaitForSeconds(jumpingDelay));

                this.TakeOff();
            }
        }
Пример #28
0
        // Use this function as a Coroutine: StartCoroutine("Land");
        public IEnumerator Land()
        {
            if (this.movingState == MovingState.InFlight || this.movingState == MovingState.Falling)
            {
                this.movingState = MovingState.Landing;
                yield return(new WaitForSeconds(landingDelay));

                this.movingState = MovingState.Idle;
            }
        }
Пример #29
0
 public static bool IsMoving(MovingState gameObject)
 {
     if (gameObject == MovingState.walking || gameObject == MovingState.running)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #30
0
 void Start()
 {
     timer          = timerObject.GetComponent <GameTimer> ();
     maxMoveFrames  = timer.GetMaxMoveFrames();
     movingState    = MovingState.Waiting;
     bodyCount      = 0;
     stuckByGrowing = false;
     bodyState      = BodyState.Moving;
     ListInitialize();
     UpdatePositionsToMap();
 }
 public YTMenuMovingComponent(Menu menu, MovingMode mode)
 {
     _Menu         = menu;
     _MovingMode   = mode;
     _MovingState  = MovingState.Static;
     _ScreenWidth  = (int)WindowsHandler.GetScreenWidth();
     _ScreenHeight = (int)WindowsHandler.GetScreenHeight();
     _xQueue       = new Queue <double>();
     _yQueue       = new Queue <double>();
     _ShakingQueue = new Queue <double>();
 }
Пример #32
0
 public void ResolveDeadPassengers()
 {
     if (!PilotAvailable && movingStatus == MovingState.able)
     {
         movingStatus = MovingState.frozen;
     }
     if (!GunnerAvailable && weaponStatus == WeaponState.able)
     {
         weaponStatus = WeaponState.frozen;
     }
 }
Пример #33
0
 public RecordingBuffer(int bufferLength, int numJoints)
 {
     this.numJoints = numJoints;
     steadyCounter = 0;
     this.bufferReady = false;
     this.bufferLength = bufferLength;
     this.currentFrame = 0;
     this.allBufferData = new float[5][,];
     this.bufferData = new float[bufferLength,this.numJoints*3]; //constant integer length
     this.ms = MovingState.IDLE; // initial state
     distanceAll = 0;
 }
Пример #34
0
    void Awake()
    {
        State = new MovingState ();
        ResetMovement ();

        _boxCollider = GetComponent<BoxCollider2D> ();
        _transform = transform.parent;
        _localScale = transform.localScale;

        _halfSize = new Vector2 (_boxCollider.size.x * Mathf.Abs (_localScale.x), _boxCollider.size.y * Mathf.Abs (_localScale.y)) / 2;
        CalculateDistanceBetweenRays ();
        _isFacingForward = transform.localScale.x > 0;

        InitializeEnergyValues();
    }
    void keyDownStateCange(float key)
    {
        if (movingState != MovingState.Stop)
            return;

        if (dodgingState == DodgingState.Dodging)
            return;

        if (key > 0 && place != Place.RightEnd)
        {
            movingState = MovingState.MovingRight;
        }
        else if (key < 0 && place != Place.LeftEnd)
        {
            movingState = MovingState.MovingLeft;
        }
    }
Пример #36
0
 public static string GetMovingStateString(MovingState state)
 {
     switch (state)
     {
         case MovingState.Idle:
             return "idle";
         case MovingState.Inactive:
             return "inactive";
         case MovingState.MovingLeft:
             return "movingLeft";
         case MovingState.MovingRight:
             return "movingRight";
         case MovingState.MovingDown:
             return "movingDown";
         case MovingState.MovingUp:
         default:
             return "movingUp";
     }
 }
Пример #37
0
 public void TurnHeadRight(MovingState state)
 {
     this.turnHeadRight = state;
 }
Пример #38
0
 public void TurnBodyRight(MovingState state)
 {
     this.turnBodyRight = state;
 }
Пример #39
0
 public void MoveForward(MovingState state)
 {
     this.movingForward = state;
 }
Пример #40
0
    void Awake()
    {
        State = new MovingState ();

        ResetMovement ();
        State.MovingMode = MoveMode.Walking;

        _boxCollider = GetComponent<BoxCollider2D> ();
        _transform = transform.parent;
        _localScale = transform.localScale;

        _halfSize = new Vector2 (_boxCollider.size.x * Mathf.Abs (_localScale.x), _boxCollider.size.y * Mathf.Abs (_localScale.y)) / 2;
        CalculateDistanceBetweenRays ();
        _isFacingForward = transform.localScale.x > 0;

        maxHorizontalReduce = Parameters.MaxSpeed -  (Parameters.MaxSpeed * horizontalMovInAirReducer);
        InitializeEnergyValues();
    }
Пример #41
0
        public void addFrame(float[] dataVector, int recordNumber)
        {
            float distanceAll = 0, distanceThreshold = .2f; //distances of the sum of joint-to-joint distances from the prev. stored point

            //data vector must be of size -- TODO spit out some error code at some point in time
            if (dataVector.Length != this.numJoints * 3)
                return;

            //movement-detection logic
            switch (this.ms)
            {
                case MovingState.IDLE:
                    //initialize
                    prevJoints = new float[numJoints * 3];
                    Array.Copy(dataVector, prevJoints, numJoints * 3);
                    this.ms = MovingState.STOPPED;
                    return;
                case MovingState.STOPPED:
                    for (int i = 0; i < numJoints; i++)
                    {
                        distanceAll += (float)Math.Sqrt(Math.Pow(dataVector[i * 3] - prevJoints[i * 3], 2) +
                                      Math.Pow(dataVector[i * 3 + 1] - prevJoints[i * 3 + 1], 2) +
                                      Math.Pow(dataVector[i * 3 + 2] - prevJoints[i * 3 + 2], 2));
                    }
                    if (distanceAll > distanceThreshold)
                    {
                        this.ms = MovingState.MOVING;
                    }
                    else
                    {
                        Array.Copy(dataVector, prevJoints, numJoints * 3); //update last joints
                    }
                    break;
                case MovingState.MOVING:

                    //add to buffer
                    for (int i = 0; i < this.numJoints * 3; i++)
                    {
                        //lazy copy
                        this.bufferData[this.currentFrame, i] = dataVector[i];
                    }
                    this.currentFrame++; //increment at end
                    if (this.currentFrame >= bufferLength)
                    {
                        this.bufferReady = true; //hit MAX capacity
                        this.allBufferData[recordNumber] = this.bufferData;
                        return;
                    }
                    //check if ACTOR has stopped
                    for (int i = 0; i < numJoints; i++)
                    {
                        distanceAll += (float)Math.Sqrt(Math.Pow(dataVector[i * 3] - prevJoints[i * 3], 2) +
                                      Math.Pow(dataVector[i * 3 + 1] - prevJoints[i * 3 + 1], 2) +
                                      Math.Pow(dataVector[i * 3 + 2] - prevJoints[i * 3 + 2], 2));
                    }
                    //set prev joints
                    prevJoints = new float[numJoints * 3];
                    Array.Copy(dataVector, prevJoints, numJoints * 3);

                    if (distanceAll < distanceThreshold)
                    {
                        steadyCounter++;
                        if (steadyCounter > statesToSteady)
                        {
                            this.bufferReady = true;
                            this.allBufferData[recordNumber] = this.bufferData;

                            return;
                        }
                    }
                    else
                    {
                        steadyCounter = 0; //reset counter
                    }

                    break;
                default:
                    break;
            }
        }
Пример #42
0
 public void clearBuffer()
 {
     steadyCounter = 0;
     this.ms = MovingState.IDLE;
     this.bufferReady = false;
     this.currentFrame = 0;
     this.distanceAll = 0;
 }
Пример #43
0
        public void Update(Point playerPoint)
        {
            base.Update();
            if (Life <= 0)
                return;
            _frame++;
            switch (State)
            {
                case MovingState.Group:
                    if (_go)
                    {
                        State = _random.Next(2) == 0
                            ? MovingState.TurnLeft
                            : MovingState.TurnRight;
                        _frame = 0;
                    }
                    break;

                case MovingState.TurnLeft:
                case MovingState.TurnRight:
                    if (_frame >= TurnTime * 4)
                    {
                        State = MovingState.Attack;
                        Direction = new Direction8(2);
                        _frame = 0;
                    }
                    break;
                case MovingState.Attack:
                    if (Type == EnemyType.Gold && _random.Next(85) == 0)
                    {
                        _vectorX = 0;
                        State = MovingState.SpinAttack;
                        _frame = 0;
                    }
                    break;
                case MovingState.SpinAttack:
                    if (Direction.Value == 2 && _random.Next(10) == 0)
                    {
                        State = MovingState.Attack;
                    }
                    break;
            }
            switch (State)
            {
                case MovingState.Group:
                    int myFrame = _frame % 140;
                    if (myFrame < 35)
                    {
                        _point.X += Speed;
                    }
                    else if (myFrame < 35 + 70)
                    {
                        _point.X -= Speed;
                    }
                    else
                    {
                        _point.X += Speed;
                    }
                    break;

                case MovingState.TurnLeft:
                    Direction = new Direction8((byte)(_frame < TurnTime
                        ? 8
                        : _frame < TurnTime * 2
                            ? 7
                            : _frame < TurnTime * 3
                                ? 4
                                : 1));
                    TurnMove();
                    break;
                case MovingState.TurnRight:
                    Direction = new Direction8((byte)(_frame < TurnTime
                        ? 8
                        : _frame < TurnTime * 2
                            ? 9
                            : _frame < TurnTime * 3
                                ? 6
                                : 3));
                    TurnMove();
                    break;
                case MovingState.Attack:
                    // 移動
                    if (_point.X < playerPoint.X)
                        _vectorX += Type == EnemyType.Blue ? 0.2 : 0.1;
                    else if (_point.X > playerPoint.X)
                        _vectorX -= Type == EnemyType.Blue ? 0.2 : 0.1;
                    if (_vectorX > VectorMax)
                        _vectorX = VectorMax;
                    else if (_vectorX < -VectorMax)
                        _vectorX = -VectorMax;
                    _point.Y += Speed;
                    _point.X += (short)_vectorX;

                    // 旋回
                    if (Type == EnemyType.Blue
                        || Type == EnemyType.Red
                        || Type == EnemyType.Silver)
                    {
                        double radian = GetRadian(Point, playerPoint);
                        Direction = Direction8.FromRadian(radian);
                        if (Type == EnemyType.Blue
                            || Type == EnemyType.Silver)
                        {
                            switch (Direction.Value)
                            {
                                case 8:
                                    Direction = new Direction8(2);
                                    break;
                                case 7:
                                case 4:
                                    Direction = new Direction8(1);
                                    break;
                                case 9:
                                case 6:
                                    Direction = new Direction8(3);
                                    break;
                            }
                        }
                    }

                    // 攻撃
                    if (_random.Next(100) == 0)
                        Shot(this, EventArgs.Empty);
                    if (_frame < TurnTime)
                        break;
                    Turn();
                    break;

                case MovingState.SpinAttack:
                    if (_frame == 0)
                        Shot(this, EventArgs.Empty);
                    if (_frame < 3)
                        break;
                    Direction = Direction.TurnRight();
                    _frame = -1;
                    break;
            }

            // 行動範囲制限
            if (_point.Y >= Point.Height)
                _point.Y -= Point.Height;
            if (_point.X >= Point.Width - 13)
            {
                _point.X = Point.Width - 13 - 1;
                _vectorX = 0;
            }
            if (_point.X < 13)
            {
                _point.X = 13;
                _vectorX = 0;
            }
        }
	public void rightMove()
	{
		movingState = MovingState.MovingRight;
	}
	void spinPlayer()
	{
		Quaternion target;

		switch(movingState)
		{
		case MovingState.MovingRight:
			target = Quaternion.Euler(0.0f, -65.0f, 0);

			if(PlayerModel.transform.localRotation == target)
			{
				movingState = MovingState.Stopping;
			}
			PlayerModel.transform.localRotation = Quaternion.RotateTowards(PlayerModel.transform.localRotation, target, spinSpeed);
			break;

		case MovingState.MovingLeft:
			target = Quaternion.Euler(0.0f, 65.0f, 0);

			if(PlayerModel.transform.localRotation == target)
			{
				movingState = MovingState.Stopping;
			}
			PlayerModel.transform.localRotation = Quaternion.RotateTowards(PlayerModel.transform.localRotation, target, spinSpeed);
			break;

		case MovingState.Stopping:
			target = Quaternion.Euler(0.0f, 0.0f, 0.0f);

			if(PlayerModel.transform.localRotation == target)
			{
				movingState = MovingState.Stop;
			}
			PlayerModel.transform.localRotation = Quaternion.RotateTowards(PlayerModel.transform.localRotation, target, spinSpeed/1.6f);
				
			break;

		default:
			break;
		}
	}
	public void leftMove()
	{
		movingState = MovingState.MovingLeft;
	}
Пример #47
0
    void Awake()
    {
        State = new MovingState ();
        ResetMovement ();

        _boxCollider = GetComponent<BoxCollider2D> ();
        _transform = transform;
        _localScale = transform.localScale;

        _halfSize = new Vector2 (_boxCollider.size.x * Mathf.Abs (_localScale.x), _boxCollider.size.y * Mathf.Abs (_localScale.y)) / 2;
        //_snapShift = Mathf.Max (_boxCollider.size.x, _boxCollider.size.y);
        _snapShift = Mathf.Max (_halfSize.x * 2, _halfSize.y * 2);
        CalculateDistanceBetweenRays ();
        _isFacingForward = transform.localScale.x > 0;
    }