Exemplo n.º 1
0
    IEnumerator JumpsFollowAction(bool isJump)
    {
        yield return(null);

        curMove = MoveDir.None;
        fromPos = transform.position;
        mvDir   = transform.position;

        if (!senF.Hit && senJ.Hit && isJump)
        {
            curMove  = (MoveDir)(MoveDir.Fwd);
            mvDir    = transform.position + transform.forward * 0.5f;
            FBMove   = MoveDir.None;
            LRRotate = MoveDir.None;
        }
        else
        {
            curMove = (MoveDir)(MoveDir.Dn);
            if (!senD.Hit)
            {
                mvDir    = transform.position - transform.up;
                FBMove   = MoveDir.None;
                LRRotate = MoveDir.None;
            }
            else
            {
                curMove = MoveDir.None;
            }
        }
    }
Exemplo n.º 2
0
 /// <summary>
 /// Reset swipe relevant data, including reseting moving direction to MoveDir.Stay, time duration user has moved
 /// in same direction to 0, and also accumulated distance user has moved in same direction to 0.
 /// </summary>
 void ResetSwipeData()
 {
     durationInOneDirection = 0;
     distInOneDirection     = 0;
     moveDir     = MoveDir.Stay;
     lastMoveDir = MoveDir.Stay;
 }
