Esempio n. 1
0
	public void PlantBomb(float horizontalCell, float verticalCell)
	{
		// If player is still moving, don't plant the bomb
		//if(isStillMoving)
		//{
		//	return;
		//}
			
		//float verticalCell = ZooMap.GetVerticalCell(transform.position.y);
		//float horizontalCell = ZooMap.GetHorizontalCell(transform.position.x);
		
		float verticalPos = ZooMap.GetVerticalPos(verticalCell);
		float horizontalPos = ZooMap.GetHorizontalPos(horizontalCell);
		
		//Vector3 bombPos = transform.position + new Vector3(0, 0, 0.01f);
		Vector3 bombPos = new Vector3(horizontalPos, verticalPos, 0.01f);
		GameObject bombInstance = Instantiate(bombGO, bombPos, transform.rotation) as GameObject;
		string bombId = (int) horizontalCell + "" + (int) verticalCell;
		
		string cellID = (int) horizontalCell + ":" + (int) verticalCell;
		
		if(bombDict.ContainsKey(bombId) == false)
		{
			bombDict.Add(bombId, bombInstance);

			// bomb is planted in the cell
			zooMapScript.UpdateCellWithBomb(cellID, true);
			
			m_bombLimit--;
		}
	}
Esempio n. 2
0
    public void InitGeneralCharacter(GameObject animalCharacter, long playerID, string playerName, int cellX, int cellY)
    {
        characterInstance = Instantiate(animalCharacter, transform.position, transform.rotation) as GameObject;
        var animationScript = characterInstance.GetComponent <CharacterAnimController>();

        animationScript.EnemyPlayer = !isSelf;

        float spawnX = ZooMap.GetHorizontalPos(cellX);
        float spawnY = ZooMap.GetVerticalPos(cellY);

        animationScript.SpawnCharacter(spawnX, spawnY);

        if (isSelf)
        {
            characterInstance.gameObject.tag = "Player";
        }

        characterInstance.gameObject.name = "" + playerID;

        // Instantiate name
        tk2dTextMesh nameScript = characterInstance.transform.Find("HUD_Name").GetComponent <tk2dTextMesh>();

        if (nameScript != null)
        {
            nameScript.text = playerName;
        }
    }
Esempio n. 3
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);
	}
    public void PlantBomb(long serverPlayerID, float cellX, float cellY, long bombLeft)
    {
        GameObject characterObject = GameObject.Find("" + serverPlayerID);

        // If the player ID is me, then i update my own prefab bombleft

        if (characterObject)
        {
            CharacterAnimController playerController = characterObject.GetComponent <CharacterAnimController>();
            playerController.PlantBomb(cellX, cellY);

            if (serverPlayerID == PlayerID)
            {
                GameObject hud = GameObject.Find("UnityHUDPrefab");
                if (hud)
                {
                    HUD hudScript = hud.GetComponent <HUD>();
                    hudScript.SetBombLeft(playerController.BombLimit);
                }

                // Play Sound
                SoundManager soundManager = GameObject.Find("SoundManager").GetComponent <SoundManager>();
                soundManager.PlayPlantBombSound(new Vector3(ZooMap.GetHorizontalPos(cellX), ZooMap.GetVerticalPos(cellY), 0));
            }
        }
    }
Esempio n. 5
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));
	}
Esempio n. 6
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));
	}
Esempio n. 7
0
    // Use this for initialization
    void Start () {
		
		hudInstance = GameObject.Find ("UnityHUDPrefab");
		if(hudInstance)
		{
			hudScript = hudInstance.GetComponent<HUD>();
		}
		
        // This script must be attached to the sprite to work.
        anim = GetComponent<tk2dSpriteAnimator>();
		
		InitAnimation();
		
		clientSocketScript = GameObject.Find("PlayerConnection").GetComponent<ClientSocket>();
		zooMapScript = GameObject.Find ("ZooMap").GetComponent<ZooMap>();
    }
Esempio n. 8
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);
		}
	}
Esempio n. 9
0
	public void RespawnPlayer(float cellX, float cellY)
	{
		float horizontalPos = ZooMap.GetHorizontalPos(cellX);
		float verticalPos = ZooMap.GetVerticalPos(cellY);
		gameObject.transform.position = new Vector3(horizontalPos, verticalPos, gameObject.transform.position.z);
	}