// Handle moving egg void UpdateBulletEggPosition() { Vector3 newPosition = bulletEgg.transform.position + currentShootingDir * 9999.0f; float step = Time.deltaTime * BULLET_SPEED; bulletEgg.transform.position = Vector3.MoveTowards(bulletEgg.transform.position, newPosition, step); if (bulletEgg.transform.position.x <= 0.0f) // Hit left wall { bulletEgg.transform.position = new Vector3 (0.0f, bulletEgg.transform.position.y, bulletEgg.transform.position.z); // weird hanging outside bound bug currentShootingDir = Vector3.Reflect(currentShootingDir, Vector3.right); } else if (bulletEgg.transform.position.x >= 5.0f) // Hit right wall { bulletEgg.transform.position = new Vector3 (5.0f, bulletEgg.transform.position.y, bulletEgg.transform.position.z); // weird hanging outside bound bug currentShootingDir = Vector3.Reflect(currentShootingDir, Vector3.left); } // special case, egg has gone to the top if (bulletEgg.transform.position.y > 0f) { SetState(STATE.IDLE); randomEgg = true; bulletEgg.SetActive(false); Playfield.Instance().AttachEggOnGrid(null, bulletEgg); bulletEgg.transform.position = gameObject.transform.position; // reset position } }
void HandleTouchUp(Vector2 touch) { if (Playfield.Instance().GetDragonState() == Playfield.PLAYER_DRAGON_STATE.RELOAD_MOVE_TO_SHOOTER || Playfield.Instance().GetDragonState() == Playfield.PLAYER_DRAGON_STATE.RELOAD_MOVE_TO_WAREHOUSE) { return; } if (!mIsSwapping) { Vector3 position = mainCamera.ScreenToWorldPoint(touch); position = new Vector3(position.x, position.y, 0.0f); // reset Z = 0 if (position.y <= -6.5f) { return; } currentShootingDir = CalculateDirection(position).normalized; bulletEgg.SetActive(true); bulletEgg.GetComponent <Bullet>().SetColor(mColor); SetColor((int)Defines.COLOR.NONE); SetState(STATE.SHOOTING); mCrossbowObject.GetComponent <SpriteRenderer>().sprite = mCrossbowShoot; AudioManager.Instance().PlaySFXShot(); } else { mIsSwapping = false; } }
void HandleTouchUpRight(Vector2 touch) { if (Playfield.Instance().GetDragonState() == Playfield.PLAYER_DRAGON_STATE.RELOAD_MOVE_TO_SHOOTER || Playfield.Instance().GetDragonState() == Playfield.PLAYER_DRAGON_STATE.RELOAD_MOVE_TO_WAREHOUSE) { return; } Playfield.Instance().SwapEgg(); }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.name == "LimitBottom" && gameObject.name == "FallenEgg") { gameObject.SetActive(false); } else if (collision.tag == "Rope" && gameObject.name != "FallenEgg") { Debug.Log("GameOver"); Playfield.Instance().SetState(Playfield.STATE.GAMEOVER); } }
void HandleTouchDown(Vector2 touch) { if (Playfield.Instance().GetDragonState() == Playfield.PLAYER_DRAGON_STATE.RELOAD_MOVE_TO_SHOOTER || Playfield.Instance().GetDragonState() == Playfield.PLAYER_DRAGON_STATE.RELOAD_MOVE_TO_WAREHOUSE) { return; } Vector3 position = mainCamera.ScreenToWorldPoint(touch); Vector2 test = new Vector2(position.x, position.y); if (mEggHolder.GetComponent <Collider2D>().OverlapPoint(test)) { mIsSwapping = true; Playfield.Instance().SwapEgg(); } }
public void Replay() { gameObject.SetActive(false); Playfield.Instance().ResetPlayfield(); }
// Update is called once per frame void Update() { if (Playfield.Instance().IsHazardState(Playfield.HAZARD_STATUS.FROZEN)) { return; } float step = AIM_MOVE_SPEED * Time.deltaTime; mAimObject.transform.position = Vector3.MoveTowards(mAimObject.transform.position, mAimPositionUp.transform.position, step); if (mAimObject.transform.position == mAimPositionUp.transform.position) { mAimObject.transform.position = mAimPositionDown.transform.position; } if (randomEgg) { if (Playfield.Instance().GetDragonState() != Playfield.PLAYER_DRAGON_STATE.SPECIAL_FLASH) { Playfield.Instance().ReloadEgg(); } randomEgg = false; } if (IsState(STATE.SHOOTING)) { UpdateBulletEggPosition(); return; } if (Input.touches.Length > 0) { Touch touch = Input.touches[0]; if (touch.phase == TouchPhase.Began) { HandleTouchDown(touch.position); } else if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended) { HandleTouchUp(touch.position); } else if (touch.phase == TouchPhase.Moved) { HandleTouchMove(touch.position); } } else { if (Input.GetMouseButtonDown(0)) { mIsMouseDown = true; HandleTouchDown(Input.mousePosition); } else if (Input.GetMouseButtonUp(0)) { mIsMouseDown = false; HandleTouchUp(Input.mousePosition); } else if (mIsMouseDown) { HandleTouchMove(Input.mousePosition); } else if (Input.GetMouseButtonUp(1)) { HandleTouchUpRight(Input.mousePosition); //Special case for swap egg } } }