Exemplo n.º 3
0
    private void Update()
    {
        device.TryGetFeatureValue(CommonUsages.primary2DAxis, out inputStick);
        device.TryGetFeatureValue(CommonUsages.secondaryButton, out exitButton);

        if (inputStick.y > .4)
        {
            currDirection = MoveDir.Up;
        }
        else if (inputStick.y < -.4)
        {
            currDirection = MoveDir.Down;
        }

        if (inputStick.x > .4)
        {
            currDirection = MoveDir.Right;
        }
        else if (inputStick.x < -.4)
        {
            currDirection = MoveDir.Left;
        }

        if (exitButton)
        {
            SceneManager.LoadScene("Menu");
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// Update swipe relevant data, including moving direction, time duration user has moved in that direction,
    /// and distance (both current frame and accumulated) user has moved in that direction.
    /// </summary>
    void UpdateSwipeData()
    {
        Vector3 velocity = Vector3.zero;

        if (velocityCalculator != null)
        {
            // Calculate hand moving velocity based on palm position.
            velocityCalculator.UpdatePositionData(this.transform.position, handLostTime, handRecoverTime);
            velocity = velocityCalculator.CalculateVelocity();
        }

        // Calculate moving direction and distance (current frame) from velocity.
        CalculateMoveDirectionAndDistance(velocity);

        // Accumulate time duration and distance if user was moving in the same direction last frame.
        if (moveDir == lastMoveDir && moveDir != MoveDir.Stay)
        {
            durationInOneDirection += Time.deltaTime;
            distInOneDirection     += distCurFrame;
        }
        else // otherwise, reset data.
        {
            durationInOneDirection = 0;
            distInOneDirection     = distCurFrame;
        }

        lastMoveDir = moveDir;
    }
Exemplo n.º 5
0
        public void OnPointerUp(PointerEventData eventData)
        {
            m_desDragPos = eventData.position;
            MoveDir dir = MoveDir.Right;

            if (m_desDragPos.x < m_originDragPos.x)
            {
                dir = MoveDir.Left;
            }
            switch (dir)
            {
            case MoveDir.Left:
                if (m_movement == MovementType.Circulation || (m_movement == MovementType.PingPong && m_curPageIndex != 0))
                {
                    OnLastPageButtonClick();
                }

                break;

            case MoveDir.Right:
                if (m_movement == MovementType.Circulation || (m_movement == MovementType.PingPong && m_curPageIndex != m_maxPageIndex))
                {
                    OnNextPageButtonClick();
                }
                break;
            }
            m_isDrag = false;
        }
Exemplo n.º 6
0
    private void setDir(Vector3 endTouPos)
    {
        float dx = endTouPos.x - m_begTouPos.x;
        float dy = endTouPos.y - m_begTouPos.y;

        if (Mathf.Abs(dx) > Mathf.Abs(dy))
        {
            if (dx > 0)
            {
                m_dir = MoveDir.R;
            }
            else
            {
                m_dir = MoveDir.L;
            }
        }
        else
        {
            if (dy > 0)
            {
                m_dir = MoveDir.U;
            }
            else
            {
                m_dir = MoveDir.D;
            }
        }
    }
Exemplo n.º 7
0
        public void Move(MoveDir dir)
        {
            SoundPlayer sp     = new SoundPlayer(@"C: \Users\Avery\Source\Repos\GenericRPG_TeamMagenta\Implementation\GenericRPG\Resources\step.wav");
            Position    newPos = pos;

            switch (dir)
            {
            case MoveDir.UP:
                newPos.row--;
                sp.Play();
                break;

            case MoveDir.DOWN:
                newPos.row++;
                sp.Play();
                break;

            case MoveDir.LEFT:
                newPos.col--;
                sp.Play();
                break;

            case MoveDir.RIGHT:
                newPos.col++;
                sp.Play();
                break;
            }
            if (map.IsValidPos(newPos))
            {
                pos = newPos;
                Position topleft = map.RowColToTopLeft(pos);
                Pic.Left = topleft.col;
                Pic.Top  = topleft.row;
            }
        }
Exemplo n.º 8
0
    /// <summary>
    /// 重写父类中的PointMove,写入ScaraRobot特定的运动控制逻辑
    /// </summary>
    /// <param name="moveDir">运动方向</param>
    public override void PointMove(MoveDir moveDir)
    {
        if (isMove)
        {
            switch (moveDir)
            {
            case MoveDir.None:
                break;

            case MoveDir.Left:
                MechanicalCCDIK.solver.IKPosition.x += MoveSpeedOld * 0.1f * Time.deltaTime;
                break;

            case MoveDir.Right:
                MechanicalCCDIK.solver.IKPosition.x -= MoveSpeedOld * 0.1f * Time.deltaTime;
                break;

            case MoveDir.Up:
                MechanicalCCDIK.solver.IKPosition.z -= MoveSpeedOld * 0.1f * Time.deltaTime;
                break;

            case MoveDir.Down:
                MechanicalCCDIK.solver.IKPosition.z += MoveSpeedOld * 0.1f * Time.deltaTime;
                break;

            default:
                break;
            }
        }
    }
Exemplo n.º 9
0
    void SwipeResponseVertical(MoveDir moveDir)
    {
        if (SwipeableObject.instances.Count <= 1)
        {
            return;
        }

        // distance between adjacent lines
        float dy = (ymax - ymin) / (SwipeableObject.instances.Count - 1);

        // Note, when swiping vertically, we are moving all the lines.
        foreach (SwipeableObject line in SwipeableObject.instances)
        {
            line.IsAvailableForSwipe = false;

            Vector3 destination = line.transform.position;
            switch (moveDir)
            {
            case MoveDir.Down:
                destination.y = (destination.y - dy < ymin) ? ymax : (destination.y - dy);     // wrap around
                break;

            case MoveDir.Up:
                destination.y = (destination.y + dy > ymax) ? ymin : (destination.y + dy);     // wrap around
                break;
            }
            StartCoroutine(DoAnimationVertical(line, destination));
        }
    }
Exemplo n.º 10
0
 public SnakeBody(Vector2Int Position, MoveDir FacingHead, bool Engorged = false)
 {
     this.Position   = Position;
     this.Engorged   = Engorged;
     this.FacingHead = FacingHead;
     Digestion       = FoodType.None;
 }
Exemplo n.º 11
0
 public void ForgeSnake(int SnakeTier)
 {
     if (ForgingSnake != null && ForgingSnake.Tier != SnakeTier)
     {
         DeforgeSnake();
     }
     if (ForgingSnake == null)
     {
         MoveDir ForgeSnakeFacing = Bodies.Count > 0 ? Bodies.Last.Value.FacingTail : GameController.OppositeDirection(Facing);
         ForgingSnake         = GameController.AddEnemySnake(Bodies.Last.Value.Position, SnakeTier, ForgeSnakeFacing);
         ForgingSnake.Forging = true;
     }
     else
     {
         if (Bodies.Count > 0)
         {
             ForgingSnake.AddTail(Bodies.Last.Value.Position, Bodies.Last.Value.FacingTail, false);
         }
         else
         {
             ForgingSnake.AddTail(Bodies.Last.Value.Position, GameController.OppositeDirection(Facing), false);
         }
         ForgingSnake.Length++;
     }
 }
Exemplo n.º 12
0
 public Robot(Board board, MoveDir moveDir = MoveDir.RIGHT)
 {
     Board = board;
     Dir   = moveDir;
     Pos   = Board.GetField(0, 0);
     Items = new List <Item>();
 }
Exemplo n.º 13
0
        private void FrmMap_KeyDown(object sender, KeyEventArgs e)
        {
            MoveDir dir = MoveDir.NO_MOVE;

            switch (e.KeyCode)
            {
            case Keys.Left:
                dir = MoveDir.LEFT;
                break;

            case Keys.Right:
                dir = MoveDir.RIGHT;
                break;

            case Keys.Up:
                dir = MoveDir.UP;
                break;

            case Keys.Down:
                dir = MoveDir.DOWN;
                break;
            }
            if (dir != MoveDir.NO_MOVE)
            {
                character.Move(dir);
                if (game.State == GameState.FIGHTING)
                {
                    FrmArena frmArena = new FrmArena();
                    frmArena.Show();
                }
            }
        }
Exemplo n.º 14
0
    public override void OnActionReceived(float[] vectorAction)
    {
        // Convert the first action to forward movement
        float forwardAmount = 0;
        // Convert the second action to turning left or right
        float turnAmount = 0f;
        float sideAmount = 0f;

        //Debug.LogError(vectorAction[0]);
        //moving up, down, left, right
        if (vectorAction[0] == 1f && canSwitchDir && position.x < -1 + globalPosition.x && (!isDrawing || isDrawing && moveDir != MoveDir.down))
        {
            moveDir = MoveDir.up;
            MoveUp();
        }
        else if (vectorAction[0] == 2f && canSwitchDir && position.x > -areaSize.x + 2 + globalPosition.x && (!isDrawing || isDrawing && moveDir != MoveDir.up))
        {
            moveDir = MoveDir.down;
            MoveDown();
        }
        else if (vectorAction[0] == 3f && canSwitchDir && position.z < -1 + globalPosition.z && (!isDrawing || isDrawing && moveDir != MoveDir.right))
        {
            moveDir = MoveDir.left;
            MoveLeft();
        }
        else if (vectorAction[0] == 4f && canSwitchDir && position.z > -areaSize.y + 2 + globalPosition.z && (!isDrawing || isDrawing && moveDir != MoveDir.left))
        {
            moveDir = MoveDir.right;
            MoveRight();
        }
        //Debug.LogError(sideAmount);
    }
Exemplo n.º 15
0
        // 내가 바라보는 방향의 바로 앞 Cell 포지션 (타격처리용)
        public Vector2Int GetFrontCellPos(MoveDir dir)
        {
            // lastDir 이라는 개념이 여긴 없으니 일단 dir을 받아옴
            Vector2Int cellPos = CellPos;

            // 내가 타격직전 마지막으로 바라보는곳 기준으로
            switch (dir)
            {
            case MoveDir.Up:
                cellPos += Vector2Int.up;
                break;

            case MoveDir.Down:
                cellPos += Vector2Int.down;
                break;

            case MoveDir.Left:
                cellPos += Vector2Int.left;
                break;

            case MoveDir.Right:
                cellPos += Vector2Int.right;
                break;
            }

            return(cellPos);
        }
Exemplo n.º 16
0
    private GameObject GetNearest(GameObject i_Source, MoveDir i_Direction)
    {
        if (i_Source == null)
        {
            return(null);
        }

        GameObject nextSelection = null;

        switch (i_Direction)
        {
        case MoveDir.Left:
            nextSelection = GetNearestOnLeft(i_Source);
            break;

        case MoveDir.Right:
            nextSelection = GetNearestOnRight(i_Source);
            break;

        case MoveDir.Up:
            nextSelection = GetNearestOnUp(i_Source);
            break;

        case MoveDir.Down:
            nextSelection = GetNearestOnDown(i_Source);
            break;
        }

        return(nextSelection);
    }
Exemplo n.º 17
0
    public void SwipeElement(MoveDir dir)
    {
        if (m_Pause)
        {
            return;
        }
        if (m_TouchElement == null)
        {
            return;
        }
        BoxElementControl curControl = m_TouchElement.GetComponent <BoxElementControl>();

        GameObject nbObj = curControl.GetNeighbor(dir);

        if (nbObj == null)
        {
            return;
        }

        BoxElementControl nbControl = nbObj.GetComponent <BoxElementControl>();
        MoveDir           opDir     = BoxElementControl.OppositeDir(dir);

        if (curControl.GetState() == BoxState.FIX && nbControl.GetState() == BoxState.FIX)
        {
            curControl.SwipeTo(dir);
            nbControl.SwipeTo(opDir);
        }
        m_TouchElement = null;
    }
        static byte[] SerializeMoveDir(object obj)
        {
            int     index = 0;
            MoveDir data  = (MoveDir)obj;

            int tmp;

            switch (data)
            {
            case MoveDir.FrontBack:
                tmp = 0;
                break;

            case MoveDir.RightLeft:
                tmp = 1;
                break;

            default:
                tmp = -1;
                break;
            }

            byte[] bytes = new byte[4];
            Protocol.Serialize(tmp, bytes, ref index);
            return(bytes);
        }
Exemplo n.º 19
0
        protected void StopPlate()
        {
            switch (_moveDir)
            {
            case MoveDir.FrontBack:
                if (Mathf.Abs(_movingPlate.position.z - TopPlate.position.z) > _movingPlate.localScale.z)
                {
                    _gameOver = true;
                }
                break;

            case MoveDir.RightLeft:
                if (Mathf.Abs(_movingPlate.position.x - TopPlate.position.x) > _movingPlate.localScale.x)
                {
                    _gameOver = true;
                }
                break;
            }
            if (_gameOver)
            {
                StartCoroutine(GameOver());
                return;
            }

            _score++;
            ScoreText.text  = _score.ToString();
            ScoreText.color = new Color(_rgb[0], _rgb[1], _rgb[2]);


            Split(ref _movingPlate, ref TopPlate, _moveDir);

            //TopPlate = _movingPlate;
            //_movingPlate = null;
            _moveDir = _moveDir == MoveDir.FrontBack ? MoveDir.RightLeft : MoveDir.FrontBack;
        }
Exemplo n.º 20
0
    public void ComputeNextMove(ChaseMode mode)
    {
        Vector2 target;

        if (Spawned)
        {
            Move();

            switch (mode)
            {
            case ChaseMode.Chase:
                target = ComputeTarget(type);
                break;

            case ChaseMode.Scatter:
                target = ScatterTarget(type);
                break;

            case ChaseMode.Frighten:
                target = ScatterTarget(type);
                break;

            default:
                target = position;
                break;
            }

            currentDir = (MoveDir)GetTurnClosestToTarget(position, target, GetOpenTiles(position));

            //Debug
            Debug.DrawLine(transform.localPosition, Misc.ConvertToMatrixCoordinates(target), GetComponent <Renderer>().material.color, FindObjectOfType <GameManager>().timeTillUpdate, false);
        }
    }
Exemplo n.º 21
0
    //Move
    private MoveDir Move()
    {
        //Picking direction
        MoveDir dir = (MoveDir)Random.Range(1, 5);

        Debug.Log("Step++");
        step++;
        //Setting end point of translation based on the direction
        switch (dir)
        {
        case (MoveDir.Up):
            endPos = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1);
            break;

        case (MoveDir.Down):
            endPos = new Vector3(transform.position.x, transform.position.y, transform.position.z - 1);
            break;

        case (MoveDir.Left):
            endPos = new Vector3(transform.position.x - 1, transform.position.y, transform.position.z);
            break;

        case (MoveDir.Right):
            endPos = new Vector3(transform.position.x + 1, transform.position.y, transform.position.z);
            break;
        }
        return(dir);
    }
Exemplo n.º 22
0
    private MoveDir MoveBack()
    {
        Debug.Log("Moving Back (Currently Adding Step?)");
        //Setting the direction to be the opposite of the previous one in order to reset the target position to the starting position
        MoveDir newDir = 0;

        step++;
        switch (movingDirection)
        {
        case (MoveDir.Up):
            endPos = new Vector3(endPos.x, endPos.y, endPos.z - 1);
            newDir = MoveDir.Down;
            break;

        case (MoveDir.Down):
            endPos = new Vector3(endPos.x, endPos.y, endPos.z + 1);
            newDir = MoveDir.Up;
            break;

        case (MoveDir.Left):
            endPos = new Vector3(endPos.x + 1, endPos.y, endPos.z);
            newDir = MoveDir.Right;
            break;

        case (MoveDir.Right):
            endPos = new Vector3(endPos.x - 1, endPos.y, endPos.z);
            newDir = MoveDir.Left;
            break;
        }
        return(newDir);
    }
Exemplo n.º 23
0
    public MoveDir GetMoveDirection()
    {
        MoveDir moveDirection = MoveDir.Forward;

        float angleDifferenceAbs = Mathf.Abs(mouseAngle - movingAngle);
        float angleDifference    = mouseAngle - movingAngle;

        if (angleDifferenceAbs < 45 || angleDifferenceAbs > 315f)
        {
            moveDirection = MoveDir.Forward;
        }
        else if (angleDifferenceAbs < 135f || angleDifferenceAbs > 225f)
        {
            if (angleDifference > 180f || (angleDifference <= 0f && angleDifference >= -180f))
            {
                moveDirection = MoveDir.Right;
            }
            else if (angleDifference < -180f || (angleDifference > 0f && angleDifference <= 180f))
            {
                moveDirection = MoveDir.Left;
            }
            else
            {
                Debug.LogError("Move Direction is Broken");
            }
        }
        else
        {
            moveDirection = MoveDir.Backward;
        }

        return(moveDirection);
    }
Exemplo n.º 24
0
        public Vector2int GetFrontCellPos(MoveDir dir)
        {
            Vector2int cellPos = CellPos;

            switch (dir)
            {
            case MoveDir.Up:
                cellPos += Vector2int.up;
                break;

            case MoveDir.Down:
                cellPos += Vector2int.down;
                break;

            case MoveDir.Left:
                cellPos += Vector2int.left;
                break;

            case MoveDir.Right:
                cellPos += Vector2int.right;
                break;
            }

            return(cellPos);
        }
Exemplo n.º 25
0
 public void GetIntoField(MoveDir moveDir)
 {
     spEnemy.spanim.Play("slime_idle");
     Vector3 targetPos = new Vector3(0, Game.instance.groundPosY, transform.position.z);
     float moveTime = 0;
     if (moveDir == MoveDir.Down) {
         targetPos.x = transform.position.x;
         moveTime = 3.0f;
     }
     if (moveDir == MoveDir.Up) {
         targetPos.x = transform.position.x;
         moveTime = 1.0f;
     }
     if (moveDir == MoveDir.Left) {
         targetPos.x = Game.instance.rightSpawnEntry.position.x - 30;
         moveTime = 1.0f;
     }
     if (moveDir == MoveDir.Right) {
         targetPos.x = Game.instance.leftSpawnEntry.position.x + 30;
         moveTime = 1.0f;
     }
     PlatformCollider platform = Game.instance.theBasePlatform;
     UpdateMoveConstraint(platform);
     gameObject.MoveTo(targetPos, moveTime, 0, EaseType.easeInOutQuad, "MoveToRandomLoc", gameObject);
     //		gameObject.MoveTo(targetPos, moveTime, 0);
 }
Exemplo n.º 26
0
        /// <summary>
        /// Moves the player according to input MoveDir
        /// </summary>
        /// <param name="dir">Direction to Move</param>
        public void Move(MoveDir dir)
        {
            Position newPos = pos;

            switch (dir)
            {
            case MoveDir.UP:
                newPos.row--;
                break;

            case MoveDir.DOWN:
                newPos.row++;
                break;

            case MoveDir.LEFT:
                newPos.col--;
                break;

            case MoveDir.RIGHT:
                newPos.col++;
                break;
            }
            Position?newNewPos = Map.CurrentMap.Enter(newPos);

            if (newNewPos != null)
            {
                pos = (Position)newNewPos;
                Position topleft = Map.RowColToTopLeft(pos);
                Pic.Left            = topleft.col;
                Pic.Top             = topleft.row;
                Pic.BackgroundImage = Map.CurrentMap.GetBackgroundImage(pos);
            }
        }
Exemplo n.º 27
0
    void Move(MoveDir moveDir)
    {
        var movement = Vector3.zero;

        switch (moveDir)
        {
        case MoveDir.Down:
            movement = new Vector3(0, -1f, 0);
            break;

        case MoveDir.Up:
            movement = new Vector3(0, 1f, 0);
            break;

        case MoveDir.Left:
            movement = new Vector3(-1f, 0, 0);
            break;

        case MoveDir.Right:
            movement = new Vector3(1f, 0, 0);
            break;

        default:
            return;
        }

        transform.Translate(movement * speed * Time.deltaTime);
    }
Exemplo n.º 28
0
    //In case of collision we return to the cell where we just moved from
    private MoveDir MoveBack()
    {
        //Setting the direction to be the opposite of the previous one in order to reset the target position to the starting position
        MoveDir newDir = 0;

        step++;
        movesDone.RemoveAt(movesDone.Count - 1);
        switch (movingDirection)
        {
        case (MoveDir.Up):
            endPos = new Vector3(endPos.x, endPos.y, endPos.z - 1);
            newDir = MoveDir.Down;
            break;

        case (MoveDir.Down):
            endPos = new Vector3(endPos.x, endPos.y, endPos.z + 1);
            newDir = MoveDir.Up;
            break;

        case (MoveDir.Left):
            endPos = new Vector3(endPos.x + 1, endPos.y, endPos.z);
            newDir = MoveDir.Right;
            break;

        case (MoveDir.Right):
            endPos = new Vector3(endPos.x - 1, endPos.y, endPos.z);
            newDir = MoveDir.Left;
            break;
        }
        SaveMove(movingDirection, false);
        return(newDir);
    }
Exemplo n.º 29
0
        public void Move(MoveDir dir)
        {
            Position newPos = pos;

            switch (dir)
            {
            case MoveDir.UP:
                newPos.row--;
                break;

            case MoveDir.DOWN:
                newPos.row++;
                break;

            case MoveDir.LEFT:
                newPos.col--;
                break;

            case MoveDir.RIGHT:
                newPos.col++;
                break;
            }
            if (map.IsValidPos(newPos))
            {
                pos = newPos;
                Position topleft = map.RowColToTopLeft(pos);
                Pic.Left = topleft.col;
                Pic.Top  = topleft.row;
            }
        }
Exemplo n.º 30
0
    private void CalSliderDir(Vector2 startPos, Vector2 endPos)
    {
        float xOffset = endPos.x - startPos.x;
        float yOffset = endPos.y - startPos.y;

        MoveDir dir = MoveDir.none;

        if (Mathf.Abs(xOffset) - Mathf.Abs(yOffset) >= 0)
        {
            if (xOffset > minMove)
            {
                dir = MoveDir.right;
            }
            else if (xOffset < -minMove)
            {
                dir = MoveDir.left;
            }
        }

        else
        {
            if (yOffset > minMove)
            {
                dir = MoveDir.up;
            }
            else if (yOffset < -minMove)
            {
                dir = MoveDir.down;
            }
        }

        gameMap.Move(dir);
    }
Exemplo n.º 31
0
        private void UpdatePosition(Point a, MoveDir dir)
        {
            //trim out redundant back and forth movement
            if (Dna.Count() > 1 && (int)dir == (int)(Dna.Last() + 2) % 4)
            {
                //reset our position back
                switch (Dna.Last())
                {
                case MoveDir.N:
                    Pos = new Point(Pos.X, Pos.Y + 1);
                    break;

                case MoveDir.W:
                    Pos = new Point(Pos.X + 1, Pos.Y);
                    break;

                case MoveDir.S:
                    Pos = new Point(Pos.X, Pos.Y - 1);
                    break;

                case MoveDir.E:
                    Pos = new Point(Pos.X - 1, Pos.Y);
                    break;
                }
                //remove last dna record
                Dna.RemoveAt(Dna.Count() - 1);
                Path.RemoveAt(Path.Count() - 1);
                return;
            }

            Path.Add(a);
            Pos = a;
            Dna.Add(dir);
        }
Exemplo n.º 32
0
 //when it's hit by player, reset postiion and wait to spawn again.
 public new void OnEnemyDie()
 {
     SpawnLoot();
     transform.position = originPos;
     moveDir = MoveDir.Stop;
     Game.instance.theLevelManager.CancelInvoke("HealthPackTimer");
     Game.instance.theLevelManager.Invoke("HealthPackTimer", 35.0f);
 }
Exemplo n.º 33
0
    // Use this for initialization
    void Start()
    {
        rigid = this.GetComponent<Rigidbody2D> ();
        dummy = transform.FindChild("dummy");
        state = MoveDir.E;

        Collider2D collider = GetComponent<Collider2D> ();
        m_extents =collider.bounds.extents;
    }
Exemplo n.º 34
0
    void determineAnimation(MoveDir horizontal, MoveDir vertical)
    {
        Vector3 camera = cameraTransform.forward;
        camera.y = 0;

        if (vertical == MoveDir.Forward)
        {
            if (Vector3.Angle(transform.forward, camera) < 90)
            {
                anim.CrossFade(forwardClip.name);
            }
            else
            {
                anim.CrossFade(backwardClip.name);
            }
        }
        else if (vertical == MoveDir.Backward)
        {
            if (Vector3.Angle(transform.forward, camera) < 90)
            {
                anim.CrossFade(backwardClip.name);
            }
            else
            {
                anim.CrossFade(forwardClip.name);
            }
        }
        else
        {
            if (horizontal == MoveDir.Idle)
            {
                anim.CrossFade(idleClip.name);
            }
            else if (horizontal == MoveDir.Left)
            {
                if (Vector3.Angle(transform.forward, camera) < 90)
                {
                    anim.CrossFade(leftClip.name);
                }
                else
                {
                    anim.CrossFade(rightClip.name);
                }
            }
            else
            {
                if (Vector3.Angle(transform.forward, camera) < 90)
                {
                    anim.CrossFade(rightClip.name);
                }
                else
                {
                    anim.CrossFade(leftClip.name);
                }
            }
        }
    }
Exemplo n.º 35
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey ("s")) {
            rigid.velocity = new Vector2 (-tank_speed, 0);
            transform.rotation = Quaternion.AngleAxis (90.0f, new Vector3 (0.0f, 0.0f, 1.0f));
            state = MoveDir.W;
            rigid.mass = 1.0f;
            print ("move");
        } else if (Input.GetKey ("f")) {
            rigid.velocity = new Vector2 (tank_speed, 0);
            transform.rotation = Quaternion.AngleAxis (-90.0f, new Vector3 (0.0f, 0.0f, 1.0f));
            state = MoveDir.E;
            rigid.mass = 1.0f;
            print ("move");
        } else if (Input.GetKey ("e")) {
            rigid.velocity = new Vector2 (0, tank_speed);
            transform.rotation = Quaternion.AngleAxis (0.0f, new Vector3 (0.0f, 0.0f, 1.0f));
            state = MoveDir.N;
            rigid.mass = 1.0f;
            print ("move");
        } else if (Input.GetKey ("d")) {
            rigid.velocity = new Vector2 (0, -tank_speed);
            transform.rotation = Quaternion.AngleAxis (180.0f, new Vector3 (0.0f, 0.0f, 1.0f));
            state = MoveDir.S;
            rigid.mass = 1.0f;
            print ("move");
        } else {
            if(Input.GetKeyUp("s") ||Input.GetKeyUp("f") ||Input.GetKeyUp("e") ||Input.GetKeyUp("d") ){//stop move
                rigid.velocity = new Vector2 (0, 0);
                rigid.mass = 1000000.0f;
                print ("stop");
            }
        }

        if (Input.GetKeyDown ("space")) {
            Bullet clone = Instantiate(ref_obj,this.dummy.position,this.dummy.rotation) as Bullet;

            Vector3 temp = dummy.position-transform.position;
            Vector2 v = new Vector2(temp.x,temp.y);
            v.Normalize();

            clone.m_velocity = Vector2.Scale(v,new Vector2(bullet_speed,bullet_speed));

        }
    }
