Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-----------------------------------------------------
- // Name, first name:De Mulder Thomas
- // Group: 1DAE2
- //-----------------------------------------------------
- //---------------------------
- // Includes
- //---------------------------
- #include "Mario.h"
- //---------------------------
- // Defines
- //---------------------------
- #define GAME_ENGINE (GameEngine::GetSingleton())
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- //---------------------------
- // Constructor & Destructor
- //---------------------------
- Mario::Mario(HitRegion *hitLevel, DOUBLE2 gravity,MATRIX3X2 scale,MATRIX3X2 position):
- m_HitLevelPtr(hitLevel),m_Gravity(gravity),
- m_MatBigger(scale),m_MatSetOrigin(position),
- m_TickCount(0),m_MarioPos(0,0),
- m_MarioScale(1,1),m_MarioVelocity(0,0),
- m_CameraPos(0,0),m_BmpMarioPtr(nullptr),
- m_DrawHitregion(false),m_HitLevelPlatformPtr(nullptr),
- m_BmpBarPtr(nullptr),m_MarioAcceleration(0),
- m_MaxSpeed(100),m_Drag(100),
- m_IsKPressed(false),m_AudioJumpPtr(nullptr),
- m_AudioDiePtr(nullptr),m_AudioSmallerPtr(nullptr),
- m_BmpBigBarPtr(nullptr),m_BigBar(4824,376),
- m_BigBarSpeed(-80),m_BigStance(false),
- m_AudioMidGatePtr(nullptr),m_AudioEndPtr(nullptr),
- m_AudioBackgroundPtr(nullptr)
- {
- m_Movement=STANDING;
- m_Stance=SMALL;
- m_BmpMarioPtr= new Bitmap("resources/MarioSprite.png");
- m_MarioRect.left=0;
- m_MarioRect.right=m_MarioRect.left+20;
- m_MarioRect.top=0;
- m_MarioRect.bottom=m_MarioRect.top+31;
- m_HitLevelPlatformPtr = new HitRegion();
- m_HitLevelPlatformPtr->CreateFromSVG("resources/WorldPlatforms.svg");
- m_BmpBarPtr= new Bitmap("Resources/Bar.png");
- for (int i = 0; i < BLOCKS; i++)
- {
- m_HitBlockArr[i]=new HitRegion();
- m_HitBlockArr[i]->CreateFromRect(0,0,16,16);
- }
- for (int i = 0; i < TURN; i++)
- {
- m_TurnBlockHitArr[i]=false;
- }
- m_AudioJumpPtr = new Audio("resources/smw_jump.wav");
- m_AudioDiePtr = new Audio("resources/smw_death.wav");
- m_AudioSmallerPtr = new Audio("resources/smw_powerdown.wav");
- m_BmpBigBarPtr= new Bitmap("resources/BigBar.png");
- m_AudioMidGatePtr= new Audio("resources/smw_midway_gate.wav");
- m_AudioEndPtr= new Audio("resources/smw_course_clear.wav");
- m_AudioBackgroundPtr= new Audio("resources/SMW_BackgroundMusic.mp3");
- }
- Mario::~Mario()
- {
- delete m_BmpMarioPtr;
- delete m_HitLevelPlatformPtr;
- delete m_BmpBarPtr;
- for (int i = 0; i < BLOCKS; i++)
- {
- delete m_HitBlockArr[i];
- }
- delete m_AudioJumpPtr;
- delete m_AudioDiePtr;
- delete m_AudioSmallerPtr;
- delete m_BmpBigBarPtr;
- delete m_AudioMidGatePtr;
- delete m_AudioEndPtr;
- delete m_AudioBackgroundPtr;
- }
- //---------------------------
- // Methods - Member functions
- //---------------------------
- void Mario::Keypressed(TCHAR ckey)
- {
- switch (ckey)
- {
- case 'H':
- m_DrawHitregion=!m_DrawHitregion;
- break;
- case 'G':
- m_MarioPos.x+=1000;
- m_MarioPos.y-=100;
- break;
- case 'F':
- m_MarioPos.x-=1000;
- m_MarioPos.y-=100;
- break;
- case 'B':
- GetBigger();
- break;
- case 'N':
- GetSmaller();
- break;
- case 'K':
- m_IsKPressed=true;
- break;
- }
- }
- void Mario::Paint()
- {
- // Choosing the pictures
- switch (m_Stance)
- {
- case BIG:
- switch (m_Movement)
- {
- case Mario::STANDING:
- m_MarioRect.left=0;
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=0;
- m_MarioRect.bottom=m_MarioRect.top+30;
- break;
- case Mario::WALKING:
- m_MarioRect.left=20*(m_TickCount/5);
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=0;
- m_MarioRect.bottom=m_MarioRect.top+30;
- break;
- case Mario::JUMPING:
- if(m_MarioVelocity.y>0)
- {
- m_MarioRect.left=140;
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=0;
- m_MarioRect.bottom=m_MarioRect.top+30;
- }
- if(m_MarioVelocity.y<0)
- {
- m_MarioRect.left=120;
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=0;
- m_MarioRect.bottom=m_MarioRect.top+30;
- }
- break;
- case Mario::CROUCHING:
- m_MarioRect.left=100;
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=0;
- m_MarioRect.bottom=m_MarioRect.top+30;
- break;
- case Mario::LOOKINGUP:
- m_MarioRect.left=80;
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=0;
- m_MarioRect.bottom=m_MarioRect.top+30;
- break;
- case Mario::RUNNING:
- m_MarioRect.left=20*(m_TickCount/5);
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=0;
- m_MarioRect.bottom=m_MarioRect.top+30;
- break;
- case Mario::CHANGE:
- m_MarioRect.left=60;
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=0;
- m_MarioRect.bottom=m_MarioRect.top+30;
- break;
- }
- break;
- case SMALL:
- switch (m_Movement)
- {
- case Mario::STANDING:
- m_MarioRect.left=0;
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=94;
- m_MarioRect.bottom=m_MarioRect.top+30;
- break;
- case Mario::WALKING:
- m_MarioRect.left=20*(m_TickCount/5);
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=94;
- m_MarioRect.bottom=m_MarioRect.top+30;
- break;
- case Mario::JUMPING:
- if(m_MarioVelocity.y>0)
- {
- m_MarioRect.left=140;
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=94;
- m_MarioRect.bottom=m_MarioRect.top+30;
- }
- if(m_MarioVelocity.y<0)
- {
- m_MarioRect.left=120;
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=94;
- m_MarioRect.bottom=m_MarioRect.top+30;
- }
- break;
- case Mario::CROUCHING:
- m_MarioRect.left=100;
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=94;
- m_MarioRect.bottom=m_MarioRect.top+30;
- break;
- case Mario::LOOKINGUP:
- m_MarioRect.left=80;
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=94;
- m_MarioRect.bottom=m_MarioRect.top+30;
- break;
- case Mario::RUNNING:
- m_MarioRect.left=20*(m_TickCount/3);
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=94;
- m_MarioRect.bottom=m_MarioRect.top+30;
- break;
- case Mario::CHANGE:
- m_MarioRect.left=60;
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=94;
- m_MarioRect.bottom=m_MarioRect.top+30;
- break;
- }
- break;
- case DEAD:
- {
- m_MarioRect.left=180;
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=94;
- m_MarioRect.bottom=m_MarioRect.top+30;
- }
- break;
- case END:
- {
- if(m_BigStance)
- {
- if(m_MarioPos.x<4930)
- {
- m_MarioRect.left=20*(m_TickCount/5);
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=0;
- m_MarioRect.bottom=m_MarioRect.top+30;
- }
- else
- {
- m_MarioRect.left=160;
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=0;
- m_MarioRect.bottom=m_MarioRect.top+30;
- }
- }
- else
- {
- if(m_MarioPos.x<4930)
- {
- m_MarioRect.left=20*(m_TickCount/5);
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=94;
- m_MarioRect.bottom=m_MarioRect.top+30;
- }
- else
- {
- m_MarioRect.left=160;
- m_MarioRect.right=m_MarioRect.left+19;
- m_MarioRect.top=94;
- m_MarioRect.bottom=m_MarioRect.top+30;
- }
- }
- }
- break;
- }
- // Locals
- MATRIX3X2 matTransform, matTranslate,matScale,matCenter;
- MATRIX3X2 matView,matCamera;
- matCamera.SetAsTranslate(m_CameraPos);
- matView=matCamera.Inverse();
- //Bar
- if(m_BmpBarPtr!=nullptr)
- {
- matTranslate.SetAsTranslate(2573,370);
- matTransform=matTranslate*matView*m_MatSetOrigin*m_MatBigger;
- GAME_ENGINE->SetTransformMatrix(matTransform);
- GAME_ENGINE->DrawBitmap(m_BmpBarPtr);
- }
- //BigBar
- if(m_BmpBigBarPtr!=nullptr)
- {
- matTranslate.SetAsTranslate(m_BigBar);
- matTransform=matTranslate*matView*m_MatSetOrigin*m_MatBigger;
- GAME_ENGINE->SetTransformMatrix(matTransform);
- GAME_ENGINE->DrawBitmap(m_BmpBigBarPtr);
- }
- // Making him move
- matTranslate.SetAsTranslate(m_MarioPos);
- matScale.SetAsScale(m_MarioScale.x,m_MarioScale.y);
- matCenter.SetAsTranslate(-8,0);
- matTransform=matCenter*matScale*matCenter.Inverse()*matTranslate*matView*m_MatSetOrigin*m_MatBigger;
- GAME_ENGINE->SetTransformMatrix(matTransform);
- GAME_ENGINE->DrawBitmap(m_BmpMarioPtr,0,0,m_MarioRect);
- //HitRegions
- if(m_DrawHitregion)
- {
- matView=matCamera.Inverse()*m_MatSetOrigin*m_MatBigger;
- GAME_ENGINE->SetTransformMatrix(matView);
- GAME_ENGINE->SetColor(COLOR(255,0,0,125));
- GAME_ENGINE->FillHitRegion(m_HitLevelPlatformPtr);
- }
- //Console Check
- /*GAME_ENGINE->ConsoleClear();
- cout <<"Vertical velocity : "<<m_MarioVelocity.y << endl;
- cout <<"Horizontal velocity : "<<m_MarioVelocity.x << endl;
- cout <<endl;
- cout <<"Vertical position : "<<m_MarioPos.y<< endl;*/
- //cout <<"Horizontal position : "<<m_MarioPos.x<< endl;
- }
- void Mario::Tick(double deltaTime)
- {
- //Audio
- m_AudioJumpPtr->Tick();
- m_AudioDiePtr->Tick();
- m_AudioSmallerPtr->Tick();
- m_AudioMidGatePtr->Tick();
- m_AudioEndPtr->Tick();
- m_AudioBackgroundPtr->Tick();
- if(m_Stance!=DEAD&&m_Stance!=END)
- {
- m_AudioBackgroundPtr->Play();
- //TickCount
- if (GAME_ENGINE->IsKeyDown('S'))
- {
- m_TickCount=0;
- m_Movement=CROUCHING;
- }
- else if(m_MarioVelocity.y!=0)
- {
- m_TickCount=0;
- m_Movement=JUMPING;
- }
- else if(m_MarioVelocity.x>5&&GAME_ENGINE->IsKeyDown('Q'))
- {
- m_Movement=CHANGE;
- }
- else if(m_MarioVelocity.x<-5&&GAME_ENGINE->IsKeyDown('D'))
- {
- m_Movement=CHANGE;
- }
- else if(m_MarioVelocity.x>120||m_MarioVelocity.x<-120)
- {
- m_TickCount=(m_TickCount+1)%9;
- m_Movement=RUNNING;
- }
- else if (GAME_ENGINE->IsKeyDown('D')||m_MarioVelocity.x>5)
- {
- m_TickCount=(m_TickCount+1)%10;
- m_Movement=WALKING;
- }
- else if (GAME_ENGINE->IsKeyDown('Q')||m_MarioVelocity.x<-5)
- {
- m_TickCount=(m_TickCount+1)%10;
- m_Movement=WALKING;
- }
- else if (GAME_ENGINE->IsKeyDown('Z'))
- {
- m_TickCount=0;
- m_Movement=LOOKINGUP;
- }
- else
- {
- m_Movement=STANDING;
- m_TickCount=0;
- }
- //Raycast working
- MoveMario(deltaTime);
- //Bar
- Bar();
- //BigBar
- BigBar();
- m_BigBar.y+=m_BigBarSpeed*deltaTime;
- if(m_BigBar.y>376&&m_BigBarSpeed>0)
- m_BigBarSpeed*=-1;
- if(m_BigBar.y<250&&m_BigBarSpeed<0)
- m_BigBarSpeed*=-1;
- //End
- if(m_MarioPos.x>4830)
- {
- if(m_Stance==BIG)
- m_BigStance=true;
- m_Stance=END;
- m_AudioBackgroundPtr->Stop();
- }
- }
- else if(m_Stance==END)
- {
- if(m_MarioPos.x<4930)
- {
- m_TickCount=(m_TickCount+1)%10;
- m_MarioPos.x+=30*deltaTime;
- }
- if(m_MarioPos.y<354)
- {
- m_MarioVelocity+=m_Gravity*deltaTime;
- m_MarioPos.y+=m_MarioVelocity.y*deltaTime;
- }
- if(m_MarioPos.y>354)
- m_MarioPos.y=354;
- }
- else
- {
- m_AudioBackgroundPtr->Stop();
- m_MarioVelocity.x=0;
- m_MarioVelocity+=m_Gravity/4*deltaTime;
- m_MarioPos+=m_MarioVelocity/4*deltaTime;
- }
- }
- void Mario::MoveMario(double deltaTime)
- {
- //Horizontal Movement
- if(m_Movement!=CROUCHING||m_MarioVelocity.y!=0)
- {
- if(GAME_ENGINE->IsKeyDown('L'))
- {
- m_MaxSpeed=150;
- }
- else m_MaxSpeed=100;
- if(GAME_ENGINE->IsKeyDown('Q'))
- {
- m_MarioAcceleration=-300;
- m_MarioScale.x=-1;
- }
- else if (GAME_ENGINE->IsKeyDown('D'))
- {
- m_MarioAcceleration=300;
- m_MarioScale.x=1;
- }
- else
- {
- m_MarioAcceleration=0;
- if(m_MarioVelocity.x>-5&&m_MarioVelocity.x<5)
- {
- m_MarioVelocity.x=0;
- }
- }
- }
- else m_MarioAcceleration=0;
- if(m_MarioVelocity.x<m_MaxSpeed&&m_MarioVelocity.x>-m_MaxSpeed)
- m_MarioVelocity.x+=m_MarioAcceleration*deltaTime;
- if(m_MarioVelocity.x>0)
- m_MarioVelocity.x+=-m_Drag*deltaTime;
- if(m_MarioVelocity.x<0)
- m_MarioVelocity.x+=m_Drag*deltaTime;
- //Gravity
- m_MarioVelocity+=m_Gravity*deltaTime;
- m_MarioPos+=m_MarioVelocity*deltaTime;
- if(m_CameraPos.x>m_MarioPos.x-50&&m_CameraPos.x>50)
- m_CameraPos.x=m_MarioPos.x-50;
- if(m_CameraPos.x<m_MarioPos.x-150)
- m_CameraPos.x=m_MarioPos.x-150;
- ////Prevent from leaving
- //if(m_MarioPos.y > 389 && m_MarioVelocity.y>0)
- //{
- // m_MarioPos.y=389;
- // m_MarioVelocity.y=0;
- //}
- //Vertical collision
- VerticalCollision(m_HitLevelPtr);
- VerticalNTopCollision(m_HitLevelPlatformPtr);
- for (int i = 0; i < 19; i++)
- {
- if(i>8)
- {
- if(!(m_TurnBlockHitArr[i-9])) VerticalCollision(m_HitBlockArr[i]);
- }
- else VerticalCollision(m_HitBlockArr[i]);
- }
- //Hoirzontal collision
- HorizontalCollision(m_HitLevelPtr);
- for (int i = 0; i < 19; i++)
- {
- if(i>8)
- {
- if(!(m_TurnBlockHitArr[i-9])) HorizontalCollision(m_HitBlockArr[i]);
- }
- else HorizontalCollision(m_HitBlockArr[i]);
- }
- }
- DOUBLE2 Mario::GetMarioPos()
- {
- return m_MarioPos;
- }
- void Mario::VerticalCollision(HitRegion *level)
- {
- /*RECT2 verticalRect=mover->CollisionTest(level);
- if(verticalRect.bottom-verticalRect.top>0)
- {
- if(abs(mover->GetBounds().bottom -verticalRect.bottom)<1)
- {
- m_MarioPos.y-=verticalRect.bottom-verticalRect.top;
- m_MarioVelocity.y=0;
- if(m_IsKPressed)
- {
- m_MarioVelocity.y=-400;
- m_IsKPressed=false;
- }
- }
- if(abs(mover->GetBounds().top -verticalRect.top)<1)
- {
- m_MarioPos.y+=verticalRect.bottom-verticalRect.top;
- m_MarioVelocity.y=0;
- }
- }*/
- HIT hitArr[1];
- DOUBLE2 startPoint = m_MarioPos;
- DOUBLE2 vector = DOUBLE2(0,13);
- startPoint.x = m_MarioPos.x+4;
- startPoint.y = m_MarioPos.y+17;
- int numbHits = 0;
- numbHits = level->Raycast(startPoint,vector,hitArr,1);
- if(numbHits > 0)
- {
- m_MarioVelocity.y = 0;
- double depth = vector.Length() * (1-hitArr[0].lambda);
- m_MarioPos.y -= depth;
- if(m_IsKPressed)
- {
- m_MarioVelocity.y=-400;
- m_IsKPressed=false;
- m_AudioJumpPtr->Play();
- }
- }
- else{
- startPoint.x = m_MarioPos.x+12;
- numbHits = 0;
- numbHits = level->Raycast(startPoint,vector,hitArr,1);
- if(numbHits > 0)
- {
- m_MarioVelocity.y = 0;
- double depth = vector.Length() * (1-hitArr[0].lambda);
- m_MarioPos.y -= depth;
- if(m_IsKPressed)
- {
- m_MarioVelocity.y=-400;
- m_IsKPressed=false;
- m_AudioJumpPtr->Play();
- }
- }
- else
- {
- vector = DOUBLE2(0,-14);
- startPoint.x = m_MarioPos.x+4;
- startPoint.y = m_MarioPos.y+17;
- numbHits = 0;
- numbHits = level->Raycast(startPoint,vector,hitArr,1);
- if(numbHits > 0)
- {
- m_MarioVelocity.y = 0;
- double depth = vector.Length() * (1-hitArr[0].lambda);
- m_MarioPos.y += depth;
- }
- else
- {
- startPoint.x = m_MarioPos.x+12;
- numbHits = 0;
- numbHits = level->Raycast(startPoint,vector,hitArr,1);
- if(numbHits > 0)
- {
- m_MarioVelocity.y = 0;
- double depth = vector.Length() * (1-hitArr[0].lambda);
- m_MarioPos.y += depth;
- }
- }
- }
- }
- }
- void Mario::VerticalNTopCollision(HitRegion *level)
- {
- /*RECT2 verticalPlatformRect=mover->CollisionTest(level);
- if(verticalPlatformRect.bottom-verticalPlatformRect.top>0&&m_MarioVelocity.y>0)
- {
- if(abs(mover->GetBounds().bottom -verticalPlatformRect.bottom)<10)
- {
- m_MarioPos.y-=verticalPlatformRect.bottom-verticalPlatformRect.top;
- m_MarioVelocity.y=0;
- if(m_IsKPressed)
- {
- m_MarioVelocity.y=-400;
- m_IsKPressed=false;
- }
- }
- }*/
- HIT hitArr[1];
- DOUBLE2 startPoint = m_MarioPos;
- DOUBLE2 vector = DOUBLE2(0,25);
- startPoint.x = m_MarioPos.x+4;
- startPoint.y = m_MarioPos.y+4;
- int numbHits = 0;
- numbHits = level->Raycast(startPoint,vector,hitArr,1);
- if(numbHits > 0&&m_MarioVelocity.y>=0)
- {
- m_MarioVelocity.y = 0;
- double depth = vector.Length() * (1-hitArr[0].lambda);
- m_MarioPos.y -= depth;
- if(m_IsKPressed)
- {
- m_MarioVelocity.y=-400;
- m_IsKPressed=false;
- m_AudioJumpPtr->Play();
- }
- }
- else
- {
- startPoint.x = m_MarioPos.x+12;
- numbHits = 0;
- numbHits = level->Raycast(startPoint,vector,hitArr,1);
- if(numbHits > 0&&m_MarioVelocity.y>=0)
- {
- m_MarioVelocity.y = 0;
- double depth = vector.Length() * (1-hitArr[0].lambda);
- m_MarioPos.y -= depth;
- if(m_IsKPressed)
- {
- m_MarioVelocity.y=-400;
- m_IsKPressed=false;
- m_AudioJumpPtr->Play();
- }
- }
- }
- }
- void Mario::HorizontalCollision(HitRegion *level)
- {
- /*RECT2 horizontalRect=mover->CollisionTest(level);
- if(horizontalRect.right-horizontalRect.left>0)
- {
- if(abs(mover->GetBounds().right -horizontalRect.right)<1)
- {
- m_MarioPos.x-=horizontalRect.right-horizontalRect.left;
- m_MarioVelocity.x=0;
- }
- if(abs(mover->GetBounds().left -horizontalRect.left)<1)
- {
- m_MarioPos.x+=horizontalRect.right-horizontalRect.left;
- m_MarioVelocity.x=0;
- }
- }*/
- HIT hitArr[1];
- DOUBLE2 startPoint = m_MarioPos;
- DOUBLE2 vector = DOUBLE2(6,0);
- startPoint.y = m_MarioPos.y+7;
- startPoint.x = m_MarioPos.x+10;
- int numbHits = 0;
- numbHits = level->Raycast(startPoint,vector,hitArr,1);
- if(numbHits > 0)
- {
- double depth = vector.Length() * (1-hitArr[0].lambda);
- m_MarioPos.x -= depth;
- m_MarioVelocity.x=0;
- }
- else
- {
- startPoint.y = m_MarioPos.y+17;
- numbHits = 0;
- numbHits = level->Raycast(startPoint,vector,hitArr,1);
- if(numbHits > 0)
- {
- double depth = vector.Length() * (1-hitArr[0].lambda);
- m_MarioPos.x -= depth;
- m_MarioVelocity.x=0;
- }
- else{
- startPoint.y = m_MarioPos.y+26;
- numbHits = 0;
- numbHits = level->Raycast(startPoint,vector,hitArr,1);
- if(numbHits > 0)
- {
- double depth = vector.Length() * (1-hitArr[0].lambda);
- m_MarioPos.x -= depth;
- m_MarioVelocity.x = 0;
- }
- else{
- vector = DOUBLE2(-10,0);
- startPoint.y = m_MarioPos.y+7;
- numbHits = 0;
- numbHits = level->Raycast(startPoint,vector,hitArr,1);
- if(numbHits > 0)
- {
- double depth = vector.Length() * (1-hitArr[0].lambda);
- m_MarioPos.x += depth;
- m_MarioVelocity.x=0;
- }
- else{
- startPoint.y = m_MarioPos.y+17;
- numbHits = 0;
- numbHits = level->Raycast(startPoint,vector,hitArr,1);
- if(numbHits > 0)
- {
- double depth = vector.Length() * (1-hitArr[0].lambda);
- m_MarioPos.x += depth;
- m_MarioVelocity.x=0;
- }
- else{
- startPoint.y = m_MarioPos.y+26;
- numbHits = 0;
- numbHits = level->Raycast(startPoint,vector,hitArr,1);
- if(numbHits > 0)
- {
- m_MarioVelocity.x = 0;
- double depth = vector.Length() * (1-hitArr[0].lambda);
- m_MarioPos.x += depth;
- }
- }
- }
- }
- }
- }
- }
- void Mario::GetBigger()
- {
- m_Stance=BIG;
- }
- void Mario::GetSmaller()
- {
- switch (m_Stance)
- {
- case Mario::SMALL:
- m_Stance=Mario::DEAD;
- m_MarioVelocity.y=-200;
- m_AudioDiePtr->Play();
- break;
- case Mario::BIG:
- m_Stance=Mario::SMALL;
- m_AudioSmallerPtr->Play();
- break;
- }
- }
- void Mario::Bar()
- {
- if(m_MarioPos.x>2570&&m_MarioPos.x<2575&&m_MarioPos.y>350)
- {
- m_AudioMidGatePtr->Play();
- delete m_BmpBarPtr;
- m_BmpBarPtr=nullptr;
- GetBigger();
- }
- }
- void Mario::SetHitregion(DOUBLE2 blockPosArr[])
- {
- for (int i = 0; i < 19; i++)
- {
- m_HitBlockArr[i]->SetPos(blockPosArr[i]);
- }
- }
- void Mario::ReadFile(string fileName,char sep)
- {
- ifstream file(fileName);
- if (!file) cout << "Could not open the file 'test.txt'." << endl;
- else
- {
- string sLine;
- getline(file, sLine);
- ProcessLine(sLine,sep);
- file.close();
- }
- }
- void Mario::ProcessLine(string line,char sep)
- {
- string text = line;
- string text1 = line.substr(0,line.find(sep));
- string text2 = line.substr(line.find(sep)+1);
- int x=0,y=0;
- stringstream bufferText1;
- bufferText1 << text1;
- bufferText1 >> x;
- stringstream bufferText2;
- bufferText2 << text2;
- bufferText2 >> y;
- m_MarioPos.x=x;
- m_MarioPos.y=y;
- }
- void Mario::SetBoolTurn(bool blockArr[])
- {
- for (int i = 0; i < TURN; i++)
- {
- m_TurnBlockHitArr[i]=blockArr[i];
- }
- }
- bool Mario::SetDead()
- {
- if(m_Stance==DEAD&&m_MarioPos.y>420)
- {
- return true;
- }
- else return false;
- }
- bool Mario::IsDead()
- {
- if(m_Stance==DEAD)
- {
- return true;
- }
- else return false;
- }
- void Mario::BigBar()
- {
- if(m_MarioPos.x>4830)
- {
- m_AudioEndPtr->Play();
- delete m_BmpBigBarPtr;
- m_BmpBigBarPtr=nullptr;
- }
- }
- void Mario::SetJump()
- {
- m_MarioVelocity.y=-300;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement