コード例 #1
0
        private void HandleMovement(float h, float v)
        {
            if (IsGrounded())
            {
                //Debug.LogError("Grounded");



                if (h != 0)
                {
                    moveVector = h * transform.right * moveSpeed;
                    dir        = (h > 0) ? MovementDir.RIGHT : MovementDir.LEFT;
                }

                else if (v != 0)
                {
                    moveVector = v * transform.forward * moveSpeed;

                    dir = (v > 0) ? MovementDir.UP : MovementDir.DOWN;
                }

                else
                {
                    moveVector = Vector3.zero;

                    dir = MovementDir.IDLE;
                }
            }
        }
コード例 #2
0
 void ResetplayerObject()
 {
     stopped = true;
     movementSpeedMultiplier = 1;
     transform.position      = new Vector3(0, 0, 0);
     transform.LookAt(transform.position + Vector3.forward);
     moveDir = MovementDir.up;
 }
コード例 #3
0
 void ToggleMovementDir()
 {
     if (CurrentDir == MovementDir.Forward)
     {
         CurrentDir = MovementDir.Backward;
     }
     else
     {
         CurrentDir = MovementDir.Forward;
     }
 }
コード例 #4
0
    private void SetMovementDir(MovementDir dir)
    {
        SpriteRenderer spriteRenderer = gameObject.GetComponent <SpriteRenderer>();

        if (dir == MovementDir.Left)
        {
            spriteRenderer.flipX = true;
            m_movementDir        = -1f;
        }
        else if (dir == MovementDir.Right)
        {
            spriteRenderer.flipX = false;
            m_movementDir        = 1f;
        }
    }
コード例 #5
0
    void Start()
    {
        stopped = true;

        MenuController.LoseEvent.AddListener(() =>
        {
            ResetplayerObject();
        });
        StartGameEvent.AddListener(() => stopped = false);

        var input = this.gameObject.AddComponent <InputScript>();

        input.InputScriptInit(UpInput, DownInput, RightInput, LeftInput);

        UpInput.AsObservable().Where(_ => moveDir != MovementDir.down).Subscribe(_ =>
        {
            transform.LookAt(transform.position + Vector3.forward);
            moveDir = MovementDir.up;
        });
        DownInput.AsObservable().Where(_ => moveDir != MovementDir.up).Subscribe(_ =>
        {
            transform.LookAt(transform.position + -Vector3.forward);
            moveDir = MovementDir.down;
        });
        RightInput.AsObservable().Where(_ => moveDir != MovementDir.left).Subscribe(_ =>
        {
            transform.LookAt(transform.position + Vector3.right);
            moveDir = MovementDir.right;
        });
        LeftInput.AsObservable().Where(_ => moveDir != MovementDir.right).Subscribe(_ =>
        {
            transform.LookAt(transform.position + -Vector3.right);
            moveDir = MovementDir.left;
        });

        transform.UpdateAsObservable().Where(_ => stopped == false)
        .Subscribe(x => transform.position += transform.forward * Time.deltaTime * baseMovementSpeed * movementSpeedMultiplier);
        MenuController.LoseEvent.AddListener(() => movementSpeedMultiplier = 1);
    }
