Guest User

Untitled

a guest
Sep 20th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.66 KB | None | 0 0
  1. //---------------------------
  2. // Includes
  3. //---------------------------
  4. #include "Bubble.h"
  5.  
  6. //---------------------------
  7. // Defines
  8. //---------------------------
  9. #define GAME_ENGINE (GameEngine::GetSingleton())
  10.  
  11. //---------------------------
  12. // Constructor & Destructor
  13. //---------------------------
  14. Bubble::Bubble():   m_BmpBubblePtr(0),
  15.                     m_RectMov(0),
  16.                     m_Timer(0),
  17.                     m_RectMovCounter(0),
  18.                     m_ScaleBubble(1,1),
  19.                     m_PosBubble(70, 445),
  20.                     m_MovBubble(0, 0),
  21.                     m_BubbleHitRegionHPPtr(0),
  22.                     m_BubbleHitRegionVPPtr(0),
  23.                     m_BoolJump(false),
  24.                     m_TimerJumping(0),
  25.                     m_RectJumpMov(0),
  26.                     m_RectJumpMovCounter(0),
  27.                     m_TimerRectJump(0),
  28.                     m_BoolShoot(false),
  29.                     m_BmpBubbleAttackPtr(0),
  30.                     m_CurrentBubble(0),
  31.                     m_BoolSwitchSide(false),
  32.                     m_RectShootMovCounter(0),
  33.                     m_RectBubbleShoot(0),
  34.                     m_TimerShoot(0),
  35.                     m_Bubblebeingshot(0),
  36.                     m_TimerBulletBubble(0),
  37.                     m_RectBulletBubbleMovCounter(0),
  38.                     m_RectBulletBubble(0,0),
  39.                     m_SVG_BulletBubblesPtr(0)
  40.                    
  41. {
  42.     m_BmpBubblePtr = new Bitmap("./Resources/sprites.png");
  43.     m_BmpBubblePtr->SetTransparencyColor(15, 79, 174);
  44.  
  45.     m_BubbleHitRegionHPPtr = new HitRegion();
  46.     m_BubbleHitRegionHPPtr->CreateFromRect(-12, -19, 32, 35 / 2);
  47.  
  48.     m_BubbleHitRegionVPPtr = new HitRegion();
  49.     m_BubbleHitRegionVPPtr->CreateFromRect(-5,-18, 32 / 2, 35);
  50.  
  51.     m_BmpBubbleAttackPtr = new Bitmap("./Resources/sprites.png");
  52.     m_BmpBubbleAttackPtr->SetTransparencyColor(15, 79, 174);
  53.  
  54.     for(m_CurrentBubble = 0; m_CurrentBubble < MAX_BUBBLES; ++m_CurrentBubble)
  55.     {
  56.         m_BubbleArr[m_CurrentBubble].shoot = false;
  57.         m_BubbleArr[m_CurrentBubble].Switch = false;
  58.         m_BubbleArr[m_CurrentBubble].Collision = false;
  59.         m_BubbleArr[m_CurrentBubble].CollisionHor = false;
  60.         m_BubbleArr[m_CurrentBubble].bubbleSpeed.x = 0;
  61.         m_BubbleArr[m_CurrentBubble].bubbleSpeed.y = 0;
  62.         m_BubbleArr[m_CurrentBubble].HittestVert = new HitRegion();
  63.         m_BubbleArr[m_CurrentBubble].HittestVert->CreateFromRect(10,-5,10, 35);
  64.         m_BubbleArr[m_CurrentBubble].HittestHor = new HitRegion();
  65.         m_BubbleArr[m_CurrentBubble].HittestHor->CreateFromRect(-3,8,35, 10);
  66.     }
  67.     m_CurrentBubble = 0;
  68.  
  69.  
  70.     m_SVG_BulletBubblesPtr = new HitRegion();
  71.     m_SVG_BulletBubblesPtr->CreateFromFile("./Resources/SVG_bulletBubble.svg");
  72. }
  73.  
  74. Bubble::~Bubble()
  75. {
  76.     for(int counter = 0; counter < MAX_BUBBLES; ++counter)
  77.     {
  78.         delete m_BubbleArr[counter].HittestHor;
  79.         delete m_BubbleArr[counter].HittestVert;
  80.     }
  81. }
  82.  
  83. //---------------------------
  84. // Own methoden
  85. //---------------------------
  86.  
  87. void Bubble::Tick(DOUBLE2 posCamera,  double deltaTime)
  88. {
  89.     if(GAME_ENGINE->IsKeyDown(VK_RIGHT) || GAME_ENGINE->IsKeyDown(VK_LEFT))
  90.     {
  91.         if(m_Timer % 10 == 0)
  92.         {
  93.             m_RectMov = (m_RectMovCounter % 5) * 42;
  94.             ++m_RectMovCounter;
  95.             m_Timer = 0;
  96.         }
  97.         ++m_Timer;
  98.     }
  99.     else
  100.     {
  101.         m_RectMov = 0;
  102.         m_Timer = 0;
  103.     }
  104.  
  105.     //Moving Bubbles
  106.  
  107.     if(GAME_ENGINE->IsKeyDown(TCHAR (VK_RIGHT)))
  108.     {
  109.         m_ScaleBubble.x = 1;
  110.         m_PosBubble.x += 2;
  111.         m_BoolSwitchSide = false;
  112.        
  113.     }
  114.  
  115.     if(GAME_ENGINE->IsKeyDown(VK_LEFT))
  116.     {
  117.         m_ScaleBubble.x = -1;
  118.         m_PosBubble.x -= 2;
  119.         m_BoolSwitchSide = true;
  120.        
  121.     }
  122.  
  123.     if(m_BoolSwitchSide == false)
  124.     {
  125.         m_BubbleArr[m_CurrentBubble].Switch = false;
  126.     }
  127.  
  128.     if(m_BoolSwitchSide == true)
  129.     {
  130.         m_BubbleArr[m_CurrentBubble].Switch = true;
  131.     }
  132.     int miniTimer(0);
  133.  
  134.     if(m_BoolJump == true)
  135.     {
  136.         if(m_TimerJumping < 47)
  137.         {
  138.             m_PosBubble.y -= 4;
  139.            
  140.  
  141.         }
  142.        
  143.  
  144.         else
  145.         {
  146.             m_BoolJump = false;
  147.             m_TimerJumping = 0;
  148.         }
  149.  
  150.         if(miniTimer % 10 == 0)
  151.         {
  152.             m_RectJumpMov = 42;
  153.         }
  154.         else
  155.         {
  156.             m_RectJumpMov = 0;
  157.         }
  158.        
  159.         ++m_TimerJumping;
  160.         ++miniTimer;
  161.     }
  162.  
  163.     //Shooting
  164.     ++m_BubbleTick;
  165.    
  166.     for(int counter = 0; counter < MAX_BUBBLES; ++counter)
  167.     {
  168.         if(m_BubbleArr[counter].shoot == false)
  169.         {
  170.             m_BubbleArr[counter].PosUpdate = m_PosBubble;
  171.         }
  172.         if(m_BubbleArr[counter].shoot == true)
  173.         {
  174.                
  175.                 if(m_BubbleArr[counter].bubbleSpeed.x > 175 || m_BubbleArr[counter].CollisionHor == true )
  176.                 {
  177.                     if(m_BubbleArr[counter].Collision == false)
  178.                     {
  179.                    
  180.                         m_BubbleArr[counter].bubbleSpeed.y -= 1;
  181.  
  182.                     }
  183.                     if(m_BubbleArr[counter].Collision == true)
  184.                     {
  185.                         m_BubbleArr[counter].bubbleSpeed.y -= 0;
  186.                     }
  187.                     if(m_BubbleArr[counter].CollisionHor == true)
  188.                     {
  189.                         m_BubbleArr[counter].bubbleSpeed.y -= 1;
  190.                         //m_BubbleArr[counter].bubbleSpeed.x -= 0;
  191.                     }
  192.                 }
  193.                 else
  194.                 {
  195.                    
  196.                         m_BubbleArr[counter].bubbleSpeed.x += 3;
  197.                    
  198.                 }
  199.                
  200.         }
  201.     }
  202.    
  203.     if(m_BoolShoot == true)
  204.     {
  205.        
  206.        
  207.        
  208.        
  209.         if(m_TimerShoot % 20 == 0)
  210.         {
  211.             m_RectBubbleShoot += 42;
  212.            
  213.             m_TimerShoot = 0;
  214.             ++m_RectShootMovCounter;
  215.         }
  216.         else
  217.         {
  218.             m_RectBubbleShoot = 0;
  219.            
  220.         }
  221.         if(m_RectShootMovCounter == 4)
  222.         {
  223.             m_RectShootMovCounter = 0;
  224.             m_BoolShoot = false;
  225.         }
  226.         ++m_TimerShoot;
  227.        
  228.        
  229.        
  230.        
  231.        
  232.        
  233.            
  234.        
  235.        
  236.     }
  237.  
  238.     //hITEST
  239.     if(m_TimerBulletBubble == 10)
  240.     {
  241.         m_TimerBulletBubble = 0;
  242.         BulletBubbleLevelCollision();
  243.     }
  244.  
  245.     ++m_TimerBulletBubble;
  246.    
  247.     //Gravity
  248.     m_PosBubble.y += 2;
  249.  
  250.    
  251.     //HitRegion Position
  252.     m_BubbleHitRegionHPPtr->SetPos(m_PosBubble);
  253.     m_BubbleHitRegionVPPtr->SetPos(m_PosBubble);
  254.    
  255.     for( int counter = 0; counter < MAX_BUBBLES ; ++counter)
  256.     {
  257.         if(m_BubbleArr[counter].shoot == true)
  258.         {
  259.             if( m_BubbleArr[counter].Switch == false)
  260.             {
  261.                 m_BubbleArr[counter].HittestVert->SetPos(m_BubbleArr[counter].PosUpdate.x + m_BubbleArr[counter].bubbleSpeed.x, m_BubbleArr[counter].PosUpdate.y - 10  + m_BubbleArr[counter].bubbleSpeed.y);
  262.                 m_BubbleArr[counter].HittestHor->SetPos(m_BubbleArr[counter].PosUpdate.x + m_BubbleArr[counter].bubbleSpeed.x, m_BubbleArr[counter].PosUpdate.y - 10  + m_BubbleArr[counter].bubbleSpeed.y);
  263.             }
  264.  
  265.             if(m_BubbleArr[counter].Switch == true)
  266.             {
  267.            
  268.                 m_BubbleArr[counter].HittestVert->SetPos(m_BubbleArr[counter].PosUpdate.x - m_BubbleArr[counter].bubbleSpeed.x, m_BubbleArr[counter].PosUpdate.y - 10  + m_BubbleArr[counter].bubbleSpeed.y);
  269.                 m_BubbleArr[counter].HittestHor->SetPos(m_BubbleArr[counter].PosUpdate.x - m_BubbleArr[counter].bubbleSpeed.x, m_BubbleArr[counter].PosUpdate.y - 10  + m_BubbleArr[counter].bubbleSpeed.y);
  270.             }
  271.         }
  272.     }
  273.            
  274. }
  275.  
  276. void Bubble::Movement(TCHAR cKey)
  277. {
  278.     //Jumping
  279.  
  280.     if(cKey == 'Z')
  281.     {
  282.         m_ScaleBubble.x = 1;
  283.         m_BoolJump = true;
  284.     }
  285.  
  286.     //Shooting
  287.     if(cKey == 'A')
  288.     {
  289.         m_BoolShoot = true;
  290.         m_BubbleArr[m_CurrentBubble].shoot = true;
  291.         ++m_CurrentBubble;
  292.     }
  293.  
  294.    
  295.        
  296.    
  297. }
  298.  
  299. void Bubble::Paint(double scale_Camera, DOUBLE2 posCamera)
  300. {
  301.  
  302.     //Camera
  303.     MATRIX3X2 matView, matCenter, matScale, matRotate, matTranslate, matTransform, matCamera;
  304.     matTranslate.SetAsTranslate(posCamera);
  305.     matScale.SetAsScale(scale_Camera);
  306.     matCamera = matScale * matTranslate;
  307.     matView = matCamera.Inverse();
  308.     matTransform = matView;
  309.     GAME_ENGINE->SetTransformMatrix(matTransform);
  310.  
  311.     matCenter.SetAsTranslate(-35 / 2, - 32 / 2);
  312.     matTranslate.SetAsTranslate(m_PosBubble);
  313.     matScale.SetAsScale(m_ScaleBubble.x, m_ScaleBubble.y);
  314.     matTransform = matCenter * matScale * matTranslate * matView;
  315.     GAME_ENGINE->SetTransformMatrix(matTransform);
  316.  
  317.     //Paint Sprite
  318.     //Moving
  319.    
  320.     if(m_BoolJump == false && m_BoolShoot == false)
  321.     {
  322.  
  323.         RECT bubble;
  324.  
  325.         bubble.top = 32;
  326.         bubble.bottom = 64;
  327.         bubble.left = 1242 - m_RectMov;
  328.         bubble.right = 1277 - m_RectMov;
  329.  
  330.         GAME_ENGINE->DrawBitmap(m_BmpBubblePtr, 0 , 0, bubble);
  331.     }
  332.     else
  333.     {
  334.         RECT bubble;
  335.  
  336.         bubble.top = 0;
  337.         bubble.bottom = 0;
  338.         bubble.left = 0;
  339.         bubble.right = 0;
  340.  
  341.         GAME_ENGINE->DrawBitmap(m_BmpBubblePtr, 0, 0, bubble);
  342.     }
  343.    
  344.  
  345.     if(m_BoolJump == true)
  346.     {
  347.        
  348.         RECT jumpBubble;
  349.  
  350.         jumpBubble.top = 72;
  351.         jumpBubble.bottom = 104;
  352.         jumpBubble.left = 821 - m_RectJumpMov;
  353.         jumpBubble.right = 856 - m_RectJumpMov;
  354.  
  355.         GAME_ENGINE->DrawBitmap(m_BmpBubblePtr, 0 , 0, jumpBubble);
  356.     }
  357.  
  358.    
  359.  
  360.     if(m_BoolShoot == true)
  361.     {
  362.         RECT shootBubble;
  363.  
  364.         shootBubble.right = 1279 - m_RectBubbleShoot;
  365.         shootBubble.left = 1241 - m_RectBubbleShoot;
  366.         shootBubble.top = 72;
  367.         shootBubble.bottom = 104;
  368.         GAME_ENGINE->DrawBitmap(m_BmpBubblePtr, 0 , 0, shootBubble);
  369.     }
  370.    
  371.  
  372.     GAME_ENGINE->SetTransformMatrix(MATRIX3X2());
  373.  
  374.     GAME_ENGINE->SetColor(0, 0,255);
  375.     GAME_ENGINE->DrawHitRegion(m_BubbleHitRegionHPPtr);
  376.     GAME_ENGINE->DrawHitRegion(m_BubbleHitRegionVPPtr);
  377.     for(int counter = 0; counter < MAX_BUBBLES; ++counter)
  378.     {
  379.         GAME_ENGINE->DrawHitRegion(m_BubbleArr[counter].HittestVert);
  380.         GAME_ENGINE->DrawHitRegion(m_BubbleArr[counter].HittestHor);
  381.     }
  382.     //GAME_ENGINE->FillHitRegion(m_SVG_BulletBubblesPtr);
  383.  
  384.  
  385.     //Shooting Bubbles Camera
  386.  
  387.     RECT shootBubbles;
  388.     for( int counter = 0; counter < MAX_BUBBLES ; ++counter)
  389.     {
  390.         if(m_BubbleArr[counter].shoot == true)
  391.         {
  392.             if( m_BubbleArr[counter].Switch == false)
  393.             {
  394.                 shootBubbles.top = 2144;
  395.                 shootBubbles.bottom = 2176;
  396.                 shootBubbles.left = 1212;
  397.                 shootBubbles.right = 1240;
  398.  
  399.                 GAME_ENGINE->DrawBitmap(m_BmpBubbleAttackPtr, m_BubbleArr[counter].PosUpdate.x + m_BubbleArr[counter].bubbleSpeed.x, m_BubbleArr[counter].PosUpdate.y - 15 + m_BubbleArr[counter].bubbleSpeed.y, shootBubbles);
  400.             }
  401.             if(m_BubbleArr[counter].Switch == true)
  402.             {
  403.                 shootBubbles.top = 2144;
  404.                 shootBubbles.bottom = 2176;
  405.                 shootBubbles.left = 1212;
  406.                 shootBubbles.right = 1240;
  407.  
  408.                 GAME_ENGINE->DrawBitmap(m_BmpBubbleAttackPtr, m_BubbleArr[counter].PosUpdate.x - m_BubbleArr[counter].bubbleSpeed.x, m_BubbleArr[counter].PosUpdate.y - 15 + + m_BubbleArr[counter].bubbleSpeed.y , shootBubbles);
  409.             }
  410.         }
  411.     }
  412.    
  413.  
  414.    
  415. }
  416.  
  417. void Bubble::HitTest(HitRegion *Hitregion)
  418. {
  419.     //SVG against Hero hit
  420.     RECT2 r = Hitregion->CollisionTest(m_BubbleHitRegionVPPtr);
  421.     if((r.bottom-r.top) > 0)
  422.     {
  423.         // hero hits level with feet
  424.         if(abs(r.bottom-m_BubbleHitRegionVPPtr->GetBounds().bottom)<0.1)
  425.         {
  426.             m_PosBubble.y -= r.bottom - r.top;
  427.            
  428.             //GAME_ENGINE->MessageBox("hit");
  429.  
  430.  
  431.         }
  432.  
  433.    
  434.         // hero hits level with head
  435.         //if(abs(r.top-m_BubbleHitRegionPtr->GetBounds().top)<0.1)
  436.         //{
  437.         //  m_PosBubble.y += r.bottom - r.top;
  438.         // 
  439.         //  //GAME_ENGINE->MessageBox("hit");
  440.         //}
  441.     }
  442.         RECT2 r2 = Hitregion->CollisionTest(m_BubbleHitRegionHPPtr);
  443.  
  444.         m_Value = r2.right-m_BubbleHitRegionHPPtr->GetBounds().right;
  445.         if(abs(m_Value) < 0.1 )
  446.         {
  447.             m_PosBubble.x -= r2.right - r2.left;
  448.            
  449.             //GAME_ENGINE->MessageBox("hit right");
  450.         }
  451.         if( abs(r2.left - m_BubbleHitRegionHPPtr->GetBounds().left) < 0.1)
  452.         {
  453.             m_PosBubble.x += r2.right - r2.left;
  454.            
  455.             //GAME_ENGINE->MessageBox("hit left");
  456.         }
  457.  
  458.  
  459.         // set the hit regions to their new positions
  460.         //m_SuperSheepHitRegionPtr->SetPos(m_PosSheep);
  461.        
  462. }
  463.  
  464. void Bubble::BulletBubbleLevelCollision()
  465. {
  466.  
  467.     for(int counter = 0; counter < MAX_BUBBLES; ++counter)
  468.     {
  469.            
  470.    
  471.         RECT2 r = m_SVG_BulletBubblesPtr->CollisionTest(m_BubbleArr[counter].HittestVert);
  472.         if((r.bottom-r.top) > 0)
  473.         {
  474.            
  475.                 if(abs(r.top-m_BubbleArr[counter].HittestVert->GetBounds().top)<0.1)
  476.                 {
  477.                     m_BubbleArr[counter].bubbleSpeed.y  += r.bottom - r.top;
  478.                     m_BubbleArr[counter].Collision = true;
  479.                
  480.            
  481.                     //GAME_ENGINE->MessageBox("hit");
  482.                 }
  483.         }
  484.            
  485.        
  486.  
  487.         RECT2 r2 = m_SVG_BulletBubblesPtr->CollisionTest(m_BubbleArr[counter].HittestHor);
  488.  
  489.         /*if((r2.right - r2.left) > 0)
  490.         {
  491.             if(abs(r2.right-m_BubbleArr[counter].HittestHor->GetBounds().right) < 0.1 )
  492.             {
  493.                 m_BubbleArr[counter].bubbleSpeed.x += 3;
  494.                 m_BubbleArr[counter].CollisionHor = true;*/
  495.            
  496.                 //GAME_ENGINE->MessageBox("hit right");
  497.             //}
  498.  
  499.         //  if( abs(r2.left - m_BubbleArr[counter].HittestHor->GetBounds().left) < 0.1)
  500.         //  {
  501.         //      m_BubbleArr[counter].bubbleSpeed.x += r2.right - r2.left;
  502.         //      m_BubbleArr[counter].CollisionHor = true;
  503.         //     
  504.         //      //GAME_ENGINE->MessageBox("hit left");
  505.         //  }
  506.        
  507.        
  508.        
  509.     }
  510.            
  511. }
Add Comment
Please, Sign In to add comment