Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------
- // Includes
- //---------------------------
- #include "Bubble.h"
- //---------------------------
- // Defines
- //---------------------------
- #define GAME_ENGINE (GameEngine::GetSingleton())
- //---------------------------
- // Constructor & Destructor
- //---------------------------
- Bubble::Bubble(): m_BmpBubblePtr(0),
- m_RectMov(0),
- m_Timer(0),
- m_RectMovCounter(0),
- m_ScaleBubble(1,1),
- m_PosBubble(70, 445),
- m_MovBubble(0, 0),
- m_BubbleHitRegionHPPtr(0),
- m_BubbleHitRegionVPPtr(0),
- m_BoolJump(false),
- m_TimerJumping(0),
- m_RectJumpMov(0),
- m_RectJumpMovCounter(0),
- m_TimerRectJump(0),
- m_BoolShoot(false),
- m_BmpBubbleAttackPtr(0),
- m_CurrentBubble(0),
- m_BoolSwitchSide(false),
- m_RectShootMovCounter(0),
- m_RectBubbleShoot(0),
- m_TimerShoot(0),
- m_Bubblebeingshot(0),
- m_TimerBulletBubble(0),
- m_RectBulletBubbleMovCounter(0),
- m_RectBulletBubble(0,0),
- m_SVG_BulletBubblesPtr(0)
- {
- m_BmpBubblePtr = new Bitmap("./Resources/sprites.png");
- m_BmpBubblePtr->SetTransparencyColor(15, 79, 174);
- m_BubbleHitRegionHPPtr = new HitRegion();
- m_BubbleHitRegionHPPtr->CreateFromRect(-12, -19, 32, 35 / 2);
- m_BubbleHitRegionVPPtr = new HitRegion();
- m_BubbleHitRegionVPPtr->CreateFromRect(-5,-18, 32 / 2, 35);
- m_BmpBubbleAttackPtr = new Bitmap("./Resources/sprites.png");
- m_BmpBubbleAttackPtr->SetTransparencyColor(15, 79, 174);
- for(m_CurrentBubble = 0; m_CurrentBubble < MAX_BUBBLES; ++m_CurrentBubble)
- {
- m_BubbleArr[m_CurrentBubble].shoot = false;
- m_BubbleArr[m_CurrentBubble].Switch = false;
- m_BubbleArr[m_CurrentBubble].Collision = false;
- m_BubbleArr[m_CurrentBubble].CollisionHor = false;
- m_BubbleArr[m_CurrentBubble].bubbleSpeed.x = 0;
- m_BubbleArr[m_CurrentBubble].bubbleSpeed.y = 0;
- m_BubbleArr[m_CurrentBubble].HittestVert = new HitRegion();
- m_BubbleArr[m_CurrentBubble].HittestVert->CreateFromRect(10,-5,10, 35);
- m_BubbleArr[m_CurrentBubble].HittestHor = new HitRegion();
- m_BubbleArr[m_CurrentBubble].HittestHor->CreateFromRect(-3,8,35, 10);
- }
- m_CurrentBubble = 0;
- m_SVG_BulletBubblesPtr = new HitRegion();
- m_SVG_BulletBubblesPtr->CreateFromFile("./Resources/SVG_bulletBubble.svg");
- }
- Bubble::~Bubble()
- {
- for(int counter = 0; counter < MAX_BUBBLES; ++counter)
- {
- delete m_BubbleArr[counter].HittestHor;
- delete m_BubbleArr[counter].HittestVert;
- }
- }
- //---------------------------
- // Own methoden
- //---------------------------
- void Bubble::Tick(DOUBLE2 posCamera, double deltaTime)
- {
- if(GAME_ENGINE->IsKeyDown(VK_RIGHT) || GAME_ENGINE->IsKeyDown(VK_LEFT))
- {
- if(m_Timer % 10 == 0)
- {
- m_RectMov = (m_RectMovCounter % 5) * 42;
- ++m_RectMovCounter;
- m_Timer = 0;
- }
- ++m_Timer;
- }
- else
- {
- m_RectMov = 0;
- m_Timer = 0;
- }
- //Moving Bubbles
- if(GAME_ENGINE->IsKeyDown(TCHAR (VK_RIGHT)))
- {
- m_ScaleBubble.x = 1;
- m_PosBubble.x += 2;
- m_BoolSwitchSide = false;
- }
- if(GAME_ENGINE->IsKeyDown(VK_LEFT))
- {
- m_ScaleBubble.x = -1;
- m_PosBubble.x -= 2;
- m_BoolSwitchSide = true;
- }
- if(m_BoolSwitchSide == false)
- {
- m_BubbleArr[m_CurrentBubble].Switch = false;
- }
- if(m_BoolSwitchSide == true)
- {
- m_BubbleArr[m_CurrentBubble].Switch = true;
- }
- int miniTimer(0);
- if(m_BoolJump == true)
- {
- if(m_TimerJumping < 47)
- {
- m_PosBubble.y -= 4;
- }
- else
- {
- m_BoolJump = false;
- m_TimerJumping = 0;
- }
- if(miniTimer % 10 == 0)
- {
- m_RectJumpMov = 42;
- }
- else
- {
- m_RectJumpMov = 0;
- }
- ++m_TimerJumping;
- ++miniTimer;
- }
- //Shooting
- ++m_BubbleTick;
- for(int counter = 0; counter < MAX_BUBBLES; ++counter)
- {
- if(m_BubbleArr[counter].shoot == false)
- {
- m_BubbleArr[counter].PosUpdate = m_PosBubble;
- }
- if(m_BubbleArr[counter].shoot == true)
- {
- if(m_BubbleArr[counter].bubbleSpeed.x > 175 || m_BubbleArr[counter].CollisionHor == true )
- {
- if(m_BubbleArr[counter].Collision == false)
- {
- m_BubbleArr[counter].bubbleSpeed.y -= 1;
- }
- if(m_BubbleArr[counter].Collision == true)
- {
- m_BubbleArr[counter].bubbleSpeed.y -= 0;
- }
- if(m_BubbleArr[counter].CollisionHor == true)
- {
- m_BubbleArr[counter].bubbleSpeed.y -= 1;
- //m_BubbleArr[counter].bubbleSpeed.x -= 0;
- }
- }
- else
- {
- m_BubbleArr[counter].bubbleSpeed.x += 3;
- }
- }
- }
- if(m_BoolShoot == true)
- {
- if(m_TimerShoot % 20 == 0)
- {
- m_RectBubbleShoot += 42;
- m_TimerShoot = 0;
- ++m_RectShootMovCounter;
- }
- else
- {
- m_RectBubbleShoot = 0;
- }
- if(m_RectShootMovCounter == 4)
- {
- m_RectShootMovCounter = 0;
- m_BoolShoot = false;
- }
- ++m_TimerShoot;
- }
- //hITEST
- if(m_TimerBulletBubble == 10)
- {
- m_TimerBulletBubble = 0;
- BulletBubbleLevelCollision();
- }
- ++m_TimerBulletBubble;
- //Gravity
- m_PosBubble.y += 2;
- //HitRegion Position
- m_BubbleHitRegionHPPtr->SetPos(m_PosBubble);
- m_BubbleHitRegionVPPtr->SetPos(m_PosBubble);
- for( int counter = 0; counter < MAX_BUBBLES ; ++counter)
- {
- if(m_BubbleArr[counter].shoot == true)
- {
- if( m_BubbleArr[counter].Switch == false)
- {
- 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);
- 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);
- }
- if(m_BubbleArr[counter].Switch == true)
- {
- 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);
- 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);
- }
- }
- }
- }
- void Bubble::Movement(TCHAR cKey)
- {
- //Jumping
- if(cKey == 'Z')
- {
- m_ScaleBubble.x = 1;
- m_BoolJump = true;
- }
- //Shooting
- if(cKey == 'A')
- {
- m_BoolShoot = true;
- m_BubbleArr[m_CurrentBubble].shoot = true;
- ++m_CurrentBubble;
- }
- }
- void Bubble::Paint(double scale_Camera, DOUBLE2 posCamera)
- {
- //Camera
- MATRIX3X2 matView, matCenter, matScale, matRotate, matTranslate, matTransform, matCamera;
- matTranslate.SetAsTranslate(posCamera);
- matScale.SetAsScale(scale_Camera);
- matCamera = matScale * matTranslate;
- matView = matCamera.Inverse();
- matTransform = matView;
- GAME_ENGINE->SetTransformMatrix(matTransform);
- matCenter.SetAsTranslate(-35 / 2, - 32 / 2);
- matTranslate.SetAsTranslate(m_PosBubble);
- matScale.SetAsScale(m_ScaleBubble.x, m_ScaleBubble.y);
- matTransform = matCenter * matScale * matTranslate * matView;
- GAME_ENGINE->SetTransformMatrix(matTransform);
- //Paint Sprite
- //Moving
- if(m_BoolJump == false && m_BoolShoot == false)
- {
- RECT bubble;
- bubble.top = 32;
- bubble.bottom = 64;
- bubble.left = 1242 - m_RectMov;
- bubble.right = 1277 - m_RectMov;
- GAME_ENGINE->DrawBitmap(m_BmpBubblePtr, 0 , 0, bubble);
- }
- else
- {
- RECT bubble;
- bubble.top = 0;
- bubble.bottom = 0;
- bubble.left = 0;
- bubble.right = 0;
- GAME_ENGINE->DrawBitmap(m_BmpBubblePtr, 0, 0, bubble);
- }
- if(m_BoolJump == true)
- {
- RECT jumpBubble;
- jumpBubble.top = 72;
- jumpBubble.bottom = 104;
- jumpBubble.left = 821 - m_RectJumpMov;
- jumpBubble.right = 856 - m_RectJumpMov;
- GAME_ENGINE->DrawBitmap(m_BmpBubblePtr, 0 , 0, jumpBubble);
- }
- if(m_BoolShoot == true)
- {
- RECT shootBubble;
- shootBubble.right = 1279 - m_RectBubbleShoot;
- shootBubble.left = 1241 - m_RectBubbleShoot;
- shootBubble.top = 72;
- shootBubble.bottom = 104;
- GAME_ENGINE->DrawBitmap(m_BmpBubblePtr, 0 , 0, shootBubble);
- }
- GAME_ENGINE->SetTransformMatrix(MATRIX3X2());
- GAME_ENGINE->SetColor(0, 0,255);
- GAME_ENGINE->DrawHitRegion(m_BubbleHitRegionHPPtr);
- GAME_ENGINE->DrawHitRegion(m_BubbleHitRegionVPPtr);
- for(int counter = 0; counter < MAX_BUBBLES; ++counter)
- {
- GAME_ENGINE->DrawHitRegion(m_BubbleArr[counter].HittestVert);
- GAME_ENGINE->DrawHitRegion(m_BubbleArr[counter].HittestHor);
- }
- //GAME_ENGINE->FillHitRegion(m_SVG_BulletBubblesPtr);
- //Shooting Bubbles Camera
- RECT shootBubbles;
- for( int counter = 0; counter < MAX_BUBBLES ; ++counter)
- {
- if(m_BubbleArr[counter].shoot == true)
- {
- if( m_BubbleArr[counter].Switch == false)
- {
- shootBubbles.top = 2144;
- shootBubbles.bottom = 2176;
- shootBubbles.left = 1212;
- shootBubbles.right = 1240;
- 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);
- }
- if(m_BubbleArr[counter].Switch == true)
- {
- shootBubbles.top = 2144;
- shootBubbles.bottom = 2176;
- shootBubbles.left = 1212;
- shootBubbles.right = 1240;
- 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);
- }
- }
- }
- }
- void Bubble::HitTest(HitRegion *Hitregion)
- {
- //SVG against Hero hit
- RECT2 r = Hitregion->CollisionTest(m_BubbleHitRegionVPPtr);
- if((r.bottom-r.top) > 0)
- {
- // hero hits level with feet
- if(abs(r.bottom-m_BubbleHitRegionVPPtr->GetBounds().bottom)<0.1)
- {
- m_PosBubble.y -= r.bottom - r.top;
- //GAME_ENGINE->MessageBox("hit");
- }
- // hero hits level with head
- //if(abs(r.top-m_BubbleHitRegionPtr->GetBounds().top)<0.1)
- //{
- // m_PosBubble.y += r.bottom - r.top;
- //
- // //GAME_ENGINE->MessageBox("hit");
- //}
- }
- RECT2 r2 = Hitregion->CollisionTest(m_BubbleHitRegionHPPtr);
- m_Value = r2.right-m_BubbleHitRegionHPPtr->GetBounds().right;
- if(abs(m_Value) < 0.1 )
- {
- m_PosBubble.x -= r2.right - r2.left;
- //GAME_ENGINE->MessageBox("hit right");
- }
- if( abs(r2.left - m_BubbleHitRegionHPPtr->GetBounds().left) < 0.1)
- {
- m_PosBubble.x += r2.right - r2.left;
- //GAME_ENGINE->MessageBox("hit left");
- }
- // set the hit regions to their new positions
- //m_SuperSheepHitRegionPtr->SetPos(m_PosSheep);
- }
- void Bubble::BulletBubbleLevelCollision()
- {
- for(int counter = 0; counter < MAX_BUBBLES; ++counter)
- {
- RECT2 r = m_SVG_BulletBubblesPtr->CollisionTest(m_BubbleArr[counter].HittestVert);
- if((r.bottom-r.top) > 0)
- {
- if(abs(r.top-m_BubbleArr[counter].HittestVert->GetBounds().top)<0.1)
- {
- m_BubbleArr[counter].bubbleSpeed.y += r.bottom - r.top;
- m_BubbleArr[counter].Collision = true;
- //GAME_ENGINE->MessageBox("hit");
- }
- }
- RECT2 r2 = m_SVG_BulletBubblesPtr->CollisionTest(m_BubbleArr[counter].HittestHor);
- /*if((r2.right - r2.left) > 0)
- {
- if(abs(r2.right-m_BubbleArr[counter].HittestHor->GetBounds().right) < 0.1 )
- {
- m_BubbleArr[counter].bubbleSpeed.x += 3;
- m_BubbleArr[counter].CollisionHor = true;*/
- //GAME_ENGINE->MessageBox("hit right");
- //}
- // if( abs(r2.left - m_BubbleArr[counter].HittestHor->GetBounds().left) < 0.1)
- // {
- // m_BubbleArr[counter].bubbleSpeed.x += r2.right - r2.left;
- // m_BubbleArr[counter].CollisionHor = true;
- //
- // //GAME_ENGINE->MessageBox("hit left");
- // }
- }
- }
Add Comment
Please, Sign In to add comment