Exemplo n.º 36
0
 void Move(MoveDir dir)
 {
     switch(dir)
     {
     case MoveDir.Up:
         transform.position += Vector3.up*moveSpeed*Time.deltaTime;
         break;
     case MoveDir.Down:
         transform.position += Vector3.down*moveSpeed*Time.deltaTime;
         break;
     case MoveDir.Right:
         transform.position += Vector3.right*moveSpeed*Time.deltaTime;
         break;
     case MoveDir.Left:
         transform.position += Vector3.left*moveSpeed*Time.deltaTime;
         break;
     }
 }
Exemplo n.º 37
0
 public void SpawnItemCarrier()
 {
     spCollider.enabled = true;
     fx.emit = true;
     //roll dice to decide spawn from left or right.
     //starting location will be fixed, not related to camera.
     int dirSelector = Random.Range(1,10);
     if (dirSelector > 5) {
         //spawn carrier from the left
         transform.position = new Vector3 (Game.instance.leftBoundary.position.x, Game.instance.leftBoundary.position.y,
                                           transform.position.z);
         moveDir = MoveDir.Right;
         WaveMoveRight();
     } else {
         //spawn carrier from the right
         transform.position = new Vector3 (Game.instance.rightBoundary.position.x, Game.instance.rightBoundary.position.y,
                                           transform.position.z);
         moveDir = MoveDir.Left;
         WaveMoveLeft();
     }
 }
