/// <summary> /// 随机出一个木块 /// </summary> public void CreateOneBlock() { while (true) { int x = Random.Range(0, field.width); int y = Random.Range(0, field.height); if (field.GetSlot(x, y)) { int id = field.GetChip(x, y); if (id >= 0 && id != 9 && (field.blocks[x, y] == 0 || field.blocks[x, y] == 5)) { Slot s = SlotManager.Instance.FindSlot(x, y); if (s != null && s.GetChip() && !s.Block && !s.IsGenerator) { s.GetChip().HideChip(false); field.blocks[x, y] = 1; GameObject o = ResourceMgr.Instance.LoadAndInstanceGameObjectFromPreload(Block.prefabName); o.name = "Block_" + x + "x" + y; // o.transform.parent = s.transform; o.transform.SetParent(s.transform, false); o.transform.position = s.transform.position; Block b = o.GetComponent <Block>(); s.SetBlock(b); b.slot = s; b.level = field.blocks[x, y]; b.Initialize(); break; } } } } }
/// <summary> /// 生成两个无法消除木块 /// </summary> public void CreateNotDestroyableBlcok() { int createCount = 2; while (createCount > 0) { int x = Random.Range(0, field.width); int y = Random.Range(0, field.height); if (field.GetSlot(x, y)) { Slot s = SlotManager.Instance.FindSlot(x, y); if (s == null || s.IsGenerator) { continue; } int blockId = field.blocks[x, y]; if (blockId >= 6 && blockId <= 10) { //boss continue; } field.blocks[x, y] = 10; if (s.GetChip()) { s.GetChip().HideChip(false); } // else if(s.Block) // { // s.SetBlock(null); // s.gameObject.SetActive(false); // } s = SlotManager.Instance.FindSlot(x, y); GameObject o = ResourceMgr.Instance.LoadAndInstanceGameObjectFromPreload(FightDefine.SpecialBlock); o.transform.position = s.transform.position; o.name = "SpecialBlock_" + x + "x" + y; // o.transform.parent = s.transform; o.transform.SetParent(s.transform, false); o.transform.position = s.transform.position; SpecialBlock boss = o.GetComponent <SpecialBlock>(); s.SetBlock(boss); boss.slot = s; boss.Initialize(); s.gameObject.SetActive(false); createCount--; } } }
public void Swap(Slot slot, Side side) { if (slot == null || slot.GetChip() == null || slot[side] == null || slot[side].GetChip() == null) { //没有相邻卡 return; } AnimationControl.Instance.SwapTwoItem(slot.GetChip(), slot[side].GetChip(), false); }
// Shadow can also discard the other chips - it's a different kind of shadow. public bool GetChipShadow() { Side direction = slotGravity.fallingDirection; Slot s = nearSlot[direction]; for (int i = 0; i < 40; i++) { if (!s) { return(false); } if (!s.gravity) { return(false); } if (!s.GetChip() || s.slotGravity.gravityDirection != direction) { direction = s.slotGravity.fallingDirection; s = s.nearSlot[direction]; } else { return(true); } } return(false); }
public static bool Freez(int x, int y) { Slot s = SlotManager.Instance.FindSlot(x, y); if (s && s.GetChip() && s.GetChip().destroyable&& !(s.Block != null && s.Block is Branch)) { s.GetChip().can_move = false; } if (FieldAssistant.Instance.field == null) { return(false); } else { return(x >= 0 && y >= 0 && x < FieldAssistant.Instance.field.width && y < FieldAssistant.Instance.field.height); } }
void Update() { if (!TargetSlot) { return; // Teleport is possible only if target is exist } if (!SessionControl.Instance.CanIGravity()) { return; // Teleport is possible only in case of mode "gravity" } if (!slot.GetChip()) { return; // Teleport is possible only if slot contains chip } if (!slot.GetChip().can_move) { return; // If chip can't be moved, then it can't be teleported } if (TargetSlot.GetChip()) { return; // Teleport is impossible if target slot already contains chip } if (slot.Block) { return; // Teleport is impossible, if the slot is blocked } if (TargetSlot.Block) { return; // Teleport is impossible, if the target slot is blocked } if (slot.GetChip().transform.position != slot.transform.position) { return; } if (lastTime + delay > Time.time) { return; // limit of frequency generation } lastTime = Time.time; AnimationControl.Instance.TeleportChip(slot.GetChip(), TargetSlot); }
public static void Grow() { List <Slot> slots = new List <Slot> (); foreach (Weed weed in all) { foreach (Side side in Utils.straightSides) { if (weed.slot[side] && !weed.slot[side].Block && !(weed.slot[side].GetChip() && weed.slot[side].GetChip().chipType == "SugarChip")) { slots.Add(weed.slot[side]); } } } while (seed > 0) { if (slots.Count == 0) { return; } Slot target = slots[Random.Range(0, slots.Count)]; slots.Remove(target); if (target.GetChip()) { target.GetChip().HideChip(false); } Weed newWeed = ResourceMgr.Instance.LoadAndInstanceGameObjectFromPreload(prefabName).GetComponent <Weed>(); newWeed.transform.position = target.transform.position; newWeed.name = "New_Weed"; newWeed.transform.SetParent(target.transform, false); target.SetBlock(newWeed); newWeed.slot = target; // AudioAssistant.Shot("WeedCreate"); newWeed.Initialize(); seed--; } }
public void Update() { if (this.Slot == null) { return; } if (!SessionControl.Instance.enabled) { return; } if (!SessionControl.Instance.CanIGravity()) { return; // Generation is possible only in case of mode "gravity" } if (Slot.GetChip()) { return; // Generation is impossible, if slot already contains chip } if (Slot.Block != null) { return; // Generation is impossible, if the slot is blocked } if (lastTime + delay > Time.time) { return; // limit of frequency generation } lastTime = Time.time; Vector3 spawnOffset = new Vector3( Utils.SideOffsetX(Utils.MirrorSide(Slot.slotGravity.gravityDirection)), Utils.SideOffsetY(Utils.MirrorSide(Slot.slotGravity.gravityDirection)), 0) * 0.4f; // if (LevelProfile.CurrentLevelProfile.target == E_FieldTarget.SugarDrop && SessionAssistant.main.creatingSugarDropsCount > 0) { // if (SugarChip.live_count == 0 || SessionAssistant.main.GetResource() <= 0.4f + 0.6f * SessionAssistant.main.creatingSugarDropsCount / LevelProfile.CurrentLevelProfile.targetSugarDropsCount) { // SessionAssistant.main.creatingSugarDropsCount--; // FieldAssistant.main.GetSugarChip(slot.x, slot.y, transform.position + spawnOffset); // creating new sugar chip // return; // } // } if (Random.value > LevelProfile.CurrentLevelProfile.StonePortion) { FieldAssistant.Instance.GetNewSimpleChip(Slot.Row, Slot.Col, Slot.transform.position + spawnOffset); // creating new chip } else { FieldAssistant.Instance.GetNewStone(Slot.Row, Slot.Col, Slot.transform.position + spawnOffset); // creating new stone } }
public static bool Crush(int x, int y) { Slot s = SlotManager.Instance.FindSlot(x, y); FieldAssistant.Instance.BlockCrush(x, y, false, true); // FieldAssistant.main.JellyCrush(x, y); if (s && s.GetChip()) { Card c = s.GetChip(); // c.SetScore(0.3f); c.DestroyChip(); // DebugUtil.Info("==== explode begin:" + s.key + "," + s.transform.localPosition); AnimationControl.Instance.Explode(s.transform.localPosition, 160, 10); } if (FieldAssistant.Instance.field == null) { return(false); } else { return(x >= 0 && y >= 0 && x < FieldAssistant.Instance.field.width && y < FieldAssistant.Instance.field.height); } }
IEnumerator TeleportChipRoutine(Card chip, Slot target) { if (!chip.parentSlot) { yield break; } if (chip.destroying) { yield break; } if (target.GetChip() || !target.gravity) { yield break; } Vector3 scale_target = Vector3.zero; chip.can_move = false; target.SetChip(chip); scale_target.z = 1; while (chip != null && chip.transform.localScale.x > 0) { chip.transform.localScale = Vector3.MoveTowards(chip.transform.localScale, scale_target, Time.deltaTime * 8); yield return(0); } chip.transform.localPosition = Vector3.zero; scale_target.x = 1; scale_target.y = 1; while (chip != null && chip.transform.localScale.x < 1) { chip.transform.localScale = Vector3.MoveTowards(chip.transform.localScale, scale_target, Time.deltaTime * 12); yield return(0); } if (chip != null) { chip.can_move = true; } //Chip new_chip = Instantiate(chip.gameObject).GetComponent<Chip>(); //new_chip.parentSlot = null; //new_chip.transform.position = target.transform.position; //target.SetChip(new_chip); //chip.HideChip(false); }