public bool HitBy(IHitter hitter) { if (this.State == BrickState.Dead) { return(false); } Rectangle r1 = new Rectangle(this.Location, this.Size); Control c = (Control)hitter; Rectangle r2 = new Rectangle(c.Location, c.Size); bool hit = r1.IntersectsWith(r2); // TODO: 實作磚塊被球打到的反應 if (hit && hitter is Ball) { switch (this.State) { case BrickState.Normal: this.State = BrickState.Falling; break; case BrickState.Falling: this.State = BrickState.Floating; break; case BrickState.Floating: this.State = BrickState.Falling; break; } } return(hit); }
private void Fall2Physics() { if (m_BrickState == BrickState.Falling) { m_BrickState = BrickState.Physics; //使用物理模拟 if (CollisionEnterEvent != null) { CollisionEnterEvent(); } //碰撞trigger不激活 foreach (var collider in AllChildCollider) { collider.gameObject.SetActive(false); } m_Rigidbody.gravityScale = 2; if (CollisionWithDown) { //播放方块碰撞音效 int SfxIndex = UnityEngine.Random.Range(1, 4); string SfxString = "Sfx_BrickLandSpring0" + SfxIndex.ToString(); AudioManager.instance.PlaySfx(SfxString); } } }
public Brick(int x, int y, Camera cam, BrickState s) { xPosition = x; yPosition = y; camera = cam; state = s; switch (s) { case BrickState.qempty: //this never happens in our level, but it's good to have in theory. BrickSprite = new Sprites.HitQBlockSprite(); break; case BrickState.bempty: case BrickState.bcoin: case BrickState.bstar: BrickSprite = new Sprites.TopBrickSprite(); break; case BrickState.destroyed: BrickSprite = null; break; default: BrickSprite = new Sprites.QBlockSprite(); break; } }
//设置砖块显示状态 void SetBrickState(BrickState brickState) { currentState = brickState; switch (brickState) { case BrickState.initial: brick.SetActive(true); monster.SetActive(false); equip.SetActive(false); break; case BrickState.monster: brick.SetActive(false); monster.SetActive(true); equip.SetActive(false); break; case BrickState.equip: brick.SetActive(false); monster.SetActive(false); equip.SetActive(true); break; case BrickState.Empty: brick.SetActive(false); monster.SetActive(false); equip.SetActive(false); break; } }
public Brick(int row, int column, float x, float y, float w, float h) { this.state = BrickState.ALIVE; this.row = row; this.column = column; this.bounds = new Rectangle((int)x, (int)y, (int)w, (int)h); }
private void CheckLeftBounds() { if (Position.x < -_maxXPosition) { Position.x = -_maxXPosition; _state = BrickState.MovingRight; } }
// Update is called once per frame void Update() { if (currentState == BrickState.Move) { transform.position = new Vector2(transform.position.x, transform.position.y - 1); currentState = BrickState.Stop; } }
private void CheckRightBounds() { if (Position.x > _maxXPosition) { Position.x = _maxXPosition; _state = BrickState.MovingLeft; } }
public void Awake() { if (Random.Range(0, 100) < 50) { _state = BrickState.MovingLeft; Position = new Vector3(-_maxXPosition, 0, 0); } else { _state = BrickState.MovingRight; Position = new Vector3(_maxXPosition, 0, 0); } }
private void Awake() { m_BrickState = BrickState.Falling; m_Pause = false; m_FallNomralSpeed = 5f; m_FallMaxSpeed = 25f; m_FallSpeed = m_FallNomralSpeed; m_Rigidbody = GetComponent <Rigidbody2D>(); AllChildCollider = new List <Collider2D>(); //收集方块所有碰撞体让它们忽略对方 for (int i = 0; i < transform.childCount; i++) { var collider = transform.GetChild(i).gameObject.GetComponent <CompositeCollider2D>(); if (collider != null) { AllChildCollider.Add(collider); } } for (int i = 0; i < transform.childCount; i++) { var collider = transform.GetChild(i).gameObject.GetComponent <BoxCollider2D>(); if (collider != null) { AllChildCollider.Add(collider); } } selfCollider = GetComponent <CompositeCollider2D>(); for (int i = 0; i < AllChildCollider.Count; i++) { Physics2D.IgnoreCollision(AllChildCollider[i], selfCollider); } for (int i = 0; i < AllChildCollider.Count - 1; i++) { for (int j = i + 1; j < AllChildCollider.Count; j++) { Physics2D.IgnoreCollision(AllChildCollider[i], AllChildCollider[j]); } } }
void SetBrickState(BrickState brickState) { this.brickState = brickState; switch (brickState) { case BrickState.Left: animator.SetTrigger("OnRightHit"); break; case BrickState.Right: animator.SetTrigger("OnLeftHit"); break; case BrickState.Top: animator.SetTrigger("OnBottomHit"); break; case BrickState.Bottom: animator.SetTrigger("OnTopHit"); break; } }
void IMovable.Move() { switch (this.State) { case BrickState.Normal: break; case BrickState.Falling: this.Top += 3; if (this.Top > this.Parent.ClientRectangle.Bottom) { this.State = BrickState.Dead; } break; case BrickState.Floating: this.Top -= 3; if (this.Top <= 0) { this.State = BrickState.Normal; } IHittable obj = HitOthers(); if (obj != null && obj is Brick) { this.State = BrickState.Normal; Control c = (Control)obj; this.Top = c.Bottom; } break; case BrickState.Dead: break; } }
//this is coupled with a few things it doesn't need to be. public void Hit(IList<IItem> items, bool isMario, bool isBig, HUD hud, SoundEffects sound) { switch (state) { case BrickState.bstar: sound.Popup(); IItem star = new Items.Star(xPosition, yPosition - 16, camera); items.Add(star); state = BrickState.qempty; BrickSprite = new Sprites.HitQBlockSprite(); break; case BrickState.bcoin: sound.Coin(); IItem c; //make the coin noise c = new Items.Coin(xPosition, yPosition - Constants.tileLength, camera); items.Add(c); if (isMario) { hud.increaseScoreMario(Constants.brokenBrickValue); hud.addCoinMario(); } else { hud.increaseScoreLuigi(Constants.brokenBrickValue); hud.addCoinLuigi(); } state = BrickState.qempty; BrickSprite = new Sprites.HitQBlockSprite(); break; case BrickState.bempty: if (isBig) { sound.BreakBlock(); if (isMario) { hud.increaseScoreMario(Constants.brokenBrickValue); } else { hud.increaseScoreLuigi(Constants.brokenBrickValue); } state = BrickState.destroyed; BrickSprite = null; } break; case BrickState.qitem: IItem i; sound.Popup(); if (!isBig) { i = new Items.Mushroom(xPosition, yPosition - Constants.tileLength, camera); } else { i = new Items.Fireflower(xPosition, yPosition - Constants.tileLength, camera); } items.Add(i); state = BrickState.qempty; BrickSprite = new Sprites.HitQBlockSprite(); break; case BrickState.qlife: items.Add(new Items.Oneup(xPosition, yPosition - Constants.tileLength, camera)); state = BrickState.qempty; BrickSprite = new Sprites.HitQBlockSprite(); break; case BrickState.qcoin: sound.Coin(); //make the coin noise c = new Items.Coin(xPosition, yPosition - Constants.tileLength, camera); items.Add(c); if (isMario) { hud.increaseScoreMario(Constants.brokenBrickValue); hud.addCoinMario(); } else { hud.increaseScoreLuigi(Constants.brokenBrickValue); hud.addCoinLuigi(); } state = BrickState.qempty; BrickSprite = new Sprites.HitQBlockSprite(); break; default: break; } }
private Animation GetValue(object obj, BrickState key) { var dictionary = Reflection.GetPrivateField <Dictionary <BrickState, Animation> >(component, "dynamicStates"); return(dictionary[key]); }
// Use this for initialization void Start() { currentState = BrickState.Stop; }
public Brick() { this.State = BrickState.Normal; }
public void StopBrick() { _state = BrickState.Stopped; }
public Brick(int row, int column, float x, float y, float w, float h) { this.state = BrickState.ALIVE; this.row = row; this.column = column; this.bounds = new Rectangle((int) x, (int) y, (int) w, (int) h); }