Exemplo n.º 38
0
        public void Update(KeyboardState keyboard, RoomLevelBase currentRoom)
        {
            //Save last position
            lastXPos = xPos;
            lastYPos = yPos;

            //Player movement / action
            if (keyboard.IsKeyDown(Config.keyLeft))
                xPos -= Config.playerMoveSpeed;
            if (keyboard.IsKeyDown(Config.keyRight))
                xPos += Config.playerMoveSpeed;
            if (keyboard.IsKeyDown(Config.keyUp))
                yPos -= Config.playerMoveSpeed;
            if (keyboard.IsKeyDown(Config.keyDown))
                yPos += Config.playerMoveSpeed;

            if (keyboard.IsKeyDown(Config.keyAction))
            {
                if (!wasDoingActionLast)
                {
                    currentRoom.doPlayerAction = true;
                    wasDoingActionLast = true;
                }
            }
            else
                wasDoingActionLast = false;

            //Determines the texture of the player depending on movement
            if (xPos != lastXPos || yPos != lastYPos)
            {
                //If player has moved
                if (xPos < lastXPos)
                    spriteDir = MoveDir.LEFT;
                else if (xPos > lastXPos)
                    spriteDir = MoveDir.RIGHT;

                if (yPos < lastYPos)
                    spriteDir = MoveDir.UP;
                else if (yPos > lastYPos)
                    spriteDir = MoveDir.DOWN;

                sprite.setMoveDir(spriteDir);
            }
            else
            {
                //If player has not moved
                sprite.setMoveDir(spriteDir);
                sprite.setNotMoving();
            }

            //Get Room objects
            Dictionary<String, RoomObjectBase> roomObjects = currentRoom.getRoomObjects();
            //Get exit gate position and size
            RoomObjectGate exitGate = (RoomObjectGate) roomObjects[Names.Objects.GATE_EXIT];
            Point exitGateTilePos = exitGate.getTilePosition();
            exitGateTilePos.X += 1; //Gate size is manually adjusted to make more realistic collisions to get through it
            Point exitGateTileMaxPos = new Point(exitGateTilePos.X + exitGate.getTileSize().X - 3, exitGateTilePos.Y + exitGate.getTileSize().Y - 1);

            //Get background sprites
            TextureManager.DUNGEON_SPRITES[,] bgSprites = currentRoom.getBackgroundTexture();
            //Get player tile position
            int halfTileSize = Reference.PIXELS_PER_GRID_SQUARE / 2;
            xTilePos = (int) Math.Floor((xPos + halfTileSize) / Reference.PIXELS_PER_GRID_SQUARE);
            yTilePos = (int) Math.Floor((yPos + halfTileSize) / Reference.PIXELS_PER_GRID_SQUARE);
            //Check tile in direction of movement for wall, unless the gate is there
            if (xPos < lastXPos)
            {
                //Moving Left
                if (xPos <= (xTilePos * Reference.PIXELS_PER_GRID_SQUARE))
                {
                    if (bgSprites[xTilePos - 1, yTilePos] == TextureManager.DUNGEON_SPRITES.WALL_L || bgSprites[xTilePos - 1, yTilePos] == TextureManager.DUNGEON_SPRITES.WALL_TL || bgSprites[xTilePos - 1, yTilePos] == TextureManager.DUNGEON_SPRITES.WALL_BL)
                        //If there's a WALL_L, WALL_TL, or WALL_BL to the left of the player
                        backToLastCoords('x');
                    //Check for object here
                    if (checkForObject(roomObjects, MoveDir.LEFT))
                        backToLastCoords('x');
                }

            }
            else if (xPos > lastXPos)
            {
                //Moving Right
                if (xPos >= (xTilePos * Reference.PIXELS_PER_GRID_SQUARE))
                {
                    if (bgSprites[xTilePos + 1, yTilePos] == TextureManager.DUNGEON_SPRITES.WALL_R || bgSprites[xTilePos + 1, yTilePos] == TextureManager.DUNGEON_SPRITES.WALL_TR || bgSprites[xTilePos + 1, yTilePos] == TextureManager.DUNGEON_SPRITES.WALL_BR)
                        //If there's a WALL_R, WALL_TR, or WALL_BR to the right of the player
                        backToLastCoords('x');
                    if (checkForObject(roomObjects, MoveDir.RIGHT))
                        backToLastCoords('x');
                }
            }
            if (yPos < lastYPos)
            {
                //Moving Up
                if (yPos <= (yTilePos * Reference.PIXELS_PER_GRID_SQUARE))
                {
                    if (bgSprites[xTilePos, yTilePos - 2] == TextureManager.DUNGEON_SPRITES.WALL_T || bgSprites[xTilePos, yTilePos - 2] == TextureManager.DUNGEON_SPRITES.WALL_TL || bgSprites[xTilePos, yTilePos - 2] == TextureManager.DUNGEON_SPRITES.WALL_TR)
                    {
                        if (!((xTilePos >= exitGateTilePos.X && xTilePos <= exitGateTileMaxPos.X) && (yTilePos - 1 >= exitGateTilePos.Y && yTilePos - 1 <= exitGateTileMaxPos.Y)))
                        {
                            //If there's a WALL_T, WALL_TL, or WALL_TR above the player and there's no gate
                            backToLastCoords('y');
                            Console.WriteLine("Stopping player at top!");
                        }
                    }
                    if (checkForObject(roomObjects, MoveDir.UP))
                        backToLastCoords('y');
                }
            }
            else if (yPos > lastYPos)
            {
                //Moving Down
                if (yPos >= (yTilePos * Reference.PIXELS_PER_GRID_SQUARE))
                {
                    if (bgSprites[xTilePos, yTilePos + 1] == TextureManager.DUNGEON_SPRITES.WALL_B || bgSprites[xTilePos, yTilePos + 1] == TextureManager.DUNGEON_SPRITES.WALL_BL || bgSprites[xTilePos, yTilePos + 1] == TextureManager.DUNGEON_SPRITES.WALL_BR)
                        //If there's a WALL_B, WALL_BL, or WALL_BR below the player
                        backToLastCoords('y');
                    if (checkForObject(roomObjects, MoveDir.DOWN))
                        backToLastCoords('y');
                }
            }
        }
