Esempio n. 1
0
	// Use this for initialization
	void Start () {
		Screen.showCursor = false;
		isPressingUp = false;
		isPressingDown = false;
		isPressingLeft = false;
		isPressingRight = false;	
		currentKeyDirection = Global.Direction.None;
	}
Esempio n. 2
0
    void Movement(Global.Direction direction, float otherDirectionSpeed = 0)
    {
        if (!CanMove)
        {
            return;
        }

        if (CheckForNoMovement() || (Input.GetKeyDown(KeyCode.Space) && ItemController.ActiveItem != null))
        {
            UpdateAnimation(State.Stoppped);
        }
        else
        {
            animator.ResetTrigger(STOP_TRIGGER);
        }

        rigibody.isKinematic = false;

        if (direction == Global.Direction.Left)
        {
            rigibody.velocity = new Vector2(-PlayerAcceleration, otherDirectionSpeed);
            UpdateState(State.WalkingLeft);
        }
        else if (direction == Global.Direction.Right)
        {
            rigibody.velocity = new Vector2(PlayerAcceleration, otherDirectionSpeed);
            UpdateState(State.WalkingRight);
        }
        else if (direction == Global.Direction.Up)
        {
            rigibody.velocity = new Vector2(otherDirectionSpeed, PlayerAcceleration);
            UpdateState(DirectionToState[Facing]);
        }
        else if (direction == Global.Direction.Down)
        {
            rigibody.velocity = new Vector2(otherDirectionSpeed, -PlayerAcceleration);
            UpdateState(DirectionToState[Facing]);
        }
        else if (direction == Global.Direction.None)
        {
            rigibody.velocity = new Vector2(0, 0);

            UpdateState(State.Stoppped);

            rigibody.isKinematic = touchingLadder;

            if (RigibodyDisabled)
            {
                rigibody.Sleep();
            }
        }


        rigibody.velocity = new Vector2(Mathf.Clamp(rigibody.velocity.x, -MaxPlayerSpeed, MaxPlayerSpeed),
                                        Mathf.Clamp(rigibody.velocity.y, -MaxPlayerSpeed, MaxPlayerSpeed));
    }
 public void ChangeAudio(Global.Direction direction, int step = 1)
 {
     if (direction == Global.Direction.NEXT)
     {
         AudioControl.NextAudio(step);
     }
     else if (direction == Global.Direction.BACK)
     {
         AudioControl.PreviousAudio(step);
     }
 }
    /*---------------------------------------------------------------*/

    public void ChangeSlide(Global.Direction direction, int step = 1)
    {
        if (direction == Global.Direction.NEXT)
        {
            SlideControl.NextSlide(step);
        }
        else if (direction == Global.Direction.BACK)
        {
            SlideControl.PreviousSlide(step);
        }
    }
Esempio n. 5
0
	// Update is called once per frame
	void Update () {
		if (!isPressingUp && Input.GetKey(KeyCode.UpArrow))
			currentKeyDirection = Global.Direction.Up;
		else if (!isPressingDown && Input.GetKey(KeyCode.DownArrow))
			currentKeyDirection = Global.Direction.Down;
		else if (!isPressingLeft && Input.GetKey(KeyCode.LeftArrow))
			currentKeyDirection = Global.Direction.Left;
		else if (!isPressingRight && Input.GetKey(KeyCode.RightArrow))
			currentKeyDirection = Global.Direction.Right;
		
		isPressingUp = Input.GetKey(KeyCode.UpArrow);
		isPressingDown = Input.GetKey(KeyCode.DownArrow);
		isPressingLeft = Input.GetKey(KeyCode.LeftArrow);
		isPressingRight = Input.GetKey(KeyCode.RightArrow);
		
		if ((currentKeyDirection == Global.Direction.Down && !isPressingDown) ||
			(currentKeyDirection == Global.Direction.Up && !isPressingUp) ||
			(currentKeyDirection == Global.Direction.Left && !isPressingLeft) ||
			(currentKeyDirection == Global.Direction.Right && !isPressingRight)){
			if (isPressingLeft)
				currentKeyDirection = Global.Direction.Left;
			else if (isPressingDown)
				currentKeyDirection = Global.Direction.Down;
			else if (isPressingUp)
				currentKeyDirection = Global.Direction.Up;
			else if (isPressingRight)
				currentKeyDirection = Global.Direction.Right;
		}
		
		if (!isPressingUp && !isPressingDown && !isPressingLeft && !isPressingRight)
			currentKeyDirection = Global.Direction.None;
		else if (Global.inGame)
			Global.rotatingCube.tryMove(currentKeyDirection);
		
		if (Global.inGame || Global.isPaused){
			if (Input.GetKeyDown(KeyCode.Escape)){
				if (Global.isPaused) {	
					Global.pauseScreen.removeFromScene();
					Global.inGame = true;
					Global.isPaused = false;
				}
				else {
					Global.pauseScreen.addToScene();
					Global.inGame = false;
					Global.isPaused = true;
				}
			}
		}
	}
