Exemplo n.º 1
0
	void FixedUpdate()
    { 
        if (mustSnapToPlayerStart > 0) {
			if (GameObject.Find ("PlayerStart")) 
			{
				Vector3 newPos = GameObject.Find ("PlayerStart").transform.position;
				this.transform.position = newPos;
			}
			mustSnapToPlayerStart--;
		}

		if (!started)
			return;
		if (mirrorActivationDelaying) 
		{ // Reentry condition: showing mirror activation
			if(elapsedTime == 0.0f) 
			{
				if (ds == null)
					ds = GameObject.Find ("MasterController").GetComponent<MasterControllerScript> ().getStorage ();
				int mirrorNumber = ds.retrieveIntValue ("ActivateMirror"); // the gates will be just the 'next' mirror

//				if(cam != null)
//				{
//					cam.warpToMarker (mirrorNumber);
//					GameObject newTarget = GameObject.Find (ds.retrieveStringValue ("ActivatedMirror"));
//					cam.target = newTarget;
//				}
				CameraSwitch cameraController = GameObject.Find("CameraController").GetComponent<CameraSwitch>();
				cameraController._wm_switchToCameraIndex (mirrorNumber);
				if (mirrorObject != null) 
				{
					mirrorObject.activate (mirrorNumber);
				}
			}

			elapsedTime += Time.deltaTime;
			if (elapsedTime > mirrorActivationDelay) {
				ds.storeStringValue ("ReentryCondition", "");
				string returnLocation = ds.retrieveStringValue ("ReturnLocation");
				SceneManager.LoadScene (returnLocation);
			}
			return;
		}

		if (agent.enabled == true) 
		{
			return;
		}

		string intern, backn;
		if (interactee != null)
			intern = interactee.name;
		else intern = "null";
		if (backupInteractee != null)
			backn = backupInteractee.name;
		else backn = "null";

        if (meditatingRemaining > 0.0f)
        {
            meditatingRemaining -= Time.deltaTime;
            return;
        }

        /* WARNING crazy statement, reformulate */
        if (blocked)
			return;
		//if ((state != PlayerState.idling) && (state != PlayerState.walking))
		//	return;

		moving = false;
		if((state != PlayerState.materializing) && (state != PlayerState.dematerialized)) state = PlayerState.idling;

		//float moveHorizontal = Input.GetAxis ("Horizontal");
		//float moveVertical = Input.GetAxis ("Vertical");
		float moveHorizontal = 0.0f;
		float moveVertical = 0.0f;

		/*if (walkType == PlayerWalkType.floating) {
			if (height < equilibriumHeight) {
				heightSpeed += (equilibriumHeight - height)*(equilibriumHeight - height) * floatingAcceleration * Time.deltaTime;
			} else if (height > equilibriumHeight) {
				heightSpeed -= (height - equilibriumHeight)*(height - equilibriumHeight) * floatingAcceleration * Time.deltaTime;
			}
			height += heightSpeed * Time.deltaTime * equilibriumStrength;
			if (heightSpeed > 0.0f) {
				if (heightSpeed > maxHeightSpeed)
					heightSpeed = maxHeightSpeed;
			} else {
				if (heightSpeed < -maxHeightSpeed)
					heightSpeed = -maxHeightSpeed;
			}
		}*/

		if (autopilot == false) {
			moveHorizontal = hud.touchHorizontal () * walkMultiplicator;
			moveVertical = hud.touchVertical () * walkMultiplicator;
		} else {
			Vector3 current = this.transform.position;
			current.y = 0.0f;
			Vector3 dest = autopilotDestination;
			dest.y = 0.0f;
			Vector3 origin = autopilotOrigin;
			origin.y = 0.0f;
			DEJAMEVERESADISTANCIA = Vector3.Dot ((dest - current).normalized, (dest - origin).normalized);
			if (Vector3.Dot ((dest - current).normalized, (dest - origin).normalized) < 0.0f) {
				autopilot = false;
				notifyFinishAction ();
			} else {
				moveHorizontal = (autopilotDestination - autopilotOrigin).normalized.x/10.0f * walkMultiplicator;
				moveVertical = (autopilotDestination - autopilotOrigin).normalized.z/10.0f * walkMultiplicator;
			}
		}

		if(lastHorizontal != 0.0f && lastVertical != 0.0f) 
			direction = Direction4FromVector (new Vector2 (lastHorizontal, lastVertical));
		if ((moveHorizontal != 0.0f) || (moveVertical != 0.0f)) {
			direction = Direction4FromVector (new Vector2 (moveHorizontal, moveVertical));
			lastHorizontal = moveHorizontal;
			lastVertical = moveVertical;
			moving = true;
			state = PlayerState.walking;
		}

		if (moving) {
			setOrientation(direction);

			elapsedTime += Time.deltaTime;
			if (elapsedTime > (1.0f / WalkingAnimationSpeed)) {
				elapsedTime = 0.0f;
				frame++;
				foreach (int f in footstepFrame) {
					if(f == frame) {
						levelRef.footstep();
					}
				}
				if (walkType == PlayerWalkType.onGround) {
					switch (direction) {
					case PlayerDirection.left:
						if (frame == WalkingLeft.Length)
							frame = 1;
						break;
					case PlayerDirection.right:
						if (frame == WalkingRight.Length)
							frame = 1;
						break;
					case PlayerDirection.front:
						if (frame == WalkingFront.Length)
							frame = 1;
						break;
					case PlayerDirection.back:
						if (frame == WalkingBack.Length)
							frame = 1;
						break;
					case PlayerDirection.backleft:
						if (frame == WalkingLeftBack.Length)
							frame = 1;
						break;
					case PlayerDirection.backright:
						if (frame == WalkingBackRight.Length)
							frame = 1;
						break;
					case PlayerDirection.frontleft:
						if (frame == WalkingFrontLeft.Length)
							frame = 1;
						break;
					case PlayerDirection.frontright:
						if (frame == WalkingRightFront.Length)
							frame = 1;
						break;
					}
				} else {
					switch (direction) {
					case PlayerDirection.left:
						if (frame == floatingLeft.Length)
							frame = 0;
						break;
					case PlayerDirection.right:
						if (frame == floatingRight.Length)
							frame = 0;
						break;
					case PlayerDirection.front:
						if (frame == floatingFront.Length)
							frame = 0;
						break;
					case PlayerDirection.back:
						if (frame == floatingBack.Length)
							frame = 0;
						break;
					case PlayerDirection.backleft:
						if (frame == floatingBackLeft.Length)
							frame = 0;
						break;
					case PlayerDirection.backright:
						if (frame == floatingBackRight.Length)
							frame = 0;
						break;
					case PlayerDirection.frontleft:
						if (frame == floatingFrontLeft.Length)
							frame = 0;
						break;
					case PlayerDirection.frontright:
						if (frame == floatingFrontRight.Length)
							frame = 0;
						break;
					}
				}
			}

		} else { // not moving
			if (walkType == PlayerWalkType.onGround) {
				switch (direction) {
				case PlayerDirection.left:
					playerRendRef.sprite = WalkingLeft [0];
					otherPlayerRendRef.sprite = WalkingLeft [0];
					break;
				case PlayerDirection.right:
					playerRendRef.sprite = WalkingRight [0];
					otherPlayerRendRef.sprite = WalkingRight [0];
					break;
				case PlayerDirection.front:
					playerRendRef.sprite = WalkingFront [0];
					otherPlayerRendRef.sprite = WalkingFront [0];
					break;
				case PlayerDirection.back:
					playerRendRef.sprite = WalkingBack [0];
					otherPlayerRendRef.sprite = WalkingBack [0];
					break;
				case PlayerDirection.backleft:
					playerRendRef.sprite = WalkingLeftBack [0];
					otherPlayerRendRef.sprite = WalkingLeftBack [0];
					break;
				case PlayerDirection.backright:
					playerRendRef.sprite = WalkingBackRight [0];
					otherPlayerRendRef.sprite = WalkingBackRight [0];
					break;
				case PlayerDirection.frontleft:
					playerRendRef.sprite = WalkingFrontLeft [0];
					otherPlayerRendRef.sprite = WalkingFrontLeft [0];
					break;
				case PlayerDirection.frontright:
					playerRendRef.sprite = WalkingRightFront [0];
					otherPlayerRendRef.sprite = WalkingRightFront [0];
					break;
				}
			}

			frame = 0;
			elapsedTime = 0.0f;
		}

		bool cannotWalk = false;

		float yVelocity = r.velocity.y;

		Vector3 movement = new Vector3 (externalForce.x + moveHorizontal*speed, externalForce.y + yVelocity, externalForce.z + moveVertical*speed); // WARNING magic number
		Vector3 flatMovement = movement;
		flatMovement.y = 0.0f;
		modulusSpeed = flatMovement.magnitude;
		if ((!blocked) && (!cannotWalk))
			r.velocity = movement;
		else
			r.velocity = new Vector3 (0.0f, 0.0f, 0.0f);

		if (Input.GetMouseButtonDown (0) && (moving == false)) 
		{
			canInteract = true;
		}

		if (moving == true)
			canInteract = false;

		if(Input.GetMouseButtonUp(0) && (canInteract == true)) {

			canInteract = false;

			switch (interaction) {

			case Interaction.None:
				break;

			default:
				if(interactee!=null) interactee.effect ();
				break;
			}
		}
	}