Exemplo n.º 39
0
        /// <summary>
        /// Returns true if the player is about to walk into an object
        /// </summary>
        /// <param name="roomObjects"></param>
        /// <param name="dir"></param>
        /// <returns></returns>
        private bool checkForObject(Dictionary<String, RoomObjectBase> roomObjects, MoveDir dir)
        {
            Point tileToCheck = new Point((int)Math.Floor(xPos / Reference.PIXELS_PER_GRID_SQUARE), (int)Math.Floor(yPos / Reference.PIXELS_PER_GRID_SQUARE));
            Point tile2ToCheck = new Point((int)Math.Floor((decimal)((int)xPos + Reference.PIXELS_PER_GRID_SQUARE)) / Reference.PIXELS_PER_GRID_SQUARE, (int)Math.Floor((decimal)((int)yPos + Reference.PIXELS_PER_GRID_SQUARE)) / Reference.PIXELS_PER_GRID_SQUARE);

            switch (dir)
            {
                case MoveDir.UP:
                    tile2ToCheck.Y -= 1;
                    break;
                case MoveDir.DOWN:
                    tileToCheck.Y += 1;
                    break;
                case MoveDir.LEFT:
                    tile2ToCheck.X -= 1;
                    break;
                case MoveDir.RIGHT:
                    tileToCheck.X += 1;
                    break;
            }

            foreach (RoomObjectBase obj in roomObjects.Values)
            {
                Point objPos = obj.getTilePosition();
                Point objSize = obj.getTileSize();
                Point objMaxPos = new Point(objPos.X + objSize.X - 1, objPos.Y + objSize.Y - 1);

                //If tile coords are the same as the space taken by an object
                if ((tileToCheck.X >= objPos.X && tileToCheck.X <= objMaxPos.X && tileToCheck.Y >= objPos.Y && tileToCheck.Y <= objMaxPos.Y) ||
                    (tile2ToCheck.X >= objPos.X && tile2ToCheck.X <= objMaxPos.X && tile2ToCheck.Y >= objPos.Y && tile2ToCheck.Y <= objMaxPos.Y))
                {
                    //If object is a closed gate or any other object, do not player move through
                    if (obj is RoomObjectGate)
                    {
                        if (!((RoomObjectGate)obj).isOpen())
                            return true;
                    }
                    else
                        return true;
                }
            }
            return false;
        }
