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;
        }
    }
Beispiel #2
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--;
		}
	}
Beispiel #3
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));
	}
Beispiel #4
0
	public void MoveUp(float originalCellX, float originalCellY, bool sendToServer)
	{
		if(previousDirection != DirectionType.Front)
		{
			UpdateRayCasting(DirectionType.Front);
			previousDirection = DirectionType.Front;
		}

		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 >= ZooMap.NumberofCols - 1 || isStillMoving)
			return;
		
		bool isObstacleAhead = ZooMap.IsObstacle((int) horizontalCell, (int) verticalCell + 1);
		
		if(isObstacleAhead)
		{
			Debug.Log ("Obstacle!!! is in front");
			return;
		}
		
		float nextPosY = ZooMap.GetVerticalPos(verticalCell + 1);
		
		Vector3 endPoint = new Vector3(transform.position.x, nextPosY, transform.position.z);
		
		float time = ZooMap.cellHeight / speed;		// time = distance over speed
		
		// client moves
		if(sendToServer)
		{
			clientSocketScript.SendMovementMessage(horizontalCell, verticalCell, "UP", speed);
			SoundManager soundManager = GameObject.Find ("SoundManager").GetComponent<SoundManager>();
			
			if(soundManager != null)
				soundManager.PlayMoveSound(transform.position);		
		}
		
		StartCoroutine(MoveObject(transform, startPoint, endPoint, time, DirectionType.Front));
	}
Beispiel #5
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);
	}
    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));
            }
        }
    }