Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-----------------------------------------------------
- // Name, first name:De Mulder Thomas
- // Group: 1DAE2
- //-----------------------------------------------------
- //---------------------------
- // Includes
- //---------------------------
- #include "Rugby.h"
- //---------------------------
- // Defines
- //---------------------------
- #define GAME_ENGINE (GameEngine::GetSingleton())
- //---------------------------
- // Constructor & Destructor
- //---------------------------
- Rugby::Rugby(HitRegion *level,DOUBLE2 gravity,int number):
- Enemy(level,gravity,number),
- m_TickCount(0),
- m_HitTopPtr(nullptr),
- m_HitWholePtr(nullptr),
- m_Lives(3),
- m_Timer(20)
- {
- m_MonsterRect.top=124;
- m_MonsterRect.bottom=150;
- m_HitTopPtr= new HitRegion();
- m_HitTopPtr->CreateFromRect(0,0,26,3);
- m_HitWholePtr= new HitRegion();
- m_HitWholePtr->CreateFromRect(0,10,26,26);
- m_MonsterVelocity.y=0;
- }
- Rugby::~Rugby()
- {
- delete m_HitTopPtr;
- delete m_HitWholePtr;
- }
- //---------------------------
- // Methods - Member functions
- //---------------------------
- void Rugby::Paint()
- {
- MATRIX3X2 matTransform,matTranslate,matScale,matCenter;
- matTranslate.SetAsTranslate(m_MonsterPos);
- matCenter.SetAsTranslate(-13,0);
- matScale.SetAsScale(m_MonsterScale.x,m_MonsterScale.y);
- matTransform=matCenter*matScale*matTranslate*matCenter.Inverse()*m_MatView;
- GAME_ENGINE->SetTransformMatrix(matTransform);
- GAME_ENGINE->DrawBitmap(m_BmpMonsterPtr,0,0,m_MonsterRect);
- /*GAME_ENGINE->SetTransformMatrix(m_MatView);
- GAME_ENGINE->SetColor(COLOR(255,0,0,125));
- GAME_ENGINE->FillHitRegion(m_HitTopPtr);
- GAME_ENGINE->FillHitRegion(m_HitWholePtr);
- GAME_ENGINE->SetColor(COLOR(0,0,0));*/
- }
- void Rugby::Tick(double deltaTime)
- {
- //Bitmaps
- m_TickCount++;
- if(m_TickCount==10)m_TickCount=0;
- m_MonsterRect.left=90+90*(m_TickCount/5);
- m_MonsterRect.right=m_MonsterRect.left+26;
- if(m_MonsterVelocity.y<0)
- {
- m_MonsterRect.left=30;
- m_MonsterRect.right=m_MonsterRect.left+16;
- }
- if(m_MonsterVelocity.x>0)
- m_MonsterScale.x=1;
- else m_MonsterScale.x=-1;
- //move
- MoveEnemy(deltaTime);
- //hitregions
- m_HitTopPtr->SetPos(m_MonsterPos);
- m_HitWholePtr->SetPos(m_MonsterPos);
- }
- void Rugby::VerticalNTopCollision(HitRegion *level)
- {
- HIT hitArr[1];
- DOUBLE2 startPoint = m_MonsterPos;
- DOUBLE2 vector = DOUBLE2(0,22);
- startPoint.x = m_MonsterPos.x+4;
- startPoint.y = m_MonsterPos.y+4;
- int numbHits = 0;
- numbHits = level->Raycast(startPoint,vector,hitArr,1);
- if(numbHits > 0)
- {
- m_MonsterVelocity.y = 0;
- double depth = vector.Length() * (1-hitArr[0].lambda);
- m_MonsterPos.y -= depth;
- }
- else
- {
- startPoint.x = m_MonsterPos.x+12;
- numbHits = 0;
- numbHits = level->Raycast(startPoint,vector,hitArr,1);
- if(numbHits > 0)
- {
- m_MonsterVelocity.y = 0;
- double depth = vector.Length() * (1-hitArr[0].lambda);
- m_MonsterPos.y -= depth;
- }
- }
- }
- void Rugby::HorizontalCollision(HitRegion *level)
- {
- HIT hitArr[1];
- DOUBLE2 startPoint = m_MonsterPos;
- DOUBLE2 vector = DOUBLE2(13,0);
- startPoint.y = m_MonsterPos.y+22;
- startPoint.x = m_MonsterPos.x+13;
- int numbHits = 0;
- numbHits = level->Raycast(startPoint,vector,hitArr,1);
- if(numbHits > 0)
- {
- double depth = vector.Length() * (1-hitArr[0].lambda);
- m_MonsterPos.x -= depth;
- m_MonsterVelocity.x = -m_MonsterVelocity.x ;
- }
- else{
- vector = DOUBLE2(-13,0);
- numbHits = 0;
- numbHits = level->Raycast(startPoint,vector,hitArr,1);
- if(numbHits > 0)
- {
- double depth = vector.Length() * (1-hitArr[0].lambda);
- m_MonsterPos.x += depth;
- m_MonsterVelocity.x= -m_MonsterVelocity.x;
- }
- }
- }
- void Rugby::MoveEnemy(double deltaTime)
- {
- if(m_MarioPos.x>m_MonsterPos.x)
- m_DogAccelaration=150;
- else m_DogAccelaration=-150;
- //Horizontal movement
- if(m_MonsterVelocity.x<100&&m_MonsterVelocity.x>-100)
- m_MonsterVelocity.x+=m_DogAccelaration*deltaTime;
- else if(m_MonsterVelocity.x>100)
- m_MonsterVelocity.x-=2;
- else m_MonsterVelocity.x+=2;
- //gravity
- m_MonsterVelocity+=m_Gravity*deltaTime;
- m_MonsterPos+=m_MonsterVelocity*deltaTime;
- //Vertical collision
- if(!(m_MonsterVelocity.y<0))
- {
- VerticalNTopCollision(m_HitLevelPtr);
- VerticalNTopCollision(m_HitLevelPlatformPtr);
- }
- //Hoirzontal collision
- HorizontalCollision(m_HitLevelPtr);
- }
- bool Rugby::IsHit()
- {
- if(m_Timer<20)
- m_Timer++;
- HIT hitArr[1];
- DOUBLE2 startPoint = m_MarioPos;
- DOUBLE2 vector = DOUBLE2(0,8);
- startPoint.x = m_MarioPos.x+4;
- startPoint.y = m_MarioPos.y+24;
- int numbHits = 0;
- numbHits = m_HitTopPtr->Raycast(startPoint,vector,hitArr,1,0);
- if(numbHits > 0&&m_Timer==20)
- {
- m_Lives--;
- m_Timer=0;
- return true;
- }
- else return false;
- }
- void Rugby::SetMarioPos(DOUBLE2 marioPos)
- {
- m_MarioPos=marioPos;
- }
- bool Rugby::IsMarioHit()
- {
- HIT hitArr[1];
- DOUBLE2 startPoint = m_MarioPos;
- DOUBLE2 vector = DOUBLE2(8,0);
- startPoint.x = m_MarioPos.x+8;
- startPoint.y = m_MarioPos.y+25;
- int numbHits = 0;
- numbHits = m_HitWholePtr->Raycast(startPoint,vector,hitArr,1,0);
- if(numbHits > 0)
- {
- return true;
- }
- else
- {
- DOUBLE2 vector = DOUBLE2(-8,0);
- numbHits = 0;
- numbHits = m_HitWholePtr->Raycast(startPoint,vector,hitArr,1,0);
- if(numbHits > 0)
- {
- return true;
- }
- else return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement