/// <summary> /// 设置地图的星星内容,附带移动过程 /// </summary> public void SetMapContent(NPCStar p, int i, int j, bool withMove, MazeMapPoint initCoord) { MMap.setMap(p, i, j); if (p == null) { return; } p.Point = new MazeMapPoint() { x = i, y = j }; p.transform.localPosition = GetMapCoordPosition(initCoord.x, initCoord.y); if (withMove) { p.BeforeOnMove(); p.transform.DOLocalMove(GetMapCoordPosition(i, j), 0.35f).OnComplete(() => { p.AfterOnMove(); }); } else { p.transform.localPosition = GetMapCoordPosition(i, j); } }
/// <summary> /// 搜索消除 /// </summary> /// <param name="p">开始搜索的星星</param> void HandleClearMap(NPCStar p) { List <NPCStar> list = MMap.OnSearchMap(p.Point.x, p.Point.y, (e) => { return(p.IsPassTestSearch() && p.IsSameAsType(e)); }); int mCount = list.Count; if (mCount >= 3) { int L = list.Count; while (L-- > 0) { NPCStar e = list[L]; e.OnDestroy(); PlayEliminateEffect(e.transform.position); MMap.setMap(null, e.Point.x, e.Point.y); } PlayEliminateSoundEffect(mCount); GameUI.SetGameAddScore(ScoringComputation(list.Count)); } else { SCSound.game_cuowu(); } }
/// <summary> /// 经过类型装饰 /// </summary> /// <param name="type"></param> /// <returns></returns> public NPCStar GetNPCStarFromType(StarType type) { NPCStar e = NPCStarPool.GetObject(); e.SpriteRenderer.sprite = GetSpriteMapping(GameConfig.Instance.GetComnmonStarMapping(type.ToString())); e.Type = type; e.Used(); return(e); }
NPCStar InstanceNpcStar() { float pixelUtil = mGameManagerScript.PixelPreUtil; GameObject g = new GameObject("star"); g.transform.parent = mgamestarRoot; NPCStar star = new NPCStar(g, pixelUtil); star.UnUsed(); return(star); }
void UpdateBlankSpace() { int[] topNum = new int[MapCell]; for (int j = 0; j < MapCell; ++j) { for (int i = 0; i < MapLine; ++i) { NPCStar e = MMap.getMap(i, j); if (e == null) { // if is Empty then FallDown NPCStar up = null; for (int k = i + 1; k < MapLine; ++k) { up = MMap.getMap(k, j); if (up != null) { MMap.setMap(null, k, j); SetMapContent(up, i, j, true, up.Point); break; } } if (up == null) { //最上面为空,以下操作是填充新的格子到上面 topNum[j]++; up = GamePool.Instance.GetNPCStarFromType(GetGameStarTypeStrategy(j)); SetMapContent(up, i, j, true, new MazeMapPoint() { x = MapLine + topNum[j], y = j }); } } } } }
// Update is called once per frame void Update() { bool misTouch = false; Vector3 mTouchPosition = Vector3.zero; if (Input.GetMouseButtonDown(0)) { mTouchPosition = Input.mousePosition; misTouch = true; } //if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Began) { // mTouchPosition = Input.GetTouch (0).position; // misTouch = true; //} if (misTouch) { Vector3 touchPosition = Camera.main.ScreenToWorldPoint(mTouchPosition); NPCStar touchObject = null; MMap.LoopHandleMapContentWithRT((e) => { if (touchObject == null && e != null) { if (e.Box2d.OverlapPoint(touchPosition)) { touchObject = e; MMap.IsLoopRT = true; } } }); if (touchObject != null) { Debug.Log("TOUCH: " + touchObject.Point.x + " " + touchObject.Point.y); if (touchObject.CanTriggerMatch()) { HandleClearMap(touchObject); } } } }
/// <summary> /// 初始化游戏矩阵地图,实际性放置星星 /// </summary> void InitMap() { int line = mapLine; int cell = mapCell; MMap = new MazeMap <NPCStar>(line, cell); for (int i = 0; i < line; ++i) { for (int j = 0; j < cell; ++j) { NPCStar star = GamePool.Instance.GetNPCStarFromType(GetGameStarTypeStrategy(j)); star.InitUsed(new MazeMapPoint() { x = i, y = j }); MMap.setMap(star, i, j); } } }
// 类型相同才被搜索 public bool IsSameAsType(NPCStar p) { return(p.Type == this.Type); }