コード例 #6
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetAxis("Vertical") > 0.05 || Input.GetAxis("Vertical") < -0.05)
        {
            CharBody.velocity += new Vector2(0.0f, 10.0f) * Input.GetAxis("Vertical") * Time.deltaTime;
            if (Input.GetAxis("Vertical") > 0.05)
            {
                DirectionMoved = MovementDir.up;
            }
            if (Input.GetAxis("Vertical") < -0.05)
            {
                DirectionMoved = MovementDir.down;
            }
        }
        if (Input.GetAxis("Horizontal") > 0.05 || Input.GetAxis("Horizontal") < -0.05)
        {
            if (Input.GetAxis("Horizontal") > 0.05)
            {
                DirectionMoved = MovementDir.right;
            }
            if (Input.GetAxis("Horizontal") < -0.05)
            {
                DirectionMoved = MovementDir.left;
            }

            //gameObject.transform.position += new Vector3(0.1f, 0.0f, 0.0f) * Input.GetAxis("Horizontal");
            CharBody.velocity += new Vector2(10.0f, 0.0f) * Input.GetAxis("Horizontal") * Time.deltaTime;
        }

        if (Input.GetMouseButton(1) && AttackCooldown + 0.5f < Time.time)
        {
            HurtCircle.enabled = !HurtCircle.enabled;
            IEnumerator coroutine = StopHurtCircle(1.1f);
            StartCoroutine(coroutine);
            AttackCooldown = Time.time;
        }

        if (Input.GetMouseButton(0) && AttackCooldown + 0.5f < Time.time)
        {
            GameObject Object;
            if (CharBody.velocity.magnitude != 0.0)
            {
                Object = LazerWeapon.FireLazer(CharBody.velocity.normalized);
            }
            else
            {
                Object = LazerWeapon.FireLazer(gameObject.transform.right);
            }

            if (Object.GetComponent <EnemyBaseScript>())
            {
                Object.GetComponent <EnemyBaseScript>().TakeDamage(5);
            }
            IEnumerator enumerator = StopLazer(0.1f);
            StartCoroutine(enumerator);
            AttackCooldown = Time.time;
        }

        if (Input.GetKey(KeyCode.E) && IsInDoorway && !IsDoorLocked)
        {
            GameObject temp = GameObject.Find("Enemy");
            if (temp == null)
            {
                globalLevelManagement.MovementSystem((LevelManager.MovementDirectionForLoad)doorwayNumer);
            }
        }

        if (Input.GetKey(KeyCode.Escape))
        {
            pauseMenu.SetActive(true);
            Time.timeScale = 0.0f;
        }

        if (CharBody.velocity.magnitude > MaxSpeed)
        {
            CharBody.velocity.Scale(new Vector2(0.9f, 0.9f));
        }

        switch (DirectionMoved)
        {
        case MovementDir.down:
            Torso.sprite = TORSOpiecesDown[CurrentSprite];
            Legs.sprite  = LEGpiecesDown[CurrentSprite];
            break;

        case MovementDir.up:
            Torso.sprite = TORSOpiecesUp[CurrentSprite];
            Legs.sprite  = LEGpiecesUp[CurrentSprite];
            break;

        case MovementDir.left:
            Torso.sprite = TORSOpiecesLeft[CurrentSprite];
            Legs.sprite  = LEGpiecesLeft[CurrentSprite];
            break;

        case MovementDir.right:
            Torso.sprite = TORSOpiecesRight[CurrentSprite];
            Legs.sprite  = LEGpiecesRight[CurrentSprite];
            break;
        }
        if (SpriteUpdate + 0.2f < Time.time)
        {
            CurrentSprite++;
            SpriteUpdate = Time.time;
            if (CurrentSprite >= 4)
            {
                CurrentSprite = 0;
            }
        }
        if (Health < 0)
        {
            Time.timeScale = 0;
            pauseMenu.SetActive(true);
        }
    }
コード例 #7
0
ファイル: FreeCamera.cs プロジェクト: domisterwoozy/LabBox
 private void EndMovement(MovementDir dir)
 {
     currentMovement.Remove(dir);
 }
コード例 #8
0
ファイル: FreeCamera.cs プロジェクト: domisterwoozy/LabBox
 private void StartMovement(MovementDir dir)
 {
     currentMovement.Add(dir);
 }
