public void Bomb() { GameObject go = hittedPart[hittedPart.Count - 1].transform.parent.gameObject; WholeCircle wc = go.GetComponent <WholeCircle>(); wc.Bomb(); SFXManager.Instance.PlaySFX(SFXEnum.bomb); Camera.main.GetComponent <FollowTarget>().ShakeCamera(); }
void GenerateScreen(int hardness) { List <GameObject> thisGeneratedList = new List <GameObject>(); if (generatedList.Count > 4) { generatedList.RemoveRange(0, generatedList.Count - 4); } for (int index = 0; index < 10; index++) { currentGeneratedY += 0.1f; float rateToGenerateCircle = Mathf.Pow(multiplierWhenDidntGenerateLastTime, emptyLineNumber) * originGenerateCircleRate; float rand = Random.Range(0, 1.0f); if (rand < rateToGenerateCircle) { emptyLineNumber = 0; //generate multiple in one line rand = Random.Range(0, sumOfGenerateNum); int generateNum = 3; if (rand <= rateToGenerateNumber[0]) { generateNum = 1; } else if (rand <= rateToGenerateNumber[0] + rateToGenerateNumber[1]) { generateNum = 2; } float randXValueLength = 1.6f * widthScale / (float)generateNum; float randXValueStart = -0.8f * widthScale; for (int num = 0; num < generateNum; num++) { float randXValue = Random.Range(randXValueStart + randXValueLength * num, randXValueStart + randXValueLength * (num + 1)); Vector3 willGeneratePosition = new Vector3(randXValue, currentGeneratedY * heightScale, 0f); //check collide with others bool shouldSkip = false; int checkNum = Mathf.Min(generatedList.Count, 4); for (int cn = 1; cn <= checkNum; cn++) { GameObject checkObject = generatedList[generatedList.Count - cn]; if (Vector3.Distance(checkObject.transform.position, willGeneratePosition) <= 1.5f) { shouldSkip = true; break; } } if (shouldSkip) { continue; } GameObject go = CachePoolManager.Instance.getCircle(); go.SetActive(true); go.transform.position = willGeneratePosition; WholeCircle wc = go.GetComponentInChildren <WholeCircle>(); //put these inside wholeCircle wc.itemObject.SetActive(false); //test only //wc.monsterObject.SetActive(false); wc.monsterObject.SetActive(true); Monster monster2 = wc.monsterObject.GetComponent <Monster>(); string monsterIdentifier = LevelManager.Instance.GenerateAMonsterIdentifier(); monster2.Init(MonsterManager.Instance.GetMonsterInfoByIdentifier(monsterIdentifier)); wc.ReactiveChildren(); wc.willChange = false; Rotator rt = go.GetComponentInChildren <Rotator>(); generatedList.Add(go); thisGeneratedList.Add(go); //decide if this circle is a change circle or block circle float rateToGenerateWillChangeCircle = Mathf.Pow(multiplierWHenDidntGenerateChangeCircle, noChangeCircleNumber) * originGenerateChangeCircleRate; rand = Random.Range(0, 1.0f); if (rand < rateToGenerateWillChangeCircle) { noChangeCircleNumber = 0; wc.willChange = true; rand = Random.Range(0, 4); GameColorEnum c1 = (GameColorEnum)((rand + 1) % 4); GameColorEnum c2 = (GameColorEnum)((rand + 2) % 4); GameColorEnum c3 = (GameColorEnum)((rand + 3) % 4); wc.SetColor(new GameColorEnum[] { c1, c2, c3, (GameColorEnum)rand }); } else { noChangeCircleNumber++; wc.willChange = false; //random to decide what color can pass block rand = Random.Range(0, sumOfNumberOfColorOfBLockCirlcle); if (rand <= rateOfNumberOfColorOfBlockCircle[0])//1 color { rand = Random.Range(0, 4); GameColorEnum c = (GameColorEnum)rand; wc.SetColor(new GameColorEnum[] { c, c, c, c }); } else if (rand <= rateOfNumberOfColorOfBlockCircle[0] + rateOfNumberOfColorOfBlockCircle[1])//2 color { rand = Random.Range(0, 4); GameColorEnum c = (GameColorEnum)rand; int rand2 = Random.Range(0, 3); GameColorEnum c2 = (GameColorEnum)((rand + rand2) % 4); wc.SetColor(new GameColorEnum[] { c, c, c2, c2 }); } else if (rand <= rateOfNumberOfColorOfBlockCircle[0] + rateOfNumberOfColorOfBlockCircle[1] + rateOfNumberOfColorOfBlockCircle[2])//1 color { rand = Random.Range(0, 4); GameColorEnum c1 = (GameColorEnum)((rand + 1) % 4); GameColorEnum c2 = (GameColorEnum)((rand + 2) % 4); GameColorEnum c3 = (GameColorEnum)((rand + 3) % 4); wc.SetColor(new GameColorEnum[] { c1, c2, c3, c3 }); } else { rand = Random.Range(0, 4); GameColorEnum c1 = (GameColorEnum)((rand + 1) % 4); GameColorEnum c2 = (GameColorEnum)((rand + 2) % 4); GameColorEnum c3 = (GameColorEnum)((rand + 3) % 4); wc.SetColor(new GameColorEnum[] { c1, c2, c3, (GameColorEnum)rand }); } } //decide the ratate speed of the circle,randge is (-100,-50)and(50,100) rand = Random.Range(-50, 50); rand += (rand > 0 ? 50 : -50); rt.speed = rand; } } else { emptyLineNumber++; } } //int rand3 = Random.Range(0, thisGeneratedList.Count); //GameObject go2 = thisGeneratedList[rand3]; //WholeCircle wc2 = go2.GetComponentInChildren<WholeCircle>(); //wc2.itemObject.SetActive(true); //GameItem gameItem = wc2.itemObject.GetComponent<GameItem>(); //gameItem.itemEnum = (GameItemEnum)Random.Range(0, (int)GameItemEnum.random+1); //gameItem.Init(); //int rand3 = Random.Range(0, thisGeneratedList.Count); //GameObject go2 = thisGeneratedList[rand3]; //WholeCircle wc2 = go2.GetComponentInChildren<WholeCircle>(); //wc2.monsterObject.SetActive(true); //Monster monster = wc2.monsterObject.GetComponent<Monster>(); //monster.Init(2,2); }
// Update is called once per frame void Update() { if (GameLogicManager.Instance.isPaused) { return; } //#if !UNITY_EDITOR if (Input.touchCount == 1) { Touch touch = Input.GetTouch(0); if (touch.phase != TouchPhase.Began) { return; } //Your raycast handling Vector3 mousePosition = touch.position; //CSUtil.LOG("screen touched " + mousePosition); mousePosition = new Vector3(mousePosition.x, mousePosition.y, 10); RaycastHit2D[] vHits = Physics2D.RaycastAll(Camera.main.ScreenToWorldPoint(mousePosition), Vector2.zero); foreach (RaycastHit2D vhit in vHits) { if (vhit.transform.tag == "wholeCircle") { (GameLogicManager.Instance.player).MoveToTarget(vhit.collider.gameObject); } } } //#endif if (Input.GetMouseButtonDown(0)) { // Your raycast handling Vector3 mousePosition = Input.mousePosition; //CSUtil.LOG("mouse click " + mousePosition); mousePosition = new Vector3(mousePosition.x, mousePosition.y, 10); RaycastHit2D[] vHits = Physics2D.RaycastAll(Camera.main.ScreenToWorldPoint(mousePosition), Vector2.zero); foreach (RaycastHit2D vhit in vHits) { WholeCircle wc = vhit.transform.GetComponent <WholeCircle>(); if (wc) { if (wc.isActive()) { if (GameLogicManager.Instance.player.MoveToTarget(vhit.collider.gameObject)) { lastPosition = GameLogicManager.Instance.player.transform.position; } } else { // CSUtil.LOG("this circle is invisible!"); //achievement: invisible target } } } } if (Input.GetMouseButtonDown(1)) { //TODO: add a cheat class for this if (GameLogicManager.Instance.player.cheatDontDie) { GameLogicManager.Instance.player.transform.position = lastPosition; GameLogicManager.Instance.player.resetHittedPart(); } } }