Esempio n. 6
0
 public bool isOpposite(Global.Direction dir)
 {
     if ((this.getDirection() == Global.Direction.South && dir == Global.Direction.North) || (this.getDirection() == Global.Direction.North && dir == Global.Direction.South))
     {
         return(true);
     }
     else if ((this.getDirection() == Global.Direction.West && dir == Global.Direction.East) || (this.getDirection() == Global.Direction.East && dir == Global.Direction.West))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 7
0
    void HandleOnPlayerCollide(Global.Direction platformSide)
    {
        Vector2 newPlayerPos;

        if (platformSide == Global.Direction.Left)
        {
            newPlayerPos   = rightMostPoint;
            newPlayerPos.y = Global.Player.transform.position.y;
            Global.Player.transform.position = newPlayerPos;
            Global.Player.transform.Translate(offset * Vector3.left);
        }
        else if (platformSide == Global.Direction.Right)
        {
            newPlayerPos   = leftMostPoint;
            newPlayerPos.y = Global.Player.transform.position.y;
            Global.Player.transform.position = newPlayerPos;
            Global.Player.transform.Translate(offset * Vector3.right);
        }
    }
    void SwapWallAt(Global.Direction dir, Vector2 pt, Vector2 distance)
    {
        GameObject[] list = GameObject.FindObjectsOfType <GameObject>();



        foreach (GameObject o in currentMapObj)
        {
            if (o.transform.position.x == pt.x && o.transform.position.z == pt.y)
            {
                //o.AddComponent<AudioListener> ();
                //Room pick = o.GetComponent<Room> ().blocksInRoom [o.GetComponent<Room> ().gridList.IndexOf (pt)];
                string s = "";
                foreach (Vector2 vec in o.GetComponent <Room>().gridList)
                {
                    s = s + " " + vec;
                }
                Debug.Log("Pt :" + pt + " List:  " + s);
            }
        }
        foreach (GameObject o in list)
        {
            if (o.name.Equals("Room") && o.GetComponent <Room>().gridList.Contains(pt))
            {
                for (int i = 0; i < o.GetComponent <Room>().gridList.Count; i++)
                {
                    //o.GetComponent<Room>().gridList [i] = o.GetComponent<Room>().gridList [i] + distance;
                    //Debug.Log(
                }

                Room pick = o.GetComponent <Room> ().blocksInRoom [o.GetComponent <Room> ().gridList.IndexOf(pt)];
                foreach (Transform wall in pick.room.transform)
                {
                    if ((int)wall.gameObject.GetComponent <Wall> ().getDirection() == (int)dir && !wall.gameObject.name.Equals("Door(Clone)"))
                    {
                        GameObject obj = Instantiate(Resources.Load("Door", typeof(GameObject)), pick.room.transform) as GameObject;
                        obj.transform.position = wall.position;
                        obj.transform.rotation = wall.rotation;
                        Destroy(wall.gameObject);
                    }
                }

                /*foreach (Transform block in o.transform) {
                 *      Debug.Log (o.GetComponent<Room>().gridList[i]);
                 *      if (o.GetComponent<Room> ().gridList [i] == pt && block.position.x == pt.x && block.position.z == pt.y) {
                 *              foreach (Transform wall in block) {
                 *                      if ((int)wall.gameObject.GetComponent<Wall> ().getDirection () == (int)dir && !wall.gameObject.name.Equals ("Door(Clone)")) {
                 *                              GameObject obj = Instantiate (Resources.Load ("Door", typeof(GameObject)), block.transform) as GameObject;
                 *                              obj.transform.position = wall.position;
                 *                              obj.transform.rotation = wall.rotation;
                 *                              Destroy (wall.gameObject);
                 *                      }
                 *
                 *              }
                 *
                 *      }
                 *
                 *      i++;
                 *
                 * }*/
                /*string s = "";
                 * foreach (Vector2 vec in o.gameObject.GetComponent<Room>().gridList) {
                 *      s = s + " " + vec;
                 * }
                 * Debug.Log ("Pt :" + pt + " List:  " + s);*/
                break;
            }
        }
    }
Esempio n. 9
0
    // Update is called once per frame
    void Update()
    {
        if (onInstructionScreen)
        {
            return;
        }

        bool noMovement = true;

        State primaryState = State.Stoppped;

        if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
        {
            primaryState = State.WalkingUp;
            Movement(Global.Direction.Up, rigibody.velocity.x);
        }
        else if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
        {
            primaryState = State.WalkingDown;
            Movement(Global.Direction.Down, rigibody.velocity.x);
        }



        if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
        {
            Facing = Global.Direction.Left;
        }

        if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
        {
            Facing = Global.Direction.Right;
        }

        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow))
        {
            primaryState = DirectionToState[Facing];
            Movement(Facing, rigibody.velocity.y);
        }


        if (primaryState != State.Stoppped)
        {
            noMovement = false;
            if (!IsWalking)
            {
                IsWalking = true;
                if (OnWalkChange != null)
                {
                    OnWalkChange(primaryState);
                }
            }
        }
        else
        {
            if (IsWalking)
            {
                IsWalking = false;
                if (OnWalkChange != null)
                {
                    OnWalkChange(primaryState);
                }
            }
        }

        if (noMovement)
        {
            Movement(Global.Direction.None);
        }
    }