コード例 #9
0
    // Update is called once per frame
    void Update()
    {
        AimDir.x = Input.GetAxis("RTSX");
        AimDir.y = -1 * Input.GetAxis("RTSY");


        if (Input.GetAxis("Vertical") > 0.05 || Input.GetAxis("Vertical") < -0.05)//Vertical
        {
            Char_Animator.SetFloat("Speed", 1.0f);

            if (Input.GetAxis("Vertical") > 0.05)
            {
                DirectionMoved = MovementDir.up;
                Char_Animator.SetFloat("Vertical", Input.GetAxis("Vertical"));
            }
            if (Input.GetAxis("Vertical") < -0.05)
            {
                DirectionMoved = MovementDir.down;
                Char_Animator.SetFloat("Vertical", Input.GetAxis("Vertical"));
            }
            CharBody.velocity += new Vector2(0.0f, 10.0f) * Input.GetAxis("Vertical") * Time.deltaTime;
        }

        if (Input.GetAxis("Horizontal") > 0.05 || Input.GetAxis("Horizontal") < -0.05) //Horizontal
        {
            Char_Animator.SetFloat("Speed", 1.0f);

            if (Input.GetAxis("Horizontal") > 0.05)
            {
                DirectionMoved = MovementDir.right;
                Char_Animator.SetFloat("Horizontal", Input.GetAxis("Horizontal"));
            }
            if (Input.GetAxis("Horizontal") < -0.05)
            {
                DirectionMoved = MovementDir.left;
                Char_Animator.SetFloat("Horizontal", Input.GetAxis("Horizontal"));
            }
            CharBody.velocity += new Vector2(10.0f, 0.0f) * Input.GetAxis("Horizontal") * Time.deltaTime;
        }

        if ((Input.GetMouseButton(1) && AttackCooldown + 0.5f < Time.time) || (Input.GetAxis("Secondary Fire") > 0.01f && AttackCooldown + 0.5f < Time.time))
        {
            HurtCircle.enabled = !HurtCircle.enabled;
            IEnumerator coroutine = StopHurtCircle(1.1f);
            StartCoroutine(coroutine);
            AttackCooldown = Time.time;
            Char_Animator.SetBool("isAttacking", true);
        }

        if ((Input.GetMouseButton(0) && AttackCooldown + 0.5f < Time.time) || (Input.GetAxis("Primary Fire") > 0.01f && AttackCooldown + 0.5f < Time.time))
        {
            GameObject Object;
            SFX[1].Play();
            SFX[1].mute = false;
            //if (Input.GetAxis("RTSX") != 0.0f || Input.GetAxis("RTSY") != 0.0f)
            //{
            //    Vector2 rts_aim = new Vector2(Input.GetAxis("RTSX"), Input.GetAxis("RTSY"));
            //    Object = Char_Laz_Wep.FireLazer(rts_aim);
            //}
            //else
            //{
            //    if (CharBody.velocity.magnitude != 0.0)
            //        Object = Char_Laz_Wep.FireLazer(CharBody.velocity.normalized);
            //    else
            //        Object = Char_Laz_Wep.FireLazer(gameObject.transform.right);
            //}

            Object = Char_Laz_Wep.FireLazer(AimDir);

            if (Object.GetComponent <EnemyBaseScript>())
            {
                Object.GetComponent <EnemyBaseScript>().TakeDamage(15);
            }
            IEnumerator enumerator = StopLazer(0.1f);
            StartCoroutine(enumerator);
            AttackCooldown = Time.time;
        }

        if ((Input.GetKey(KeyCode.E) || Input.GetButton("X")) && IsInDoorway && !IsDoorLocked)
        {
            GameObject temp = GameObject.Find("Enemy");
            if (temp == null)
            {
                globalLevelManagement.MovementSystem((LevelManager.MovementDirectionForLoad)doorwayNumer);
            }
        }

        if (Input.GetKey(KeyCode.Escape) || Input.GetButton("Start"))
        {
            Char_Pause_Menu.SetActive(true);
            Time.timeScale = 0.0f;
        }

        if (CharBody.velocity.magnitude > MaxSpeed)
        {
            CharBody.velocity.Scale(new Vector2(0.9f, 0.9f));
        }

        switch (DirectionMoved)
        {
        case MovementDir.down:

            break;

        case MovementDir.up:
            break;

        case MovementDir.left:
            break;

        case MovementDir.right:
            break;
        }

        if (CharBody.velocity.magnitude > 0.1f)
        {
            SFX[0].mute = false;
        }
        else
        {
            SFX[0].mute = true;
        }


        if (Health < 0)
        {
            globalLevelManagement.OnDieSaveMyScore();
            Time.timeScale = 0;
            Char_Pause_Menu.SetActive(true);
        }
    }
