public void RemoveAtPos(Vector2 pos) { if (Collision(pos) == Block.Type.Empty) { return; } Block block = BlockAtPos(pos); Block.Group group = block.group; foreach (Block member in group) { UnFixed(member); member.type = Block.Type.Empty; Destroy(member.gameObject); } this.player.DropStart(); foreach (Block.Group upperGroup in group.LookUpUpperGroups()) { SetUnbalanceGroups(upperGroup); } }
// Use this for initialization void Start() { // Grouping all for (int row = 0; row < this.numBlockRows; row++) { for (int col = 0; col < this.numBlockCols; col++) { if (this.hitTable[row, col] == Block.Type.Empty) { continue; } Block block = this.fixedBlocks[row, col]; if (block.group != null) { continue; } Block.Group group = new Block.Group(this); group.Grouping(block); } } this.playerObj = GameObject.Find("Player"); this.player = playerObj.GetComponent <Player>(); }
void SetUnbalanceGroups(Block.Group group) { HashSet <Block.Group> unbalanceGroups = group.LookUpUnbalanceGroups(); foreach (Block.Group g in unbalanceGroups) { foreach (Block member in g) { this.unbalanceBlocks.Add(member); member.ShakeStart(this.shakeTime); } } this.unbalanceBlocks.Sort(delegate(Block a, Block b) { return(a.pos.y < b.pos.y ? 1 : -1); }); }
void Update() { // check // for (int row = 0; row < this.numBlockRows; row++) { // for (int col = 0; col < this.numBlockCols; col++) { // Block.Type type = this.hitTable[row, col]; // Block block = this.fixedBlocks[row, col]; // block.type = type; // } // } foreach (Block block in this.fixedBlocks) { if (block == null) { continue; } if (block.blinking && !block.BlinkNext()) { RemoveAtPos(block.pos); } } HashSet <Block.Group> fixedGroups = new HashSet <Block.Group>(); foreach (Block block in this.unbalanceBlocks) { if (!block.unbalance) { continue; } if (block.shaking && !block.ShakeNext()) { UnFixed(block); } else if (block.dropping) { block.DropNext(); if (Collision(block.pos, Direction.Down) != Block.Type.Empty || Collision(block.pos, Direction.Left) == block.type || Collision(block.pos, Direction.Right) == block.type) { block.DropEnd(); fixedGroups.Add(block.group); } } } foreach (Block.Group fixedGroup in fixedGroups) { Block firstMember = null; foreach (Block member in fixedGroup) { if (firstMember == null) { firstMember = member; } Fixed(member); } Block.Group reGroup = new Block.Group(this); reGroup.Grouping(firstMember); if (reGroup.Count >= 4) { foreach (Block member in reGroup) { member.BlinkStart(this.blinkTime); } } } this.unbalanceBlocks.RemoveAll(delegate(Block block) { return(!block.unbalance); }); }
void Update() { // check // for (int row = 0; row < this.numBlockRows; row++) { // for (int col = 0; col < this.numBlockCols; col++) { // Block.Type type = this.hitTable[row, col]; // Block block = this.fixedBlocks[row, col]; // block.type = type; // } // } foreach (Block block in this.fixedBlocks) { if (block == null) continue; if (block.blinking && !block.BlinkNext()) { RemoveAtPos(block.pos); } } HashSet<Block.Group> fixedGroups = new HashSet<Block.Group>(); foreach (Block block in this.unbalanceBlocks) { if (!block.unbalance) continue; if (block.shaking && !block.ShakeNext()) { UnFixed(block); } else if (block.dropping) { block.DropNext(); if (Collision(block.pos, Direction.Down) != Block.Type.Empty || Collision(block.pos, Direction.Left) == block.type || Collision(block.pos, Direction.Right) == block.type) { block.DropEnd(); fixedGroups.Add(block.group); } } } foreach (Block.Group fixedGroup in fixedGroups) { Block firstMember = null; foreach (Block member in fixedGroup) { if (firstMember == null) firstMember = member; Fixed(member); } Block.Group reGroup = new Block.Group(this); reGroup.Grouping(firstMember); if (reGroup.Count >= 4) { foreach (Block member in reGroup) { member.BlinkStart(this.blinkTime); } } } this.unbalanceBlocks.RemoveAll(delegate(Block block) { return !block.unbalance; }); }
// Use this for initialization void Start() { // Grouping all for (int row = 0; row < this.numBlockRows; row++) { for (int col = 0; col < this.numBlockCols; col++) { if (this.hitTable[row, col] == Block.Type.Empty) continue; Block block = this.fixedBlocks[row, col]; if (block.group != null) continue; Block.Group group = new Block.Group(this); group.Grouping(block); } } this.playerObj = GameObject.Find("Player"); this.player = playerObj.GetComponent<Player>(); }