public void Init() { if (_lock == null) { _lock = new Object(); } m_level = GamePlaying.Instance().currentLevel; m_resource = ResourceMgr.Instance(); speed = 0.005f; moveSpeed = -speed; canLink = true; isLoadDone = false; usingPropID = GamePropsId.None; isUsingProp = false; m_CanTouch = true; boxPanelW = m_level.width * ConstValue.BoxWidth; boxPanelH = m_level.height * ConstValue.BoxHeight; Debug.Log("boxPanelWH:" + boxPanelW + "," + boxPanelH); transform.position = new Vector3(0, ScreenInfo.h / 2 - ConstValue.BoxHeight * visibleRow + boxPanelH / 2, 0); background = Instantiate(m_resource.GetResFromName(ConstValue.GAME_BACKGROUND), new Vector3(10f, 10f, 0), Quaternion.identity) as GameObject; background.transform.parent = transform; boxManager = BoxManager.GetInstance(); boxManager.Init(); bottomRow = m_level.height - 1; InitBoxs(bottomRow, visibleRow); GetBottomBox(); }
void Explode() { gameObject.SetActive(false); exp = GameObject.Instantiate(ResourceMgr.Instance().GetResFromName(ConstValue.GAME_BOMB_EXP), transform.position, Quaternion.identity) as GameObject; ParticleSystem ps = exp.GetComponent <ParticleSystem>(); ps.Play(); Invoke("DestoryExp", 1f); List <ComBox> neighborBoxs = BoxManager.GetInstance().GetNeighborBoxs(box); box.Explode(); foreach (ComBox comBox in neighborBoxs) { comBox.Explode(); } GamePlaying.Instance().boxPanel.CheckPanelState(); GamePlaying.Instance().boxPanel.BackMoveSpeed(); GamePlaying.Instance().isPlaying = true; GamePlaying.Instance().boxPanel.m_CanTouch = true; GamePlaying.Instance().boxPanel.isUsingProp = false; GamePlaying.Instance().boxPanel.usingPropID = GamePropsId.None; Messenger.Broadcast(ConstValue.MSG_USE_PROP_SUC, GamePropsId.Bomb); }
void Explode() { gameObject.SetActive(false); List <ComBox> sameBoxs = BoxManager.GetInstance().GetSameBoxs(box); box.Explode(); int c = sameBoxs.Count; if (c == 1) { sameBoxs[0].Explode(); } else if (c > 1) { int same = Random.Range(0, c); sameBoxs[same].Explode(); } GamePlaying.Instance().boxPanel.CheckPanelState(); GamePlaying.Instance().boxPanel.BackMoveSpeed(); GamePlaying.Instance().isPlaying = true; GamePlaying.Instance().boxPanel.m_CanTouch = true; GamePlaying.Instance().boxPanel.isUsingProp = false; GamePlaying.Instance().boxPanel.usingPropID = GamePropsId.None; Messenger.Broadcast(ConstValue.MSG_USE_PROP_SUC, GamePropsId.Same); Destroy(gameObject); }
public static GamePlaying Instance() { if (instance == null) { instance = new GamePlaying(); } return(instance); }
private void Awake() { _spriteRenderer = GetComponent <SpriteRenderer>(); _rigidbody2D = GetComponent <Rigidbody2D>(); _boxCollider2D = GetComponent <BoxCollider2D>(); _spriteRenderer.sprite = spriteAtlas.GetSprite($"{itemType.ToString()}_01"); _gamePlaying = null; }
// Update is called once per frame void FixedUpdate() { transform.position = new Vector3(transform.position.x, transform.position.y + speed, transform.position.z); if (transform.position.y > ScreenInfo.h / 2) { Destroy(gameObject); GamePlaying.Instance().boxPanel.BackMoveSpeed(); GamePlaying.Instance().isPlaying = true; GamePlaying.Instance().boxPanel.m_CanTouch = true; GamePlaying.Instance().boxPanel.isUsingProp = false; GamePlaying.Instance().boxPanel.usingPropID = GamePropsId.None; Messenger.Broadcast(ConstValue.MSG_USE_PROP_SUC, GamePropsId.Shock); } }
void DestoryTrail() { CancelInvoke("DestoryBox"); Destroy(leftTrail); Destroy(rightTrail); Destroy(gameObject); GamePlaying.Instance().boxPanel.CheckPanelState(); GamePlaying.Instance().boxPanel.BackMoveSpeed(); GamePlaying.Instance().isPlaying = true; GamePlaying.Instance().boxPanel.m_CanTouch = true; GamePlaying.Instance().boxPanel.isUsingProp = false; GamePlaying.Instance().boxPanel.usingPropID = GamePropsId.None; Messenger.Broadcast(ConstValue.MSG_USE_PROP_SUC, GamePropsId.Rocket); }
void UsingProp(ComBox hitBox) { GamePlaying.Instance().isPlaying = true; m_CanTouch = false; background.transform.localPosition = new Vector3(10f, 10f, 0f); switch (usingPropID) { case GamePropsId.Bomb: SetMoveSpeed(0f); GameObject bomb = Instantiate(m_resource.GetResFromName(ConstValue.GAME_PROP_BOMB), Vector3.zero, Quaternion.identity) as GameObject; bomb.transform.parent = transform; bomb.transform.localPosition = hitBox.gameObject.transform.localPosition; bomb.GetComponent <PropBomb>().Init(hitBox); break; case GamePropsId.Rocket: SetMoveSpeed(0f); GameObject rocket = Instantiate(m_resource.GetResFromName(ConstValue.GAME_PROP_ROCKET), Vector3.zero, Quaternion.identity) as GameObject; rocket.transform.parent = transform; rocket.transform.localPosition = hitBox.gameObject.transform.localPosition; rocket.GetComponent <PropRocket>().Init(hitBox); break; case GamePropsId.Shock: GameObject shock = Instantiate(m_resource.GetResFromName(ConstValue.GAME_PROP_SHOCK), Vector3.zero, Quaternion.identity) as GameObject; shock.transform.parent = transform; shock.transform.position = new Vector3(0f, -ScreenInfo.h / 2 + ConstValue.BOTTOM_BAN_HEIGHT, 0f); SetMoveSpeed(0.2f); Invoke("BackMoveSpeed", 0.5f); break; case GamePropsId.Same: SetMoveSpeed(0f); GameObject same = Instantiate(m_resource.GetResFromName(ConstValue.GAME_PROP_SAME), Vector3.zero, Quaternion.identity) as GameObject; same.transform.parent = transform; same.transform.localPosition = hitBox.gameObject.transform.localPosition; same.GetComponent <PropSame>().Init(hitBox); break; } }
void StartGame() { Debug.Log("start " + ConstValue.level); Target.GetFSM().ChangeState(GamePlaying.Instance()); }
public void SetGamePlaying(GamePlaying gamePlaying) { _gamePlaying = gamePlaying; }
void Start() { gameManager = GameManager.instance; game = this; }
public void Init() { m_BoxList.Clear(); levelWidth = GamePlaying.Instance().currentLevel.width; levelHeight = GamePlaying.Instance().currentLevel.height; }
List <Vector2> CheckThreePoint(int oneX, int oneY, int twoX, int twoY) { bool left = true, right = true, up = true, down = true; int len = Math.Max(levelWidth, levelHeight); List <Vector2> list = new List <Vector2>(); int j; Vector2 temV; for (int i = 1; i < len - 1; i++) { if (left) { j = oneX - i; if (j < 0 || this[j, oneY] != null) { left = false; } else { temV = CheckTwoPoint(j, oneY, twoX, twoY); if (temV.x > -1) { list.Add(new Vector2(j, oneY)); list.Add(temV); return(list); } } } if (right) { j = oneX + i; if (j > levelWidth - 1 || this[j, oneY] != null) { right = false; } else { temV = CheckTwoPoint(j, oneY, twoX, twoY); if (temV.x > -1) { list.Add(new Vector2(j, oneY)); list.Add(temV); return(list); } } } if (up) { j = oneY - i; if (j < GamePlaying.Instance().boxPanel.topRow || this[oneX, j] != null) { up = false; } else { temV = CheckTwoPoint(oneX, j, twoX, twoY); if (temV.x > -1) { list.Add(new Vector2(oneX, j)); list.Add(temV); return(list); } } } if (down) { j = oneY + i; if (j > GamePlaying.Instance().boxPanel.bottomRow || this[oneX, j] != null) { down = false; } else { temV = CheckTwoPoint(oneX, j, twoX, twoY); if (temV.x > -1) { list.Add(new Vector2(oneX, j)); list.Add(temV); return(list); } } } if (!left && !right && !up && !down) { break; } } return(null); }