コード例 #10
0
    // Update is called once per frame
    void Update()
    {
        ///////////////////////////////////////////////////////////////////////////////////
        // When the mouse button is first pressed down
        ///////////////////////////////////////////////////////////////////////////////////
        if (Input.GetMouseButtonDown(0))
        {
            // get mouse position and 2d raycast hit
            Vector2      mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            RaycastHit2D hit      = Physics2D.Raycast(mousePos, Vector2.zero);

            if (hit.collider != null)
            {
                if (hit.collider.tag == "Chamber")
                {
                    //define intial chamber position
                    initPos = hit.collider.gameObject.transform.position;

                    initPos.x = Mathf.Round(initPos.x);
                    initPos.y = Mathf.Round(initPos.y);

                    Debug.Log(" inital position : x :" + initPos.x + " y " + initPos.y);
                }
            }
        }

        ///////////////////////////////////////////////////////////////////////////////////
        // If left mouse is down
        ///////////////////////////////////////////////////////////////////////////////////
        if (Input.GetMouseButton(0))
        {
            // get mouse position and 2d raycast hit
            Vector2      mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            RaycastHit2D hit      = Physics2D.Raycast(mousePos, Vector2.zero);

            if (hit.collider != null)
            {
                if (hit.collider.tag == "Chamber")
                {
                    // define chamber position
                    pos = hit.collider.gameObject.transform.position;
                    // round the postion so it is only moves by one unit
                    pos.x = Mathf.Round(pos.x);
                    pos.y = Mathf.Round(pos.y);

                    ///////////////
                    // DIRECTION //
                    ///////////////
                    if (pos.x == initPos.x && pos.y == initPos.y)
                    {
                        movementDir = MovementDir.current;
                    }
                    else if (pos.x > initPos.x)
                    {
                        movementDir = MovementDir.Right;
                    }
                    else if (pos.x < initPos.x)
                    {
                        movementDir = MovementDir.Left;
                    }
                    else if (pos.y > initPos.y)
                    {
                        movementDir = MovementDir.Up;
                    }
                    else if (pos.y < initPos.y)
                    {
                        movementDir = MovementDir.Down;
                    }

                    // find out the distance that the chamber has moved
                    float differencePos = Vector2.Distance(initPos, pos);
                }
            }
        }

        ///////////////////////////////////////////////////////////////////////////////////
        // if left mouse Button is up
        ///////////////////////////////////////////////////////////////////////////////////
        if (Input.GetMouseButtonUp(0))
        {
            // get mouse position and 2d raycast hit
            Vector2      mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            RaycastHit2D hit      = Physics2D.Raycast(mousePos, Vector2.zero);

            if (hit.collider != null)
            {
                if (hit.collider.tag == "Chamber")
                {
                    // update the chamber array with the new content
                    // move left
                    if (movementDir == MovementDir.Left)
                    {
                        //debug
                        Debug.Log("left");
                        //move chambers method
                        moveChambers(MovementDir.Left, pos, true);
                    }
                    else if (movementDir == MovementDir.Right)
                    {
                        //debug
                        Debug.Log("right");
                        //move chambers
                        moveChambers(MovementDir.Right, pos, false);
                    }
                    else if (movementDir == MovementDir.Up)
                    {
                        Debug.Log("up");
                        //move chambers
                        moveChambers(MovementDir.Up, pos, true);
                    }
                    else if (movementDir == MovementDir.Down)
                    {
                        Debug.Log("down");
                        //move chambers
                        moveChambers(MovementDir.Down, pos, false);
                    }
                }
            }
        }
    }