Exemplo n.º 40
0
 //if out of bound, reset postion and wait to spawn again.
 void OnOutOfBound()
 {
     transform.position = originPos;
     moveDir = MoveDir.Stop;
     Game.instance.theLevelManager.CancelInvoke("HealthPackTimer");
     Game.instance.theLevelManager.Invoke("HealthPackTimer", 35.0f);
 }
Exemplo n.º 41
0
 void Start()
 {
     originPos = transform.position;
     moveDir = MoveDir.Stop;
 }
Exemplo n.º 42
0
    private float CalculateMoveScore(Selectable sel, MoveDir moveDir)
    {
        //var myRt = gameObject.GetComponent<RectTransform>();
        //var rt = sel.gameObject.GetComponent<RectTransform>();

        //Vector2 start;
        //Vector2 end;

        //switch (moveDir)
        //{
        //    case MoveDir.Up:
        //        start = new Vector2(myRt.rect.center.x, myRt.rect.center.y);
        //        end = rt.rect.min;
        //        break;
        //}

        var offset = sel.transform.position - transform.position;
        if (navigation.mode == Navigation.Mode.Vertical)
            offset.x = 0;
        else if(navigation.mode == Navigation.Mode.Horizontal)
            offset.y = 0;
        else if(moveDir == MoveDir.Left || moveDir == MoveDir.Right)
            offset.y *= 5;
        else
            offset.x *= 5;

        return offset.sqrMagnitude;
    }
