Esempio n. 1
0
        public void Update(CAnimationObject _Object, int _WidthMap, int _HeightMap)
        {
            //if (_Object.Velocity.X > 0.0f)
            float _positionX;

            _positionX   = m_Position.X;
            m_Position.X = _Object.Position.X - viewSize.X / 2;


            if (m_Position.X >= _WidthMap - viewSize.X)  // điểm dừng trong con mario
            {
                m_Position.X = _WidthMap - viewSize.X;
            }

            m_Position.Y = _Object.Position.Y - viewSize.Y / 3;

            if (m_Position.Y >= _HeightMap - viewSize.Y)
            {
                m_Position.Y = _HeightMap - viewSize.Y;
            }
            if (m_Position.Y <= 0.0f)
            {
                m_Position.Y = 0;
            }

            if (m_Position.X < 0)
            {
                m_Position.X = 0;
            }

            if (_Object.Position.X < m_Position.X)
            {
            }
            GlobalValue.CAMERA_RECTANGLE = new Rectangle((int)m_Position.X, (int)m_Position.Y, (int)viewSize.X, (int)viewSize.Y);
        }
 public override void UpdateCollision(CAnimationObject _Object)
 {
     if (CheckCollision(_Object) != DirectCollision.NONE && m_Status != IDStatus.UNACTIVATE)
     {
         switch (_Object.IDObject)
         {
             case IDObject.MISC_IRON_BRICK:
             case IDObject.MISC_BASE_BRICK:
             case IDObject.MISC_HARD_BRICK:
                 if (CheckCollision(_Object) == DirectCollision.TOP)
                 {
                     m_Velocity.Y = 0.0f;
                     m_Position.Y = _Object.Position.Y - Sprite.FrameHeight;
                 }
                 else if (CheckCollision(_Object) == DirectCollision.RIGHT)
                 {
                     m_Dir = IDDir.RIGHT;
                 }
                 else if (CheckCollision(_Object) == DirectCollision.LEFT)
                 {
                     m_Dir = IDDir.LEFT;
                 }
                 else if (CheckCollision(_Object) == DirectCollision.BOTTOM)
                 {
                     m_Velocity.Y = -m_Velocity.Y;
                 }
                 break;
             default:
                 break;
         }
     }
     base.UpdateCollision(_Object);
 }
 public QuestionBrick_1(Vector2 _Position, IDObject _IDItem)
     : base(_Position)
 {
     m_IDObject = IDObject.MISC_QUESTION_BRICK;
     m_Sprite = new CSprite(CResourceManager.GetInstance().GetResource(IDResource.MISC_QUESTION_BRICK));
     m_Status = IDStatus.ALIVE;
     Sprite.Depth = GlobalValue.MISC_SPRITE_DEPTH;
     switch (_IDItem)
     {
         case IDObject.ITEM_COIN_ACTIVATED:
             m_Item = new ItemCoin(_Position, _IDItem);
             break;
         case IDObject.ITEM_GROW_UP:
             m_Item = new ItemGrowUp(_Position);
             //m_Item = new CAnimationObject(_Position);
             break;
         case IDObject.ITEM_1UP_MUSHROOM:
             m_Item = new Item1UpMushroom(_Position);
             //m_Item = new GreenMushroom(_Position);
             break;
         case IDObject.ITEM_STARMAN:
             m_Item = new ItemStarman(_Position);
             break;
         default:
             break;
     }
 }
Esempio n. 4
0
        public void Update(CAnimationObject _Object, int _WidthMap, int _HeightMap)
        {
            //if (_Object.Velocity.X > 0.0f)
            float _positionX;
            _positionX = m_Position.X;
             m_Position.X = _Object.Position.X - viewSize.X / 2;

             if (m_Position.X >= _WidthMap - viewSize.X) // điểm dừng trong con mario
             {
                   m_Position.X = _WidthMap - viewSize.X;

             }

            m_Position.Y = _Object.Position.Y - viewSize.Y / 3;

            if (m_Position.Y >= _HeightMap - viewSize.Y)
                m_Position.Y = _HeightMap - viewSize.Y;
            if (m_Position.Y <= 0.0f)
                m_Position.Y = 0;

            if (m_Position.X < 0)
                m_Position.X = 0;

            if (_Object.Position.X < m_Position.X)
            {

            }
            GlobalValue.CAMERA_RECTANGLE = new Rectangle((int)m_Position.X, (int)m_Position.Y, (int)viewSize.X, (int)viewSize.Y);
        }
Esempio n. 5
0
 public override void UpdateCollision(CAnimationObject _Object)
 {
     if (CheckCollision(_Object) != DirectCollision.NONE)
     {
         if (_Object.IDObject == IDObject.MISC_HARD_BRICK)
         {
             Velocity = Vector2.Zero;
             Accel = Vector2.Zero;
         }
     }
     base.UpdateCollision(_Object);
 }
Esempio n. 6
0
 public override void UpdateCollision(CAnimationObject _Object)
 {
     //Console.WriteLine("aaaa");
     if ((_Object.IDObject == IDObject.FIRE_MARIO || _Object.IDObject == IDObject.SMALL_MARIO || _Object.IDObject == IDObject.SUPER_MARIO) && Status == IDStatus.TELEPORT)
     {
         _Object.Position = Portal;
         _Object.Status = IDStatus.MARIO_JUMP;
         _Object.Accel = new Vector2(0, 0.00098f);
         MediaPlayer.Resume();
         Status = IDStatus.NORMAL_GATE_PIPE;
     }
     base.UpdateCollision(_Object);
 }
 public override void UpdateCollision(CAnimationObject _Object)
 {
     if (CheckCollision(_Object) != DirectCollision.NONE)
     {
         switch (_Object.IDObject)
         {
             case IDObject.FIRE_MARIO:
             case IDObject.SMALL_MARIO:
             case IDObject.SUPER_MARIO:
                 Status = IDStatus.DIE;
                 break;
             default:
                 break;
         }
     }
     base.UpdateCollision(_Object);
 }
