Exemple #1
0
	// Move object within a set of time. The time here is distance over speed
	IEnumerator MoveObject (Transform thisTransform, Vector3 startPos, Vector3 endPos, float time, DirectionType direction) {
	    float i = 0.0f;
	    float rate = 1.0f / time;
		
	    while (i < 1.0f) {
			isStillMoving = true;
	        i += Time.deltaTime * rate;
	        thisTransform.position = Vector3.Lerp(startPos, endPos, i);
			
			if(direction == DirectionType.Left)
				playAnimation(left_anim);
			else if(direction == DirectionType.Right)
				playAnimation(right_anim);
			else if(direction == DirectionType.Front)
				playAnimation(front_anim);
			else if(direction == DirectionType.Down)
				playAnimation(back_anim);
			
	        yield return null; 
	    }
		
		isStillMoving = false;
		
		float verticalCell = ZooMap.GetVerticalCell(transform.position.y);
		float horizontalCell = ZooMap.GetHorizontalCell(transform.position.x);
		//Debug.Log ("Cell X: "+horizontalCell);
		//Debug.Log ("Cell Y: "+verticalCell);
	}
Exemple #2
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));
	}
Exemple #3
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));
	}
Exemple #4
0
	public void SendPlantBombMessage()
	{
		// If player is still moving, don't sends update to the server
		//if(isStillMoving)
		//{
		//	return;
		//}
		
		float verticalCell = ZooMap.GetVerticalCell(transform.position.y);
		float horizontalCell = ZooMap.GetHorizontalCell(transform.position.x);
		string bombId = (int) horizontalCell + "" + (int) verticalCell;
		
		if(bombDict.ContainsKey(bombId) == false)
		{
			clientSocketScript.SendPlantBombMessage(horizontalCell, verticalCell);
		}
	}