Ejemplo n.º 1
0
        public void PlayerMove(int x, int y)
        {
            InitMsg im = new InitMsg();

            im.x = x;
            im.y = y;
            string json = JsonUtility.ToJson(im);

            m_Pelagia.Call("play_move", json);
        }
Ejemplo n.º 2
0
    void Awake()
    {
        m_Pelagia = new Pelagia();
        m_Pelagia.Init("./3drpg2.json");

        InitMsg im = new InitMsg();

        im.cmd      = "init";
        im.global_x = columns;
        im.global_y = rows;
        string json = JsonUtility.ToJson(im);

        m_Pelagia.Call("manager", json);

        name_obj = new Dictionary <string, GameObject>();
    }
Ejemplo n.º 3
0
    //Update is called every frame.
    void Update()
    {
        long ms = m_Pelagia.MS();

        while (true)
        {
            string msg = m_Pelagia.GetRec();
            //Debug.Log(msg);
            if (msg == null || ((m_Pelagia.MS() - ms) >= 1000))
            {
                return;
            }
            else
            {
                RecMsg rm = JsonUtility.FromJson <RecMsg>(msg);

                if (rm.cmd == "move")
                {
                    NpcMove(rm.name, rm.d_x, rm.d_z);
                    print("cmd move" + rm.name + "  " + rm.d_x + "  " + rm.d_z);
                }
                else if (rm.cmd == "init")
                {
                    uint       count       = 0;
                    GameObject gameObject1 = GameObject.Find("Cube");
                    for (int x = 0; x < MaxX; x++)
                    {
                        for (int z = 0; z < MaxZ; z++)
                        {
                            GameObject newobj = Instantiate(gameObject1, new Vector3(x, 0, z), Quaternion.identity);

                            string key = "role" + (count++);
                            name_obj[key] = newobj;

                            InitMsg im = new InitMsg();
                            im.cmd  = "create";
                            im.name = key;
                            im.x    = x;
                            im.z    = z;
                            string json = JsonUtility.ToJson(im);
                            m_Pelagia.Call("manager", json);
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 4
0
        void Awake()
        {
            //Check if instance already exists
            if (instance == null)
            {
                //if not, set instance to this
                instance = this;
            }

            //If instance already exists and it's not this:
            else if (instance != this)
            {
                //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
                Destroy(gameObject);
            }

            //Sets this to not be destroyed when reloading scene
            DontDestroyOnLoad(gameObject);

            GameObject go = GameObject.FindGameObjectWithTag("Player");

            player = go.GetComponent <Player>();

            m_Pelagia = new Pelagia();
            m_Pelagia.Init("./rpg.json");

            InitMsg im = new InitMsg();

            im.global_x   = columns;
            im.global_y   = rows;
            im.view_x     = viewColumns;
            im.view_y     = viewRows;
            im.npc_count  = enemyCount;
            im.wall_count = wallCount;
            im.food_count = foodCount;
            string json = JsonUtility.ToJson(im);

            m_Pelagia.Call("init", json);

            //Call the InitGame function to initialize the first level
            InitGame();
        }