Esempio n. 8
0
        public override void UpdateCollision(CAnimationObject _Object)
        {
            if (CheckCollision(_Object) != DirectCollision.NONE)
            {
                switch (_Object.IDObject)
                {
                    case IDObject.MISC_BASE_BRICK:
                    case IDObject.MISC_IRON_BRICK:
                    case IDObject.MISC_QUESTION_BRICK:
                    case IDObject.MISC_STOCK_PIPE:
                    case IDObject.MISC_SOFT_BRICK:
                    case IDObject.MISC_GATE_PIPE:
                    case IDObject.MISC_HARD_BRICK:
                        if (CheckCollision(_Object) == DirectCollision.TOP && m_Status != IDStatus.SHOOTED)
                        {
                            m_Velocity.Y = 0.0f;
                            m_Position.Y = _Object.Position.Y - Sprite.FrameHeight;
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.RIGHT)
                        {
                            Direction = IDDir.RIGHT;
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.LEFT)
                        {
                            Direction = IDDir.LEFT;
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.BOTTOM)
                        {

                        }
                        break;
                    //case IDObject.MARIO_FIRE:
                    //    if(CheckCollision(_Object) == DirectCollision.BOTTOM)
                    //         m_Status = IDStatus.BEFORE_DIE;
                    //    break;
                    case IDObject.ENEMY_GOOMBA_OW:
                    case IDObject.ENEMY_KOOPA_OW:
                        //if ((CheckCollision(_Object) == DirectCollision.LEFT || CheckCollision(_Object) == DirectCollision.RIGHT) && _Object.Status == IDStatus.SPIN && Status != IDStatus.SHOOTED)
                        //{
                        //    CResourceManager.GetInstance().GetSoundEffect(IDResource.SFX_KICK).Play();
                        //   // _Object.Velocity = new Vector2(0, -0.2f);
                        //    m_Status = IDStatus.SHOOTED;
                        //}
                        if ((CheckCollision(_Object) == DirectCollision.LEFT || CheckCollision(_Object) == DirectCollision.RIGHT) && (_Object.Status == IDStatus.HIDE || _Object.Status == IDStatus.ALIVE))
                        {
                            if (CheckCollision(_Object) == DirectCollision.RIGHT)
                            {
                                Direction = IDDir.RIGHT;
                            }
                            if (CheckCollision(_Object) == DirectCollision.LEFT)
                            {
                                Direction = IDDir.LEFT;
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            base.UpdateCollision(_Object);
        }
 public override void SetItem(CAnimationObject _Item)
 {
     m_Item = _Item;
 }
 public override void UpdateCollision(CAnimationObject _Object)
 {
     base.UpdateCollision(_Object);
 }
Esempio n. 11
0
 virtual public void UpdateCollision(CAnimationObject _Object)
 {
 }
Esempio n. 12
0
 virtual public void SetItem(CAnimationObject _Item)
 {
 }
Esempio n. 13
0
 public virtual void UpdateCollision(CAnimationObject _Object)
 {
 }
Esempio n. 14
0
        public override void UpdateCollision(CAnimationObject _Object)
        {
            if (CheckCollision(_Object) != DirectCollision.NONE && Status != IDStatus.SHOOTED && _Object.Index != Index)
            {
                switch (_Object.IDObject)
                {
                    case IDObject.MISC_BASE_BRICK:
                    case IDObject.MISC_IRON_BRICK:
                    case IDObject.MISC_QUESTION_BRICK:
                    case IDObject.MISC_STOCK_PIPE:
                    case IDObject.MISC_SOFT_BRICK:
                    case IDObject.MISC_GATE_PIPE:
                    case IDObject.MISC_HARD_BRICK:
                        if (CheckCollision(_Object) == DirectCollision.TOP)
                        {
                            m_Velocity.Y = 0.0f;
                            m_Position.Y = _Object.Position.Y - m_Sprite.FrameHeight;
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.BOTTOM)
                        {

                        }
                        else if (CheckCollision(_Object) == DirectCollision.RIGHT)
                        {
                            m_Direction = IDDir.RIGHT;
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.LEFT)
                        {
                            m_Direction = IDDir.LEFT;
                            break;
                        }
                        break;
                    case IDObject.ENEMY_GOOMBA_OW:
                    case IDObject.ENEMY_KOOPA_OW:
                        if (CheckCollision(_Object) == DirectCollision.TOP)
                        {
                            m_Velocity.Y = 0.0f;
                            m_Position.Y = _Object.Position.Y - m_Sprite.FrameHeight;
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.BOTTOM)
                        {

                        }
                        else if (CheckCollision(_Object) == DirectCollision.RIGHT && Status != IDStatus.SPIN)
                        {
                            m_Direction = IDDir.RIGHT;
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.LEFT && Status != IDStatus.SPIN)
                        {
                            m_Direction = IDDir.LEFT;
                            break;
                        }
                        if (CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.LEFT && Status == IDStatus.SPIN)
                        {
                            _Object.Velocity = new Vector2(0, -0.2f);
                            _Object.Status = IDStatus.SHOOTED;
                            break;
                        }
                        break;
                    default:
                        break;
                }
            }
            //base.UpdateCollision(_Object);
        }
        public DirectCollision CheckCollision(CAnimationObject _Object)
        {
            #region. Thuật toán sweptAABB cũ
            //float DisMinX, DisMaxX;
            //float DisMinY, DisMaxY;

            //Vector2 tempVelocity;
            //tempVelocity = new Vector2(m_Velocity.X - _Object.Velocity.X, m_Velocity.Y - _Object.Velocity.Y);
            //if (tempVelocity.X > 0.0f)
            //{
            //    DisMinX = _Object.Position.X - (Position.X + m_Sprite.FrameWidht);
            //    DisMaxX = (_Object.Position.X + _Object.Sprite.FrameWidht) - (Position.X);
            //}
            //else
            //{
            //    DisMinX = (_Object.Position.X + _Object.Sprite.FrameWidht) - (Position.X);
            //    DisMaxX = _Object.Position.X - (Position.X + m_Sprite.FrameWidht);
            //}

            //if (tempVelocity.Y > 0.0f)
            //{
            //    DisMinY = _Object.Position.Y - (Position.Y + m_Sprite.FrameHeight);
            //    DisMaxY = (_Object.Position.Y + _Object.Sprite.FrameHeight) - (Position.Y);
            //}
            //else
            //{
            //    DisMinY = (_Object.Position.Y + _Object.Sprite.FrameHeight) - (Position.Y);
            //    DisMaxY = _Object.Position.Y - (Position.Y + m_Sprite.FrameHeight);
            //}

            //float EntryTimeX, ExitTimeX;
            //float EntryTimeY, ExitTimeY;

            //if (m_Velocity.X == 0.0f)
            //{
            //    EntryTimeX = float.NegativeInfinity;
            //    ExitTimeX = float.PositiveInfinity;
            //}
            //else
            //{
            //    EntryTimeX = DisMinX / (tempVelocity.X * m_GameTime);
            //    ExitTimeX = DisMaxX / (tempVelocity.X * m_GameTime);
            //}

            //if (m_Velocity.Y == 0.0f)
            //{
            //    EntryTimeY = float.NegativeInfinity;
            //    ExitTimeY = float.PositiveInfinity;
            //}
            //else
            //{
            //    EntryTimeY = DisMinY / (tempVelocity.Y * m_GameTime);
            //    ExitTimeY = DisMaxY / (tempVelocity.Y * m_GameTime);
            //}

            //if (m_Velocity.X == 0.0f && _Object.Velocity.X != 0)
            //{
            //    EntryTimeX = DisMinX / (tempVelocity.X * m_GameTime);
            //    ExitTimeX = DisMaxX / (tempVelocity.X * m_GameTime);
            //}

            //if (m_Velocity.Y == 0.0f && _Object.Velocity.Y != 0)
            //{
            //    EntryTimeY = DisMinY / (tempVelocity.Y * m_GameTime);
            //    ExitTimeY = DisMaxY / (tempVelocity.Y * m_GameTime);
            //}

            //float EntryTime;
            //float ExitTime;

            //EntryTime = Math.Max(EntryTimeX, EntryTimeY);
            //ExitTime = Math.Min(ExitTimeX, ExitTimeY);

            //if (EntryTime > ExitTime)
            //    return DirectCollision.NONE;
            //if (EntryTimeX < 0.0f && EntryTimeY < 0.0f)
            //    return DirectCollision.NONE;
            //if (EntryTimeX > 1.0f || EntryTimeY > 1.0f)
            //    return DirectCollision.NONE;

            //if (EntryTimeX < 0.0f)
            //{
            //    if (Position.X + Sprite.FrameWidht < _Object.Position.X || Position.X > _Object.Position.X + _Object.Sprite.FrameWidht)
            //        return DirectCollision.NONE;
            //}
            //if (EntryTimeY < 0.0f)
            //{
            //    if (Position.Y + Sprite.FrameHeight < _Object.Position.Y || Position.Y > _Object.Position.Y + _Object.Sprite.FrameHeight)
            //        return DirectCollision.NONE;
            //}

            //if (EntryTimeX > EntryTimeY && Position.Y + Sprite.FrameHeight != _Object.Position.Y)
            //{
            //    if (DisMinX < 0.0f)
            //    {
            //        return DirectCollision.RIGHT;
            //    }
            //    else
            //    {
            //        return DirectCollision.LEFT;
            //    }
            //}
            //else
            //{
            //    if (DisMinY < 0.0f)
            //    {
            //        return DirectCollision.BOTTOM;
            //    }
            //    else
            //    {
            //        return DirectCollision.TOP;
            //    }
            //}
            #endregion

            float moveX = 0.0f;
            float moveY = 0.0f;
            float normalX = 0.0f;
            float normalY = 0.0f;
            float timeCollsion = 0.0f;
            Vector2 velocity = Vector2.Zero;

            // kiểm tra 2 vật có va chạm với nhau không (không tính trường hợp có vận tốc)
            if (SweptAABB.CheckAABB(this.GetBox(), _Object.GetBox(), ref moveX, ref moveY) == false)
            {
                // nếu vật thứ 2 có vận tốc thì ta trừ vận tốc với nhau, xem vật thứ 2 là vật tĩnh
                velocity = new Vector2(this.Velocity.X - _Object.Velocity.X, this.Velocity.Y - _Object.Velocity.Y);
                // kiểm tra xem vật thứ 2 có nằm trong vùng di chuyển của vật 1 hay không ?
                if (SweptAABB.CheckAABB(this.BoxToBroadPhase(GetBox(velocity)), _Object.GetBox(), ref moveX, ref moveY) == true)
                {
                    // chạy sweptAABB, nếu có khả năng xảy ra va chạm
                    timeCollsion = SweptAABB.Swept_AABB(GetBox(velocity), _Object.GetBox(), ref normalX, ref normalY);
                    if (timeCollsion < 1.0f && timeCollsion > 0.0f)
                    {
                        if (Math.Abs(m_MoveX) >= Math.Abs(velocity.X * m_GameTime * timeCollsion + normalX))
                        {
                            m_MoveX = velocity.X * m_GameTime * timeCollsion + normalX;
                        }

                        if (Math.Abs(m_MoveY) >= Math.Abs(velocity.Y * m_GameTime * timeCollsion + normalY))
                        {
                            m_MoveY = velocity.Y * m_GameTime * timeCollsion + normalY; // trong collision tao lam += move Y ma, ko chuyên position
                        }

                        if (normalX != 0)
                        {
                            if (moveX != 0)
                            {
                                if (normalX == 1)
                                {
                                    return DirectCollision.RIGHT;
                                }
                                else if (normalX == -1)
                                {
                                    return DirectCollision.LEFT;
                                }
                            }
                        }
                        else
                        {
                            if (moveY != 0)
                            {
                                if (normalY == -1)
                                {
                                    return DirectCollision.TOP;
                                }
                                else if (normalY == 1)
                                {
                                    return DirectCollision.BOTTOM;
                                }
                            }
                        }
                    }
                }
                else
                {
                    // làm cái gì đó tùy thích !!!!!
                }
            }
            else
            {
                m_MoveX = moveX;
                m_MoveY = moveY;

                //if (m_MoveX <= moveX)
                //    m_MoveX = moveX;

                //if (m_MoveY <= moveY)
                //    m_MoveY = moveY;

                if (moveX != 0)
                {

                    if (moveX < 0.0f)
                    {
                        return DirectCollision.LEFT;
                    }
                    else
                    {
                        return DirectCollision.RIGHT;
                    }
                }
                else if (moveY != 0)
                {

                    if (moveY <= 0.0f)
                    {
                        return DirectCollision.TOP;
                    }
                    else
                    {
                        return DirectCollision.BOTTOM;
                    }
                }
                else
                {
                    if ((GetBound().X + GetBound().Width == _Object.GetBound().X && GetBound().Y + GetBound().Height == _Object.GetBound().Y)
                        || (GetBound().X == _Object.GetBound().X + _Object.GetBound().Width && GetBound().Y + GetBound().Height == _Object.GetBound().Y))
                        return DirectCollision.NONE;

                    if (GetBound().Y + GetBound().Height == _Object.GetBound().Y)
                    {
                        m_Position.Y -= 0.0001f;
                        return DirectCollision.TOP;
                    }
                    else if (_Object.GetBound().Y + _Object.GetBound().Height == GetBound().Y)
                    {
                        m_Position.Y += 0.0001f;
                        return DirectCollision.BOTTOM;
                    }
                    else if (GetBound().X + GetBound().Width == _Object.GetBound().X)
                    {
                        m_Position.X -= 0.0001f;
                        return DirectCollision.LEFT;
                    }
                    else if (_Object.GetBound().X + _Object.GetBound().Width == GetBound().X)
                    {
                        m_Position.X += 0.0001f;
                        return DirectCollision.RIGHT;
                    }
                }
            }

            return DirectCollision.NONE;
        }
Esempio n. 16
0
        public override void UpdateCollision(CAnimationObject _Object)
        {
            GlobalValue.ID_MARIO = IDObject;
            GlobalValue.MARIO_STATUS = Status;
            UpdateCollisionBullet(_Object);
            if (CheckCollision(_Object) != DirectCollision.NONE && m_Status != IDStatus.DIE)
            {
                switch (_Object.IDObject)
                {
                    #region Goomba
                    case IDObject.ENEMY_GOOMBA_OW:
                        if((CheckCollision(_Object) == DirectCollision.TOP || CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.LEFT || CheckCollision(_Object) == DirectCollision.BOTTOM) && IsInvincible && _Object.Status != IDStatus.SHOOTED)
                        {
                            _Object.Status = IDStatus.SHOOTED;
                            _Object.Velocity = new Vector2(0, -0.2f);
                        }
                        if (CheckCollision(_Object) == DirectCollision.TOP && _Object.Status == IDStatus.ALIVE && !IsWorldFreeze)
                        {
                            SoundManager.PlaySound(ESound.SFX_STOMP);
                            _Object.Status = IDStatus.BEFORE_DIE;
                            m_Velocity.Y = -m_Velocity.Y;
                            break;
                        }
                        if ((CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.LEFT) && _Object.Status == IDStatus.ALIVE && !IsWorldFreeze)
                        {
                            if (m_IDObject == IDObject.FIRE_MARIO)
                            {
                                SoundManager.PlaySound(ESound.SFX_MARIO_HURT);
                                Sprite = new CSprite(CResourceManager.GetInstance().GetResource(IDResource.SUPER_MARIO));
                                IDObject = IDObject.SUPER_MARIO;
                                Status = IDStatus.MARIO_DOWNCAST;
                                IsWorldFreeze = true;
                                break;
                            }
                            if (m_IDObject == IDObject.SUPER_MARIO)
                            {
                                SoundManager.PlaySound(ESound.SFX_MARIO_HURT);
                                Sprite = new CSprite(CResourceManager.GetInstance().GetResource(IDResource.SMALL_MARIO));
                                IsWorldFreeze = true;
                                Status = IDStatus.MARIO_DOWNCAST;
                                IDObject = IDObject.SMALL_MARIO;
                                break;
                            }
                            if (m_IDObject == IDObject.SMALL_MARIO)
                            {
                                m_Status = IDStatus.DIE;
                                break;
                            }
                            if (Direction == IDDir.RIGHT)
                            {
                                Position = new Vector2(Position.X - 5f, Position.Y);
                            }
                            if (Direction == IDDir.LEFT)
                            {
                                Position = new Vector2(Position.X + 5f, Position.Y);
                            }
                            Velocity = Vector2.Zero;
                        }
                        break;
                    #endregion
                    #region Soft Brick
                    case IDObject.MISC_SOFT_BRICK:
                        if (CheckCollision(_Object) == DirectCollision.TOP && _Object.Status != IDStatus.ACTIVATE && _Object.Status != IDStatus.DIE)
                        {
                            if (Status == IDStatus.MARIO_JUMP)
                            {
                                Status = IDStatus.MARIO_STAND;
                            }
                            m_IsJumping = false;
                            m_Velocity = new Vector2(m_Velocity.X, 0.0f);
                            m_Position.Y = _Object.Position.Y - Sprite.FrameHeight;
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.BOTTOM && _Object.Status != IDStatus.ACTIVATE && _Object.Status != IDStatus.DIE)
                        {
                            m_Velocity = new Vector2(m_Velocity.X, 0.01f);
                            if (_Object.Status != IDStatus.MOVE)
                            {
                                _Object.Velocity = new Vector2(0, -0.04f);
                            }
                            m_Position.Y = _Object.Position.Y + _Object.Sprite.FrameHeight + 2f;
                            if (this.IDObject == Framework.IDObject.SMALL_MARIO)
                            {
                                _Object.Status = IDStatus.MOVE;
                                break;
                            }
                            if (this.IDObject == Framework.IDObject.FIRE_MARIO || this.IDObject == Framework.IDObject.SUPER_MARIO)
                            {
                                SoundManager.PlaySound(ESound.SFX_BREAKBLOCK);
                                _Object.Velocity = new Vector2(0, m_Velocity.Y - 1);
                                _Object.Status = IDStatus.BEFORE_DIE;
                                break;
                            }
                        }
                        else if (CheckCollision(_Object) == DirectCollision.LEFT)
                        {
                            m_Velocity = new Vector2(0.0f, m_Velocity.Y);
                            Position = new Vector2(_Object.Position.X - Sprite.FrameWidht - 1, Position.Y);
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.RIGHT)
                        {
                            m_Velocity = new Vector2(0.0f, m_Velocity.Y);
                            Position = new Vector2(_Object.Position.X + _Object.Sprite.FrameWidht + 1, Position.Y);
                            break;
                        }
                        break;
                    #endregion
                    #region Item Coin
                    case IDObject.ITEM_COIN_NORMAL:
                        if ((CheckCollision(_Object) == DirectCollision.TOP || CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.LEFT) && _Object.Status == IDStatus.ALIVE)
                        {
                            SoundManager.PlaySound(ESound.SFX_COIN);
                            _Object.Status = IDStatus.DIE;
                            GlobalValue.MARIO_SCORE += 100;
                            GlobalValue.MARIO_COIN += 100;
                        }
                        break;
                    #endregion
                    #region Fire Flower
                    case IDObject.ITEM_FIRE_FLOWER:
                        if ((CheckCollision(_Object) == DirectCollision.TOP || CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.LEFT) && _Object.Status == IDStatus.ALIVE)
                        {
                            SoundManager.PlaySound(ESound.SFX_POWER_UP);
                            _Object.Status = IDStatus.DIE;
                            if (m_IDObject == IDObject.SMALL_MARIO || m_IDObject == IDObject.SUPER_MARIO)
                            {
                                if (IDObject == IDObject.SMALL_MARIO)
                                {
                                    m_Position.Y -= 16;
                                }
                                IDObject = IDObject.FIRE_MARIO;
                                m_Status = IDStatus.MARIO_UPCAST;
                                tempSprite = new CSprite(CResourceManager.GetInstance().GetResource(IDResource.FIRE_MARIO));
                                IsWorldFreeze = true;
                                GlobalValue.IS_LOCK_KEYBOARD = true;
                                m_isMarioFreeze = true;
                            }
                            GlobalValue.MARIO_SCORE += 1000;
                            break;
                        }
                        break;
                    case IDObject.ITEM_SUPER_MUSHROOM:
                        if ((CheckCollision(_Object) == DirectCollision.TOP || CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.LEFT))
                        {
                            SoundManager.PlaySound(ESound.SFX_POWER_UP);
                            _Object.Status = IDStatus.DIE;
                            if (m_IDObject == IDObject.SMALL_MARIO)
                            {
                                m_Position.Y -= 16;
                                IDObject = IDObject.SUPER_MARIO;
                                m_Status = IDStatus.MARIO_UPCAST;
                                tempSprite = new CSprite(CResourceManager.GetInstance().GetResource(IDResource.SUPER_MARIO));
                                IsWorldFreeze = true;
                                GlobalValue.IS_LOCK_KEYBOARD = true;
                                m_isMarioFreeze = true;
                                oldPosition = Position;
                            }
                            GlobalValue.MARIO_SCORE += 1000;
                            break;
                        }
                        break;
                    case IDObject.ITEM_1UP_MUSHROOM:
                        if ((CheckCollision(_Object) == DirectCollision.TOP || CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.LEFT))
                        {
                            SoundManager.PlaySound(ESound.SFX_1_UP);
                            _Object.Status = IDStatus.DIE;
                            ++GlobalValue.MARIO_LIFE;
                            break;
                        }
                        break;
                    #endregion
                    #region Case Koopa
                    case IDObject.ENEMY_KOOPA_OW:
                        if ((CheckCollision(_Object) == DirectCollision.TOP || CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.LEFT || CheckCollision(_Object) == DirectCollision.BOTTOM) && IsInvincible && _Object.Status != IDStatus.SHOOTED)
                        {
                            _Object.Status = IDStatus.SHOOTED;
                            _Object.Velocity = new Vector2(0, -0.2f);
                        }
                        if (CheckCollision(_Object) == DirectCollision.TOP && _Object.Status == IDStatus.ALIVE )
                        {
                            m_Velocity.Y = -0.02f;
                            _Object.Status = IDStatus.HIDE;
                            _Object.Sprite = new CSprite(CResourceManager.GetInstance().GetResource(IDResource.ENEMY_HIDE_KOOPA_OW));
                        }
                        if ((CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.LEFT) && _Object.Status == IDStatus.HIDE)
                        {
                            if (Direction == IDDir.LEFT && CheckCollision(_Object) == DirectCollision.RIGHT)
                            {
                                _Object.Direction = IDDir.LEFT;
                                _Object.Status = IDStatus.SPIN;
                                SoundManager.PlaySound(ESound.SFX_KICK);
                                break;
                            }
                            if (Direction == IDDir.RIGHT && CheckCollision(_Object) == DirectCollision.LEFT)
                            {
                                _Object.Direction = IDDir.RIGHT;
                                _Object.Status = IDStatus.SPIN;
                                SoundManager.PlaySound(ESound.SFX_KICK);
                                break;
                            }
                            break;
                        }
                        if (CheckCollision(_Object) == DirectCollision.TOP && _Object.Status == IDStatus.HIDE)
                        {
                            if (Status == IDStatus.MARIO_JUMP)
                            {
                                Status = IDStatus.MARIO_STAND;
                            }
                            m_Velocity.Y = 0;
                            //m_IsDisableUp = true;
                            IsJumping = false;
                            break;
                        }
                        if (CheckCollision(_Object) == DirectCollision.TOP && _Object.Status == IDStatus.SPIN)
                        {
                            if (Status == IDStatus.MARIO_JUMP)
                            {
                                Status = IDStatus.MARIO_STAND;
                            }
                            m_Velocity.Y = 0;
                            IsJumping = false;
                            _Object.Status = IDStatus.HIDE;
                            break;
                        }
                        if ((CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.LEFT) && _Object.Status == IDStatus.SPIN && !IsWorldFreeze)
                        {
                            if (m_IDObject == IDObject.FIRE_MARIO)
                            {
                                SoundManager.PlaySound(ESound.SFX_MARIO_HURT);
                                IDObject = IDObject.SUPER_MARIO;
                                IsWorldFreeze = true;
                                Sprite = new CSprite(CResourceManager.GetInstance().GetResource(IDResource.SUPER_MARIO));
                                Status = IDStatus.MARIO_DOWNCAST;
                                break;
                            }
                            if (m_IDObject == IDObject.SUPER_MARIO)
                            {
                                SoundManager.PlaySound(ESound.SFX_MARIO_HURT);
                                IDObject = IDObject.SMALL_MARIO;
                                Sprite = new CSprite(CResourceManager.GetInstance().GetResource(IDResource.SMALL_MARIO));
                                IsWorldFreeze = true;
                                Status = IDStatus.MARIO_DOWNCAST;
                                break;
                            }
                            if (m_IDObject == IDObject.SMALL_MARIO)
                            {
                                //m_Velocity.Y = -3.0f;
                                m_Status = IDStatus.DIE;
                                break;
                            }
                        }
                        if ((CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.LEFT) && _Object.Status == IDStatus.ALIVE && !IsWorldFreeze)
                        {
                            if (m_IDObject == IDObject.FIRE_MARIO)
                            {
                                SoundManager.PlaySound(ESound.SFX_MARIO_HURT);
                                IDObject = IDObject.SUPER_MARIO;
                                Sprite = new CSprite(CResourceManager.GetInstance().GetResource(IDResource.SUPER_MARIO));
                                IsWorldFreeze = true;
                                Status = IDStatus.MARIO_DOWNCAST;
                                break;
                            }
                            if (m_IDObject == IDObject.SUPER_MARIO)
                            {
                                SoundManager.PlaySound(ESound.SFX_MARIO_HURT);
                                IDObject = IDObject.SMALL_MARIO;
                                Sprite = new CSprite(CResourceManager.GetInstance().GetResource(IDResource.SMALL_MARIO));
                                IsWorldFreeze = true;
                                Status = IDStatus.MARIO_DOWNCAST;
                                break;
                            }
                            if (m_IDObject == IDObject.SMALL_MARIO)
                            {
                                m_Status = IDStatus.DIE;
                                break;
                            }
                        }
                        break;
                    #endregion
                    #region Case Base Brick
                    case IDObject.MISC_BASE_BRICK:
                    case IDObject.MISC_HARD_BRICK:
                        if (CheckCollision(_Object) == DirectCollision.TOP)
                        {
                            //if (Status != IDStatus.MARIO_RUN && Status != IDStatus.MARIO_STAND && Status != IDStatus.MARIO_ATTACK && Status != IDStatus.MARIO_STRIPPED && Status != IDStatus.MARIO_WIN && Status != IDStatus.MARIO_AUTO_RUN && Status != IDStatus.MARIO_DOWNCAST)
                            if(Status == IDStatus.MARIO_JUMP)
                            {
                                Status = IDStatus.MARIO_STAND;
                            }
                            //m_IsDisableUp = false;
                            m_IsJumping = false;
                            m_Velocity = new Vector2(m_Velocity.X, 0.0f);
                            m_Position.Y = _Object.Position.Y - Sprite.FrameHeight;
                            if (Status == IDStatus.MARIO_STRIPPED)
                            {
                                Position = new Vector2(Position.X + 12, Position.Y);
                                Console.WriteLine(Status.ToString());
                                Direction = IDDir.LEFT;
                                Status = IDStatus.MARIO_WIN;
                            }
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.BOTTOM)
                        {
                            m_Velocity = new Vector2(m_Velocity.X, 0.0098f);
                            m_Position.Y = _Object.Position.Y + _Object.Sprite.FrameHeight + 1;
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.LEFT)
                        {
                            m_Velocity = new Vector2(0.0f, m_Velocity.Y);
                            Position = new Vector2(Position.X - 0.05f, Position.Y);
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.RIGHT)
                        {
                            m_Velocity = new Vector2(0.0f, m_Velocity.Y);
                            Position = new Vector2(Position.X + 0.05f, Position.Y);
                            break;
                        }
                        break;
                        #endregion
                    #region Goal Pole
                    case IDObject.MISC_GOAL_POLE:
                        if ((CheckCollision(_Object) == DirectCollision.BOTTOM || CheckCollision(_Object) == DirectCollision.LEFT || CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.TOP) && !GlobalValue.IS_LOCK_KEYBOARD)
                        {
                            if (!GlobalValue.IS_LOCK_KEYBOARD)
                            {
                                Position = new Vector2(_Object.Position.X - 9, Position.Y);
                                SoundManager.PlaySound(ESound.SFX_FLAGPOLE);
                                MediaPlayer.Stop();
                            }
                            GlobalValue.KillBoss = true;
                            Status = IDStatus.MARIO_STRIPPED;
                            GlobalValue.IS_LOCK_KEYBOARD = true;
                            Accel = Vector2.Zero;
                            Velocity = Vector2.Zero;
                            _Object.Status = IDStatus.ACTIVATE;
                        }
                        break;
                    #endregion
                    #region Pipe
                    //case IDObject.MISC_IN_PORTAL_PIPE:
                    //    if (CheckCollision(_Object) == DirectCollision.TOP)
                    //    {
                    //        if (Status == IDStatus.MARIO_JUMP)
                    //        {
                    //            Status = IDStatus.MARIO_STAND;
                    //        }
                    //        if (Status != IDStatus.TELEPORT)
                    //        {
                    //            m_IsJumping = false;
                    //            m_Velocity = new Vector2(m_Velocity.X, 0.0f);
                    //            m_Position.Y = _Object.Position.Y - Sprite.FrameHeight;
                    //        }
                    //        break;
                    //    }
                    //    if (CheckCollision(_Object) == DirectCollision.LEFT)
                    //    {
                    //        m_Velocity = new Vector2(0.0f, m_Velocity.Y);
                    //        Position = new Vector2(Position.X - 0.05f, Position.Y);
                    //        break;
                    //    }
                    //    else if (CheckCollision(_Object) == DirectCollision.RIGHT)
                    //    {
                    //        m_Velocity = new Vector2(0.0f, m_Velocity.Y);
                    //        Position = new Vector2(Position.X + 0.05f, Position.Y);
                    //        break;
                    //    }
                    //    break;
                    case IDObject.MISC_STOCK_PIPE:
                    case IDObject.MISC_GATE_PIPE:
                    //case IDObject.MISC_NORMAL_PIPE:
                    //case IDObject.MISC_OUT_2_PIPE:
                        if (CheckCollision(_Object) == DirectCollision.TOP)
                        {
                            if (Status != IDStatus.TELEPORT)
                            {
                                if (Status == IDStatus.MARIO_JUMP)
                                {
                                    Status = IDStatus.MARIO_STAND;
                                }
                                m_IsJumping = false;
                                m_Velocity = new Vector2(m_Velocity.X, 0.0f);
                                m_Position.Y = _Object.Position.Y - Sprite.FrameHeight;
                                break;
                            }
                        }
                        //if (CheckCollision(_Object) == DirectCollision.BOTTOM)
                        //{
                        //    m_Velocity = new Vector2(m_Velocity.X, 0.0098f);
                        //    m_Position.Y = _Object.Position.Y + _Object.Sprite.FrameHeight + 1;
                        //    break;
                        //}
                        else if (CheckCollision(_Object) == DirectCollision.LEFT)
                        {
                            if (Status != IDStatus.TELEPORT)
                            {
                                m_Velocity = new Vector2(0.0f, m_Velocity.Y);
                                Position = new Vector2(Position.X - 0.05f, Position.Y);
                                break;
                            }
                        }
                        else if (CheckCollision(_Object) == DirectCollision.RIGHT)
                        {
                            if (Status != IDStatus.TELEPORT)
                            {
                                m_Velocity = new Vector2(0.0f, m_Velocity.Y);
                                Position = new Vector2(Position.X + 0.05f, Position.Y);
                                break;
                            }
                        }
                        break;
                    //case IDObject.MISC_OUT_1_PIPE:
                    //    if (CheckCollision(_Object) == DirectCollision.TOP && Status != IDStatus.MARIO_AUTO_RUN)
                    //    {
                    //        if (Status == IDStatus.MARIO_JUMP)
                    //        {
                    //            Status = IDStatus.MARIO_STAND;
                    //        }
                    //        m_IsJumping = false;
                    //        m_Velocity = new Vector2(m_Velocity.X, 0.0f);
                    //        m_Position.Y = _Object.Position.Y - Sprite.FrameHeight;
                    //        break;
                    //    }
                        //if (CheckCollision(_Object) == DirectCollision.LEFT && Status != IDStatus.MARIO_AUTO_RUN && Status != IDStatus.TELEPORT && Position.Y >= _Object.Position.Y)
                        //{
                        //    Velocity = Vector2.Zero;
                        //    Accel = Vector2.Zero;
                        //    SoundManager.PlaySound(ESound.SFX_PIPE);
                        //    Sprite.Depth = 0.05f;
                        //    Status = IDStatus.MARIO_AUTO_RUN;
                        //    GlobalValue.IS_LOCK_KEYBOARD = true;
                        //}
                        //break;
                    #endregion
                    #region Question Brick
                    case IDObject.MISC_QUESTION_BRICK:
                    if (CheckCollision(_Object) == DirectCollision.TOP)
                        {
                            if (Status == IDStatus.MARIO_JUMP)
                            {
                                Status = IDStatus.MARIO_STAND;
                            }
                            m_IsJumping = false;
                            m_Velocity = new Vector2(m_Velocity.X, 0.0f);
                            m_Position.Y = _Object.Position.Y - Sprite.FrameHeight;
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.BOTTOM)
                        {
                            m_Velocity = new Vector2(m_Velocity.X, 0.0098f);
                            m_Position.Y = _Object.Position.Y + _Object.Sprite.FrameHeight + 1;
                            if (_Object.Status != IDStatus.UNACTIVATE)
                            {
                                _Object.Status = IDStatus.DEACTIVATE;
                            }
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.LEFT)
                        {
                            m_Velocity = new Vector2(0.0f, m_Velocity.Y);
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.RIGHT)
                        {
                            m_Velocity = new Vector2(0.0f, m_Velocity.Y);
                            break;
                        }
                        break;
                    #endregion
                    #region Case Starman
                    case IDObject.ITEM_STARMAN:
                        if ((CheckCollision(_Object) == DirectCollision.TOP || CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.LEFT || CheckCollision(_Object) == DirectCollision.BOTTOM) && _Object.Status != IDStatus.UNACTIVATE)
                        {
                            SoundManager.PlaySound(ESound.SFX_POWER_UP);
                            Status = IDStatus.MARIO_INVINCIBLE;
                            tempSprite = Sprite;
                            _Object.Status = IDStatus.DIE;

                            break;
                        }
                        break;
                    #endregion
                    case IDObject.ENEMY_BOSS:
                        if ((CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.LEFT) && !IsWorldFreeze)
                        {
                            if (m_IDObject == IDObject.FIRE_MARIO)
                            {
                                SoundManager.PlaySound(ESound.SFX_MARIO_HURT);
                                Sprite = new CSprite(CResourceManager.GetInstance().GetResource(IDResource.SUPER_MARIO));
                                IDObject = IDObject.SUPER_MARIO;
                                Status = IDStatus.MARIO_DOWNCAST;
                                IsWorldFreeze = true;
                                break;
                            }
                            if (m_IDObject == IDObject.SUPER_MARIO)
                            {
                                SoundManager.PlaySound(ESound.SFX_MARIO_HURT);
                                Sprite = new CSprite(CResourceManager.GetInstance().GetResource(IDResource.SMALL_MARIO));
                                IsWorldFreeze = true;
                                Status = IDStatus.MARIO_DOWNCAST;
                                IDObject = IDObject.SMALL_MARIO;
                                break;
                            }
                            if (m_IDObject == IDObject.SMALL_MARIO)
                            {
                                m_Status = IDStatus.DIE;
                                break;
                            }
                            if (Direction == IDDir.RIGHT)
                            {
                                Position = new Vector2(Position.X - 5f, Position.Y);
                            }
                            if (Direction == IDDir.LEFT)
                            {
                                Position = new Vector2(Position.X + 5f, Position.Y);
                            }
                            Velocity = Vector2.Zero;
                        }
                        break;
                    case IDObject.ENEMY_BOSS_BULLET:
                        if (CheckCollision(_Object) != DirectCollision.NONE && !IsWorldFreeze)
                        {
                            if (m_IDObject == IDObject.FIRE_MARIO)
                            {
                                SoundManager.PlaySound(ESound.SFX_MARIO_HURT);
                                Sprite = new CSprite(CResourceManager.GetInstance().GetResource(IDResource.SUPER_MARIO));
                                IDObject = IDObject.SUPER_MARIO;
                                Status = IDStatus.MARIO_DOWNCAST;
                                IsWorldFreeze = true;
                                break;
                            }
                            if (m_IDObject == IDObject.SUPER_MARIO)
                            {
                                SoundManager.PlaySound(ESound.SFX_MARIO_HURT);
                                Sprite = new CSprite(CResourceManager.GetInstance().GetResource(IDResource.SMALL_MARIO));
                                IsWorldFreeze = true;
                                Status = IDStatus.MARIO_DOWNCAST;
                                IDObject = IDObject.SMALL_MARIO;
                                break;
                            }
                            if (m_IDObject == IDObject.SMALL_MARIO)
                            {
                                m_Status = IDStatus.DIE;
                                break;
                            }
                            if (Direction == IDDir.RIGHT)
                            {
                                Position = new Vector2(Position.X - 5f, Position.Y);
                            }
                            if (Direction == IDDir.LEFT)
                            {
                                Position = new Vector2(Position.X + 5f, Position.Y);
                            }
                            Velocity = Vector2.Zero;
                        }
                        break;
                    #region Case Default
                    default:
                        break;
                    #endregion
                }
            }
            base.UpdateCollision(_Object);
        }
Esempio n. 17
0
 private void UpdateCollisionBullet(CAnimationObject _Object)
 {
     if (m_Bullet1 != null)
     {
         m_Bullet1.UpdateCollision(_Object);
         _Object.UpdateCollision(m_Bullet1);
         if (m_Bullet1.Status == IDStatus.DIE)
         {
             m_Bullet1 = null;
         }
     }
     if (m_Bullet2 != null)
     {
         m_Bullet2.UpdateCollision(_Object);
         _Object.UpdateCollision(m_Bullet2);
         if (m_Bullet2.Status == IDStatus.DIE)
         {
             m_Bullet2 = null;
         }
     }
 }
Esempio n. 18
0
 public override void UpdateCollision(CAnimationObject _Object)
 {
     if (CheckCollision(_Object) != DirectCollision.NONE)
     {
         switch (_Object.IDObject)
         {
             case IDObject.MISC_BASE_BRICK:
             case IDObject.MISC_GATE_PIPE:
             case IDObject.MISC_STOCK_PIPE:
             case IDObject.MISC_UP_PIPE:
             case IDObject.MISC_SOFT_BRICK:
             case IDObject.MISC_HARD_BRICK:
                 if (CheckCollision(_Object) == DirectCollision.TOP)
                 {
                     m_Velocity.Y = -0.1f;
                     break;
                 }
                 if (CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.LEFT)
                 {
                     Status = IDStatus.DIE;
                     break;
                 }
                 break;
             case IDObject.ENEMY_KOOPA_OW:
             case IDObject.ENEMY_GOOMBA_OW:
                 if (CheckCollision(_Object) != DirectCollision.NONE && _Object.Status != IDStatus.SHOOTED)
                 {
                     _Object.Status = IDStatus.SHOOTED;
                     if (!isContact)
                     {
                         SoundManager.PlaySound(ESound.SFX_KICK);
                         isContact = true;
                     }
                     _Object.Velocity = new Vector2(0, -0.2f);
                     Status = IDStatus.DIE;
                     break;
                 }
                 break;
             //case IDObject.MISC_HARD_BRICK:
             //    if (CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.LEFT)
             //    {
             //        Status = IDStatus.DIE;
             //        break;
             //    }
             //    if (CheckCollision(_Object) == DirectCollision.TOP)
             //    {
             //        m_Velocity.Y = -0.1f;
             //        break;
             //    }
             //    break;
             //case IDObject.MISC_STOCK_PIPE:
             //    if (CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.LEFT || CheckCollision(_Object) == DirectCollision.TOP)
             //    {
             //        Status = IDStatus.DIE;
             //        break;
             //    }
             //    break;
             case IDObject.ENEMY_BOSS:
                 if (CheckCollision(_Object) == DirectCollision.TOP || CheckCollision(_Object) == DirectCollision.BOTTOM || CheckCollision(_Object) == DirectCollision.RIGHT || CheckCollision(_Object) == DirectCollision.LEFT && _Object.Status != IDStatus.SHOOTED)
                 {
                     if (!isContact)
                     {
                         SoundManager.PlaySound(ESound.SFX_KICK);
                         isContact = true;
                     }
                     Status = IDStatus.DIE;
                     break;
                 }
                 break;
             default:
                 break;
         }
     }
     base.UpdateCollision(_Object);
 }
Esempio n. 19
0
 public void RemoveObject(CAnimationObject _object)
 {
     m_ListObjects.Remove(_object);
 }
Esempio n. 20
0
 public void RemoveObject(CAnimationObject _object, QNode _node)
 {
     if (_node.GetChildNode(1) == null)
     {
         _node.RemoveObject(_object);
     }
     else
     {
         RemoveObject(_object, _node.GetChildNode(1));
         RemoveObject(_object, _node.GetChildNode(2));
         RemoveObject(_object, _node.GetChildNode(3));
         RemoveObject(_object, _node.GetChildNode(4));
     }
 }
Esempio n. 21
0
        public override void UpdateCollision(CAnimationObject _Object)
        {
            if (_Object.IDObject == IDObject.FIRE_MARIO || _Object.IDObject == IDObject.SMALL_MARIO || _Object.IDObject == IDObject.SUPER_MARIO)
            {
                if (Math.Abs(Position.X - _Object.Position.X) < 368)
                {
                    CanFire = true;
                    if (Position.X > _Object.Position.X && Status == IDStatus.FIRE)
                    {
                        Direction = IDDir.LEFT;
                    }
                    if (Position.X < _Object.Position.X && Status == IDStatus.FIRE)
                    {
                        Direction = IDDir.RIGHT;
                    }
                }
            }

            //for (int i = 0; i < List_Of_Bullet.Count; i++)
            //{
            //    List_Of_Bullet[i].UpdateCollision(_Object);
            //}

            if (CheckCollision(_Object) != DirectCollision.NONE)
            {
                switch (_Object.IDObject)
                {
                    case IDObject.MISC_BASE_BRICK:
                    case IDObject.MISC_IRON_BRICK:
                    case IDObject.MISC_QUESTION_BRICK:
                    case IDObject.MISC_STOCK_PIPE:
                    case IDObject.MISC_HARD_BRICK:
                        if (CheckCollision(_Object) == DirectCollision.TOP)
                        {
                            m_Velocity.Y = 0.0f;
                            m_Position.Y = _Object.Position.Y - Sprite.FrameHeight;
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.RIGHT)
                        {
                            Direction = IDDir.RIGHT;
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.LEFT)
                        {
                            Direction = IDDir.LEFT;
                            break;
                        }
                        else if (CheckCollision(_Object) == DirectCollision.BOTTOM)
                        {

                        }
                        break;
                    case IDObject.FIRE_MARIO:
                    case IDObject.SMALL_MARIO:
                    case IDObject.SUPER_MARIO:
                        if (CheckCollision(_Object) == DirectCollision.BOTTOM && _Object.Status != IDStatus.DIE)
                        {
                            Boss_Heath_Point -= 200;
                            _Object.Velocity = new Vector2(_Object.Velocity.X, -0.35f);
                        }
                        break;
                    case IDObject.BULLET:
                        if (CheckCollision(_Object) != DirectCollision.NONE)
                        {
                            Boss_Heath_Point -= 200;
                        }
                        break;
                    default:
                        break;
                }
            }
            base.UpdateCollision(_Object);
        }
Esempio n. 22
0
        public DirectCollision CheckCollision(CAnimationObject _Object)
        {
            #region . Thuật toán sweptAABB cũ
            //float DisMinX, DisMaxX;
            //float DisMinY, DisMaxY;

            //Vector2 tempVelocity;
            //tempVelocity = new Vector2(m_Velocity.X - _Object.Velocity.X, m_Velocity.Y - _Object.Velocity.Y);
            //if (tempVelocity.X > 0.0f)
            //{
            //    DisMinX = _Object.Position.X - (Position.X + m_Sprite.FrameWidht);
            //    DisMaxX = (_Object.Position.X + _Object.Sprite.FrameWidht) - (Position.X);
            //}
            //else
            //{
            //    DisMinX = (_Object.Position.X + _Object.Sprite.FrameWidht) - (Position.X);
            //    DisMaxX = _Object.Position.X - (Position.X + m_Sprite.FrameWidht);
            //}

            //if (tempVelocity.Y > 0.0f)
            //{
            //    DisMinY = _Object.Position.Y - (Position.Y + m_Sprite.FrameHeight);
            //    DisMaxY = (_Object.Position.Y + _Object.Sprite.FrameHeight) - (Position.Y);
            //}
            //else
            //{
            //    DisMinY = (_Object.Position.Y + _Object.Sprite.FrameHeight) - (Position.Y);
            //    DisMaxY = _Object.Position.Y - (Position.Y + m_Sprite.FrameHeight);
            //}

            //float EntryTimeX, ExitTimeX;
            //float EntryTimeY, ExitTimeY;

            //if (m_Velocity.X == 0.0f)
            //{
            //    EntryTimeX = float.NegativeInfinity;
            //    ExitTimeX = float.PositiveInfinity;
            //}
            //else
            //{
            //    EntryTimeX = DisMinX / (tempVelocity.X * m_GameTime);
            //    ExitTimeX = DisMaxX / (tempVelocity.X * m_GameTime);
            //}

            //if (m_Velocity.Y == 0.0f)
            //{
            //    EntryTimeY = float.NegativeInfinity;
            //    ExitTimeY = float.PositiveInfinity;
            //}
            //else
            //{
            //    EntryTimeY = DisMinY / (tempVelocity.Y * m_GameTime);
            //    ExitTimeY = DisMaxY / (tempVelocity.Y * m_GameTime);
            //}

            //if (m_Velocity.X == 0.0f && _Object.Velocity.X != 0)
            //{
            //    EntryTimeX = DisMinX / (tempVelocity.X * m_GameTime);
            //    ExitTimeX = DisMaxX / (tempVelocity.X * m_GameTime);
            //}

            //if (m_Velocity.Y == 0.0f && _Object.Velocity.Y != 0)
            //{
            //    EntryTimeY = DisMinY / (tempVelocity.Y * m_GameTime);
            //    ExitTimeY = DisMaxY / (tempVelocity.Y * m_GameTime);
            //}

            //float EntryTime;
            //float ExitTime;

            //EntryTime = Math.Max(EntryTimeX, EntryTimeY);
            //ExitTime = Math.Min(ExitTimeX, ExitTimeY);

            //if (EntryTime > ExitTime)
            //    return DirectCollision.NONE;
            //if (EntryTimeX < 0.0f && EntryTimeY < 0.0f)
            //    return DirectCollision.NONE;
            //if (EntryTimeX > 1.0f || EntryTimeY > 1.0f)
            //    return DirectCollision.NONE;

            //if (EntryTimeX < 0.0f)
            //{
            //    if (Position.X + Sprite.FrameWidht < _Object.Position.X || Position.X > _Object.Position.X + _Object.Sprite.FrameWidht)
            //        return DirectCollision.NONE;
            //}
            //if (EntryTimeY < 0.0f)
            //{
            //    if (Position.Y + Sprite.FrameHeight < _Object.Position.Y || Position.Y > _Object.Position.Y + _Object.Sprite.FrameHeight)
            //        return DirectCollision.NONE;
            //}


            //if (EntryTimeX > EntryTimeY && Position.Y + Sprite.FrameHeight != _Object.Position.Y)
            //{
            //    if (DisMinX < 0.0f)
            //    {
            //        return DirectCollision.RIGHT;
            //    }
            //    else
            //    {
            //        return DirectCollision.LEFT;
            //    }
            //}
            //else
            //{
            //    if (DisMinY < 0.0f)
            //    {
            //        return DirectCollision.BOTTOM;
            //    }
            //    else
            //    {
            //        return DirectCollision.TOP;
            //    }
            //}
            #endregion

            float   moveX        = 0.0f;
            float   moveY        = 0.0f;
            float   normalX      = 0.0f;
            float   normalY      = 0.0f;
            float   timeCollsion = 0.0f;
            Vector2 velocity     = Vector2.Zero;

            // kiểm tra 2 vật có va chạm với nhau không (không tính trường hợp có vận tốc)
            if (SweptAABB.CheckAABB(this.GetBox(), _Object.GetBox(), ref moveX, ref moveY) == false)
            {
                // nếu vật thứ 2 có vận tốc thì ta trừ vận tốc với nhau, xem vật thứ 2 là vật tĩnh
                velocity = new Vector2(this.Velocity.X - _Object.Velocity.X, this.Velocity.Y - _Object.Velocity.Y);
                // kiểm tra xem vật thứ 2 có nằm trong vùng di chuyển của vật 1 hay không ?
                if (SweptAABB.CheckAABB(this.BoxToBroadPhase(GetBox(velocity)), _Object.GetBox(), ref moveX, ref moveY) == true)
                {
                    // chạy sweptAABB, nếu có khả năng xảy ra va chạm
                    timeCollsion = SweptAABB.Swept_AABB(GetBox(velocity), _Object.GetBox(), ref normalX, ref normalY);
                    if (timeCollsion < 1.0f && timeCollsion > 0.0f)
                    {
                        if (Math.Abs(m_MoveX) >= Math.Abs(velocity.X * m_GameTime * timeCollsion + normalX))
                        {
                            m_MoveX = velocity.X * m_GameTime * timeCollsion + normalX;
                        }

                        if (Math.Abs(m_MoveY) >= Math.Abs(velocity.Y * m_GameTime * timeCollsion + normalY))
                        {
                            m_MoveY = velocity.Y * m_GameTime * timeCollsion + normalY; // trong collision tao lam += move Y ma, ko chuyên position
                        }

                        if (normalX != 0)
                        {
                            if (moveX != 0)
                            {
                                if (normalX == 1)
                                {
                                    return(DirectCollision.RIGHT);
                                }
                                else if (normalX == -1)
                                {
                                    return(DirectCollision.LEFT);
                                }
                            }
                        }
                        else
                        {
                            if (moveY != 0)
                            {
                                if (normalY == -1)
                                {
                                    return(DirectCollision.TOP);
                                }
                                else if (normalY == 1)
                                {
                                    return(DirectCollision.BOTTOM);
                                }
                            }
                        }
                    }
                }
                else
                {
                    // làm cái gì đó tùy thích !!!!!
                }
            }
            else
            {
                m_MoveX = moveX;
                m_MoveY = moveY;

                //if (m_MoveX <= moveX)
                //    m_MoveX = moveX;

                //if (m_MoveY <= moveY)
                //    m_MoveY = moveY;

                if (moveX != 0)
                {
                    if (moveX < 0.0f)
                    {
                        return(DirectCollision.LEFT);
                    }
                    else
                    {
                        return(DirectCollision.RIGHT);
                    }
                }
                else if (moveY != 0)
                {
                    if (moveY <= 0.0f)
                    {
                        return(DirectCollision.TOP);
                    }
                    else
                    {
                        return(DirectCollision.BOTTOM);
                    }
                }
                else
                {
                    if ((GetBound().X + GetBound().Width == _Object.GetBound().X&& GetBound().Y + GetBound().Height == _Object.GetBound().Y) ||
                        (GetBound().X == _Object.GetBound().X + _Object.GetBound().Width&& GetBound().Y + GetBound().Height == _Object.GetBound().Y))
                    {
                        return(DirectCollision.NONE);
                    }

                    if (GetBound().Y + GetBound().Height == _Object.GetBound().Y)
                    {
                        m_Position.Y -= 0.0001f;
                        return(DirectCollision.TOP);
                    }
                    else if (_Object.GetBound().Y + _Object.GetBound().Height == GetBound().Y)
                    {
                        m_Position.Y += 0.0001f;
                        return(DirectCollision.BOTTOM);
                    }
                    else if (GetBound().X + GetBound().Width == _Object.GetBound().X)
                    {
                        m_Position.X -= 0.0001f;
                        return(DirectCollision.LEFT);
                    }
                    else if (_Object.GetBound().X + _Object.GetBound().Width == GetBound().X)
                    {
                        m_Position.X += 0.0001f;
                        return(DirectCollision.RIGHT);
                    }
                }
            }

            return(DirectCollision.NONE);
        }
Esempio n. 23
0
 public virtual void SetItem(CAnimationObject _Item)
 {
 }