Esempio n. 10
0
    // Update is called once per frame
    void Update()
    {
        if (onInstructionScreen) {
            return;
        }

        bool noMovement = true;

        State primaryState = State.Stoppped;

        if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) {
            primaryState = State.WalkingUp;
            Movement(Global.Direction.Up, rigibody.velocity.x);
        } else if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) {
            primaryState = State.WalkingDown;
            Movement(Global.Direction.Down, rigibody.velocity.x);
        }

        if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow)) {
            Facing = Global.Direction.Left;
        }

        if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow)) {
            Facing = Global.Direction.Right;
        }

        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow)) {
            primaryState = DirectionToState[Facing];
            Movement(Facing, rigibody.velocity.y);
        }

        if (primaryState != State.Stoppped) {
            noMovement = false;
            if (!IsWalking) {
                IsWalking = true;
                if (OnWalkChange != null) {
                    OnWalkChange(primaryState);
                }
            }
        } else {
            if (IsWalking) {
                IsWalking = false;
                if (OnWalkChange != null) {
                    OnWalkChange(primaryState);
                }
            }
        }

        if (noMovement) {
            Movement(Global.Direction.None);
        }
    }
Esempio n. 11
0
    // Trigger event based on event name and event attribute+value
    private void TriggerEvent(string eventName)
    {
        if (eventName == "gesture")
        {
            float  speed = 1.0f, blend = 0.15f;
            int    strength = 100;
            string type     = "neutral";

            // Required
            int poseIndex = int.Parse(root.ChildNodes.Item(action).Attributes["pose"].Value);
            // Optional
            if (root.ChildNodes.Item(action).Attributes["speed"] != null)
            {
                speed = float.Parse(root.ChildNodes.Item(action).Attributes["speed"].Value);
            }
            if (root.ChildNodes.Item(action).Attributes["blend"] != null)
            {
                blend = float.Parse(root.ChildNodes.Item(action).Attributes["blend"].Value);
            }
            if (root.ChildNodes.Item(action).Attributes["offset"] != null)
            {
                type = root.ChildNodes.Item(action).Attributes["offset"].Value;
            }
            if (root.ChildNodes.Item(action).Attributes["strength"] != null)
            {
                strength = int.Parse(root.ChildNodes.Item(action).Attributes["strength"].Value);
            }

            //
            Global.BodyOffset offsetType = Global.BodyOffset.NEUTRAL;
            if (type == "forward")
            {
                offsetType = Global.BodyOffset.FORWARD;
            }
            else if (type == "backward")
            {
                offsetType = Global.BodyOffset.BACKWARD;
            }
            else if (type == "inward")
            {
                offsetType = Global.BodyOffset.INWARD;
            }
            else if (type == "outward")
            {
                offsetType = Global.BodyOffset.OUTWARD;
            }

            currentEvent.ChangePose(poseIndex, speed, blend);
            currentEvent.CharacterOffset(offsetType, strength);
        }

        if (eventName == "facial")
        {
            int strength = 100;

            // Required
            string emotion = root.ChildNodes.Item(action).Attributes["emotion"].Value;
            // Optional
            if (root.ChildNodes.Item(action).Attributes["strength"] != null)
            {
                strength = int.Parse(root.ChildNodes.Item(action).Attributes["strength"].Value);
            }

            //
            Global.Emotion emotionType = Global.Emotion.CONTENT;
            if (emotion == "angry")
            {
                emotionType = Global.Emotion.ANGRY;
            }
            else if (emotion == "bored")
            {
                emotionType = Global.Emotion.BORED;
            }
            else if (emotion == "content")
            {
                emotionType = Global.Emotion.CONTENT;
            }
            else if (emotion == "happy")
            {
                emotionType = Global.Emotion.HAPPY;
            }

            currentEvent.SetExpression(emotionType, strength);
        }

        if (eventName == "hand")
        {
            // Required
            string side  = root.ChildNodes.Item(action).Attributes["side"].Value;
            string shape = root.ChildNodes.Item(action).Attributes["shape"].Value;

            //
            Global.Side sideType = Global.Side.BOTH;
            if (side == "L")
            {
                sideType = Global.Side.LEFT;
            }
            else if (side == "R")
            {
                sideType = Global.Side.RIGHT;
            }

            Global.HandPose handType = Global.HandPose.RELAX;
            if (shape == "relax")
            {
                handType = Global.HandPose.RELAX;
            }
            else if (shape == "palm")
            {
                handType = Global.HandPose.PALM;
            }
            else if (shape == "fist")
            {
                handType = Global.HandPose.FIST;
            }

            currentEvent.SetHandShape(sideType, handType);
        }

        if (eventName == "foot")
        {
            // Required
            string status = root.ChildNodes.Item(action).Attributes["status"].Value;
            //
            if (status == "lock")
            {
                currentEvent.LockFoot(true);
            }
            else
            {
                currentEvent.LockFoot(false);
            }
        }

        if (eventName == "request")
        {
            string message = "";
            // Optional
            if (root.ChildNodes.Item(action).Attributes["message"] != null)
            {
                message = root.ChildNodes.Item(action).Attributes["message"].Value;
            }

            currentEvent.CheckSignal();
        }

        if (eventName == "slide")
        {
            int step = 1;
            // Required
            string direction = root.ChildNodes.Item(action).Attributes["direction"].Value;
            // Optional
            if (root.ChildNodes.Item(action).Attributes["step"] != null)
            {
                step = int.Parse(root.ChildNodes.Item(action).Attributes["step"].Value);
            }

            //
            Global.Direction directionType = Global.Direction.NEXT;
            if (direction == "back")
            {
                directionType = Global.Direction.BACK;
            }

            currentEvent.ChangeSlide(directionType, step);
            currentEvent.ChangeAudio(directionType, step);
        }
    }