public void AddBall(int id, GameObject ball, ELevelBallType type) { base.Add(id, ball); if (!m_ballsTypeDic.ContainsKey(id)) { m_ballsTypeDic.Add(id, type); } }
public GameObject GetBallResource(ELevelBallType type) { if (m_ballResources.ContainsKey(type)) { return(m_ballResources[type]); } return(null); }
public void RandomMap() { for (int col = -20; col <= 0; col++) { for (int row = -3; row <= 3; row++) { ELevelBallType type = (ELevelBallType)UnityEngine.Random.Range(0, 6); AddBall(col, row, type); } } }
public void ExChangeBall(int side) { GameObject ballTmp = m_waitBalls[side]; ELevelBallType ballTypeTmp = m_waitBallsType[side]; m_waitBalls[side] = m_waitBalls[side + 2]; m_waitBallsType[side] = m_waitBallsType[side + 2]; m_waitBalls[side + 2] = ballTmp; m_waitBallsType[side + 2] = ballTypeTmp; m_isExBall[side] = true; m_exBallTimer[side] = 0f; }
public void TryEraseBubble(ServerBubble bubble, ELevelBallType type, List <ServerBubble> eraseBubbles) { for (int i = 0; i < bubble.NeighborGrids.Count; i++) { ServerBubble neighbor = GetBubbleByGrid(bubble.NeighborGrids[i]); if (neighbor != null && neighbor.isVisited == false) { neighbor.isVisited = true; if (neighbor.CanErase(type)) { eraseBubbles.Add(neighbor); TryEraseBubble(neighbor, type, eraseBubbles); } } } }
private void SendMessage(int side, ELevelBallType type, Vector2 startPos, Vector2 dir, Vector2 hitPoint, bool isFlyout, float flyDistance) { Vector2 point = m_battleFieldObj.transform.InverseTransformPoint(hitPoint); Vector2 cellPoint = point; float speed = flyDistance / ConfigHelper.GetBubbleFlyDuration(); cellPoint.y = -cellPoint.y; if (GameCore.Instance.IsOfflineMode) { CmdFireBallResponse cmd = new CmdFireBallResponse(0, (int)type, startPos, dir, point, CellManager.GetCellID(cellPoint), m_lastBallId, speed, 0); ++m_lastBallId; m_battle.HandleBattleCommand(cmd); } else { ProtoCSBattleCommand proto = new ProtoCSBattleCommand(new CmdFireBall(side, (int)type, startPos, dir, point, CellManager.GetCellID(cellPoint), isFlyout, speed)); NetworkMgr.Instance.Send(proto); } }
public void SetBall(int col, int row, ELevelBallType type) { GridPosition gridId = new GridPosition(col, row); bool needSet = true; if (Balls.ContainsKey(gridId)) { if (Balls[gridId].Type != type) { RemoveBall(col, row); } else { needSet = false; } } if (needSet) { AddBall(col, row, type); } }
public void AddBall(int col, int row, ELevelBallType type) { GameObject prefab = BallPrefabs[type]; GameObject ball = PrefabUtility.InstantiatePrefab(prefab) as GameObject; ball.name = string.Format("[{0},{1}][{2}]", col, row, type.ToString()); ball.transform.SetParent(this.transform); ball.transform.localPosition = GridToPosition(col, row); //ball.hideFlags = HideFlags.HideInHierarchy; LevelBall newball = ball.GetComponent <LevelBall>(); newball.Id = NewBallId; List <LevelBall> connectedBalls = new List <LevelBall>(); GetConnectedBalls(col, row, connectedBalls); foreach (var b in connectedBalls) { newball.Connections.Add(b); b.Connections.Add(newball); } Balls.Add(new GridPosition(col, row), newball); }
public void LoadLevelMap() { byte[] databytes = File.ReadAllBytes(GetLevelDataPath(LevelId)); LevelMapData data = new LevelMapData(); data.LoadFromBytes(databytes); MapType = (ELevelMapType)data.mapType; nextBallId = data.maxBallId + 1; foreach (var ballData in data.balls) { ELevelBallType type = (ELevelBallType)ballData.type; int col = ballData.grids[0].col; int row = ballData.grids[0].row; int ballId = ballData.id; GameObject prefab = BallPrefabs[type]; GameObject ball = PrefabUtility.InstantiatePrefab(prefab) as GameObject; ball.name = string.Format("[{0},{1}][{2}]", col, row, type.ToString()); ball.transform.SetParent(this.transform); ball.transform.localPosition = GridToPosition(col, row); ball.hideFlags = HideFlags.HideInHierarchy; LevelBall newball = ball.GetComponent <LevelBall>(); newball.Id = ballId; List <LevelBall> connectedBalls = new List <LevelBall>(); GetConnectedBalls(col, row, connectedBalls); foreach (var b in connectedBalls) { newball.Connections.Add(b); b.Connections.Add(newball); } Balls.Add(new GridPosition(col, row), newball); } }
public bool CanErase(ELevelBallType type) { return(m_type == type); }
public ServerBubble(int id, ELevelBallType type, List <GridPosition> grids) { m_id = id; m_type = type; m_takenGrids = grids; }
public void CalFireBall(int side, ELevelBallType type, Vector2 startPos, Vector2 fingerPos, float lineLength = 0f, bool isPresent = false) { ClearLineRender(); float drawLineLength = lineLength; Vector2 dir = (fingerPos - startPos).normalized; Vector2 startPoint = startPos; Vector2 normal = dir; if (normal.y == 0) { Debug.Log("CallFireBall Y shoud != 0!"); return; } float flyDistance = 0; bool isCalOver = false; bool hasBouncedBack = false; do { Vector2 endPos = RayCast(startPoint, normal); if (m_hit.collider == null) { flyDistance += Vector2.Distance(startPoint, endPos); if (isPresent) { drawLineLength -= DrawLine(startPoint, endPos, normal, drawLineLength); } if (endPos.y >= GlobalData.m_windowHight / 2 || endPos.y <= (-GlobalData.m_windowHight / 2) || hasBouncedBack) { //打空了 if (!isPresent) { SendMessage(side, type, startPos, dir, endPos, true, flyDistance); } return; } startPoint = endPos; normal.x = -normal.x; hasBouncedBack = true; } else { //打中了 flyDistance += Vector2.Distance(startPoint, m_hit.point); if (isPresent) { drawLineLength -= DrawLine(startPoint, m_hit.point, normal, drawLineLength); } else { SendMessage(side, type, startPos, dir, m_hit.point, false, flyDistance); } isCalOver = true; } } while (!isCalOver); }