void InitGame() { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { Vector2 index = new Vector2(i, j); INumberObject numberObject = (INumberObject)gameRender.CreateObject(RenderProtocol.CreateNumberObject, 0); numberObject.SetNumber(2); numberObject.SetIndex(index); numberObject.SetPosition(index * IndexToPos); numberObjList.Add(numberObject); numberTable[i, j] = new NumberData { Index = new Vector2(i, j), TargetIndex = new Vector2(i, j), Number = 2 }; } } for (int i = 0; i < 4; i++) { SetNewNumber(2); } }
public void Moving(float speed, int i, int j) { Debug.Log("移动"); Vector2 last = numbers[i, j].GetLastIndex(); Vector2 current = numbers[i, j].GetIndex(); if (last != current) { Vector2 direct = (current - last).normalized; Vector2 currentPos = numbers[i, j].GetCurrentPos(); currentPos += direct * Time.deltaTime * speed * Mathf.Abs(current.x + current.y - last.x - last.y); numbers[i, j].SetPosition(currentPos); if (Mathf.Abs((currentPos - current).magnitude) < 0.1) { int num = numbers[i, j].GetDestNum(); GameFramework.singleton.getGameRender().DestroyObject(numbers[i, j]); INumberObject number1 = GameFramework.singleton.getGameRender().CreateObject(RenderProtocol.CreateNumberObject, size) as INumberObject; number1.SetNumber(num); number1.SetDestNum(num); number1.SetIndex(current); number1.SetLastIndex(current); number1.SetPosition(current); GameFramework.singleton.getGameRender().DestroyObject(numbers[(int)current.x, (int)current.y]); numbers[(int)current.x, (int)current.y] = number1; INumberObject number2 = GameFramework.singleton.getGameRender().CreateObject(RenderProtocol.CreateNumberObject, size) as INumberObject; number2.SetNumber(0); number2.SetNumber(0); number2.SetIndex(new Vector2(i, j)); number2.SetLastIndex(new Vector2(i, j)); number2.SetPosition(new Vector2(i, j)); numbers[i, j] = number2; } } }