예제 #1
0
    public void move(int x)
    {
        createPossibleSteps(false, pos);
//		if (isMoving)
//		{
        CtrlGrid grid = GameObject.Find("Grid").GetComponent <CtrlGrid> ();

        if (x == 0 && pos.y + 1 < grid.height)             //N
        {
            pos.y += 1;
            transform.Find("Robot").transform.localEulerAngles = Vector3.zero;
        }
        else if (x == 1 && pos.y > 0)               //S
        {
            pos.y -= 1;
            transform.Find("Robot").transform.localEulerAngles = new Vector3(0, 0, 180);
        }
        else if (x == 3 && pos.x + 1 < grid.width)             //E
        {
            pos.x += 1;
            transform.Find("Robot").transform.localEulerAngles = new Vector3(0, 0, 90);
        }
        else if (x == 2 && pos.x > 0)               //W
        {
            pos.x -= 1;
            transform.Find("Robot").transform.localEulerAngles = new Vector3(0, 0, -90);
        }

        GetComponent <Animator>().SetBool("walk", true);

        checkIfRightMoveandIncrementIndex();
        createPossibleSteps(true, pos);
//		}
    }
예제 #2
0
    // Use this for initialization
    void Awake()
    {
        grid             = GameObject.Find("Grid").GetComponent <CtrlGrid>();
        transform.parent = GameObject.Find("Players").transform;
        name             = "player" + transform.parent.childCount;

        //// Debug.Log ("Awake from player:" + name);

        gameInstance = GameObject.Find("Main").GetComponent <Game>();

        gameUi        = GameObject.Find("GameUi");
        GoUpButton    = GameObject.Find("UpButton");
        GoDownButton  = GameObject.Find("DownButton");
        GoLeftButton  = GameObject.Find("LeftButton");
        GoRightButton = GameObject.Find("RightButton");
        GoLocalTime   = GameObject.Find("LocalTime");

        if (networkView.isMine)
        {
            GoUpButton.GetComponent <Button> ().onClick.RemoveAllListeners();
            GoUpButton.GetComponent <Button> ().onClick.AddListener(() => move(0));

            GoDownButton.GetComponent <Button> ().onClick.RemoveAllListeners();
            GoDownButton.GetComponent <Button> ().onClick.AddListener(() => move(1));

            GoLeftButton.GetComponent <Button> ().onClick.RemoveAllListeners();
            GoLeftButton.GetComponent <Button> ().onClick.AddListener(() => move(2));

            GoRightButton.GetComponent <Button> ().onClick.RemoveAllListeners();
            GoRightButton.GetComponent <Button> ().onClick.AddListener(() => move(3));

            gameUi.SetActive(false);
        }
    }
예제 #3
0
 void Awake()
 {
     grid = GameObject.Find("Grid").GetComponent <CtrlGrid> ();
     spawnPoints.Add(new Point(0, 0));
     spawnPoints.Add(new Point(grid.width - 1, 0));
     spawnPoints.Add(new Point(0, grid.height - 1));
     spawnPoints.Add(new Point(grid.width - 1, grid.height - 1));
 }
예제 #4
0
    // Use this for initialization
    void Start()
    {
        timeLeftOnTile = maxTimeLeftOnTile;
        CtrlGrid grid = GameObject.Find("Grid").GetComponent <CtrlGrid> ();

        if (isMe)
        {
            path = new PathModeler().generatePath(pos, new Point(grid.width / 2, grid.height / 2), 10);
        }

        goPlayer = this.gameObject;
        goPlayer.transform.localPosition = new Vector3(spawnPoint.x, spawnPoint.y, 0);
//		GameObject goPlayerSphere=GameObject.CreatePrimitive(PrimitiveType.Sphere);
//		goPlayerSphere.transform.parent=this.transform;
//		goPlayerSphere.transform.localPosition = Vector3.zero;
//		goPlayerSphere.renderer.material.color = Color.red;

//		if (!isMe)
//		{
//			for (int i=0;i<path.Length;i++)
//			{
//				GameObject go=GameObject.CreatePrimitive(PrimitiveType.Sphere);
//				float z=0;
//				switch (gameObject.name)
//				{
//					case "player1": go.renderer.material.color=Color.red; z=-0.2f; break;
//					case "player2": go.renderer.material.color=Color.blue;z=-0.1f; break;
//					case "player3": go.renderer.material.color=Color.green;z=0.0f; break;
//					case "player4": go.renderer.material.color=Color.cyan;z=0.1f; break;
//				}
//
//				go.transform.parent=this.transform.parent;
//				go.transform.localPosition=new Vector3((float)path[i].x,(float)path[i].y,z);
//				go.transform.localScale=new Vector3(0.2f,0.2f,0.2f);
//			}
//		}

        if (isMe)
        {
            createPossibleSteps(true, pos);
            GameObject.Find(getTileName(pos)).GetComponent <CtrlTile>().onTileUp(timeLeftOnTile);
        }
        else
        {
            if (pathIndex < path.Length)
            {
                // Debug.Log(getTileName(path [pathIndex + 1]));
                GameObject.Find(getTileName(path [pathIndex + 1])).GetComponent <CtrlTile>().onTileMarkNext();
            }
        }
    }