Exemplo n.º 43
0
 protected virtual void Awake()
 {
     //get the reference of playmaker fsms.
     PlayMakerFSM[] fsms = GetComponents<PlayMakerFSM>();
     foreach (PlayMakerFSM fsm in fsms) {
         if (fsm.FsmName == "FSM_Control") {
             FSM_Control = fsm;
         }
         if (fsm.FsmName == "FSM_Hit") {
             FSM_Hit = fsm;
         }
         if (fsm.FsmName == "FSM_Charge") {
             FSM_Charge = fsm;
         }
     }
     //initialize key variables.
     player = transform.GetComponent<PlayerBase>();
     layer = GetComponent<exLayer>();
     velocity = new Vector2(0, 0);
     comboLevel = 0;
     charMoveDir = MoveDir.Stop;
     downButton = BtnHoldState.None;
     initJumpSpeedStatic = jumpSpeed;
     initMoveSpeedStatic = moveSpeed;
     initAttackPowerStatic = attackPower;
     initInvincibleDuration = FSM_Hit.FsmVariables.GetFsmFloat("varInvincibleDuration").Value;
     currentPlatform = Game.instance.theBasePlatform;
 }
Exemplo n.º 44
0
 public void Reorder(Order order, MoveDir dir)
 {
     if (dir == MoveDir.Up)
     {
         if (this.Count > 1 && this.Contains(order) && order.CanMoveUp)
         {
             int num = this.IndexOf(order) - 1;
             this.Remove(order);
             this.Insert(num, order);
             return;
         }
     }
     else if (dir == MoveDir.Down)
     {
         if (this.Count > 1 && this.Contains(order) && order.CanMoveDown)
         {
             int num = this.IndexOf(order) + 1;
             this.Remove(order);
             this.Insert(num, order);
             return;
         }
     }
     throw new InvalidOperationException();
 }