Example #1
0
        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);
        }
Example #2
0
    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);
            }
        }
    }
Example #3
0
 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;
     }
 }
Example #4
0
    //设置砖块显示状态
    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;
        }
    }
Example #5
0
 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);
 }
Example #6
0
 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;
     }
 }
Example #8
0
 private void CheckRightBounds()
 {
     if (Position.x > _maxXPosition)
     {
         Position.x = _maxXPosition;
         _state     = BrickState.MovingLeft;
     }
 }
Example #9
0
 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);
     }
 }
Example #10
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]);
            }
        }
    }
Example #11
0
    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;
        }
    }
Example #12
0
        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;
            }
        }
Example #13
0
        //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;
            }
        }
Example #14
0
    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;
 }
Example #16
0
 public Brick()
 {
     this.State = BrickState.Normal;
 }
Example #17
0
 public void StopBrick()
 {
     _state = BrickState.Stopped;
 }
Example #18
0
 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);
 }