コード例 #11
0
    /// <summary>
    /// Moves the chambers.
    /// </summary>
    /// <param name="direction">Direction.</param>
    /// <param name="currentChamber">Current chamber.</param>
    /// <param name="positive">If set to <c>true</c> positive.</param>
    void moveChambers(MovementDir direction, Vector2 currentChamber, bool positive)
    {
        for (int x = 0; x < 8; x++)
        {
            for (int y = 0; y < 8; y++)
            {
                //define the chamber
                Chamber Chambers = CreateChamberArray.ChamberArray[x, y];

                // define the direction
                float changedPos = 0;

                // change the value based on the direction
                if (direction == MovementDir.Left || direction == MovementDir.Right)
                {
                    if (currentChamber.y == y)
                    {
                        if (positive)
                        {
                            // DEFINE A ROW OF CHAMBERS TO MOVE
                            ChambersToMove[x] = Chambers;
                            // EMPTY THE CHAMBER IN THE 2D ARRAY
                            CreateChamberArray.ChamberArray[x, y] = null;

                            if (Chambers.Object.transform.position.x == 7)
                            {
                                CreateNewChamber(x, y);
                            }

                            //null check
                            if (Chambers != null)
                            {
                                // DEFINE THE MOVEMENT OF THE CHAMBER (one to the right)
                                changedPos = Chambers.Object.transform.position.x - 1;

                                // DELETE CHAMBER ON THE END
                                if (Chambers.Object.transform.position.x == 0)
                                {
                                    Debug.Log("Destory Extra");
                                    // destroy the gameobject
                                    Destroy(Chambers.Object);
                                    // remove from chamber array
                                    Chambers = null;
                                }
                            }
                        }
                        else
                        {
                            // DEFINE A ROW OF CHAMBERS TO MOVE
                            ChambersToMove[x] = Chambers;
                            // EMPTY THE CHAMBER IN THE 2D ARRAY
                            CreateChamberArray.ChamberArray[x, y] = null;


                            if (Chambers.Object.transform.position.x == 0)
                            {
                                CreateNewChamber(x, y);
                            }

                            //null check
                            if (Chambers != null)
                            {
                                // DEFINE THE MOVEMENT OF THE CHAMBER (one to the right)
                                changedPos = Chambers.Object.transform.position.x + 1;

                                // DELETE CHAMBER ON THE END
                                if (Chambers.Object.transform.position.x == 7)
                                {
                                    Debug.Log("Destory Extra");
                                    // destroy the gameobject
                                    Destroy(Chambers.Object);
                                    // remove from chamber array
                                    Chambers = null;
                                }
                            }
                        }

                        //null check before moving the objects
                        if (Chambers != null)
                        {
                            // and move the chambers
                            Chambers.Object.transform.position = new Vector2(changedPos, currentChamber.y);
                        }
                    }
                }
                else if (direction == MovementDir.Down || direction == MovementDir.Up)
                {
                    if (currentChamber.x == x)
                    {
                        if (positive)
                        {
                            changedPos = Chambers.Object.transform.position.y + 1;
                        }
                        else
                        {
                            changedPos = Chambers.Object.transform.position.y - 1;
                        }
                        // and move the chambers
                        Chambers.Object.transform.position = new Vector2(currentChamber.x, changedPos);
                    }
                }
            }
        }


        //
        // UPDATE THE MAIN CHAMBER ARRAY //
        //
        for (int x = 0; x < 7; x++)
        {
            for (int y = 0; y < 7; y++)
            {
                if (currentChamber.y == y)
                {
                    //
                    // find the movement direction and move the chamber acordinginly in the main array
                    //
                    if (direction == MovementDir.Right)
                    {
                        CreateChamberArray.ChamberArray[x + 1, y] = null;
                        CreateChamberArray.ChamberArray[x + 1, y] = ChambersToMove[x];
                    }
                    else if (direction == MovementDir.Left)
                    {
                        Debug.Log(CreateChamberArray.ChamberArray[x - 1, y].Name);

                        CreateChamberArray.ChamberArray[x - 1, y] = null;
                        CreateChamberArray.ChamberArray[x - 1, y] = ChambersToMove[x];
                    }
                    else if (direction == MovementDir.Up)
                    {
                        CreateChamberArray.ChamberArray[x, y + 1] = null;
                        CreateChamberArray.ChamberArray[x, y + 1] = ChambersToMove[y];
                    }
                    else if (direction == MovementDir.Down)
                    {
                        CreateChamberArray.ChamberArray[x, y - 1] = null;
                        CreateChamberArray.ChamberArray[x, y - 1] = ChambersToMove[y];
                    }

                    Debug.Log("Main Chamber Array Updated");
                }
            }
        }
    }
コード例 #12
0
 public void Move(float amount, MovementDir dir)
 {
     SetMovementDir(dir);
     m_bufferedMovement = amount;
     m_movementSpeed    = amount;
 }
コード例 #13
0
ファイル: FreeCamera.cs プロジェクト: domisterwoozy/LabBox
 private void EndMovement(MovementDir dir)
 {
     currentMovement.Remove(dir);
 }
コード例 #14
0
ファイル: FreeCamera.cs プロジェクト: domisterwoozy/LabBox
 private void StartMovement(MovementDir dir)
 {
     currentMovement.Add(dir);
 }