コード例 #1
0
	public void MoveDown(float originalCellX, float originalCellY, bool sendToServer)
	{
		if(previousDirection != DirectionType.Down)
		{
			UpdateRayCasting(DirectionType.Down);
			previousDirection = DirectionType.Down;
		}

		Vector3 startPoint = transform.position;

		float verticalCell = 0; 
		float horizontalCell = 0; 
		
		if(sendToServer)
		{
			verticalCell = ZooMap.GetVerticalCell(transform.position.y);
			horizontalCell = ZooMap.GetHorizontalCell(transform.position.x);
		}
		else
		{
			horizontalCell = originalCellX;
			verticalCell = originalCellY;
		}
		
		// exceed the map
		if(verticalCell <= 0 || isStillMoving)
			return;
		
		bool isObstacleAhead = ZooMap.IsObstacle((int) horizontalCell, (int) verticalCell - 1);
		
		if(isObstacleAhead)
		{
			Debug.Log ("Obstacle!!! is on down");
			return;
		}
		
		float nextPosY = ZooMap.GetVerticalPos(verticalCell - 1);
		
		Vector3 endPoint = new Vector3(transform.position.x, nextPosY, transform.position.z);

		// The step size is equal to speed times frame time.
		//var step = speed * Time.deltaTime;

		float time = ZooMap.cellHeight / speed;		// time = distance over speed
		
		// client moves
		if(sendToServer)
		{
			clientSocketScript.SendMovementMessage(horizontalCell, verticalCell, "DOWN", speed);
			SoundManager soundManager = GameObject.Find ("SoundManager").GetComponent<SoundManager>();
			
			if(soundManager != null)
				soundManager.PlayMoveSound(transform.position);				
		}
		
		StartCoroutine(MoveObject(transform, startPoint, endPoint, time, DirectionType.Down));
	}
コード例 #2
0
	public void MoveRight(float originalCellX, float originalCellY, bool sendToServer)
	{
		if(previousDirection != DirectionType.Right)
		{
			UpdateRayCasting(DirectionType.Right);
			previousDirection = DirectionType.Right;
		}
		
		Vector3 startPoint = transform.position;
		
		float verticalCell = 0; 
		float horizontalCell = 0; 
		
		if(sendToServer)
		{
			verticalCell = ZooMap.GetVerticalCell(transform.position.y);
			horizontalCell = ZooMap.GetHorizontalCell(transform.position.x);
		}
		else
		{
			horizontalCell = originalCellX;
			verticalCell = originalCellY;
		}
		
		// exceed the map
		if( horizontalCell >= ZooMap.NumberofRows - 1 || isStillMoving)
			return;
		
		bool isObstacleAhead = ZooMap.IsObstacle((int) horizontalCell + 1, (int) verticalCell);
		
		if(isObstacleAhead)
		{
			Debug.Log ("Obstacle!!! is on right");
			return;
		}
		
		float nextPosX = ZooMap.GetHorizontalPos(horizontalCell + 1);
		
		Vector3 endPoint = new Vector3(nextPosX, transform.position.y, transform.position.z);

		//transform.position = Vector3.Lerp(startPoint, endPoint, (speed * Time.deltaTime));
		
		float time = ZooMap.cellWidth / speed;		// time = distance over speed
		
		// client moves
		if(sendToServer)
		{
			clientSocketScript.SendMovementMessage(horizontalCell, verticalCell, "RIGHT", speed);
			SoundManager soundManager = GameObject.Find ("SoundManager").GetComponent<SoundManager>();
			
			if(soundManager != null)
				soundManager.PlayMoveSound(transform.position);				
		}
		
		StartCoroutine(MoveObject(transform, startPoint, endPoint, time, DirectionType.Right));
	}