void HUDSettup( TSquare ** pButtons ) { TGfxVec2 tGroupPos = TGfxVec2( fHUD_BUTTON_POS_X, fHUD_BUTTON_POS_Y ); TGfxVec2 tButtonSize = TGfxVec2( fHUD_BUTTON_RADIUS, fHUD_BUTTON_RADIUS ); TGfxVec2 tMargin = TGfxVec2( 0.f, fHUD_BUTTON_MARGIN ); VerticalSettup(pButtons, EItemType_Count, tGroupPos, tButtonSize, tMargin, 0, ETextureData_HUD ); //return &pButtons[0]; }
void MainMenuSettup( TSquare ** pButtons ) { TGfxVec2 tGroupPos = TGfxVec2( fMENU_BUTTON_POS_X, fMENU_BUTTON_POS_Y ); TGfxVec2 tButtonSize = TGfxVec2( fMENU_BUTTON_RADIUS_X, fMENU_BUTTON_RADIUS_Y ); TGfxVec2 tMargin = TGfxVec2( 0.f, fMENU_BUTTON_MARGIN ); VerticalSettup(pButtons, EMainMenuState_Count, tGroupPos, tButtonSize, tMargin, BUTTON_NULL, ETextureData_MainMenu ); //return &pButtons[0]; }
TItem::TItem(const TGfxVec2 & tPos, float fRadius, EItemType eType) :TCircle( tPos, 0.f, fRadius ), m_eType( eType ) { //Sprite settup SpriteSettup(ETextureData_Item, TGfxVec2(m_fRadius, m_fRadius)); SetTile(0, eType); }
TGfxVec2 TCamera::ConvertScreenPosToWorldPos(const TGfxVec2 & tScreenPos) const { const TGfxVec2 tRelativeToFocusPos = TGfxVec2(tScreenPos.x - GfxGetDisplaySizeX() / 2.0f, -tScreenPos.y + GfxGetDisplaySizeY() / 2.0f); const TGfxVec2 tWorldPos = tRelativeToFocusPos + m_pFocus->GetWorldPos(); return tWorldPos; }
void VerticalSettup( TSquare ** pButtons, int iButtonCount, const TGfxVec2 & pGroupPos, const TGfxVec2 & tButtonSize, const TGfxVec2 & tMargin, int iSelected, ETextureData eTexture ) { //TSquare * pButtons[BUTTON_MAX]; for( int i = 0; i < BUTTON_MAX; i++ ) { if( i < iButtonCount ) { TGfxVec2 tButtonPos = pGroupPos + TGfxVec2( tButtonSize.x, tButtonSize.y * 2.f * float( i ) ) + ( tMargin * float( i + 1 ) ); pButtons[i] = new TSquare( tButtonPos, 0.f, tButtonSize, eTexture ); if( i == iSelected ) pButtons[i]->SetTile( i, EButtonAnimState_Unavailable_Selected ); else pButtons[i]->SetTile( i, EButtonAnimState_Unavailable ); } else { pButtons[i] = nullptr; } } //return &pButtons[0]; }
TTransition::TTransition( ERoomResult eTransitionType, TRoom & pCurrentRoom, TRoom & pOtherRoom, int iDelay ) :m_tDir(TGfxVec2(0.f, 0.f)), m_eTransitionType(eTransitionType), m_pCurrentRoom(nullptr), m_pOtherRoom(nullptr), m_pTimer(nullptr), m_eState(ETransitionState_DoorOpening) { //init m_pCurrentRoom = &pCurrentRoom; m_pOtherRoom = &pOtherRoom; m_pTimer = new TWait( 0, iDelay, false ); //settup TGfxVec2 tPrecDoorPos; TGfxVec2 tNextDoorPos; if( m_eTransitionType != ERoomResult_EntryDoor ) { tNextDoorPos = m_pCurrentRoom->GetExitDoor().GetPos(); tPrecDoorPos = m_pOtherRoom->GetEntryDoor().GetPos(); } else { tNextDoorPos = m_pCurrentRoom->GetEntryDoor().GetPos(); tPrecDoorPos = m_pOtherRoom->GetExitDoor().GetPos(); } m_tDir = (tPrecDoorPos - tNextDoorPos).Normalize(); }
void MenuPageSettup( TSquare ** pButtons ) { // TSquare * pButtons[BUTTON_MAX]; TTileInfo tTileSize = TTextureControler::GetTileSize( ETextureData_MenuButton ); TGfxVec2 tButtonSize = TGfxVec2( float( tTileSize.x/2 ), float( tTileSize.y /2) ); TGfxVec2 tPos = TGfxVec2( ( float ) SCREEN_SIZE_X, ( float ) SCREEN_SIZE_Y ) - tButtonSize; pButtons[0] = new TSquare( tPos, 0.f, tButtonSize, ETextureData_MenuButton ); for( int i = 1; i < BUTTON_MAX; i++ ) { pButtons[i] = nullptr; } //return &pButtons[0]; }
void TPlayer::Respawn(const int MAX_Wall) { GfxSpriteSetPosition(tMap.g_tLevelSprite, GfxSpriteGetPositionX(tMap.g_tLevelSprite) - m_tRespawnVector.x, GfxSpriteGetPositionY(tMap.g_tLevelSprite) - m_tRespawnVector.y); for (int i = 0; i < MAX_Wall; i++) { // if different from -2000, -2000 if (tWall[i].tPosition != TGfxVec2(-2000, -2000)) { tWall[i].tPosition -= m_tRespawnVector; } } m_fSpeed = 0; m_tDirection = TGfxVec2(0, 0); m_tRespawnVector = TGfxVec2(0, 0); }
void TrophySettup( TSquare ** pButtons ) { //TSquare * pButtons[BUTTON_MAX]; TGfxVec2 tScreenCenter = TGfxVec2( ( float ) SCREEN_SIZE_X/2, ( float ) SCREEN_SIZE_Y/2 ); TTileInfo tTileSize = TTextureControler::GetTileSize( ETextureData_Trophy ); TGfxVec2 tButtonSize = TGfxVec2( float( tTileSize.x ), float( tTileSize.y ) ); TGfxVec2 tMarginX = TGfxVec2( fTROPHY_MARGIN, 0.f ); TGfxVec2 tMarginY = TGfxVec2( 0.f, fTROPHY_MARGIN ); int iColCount = ( TROPHY_MAX / 2 ); TGfxVec2 tGroupPos = tScreenCenter - ( ( TGfxVec2( tButtonSize.x, tButtonSize.y/2 ) + tMarginX ) * float( iColCount / 2 ) ); for( int i = 0; i < BUTTON_MAX; i++ ) { TGfxVec2 tPosX = ( TGfxVec2( tButtonSize.x, 0.f) + tMarginX ) * float( i % iColCount ); TGfxVec2 tPosY = ( TGfxVec2( 0.f, tButtonSize.y ) + tMarginY) * float( i / iColCount ); TGfxVec2 tButtonPos = tGroupPos + tPosX + tPosY; pButtons[i] = new TSquare( tButtonPos, 0.f, tButtonSize/2, ETextureData_Trophy ); pButtons[i]->SetTile( i, EButtonAnimState_Unavailable ); } //return &pButtons[0]; }
void PlayerState_GoingToBase() { if (g_bMoving == false) { GfxDbgPrintf("You are going to the base\n"); } g_bMoving = true; //----------------------------------------- TRY ---------------------------------------------------------------- int sizeX = (GfxGetDisplaySizeX() / 2); int sizeY = (GfxGetDisplaySizeY() / 2); ArcheoStuffs::Move(TGfxVec2(sizeX - 8, sizeY - 8), TGfxVec2(float(g_TPlayerData.iPosX), float(g_TPlayerData.iPosY))); }
void TBox::CreateSpriteBox(TGfxTexture * pTexture) { m_bIsDrawable = true; m_pSprite = GfxSpriteCreate(pTexture); int iSizeX = GfxSpriteGetSizeX(m_pSprite); int iSizeY = GfxSpriteGetSizeY(m_pSprite); GfxSpriteSetFilteringEnabled(m_pSprite, false); GfxSpriteSetPivot(m_pSprite, iSizeX / 2.0f, iSizeY / 2.0f); SetBox(TGfxVec2(0.0f, 0.0f), (float)iSizeX, (float)iSizeY); }
void TBox::CreateTextBox(const char * pName) { m_bIsDrawable = true; m_pTextSprite = GfxTextSpriteCreate(); GfxSpriteSetFilteringEnabled(m_pTextSprite, false); GfxTextSpritePrintf(m_pTextSprite, pName); int iSizeX = GfxSpriteGetSizeX(m_pTextSprite); int iSizeY = GfxSpriteGetSizeY(m_pTextSprite); GfxSpriteSetPivot(m_pTextSprite, iSizeX / 2.0f, iSizeY / 2.0f); SetBox(TGfxVec2(0.0f, 0.0f), (float)iSizeX, (float)iSizeY); }
void TBox::CreateSpriteBox(TGfxTexture * pTexture, const int iTextureSize, int iTileX, int iTileY, int iTextureSizeY) { iTextureSizeY = (iTextureSizeY != 0) ? iTextureSizeY : iTextureSize; m_bIsDrawable = true; m_pSprite = GfxSpriteCreate(pTexture); GfxSpriteSetFilteringEnabled(m_pSprite, false); GfxSpriteSetCutout(m_pSprite, iTileX*iTextureSize, iTileY*iTextureSizeY, iTextureSize, iTextureSizeY); GfxSpriteSetPivot(m_pSprite, iTextureSize / 2.0f, iTextureSizeY / 2.0f); SetBox(TGfxVec2(0.0f, 0.0f), (float)iTextureSize, (float)iTextureSizeY); }
//----Show void TBox::DrawBox() { if (m_pSprite != nullptr) { GfxSpriteSetPosition(m_pSprite, m_tCenter.x, m_tCenter.y); GfxSpriteSetAngle(m_pSprite, GfxMathDegToRad(-m_fAngle)); } //Line if (m_pLineSprite != nullptr) { if (m_pLineSprite != nullptr) GfxLineSpriteReset(m_pLineSprite); GfxLineSpriteSetDrawingColor(m_pLineSprite, GfxColor(150, 150, 150, 255)); TGfxVec2 tAxisX = TGfxVec2(m_fRay_W, 0).Rotate(GfxMathDegToRad(m_fAngle))*m_fScale; TGfxVec2 tAxisY = TGfxVec2(0, m_fRay_H).Rotate(GfxMathDegToRad(m_fAngle))*m_fScale; TGfxVec2 tUR = TGfxVec2(m_tCenter.x + tAxisX.x + tAxisY.x, m_tCenter.y + tAxisX.y + tAxisY.y); TGfxVec2 tUL = TGfxVec2(m_tCenter.x - tAxisX.x + tAxisY.x, m_tCenter.y - tAxisX.y + tAxisY.y); TGfxVec2 tDL = TGfxVec2(m_tCenter.x - tAxisX.x - tAxisY.x, m_tCenter.y - tAxisX.y - tAxisY.y); TGfxVec2 tDR = TGfxVec2(m_tCenter.x + tAxisX.x - tAxisY.x, m_tCenter.y + tAxisX.y - tAxisY.y); GfxLineSpriteJumpTo(m_pLineSprite, tUL.x, tUL.y); GfxLineSpriteLineTo(m_pLineSprite, tDL.x, tDL.y); GfxLineSpriteLineTo(m_pLineSprite, tDR.x, tDR.y); GfxLineSpriteLineTo(m_pLineSprite, tUR.x, tUR.y); GfxLineSpriteLineTo(m_pLineSprite, tUL.x, tUL.y); } if (m_pTextSprite != nullptr) { GfxSpriteSetPosition(m_pTextSprite, m_tCenter.x, m_tCenter.y); GfxSpriteSetAngle(m_pTextSprite,GfxMathDegToRad(-m_fAngle)); } }
void Initialize() { int sizeX = (GfxGetDisplaySizeX() / 2); int sizeY = (GfxGetDisplaySizeY() / 2); g_pLines = GfxLineSpriteCreate(); g_pLines2 = GfxLineSpriteCreate(); ArcheoStuffs::DrawCircle(g_pLines, TGfxVec2(0, 0), 8, GfxColor(255, 255, 0, 255), true); // Player creation for (int i = 0; i < g_iNbrCave; i++) { g_bCaveSearched[i] = false; } g_pImage = GfxImageCreate(1,1); unsigned int * pData = GfxImageGetData(g_pImage); *pData = EGfxColor_White; g_pTexture = GfxTextureCreate(g_pImage); g_pSpritePlayer = GfxSpriteCreate(g_pTexture); g_pSpriteBase = GfxSpriteCreate(g_pTexture); GfxSpriteSetScale(g_pSpritePlayer, 16, 16); GfxSpriteSetColor(g_pSpritePlayer, GfxColor(255, 255, 0, 255)); g_TPlayerData.iPos = TGfxVec2(sizeX - 8, sizeY - 8); g_TPlayerData.iPosX = sizeX - 8; g_TPlayerData.iPosY = sizeY - 8; GfxSpriteSetScale(g_pSpriteBase, 32, 32); GfxSpriteSetColor(g_pSpriteBase, GfxColor(0, 255, 0, 255)); GfxSpriteSetPosition(g_pSpriteBase, sizeX-16, sizeY-16); for (int i = 0; i < g_iNbrCave; i++) { ArcheoStuffs::CreateCave(i); } }
void TPlatform::Initialize(const TGfxTexture * pTexture, const TGfxVec2 & tWorldPos, const TGfxVec2 & tRadius) { InitializeUoBox(tWorldPos, tRadius); const float fCutoutSizeX = fmaxf(m_tRadius.x * 2 * (1/SCALE), m_tRadius.y * 2 * (1/SCALE)); m_tSprite.Initialize(this, pTexture, PLATFORM_CUTOUT, TGfxVec2(fCutoutSizeX, float(TILE_SIZE)), TGfxVec2(SCALE, SCALE)); m_tSprite.SetFilter(false); if (fCutoutSizeX == m_tRadius.y * 2 * (1 / SCALE)) { m_tSprite.Rotate(EOrientation_Left); } }
void TAnimation::Initialize(TSprite * pSprite, const TGfxVec2 & tInitialCutout, const ECutOutIncrement eCutOutIncrement, const int iTimePerFrame, const int iFrameNumber) { m_pSprite = pSprite; m_tInitialCutout = tInitialCutout; m_iTimePerFrame = iTimePerFrame; m_iFrameNumber = iFrameNumber; switch (eCutOutIncrement) { case ECutOutIncrement_X_Positive: m_tCutOutIncrement = TGfxVec2(m_pSprite->GetSize().x, 0); break; case ECutOutIncrement_X_Negative: m_tCutOutIncrement = TGfxVec2(-m_pSprite->GetSize().x, 0); break; case ECutOutIncrement_Y_Positive: m_tCutOutIncrement = TGfxVec2(0, m_pSprite->GetSize().y); break; case ECutOutIncrement_Y_Negative: m_tCutOutIncrement = TGfxVec2(0, -m_pSprite->GetSize().y); break; } }
int TInterface::CheckInput() { if( GfxInputIsJustReleased( EGfxInputID_MouseLeft ) ) { const float fMouseX = ( float ) GfxGetCurrentMouseX(); const float fMouseY = ( float ) GfxGetCurrentMouseY(); const TGfxVec2 tMousePos = TGfxVec2( fMouseX, fMouseY ); for( int i = 0; i < BUTTON_MAX; i++ ) { if( m_pButtons[i] != nullptr && m_pButtons[i]->CollidePoint( tMousePos ) ) { GfxDbgPrintf( "CLICK %d\n", i ); return i; } } } return BUTTON_NULL; }
void DrawCircle(TGfxSprite * pLines, const TGfxVec2 tCenter, const float fRadius, const unsigned int tColor, const bool tPlayer) { GfxSpriteSetPosition(pLines, g_TPlayerData.iPosX, g_TPlayerData.iPosY); const int NUM_LINES = 32; GfxLineSpriteJumpTo(pLines, tCenter.x + fRadius, tCenter.y); GfxLineSpriteSetDrawingColor(pLines, tColor); if (tPlayer == true) { ArcheoStuffs::DrawArrow(pLines, tCenter, TGfxVec2(tCenter.x + cos(GfxMathDegToRad((360.f / NUM_LINES) * (1))) * fRadius, tCenter.y + sin(GfxMathDegToRad((360.f / NUM_LINES) * (1))) * fRadius)); } for (int i = 0; i < NUM_LINES; ++i) { const float fAngle = GfxMathDegToRad((360.f / NUM_LINES) * (i + 1)); const float fPosX = tCenter.x + cos(fAngle) * fRadius; const float fPosY = tCenter.y + sin(fAngle) * fRadius; GfxLineSpriteLineTo(pLines, fPosX, fPosY); } }
void PlayerState_GoingToCave() { if (g_bMoving == false) { do { g_iCurrentCaveTarget = GfxMathGetRandomInteger(0, 5); } while (g_pCave[g_iCurrentCaveTarget].bIsSearched == true); GfxDbgPrintf("You are going to the cave number %d\n", g_iCurrentCaveTarget + 1); } g_bMoving = true; //----------------------------------------- TRY ---------------------------------------------------------------- ArcheoStuffs::Move(TGfxVec2(float(g_pCave[g_iCurrentCaveTarget].iPosX), float(g_pCave[g_iCurrentCaveTarget].iPosY)), TGfxVec2(float(g_TPlayerData.iPosX), float(g_TPlayerData.iPosY))); }
void TPlayer::Render(const int MAX_Wall) { TGfxVec2 tBackToCenter = (m_tPosition - m_tStartPosition); m_tPosition -= tBackToCenter; GfxSpriteSetPosition(m_pSpritePlayer, GfxSpriteGetPositionX(m_pSpritePlayer) - tBackToCenter.x, GfxSpriteGetPositionY(m_pSpritePlayer) - tBackToCenter.y); GfxSpriteSetPosition(tMap.g_tLevelSprite, GfxSpriteGetPositionX(tMap.g_tLevelSprite) - tBackToCenter.x, GfxSpriteGetPositionY(tMap.g_tLevelSprite) - tBackToCenter.y); m_tSpawnPosition -= tBackToCenter; for (int i = 0; i < MAX_Wall; i++) { // if different from -2000, -2000 if (tWall[i].tPosition != TGfxVec2(-2000, -2000)) { tWall[i].tPosition -= tBackToCenter; } } m_tRespawnVector -= tBackToCenter; GfxSpriteRender(tMap.g_tLevelSprite); GfxSpriteRender(m_pSpritePlayer); }
void CreateCave(int ActCave) { g_pCave[ActCave].iScale = GfxMathGetRandomInteger(32, 64); bool Collisioned = true; do { g_pCave[ActCave].iPosX = (GfxMathGetRandomInteger(g_pCave[ActCave].iScale, GfxGetDisplaySizeX() - g_pCave[ActCave].iScale)); g_pCave[ActCave].iPosY = (GfxMathGetRandomInteger(g_pCave[ActCave].iScale, GfxGetDisplaySizeY() - g_pCave[ActCave].iScale)); Collisioned = false; for (int e = 0; e < ActCave; e++) { if (!(g_pCave[ActCave].iPosX > g_pCave[e].iPosX + g_pCave[e].iScale + 20) && !(g_pCave[ActCave].iPosX < g_pCave[e].iPosX - g_pCave[ActCave].iScale - 20) && !(g_pCave[ActCave].iPosY < g_pCave[e].iPosY - g_pCave[ActCave].iScale - 20) && !(g_pCave[ActCave].iPosY > g_pCave[e].iPosY + g_pCave[e].iScale + 20)) { Collisioned = true; } } if (ActCave == 0) { Collisioned = false; } } while (Collisioned == true); g_pCave[ActCave].pLines = GfxLineSpriteCreate(); ArcheoStuffs::DrawCircle(g_pCave[ActCave].pLines, TGfxVec2(0, 0), g_pCave[ActCave].iScale / 2, EGfxColor_Blue, false); GfxSpriteSetPosition(g_pCave[ActCave].pLines, g_pCave[ActCave].iPosX, g_pCave[ActCave].iPosY); g_pCave[ActCave].g_pSpriteCave = GfxSpriteCreate(g_pTexture); GfxSpriteSetPivot(g_pCave[ActCave].g_pSpriteCave, 0.5, 0.5); GfxSpriteSetScale(g_pCave[ActCave].g_pSpriteCave, g_pCave[ActCave].iScale, g_pCave[ActCave].iScale); GfxSpriteSetColor(g_pCave[ActCave].g_pSpriteCave, GfxColor(0, 0, 255, 255)); GfxSpriteSetPosition(g_pCave[ActCave].g_pSpriteCave, g_pCave[ActCave].iPosX, g_pCave[ActCave].iPosY); g_iNbrCaveCreated++; }
void TPlayer::Move(float fSpeed, TGfxVec2 tDirection, const int MAX_WALL, const int TILE_SIZE) { TGfxVec2 tVelocity = TGfxVec2(0, 0); TGfxVec2 tMove = TGfxVec2(0, 0); TGfxVec2 tDirectionX = TGfxVec2(1, 0); TGfxVec2 tDirectionY = TGfxVec2(0, 1); float fSpeedX = (tDirection*fSpeed).DotProduct(tDirectionX); float fSpeedY = (tDirection*fSpeed).DotProduct(tDirectionY); const int iMaxPossibleCollision = 8; int iCollisionableWall[iMaxPossibleCollision]; float fCollisionableWallLength[iMaxPossibleCollision]; int iCollisionableWallCpt = 0; int iCloserCollisionableWall = 0; int iCollisionDirection = 0; // 0 = en haut, 1 = à gauche, 2 = en bas, 3 = à droite bool bCollision = false; bool bInputPressed = false; bool bNextToWallRight = true; bool bNextToWallLeft = true; for (int i = 0; i < MAX_WALL; i++) { if (m_tPosition.x + TILE_SIZE == tWall[i].tPosition.x && m_tPosition.y > tWall[i].tPosition.y - TILE_SIZE && m_tPosition.y < tWall[i].tPosition.y + TILE_SIZE) { bNextToWallRight = false; } if (m_tPosition.x - TILE_SIZE == tWall[i].tPosition.x && m_tPosition.y > tWall[i].tPosition.y - TILE_SIZE && m_tPosition.y < tWall[i].tPosition.y + TILE_SIZE) { bNextToWallLeft = false; } } int iMouseOneX = 0; int iMouseOneY = 0; int iMouseTwoX = 0; int iMouseTwoY = 0; int iNumberOfMouse = 0; if (GfxInputGetMouseCount() == 0) { iNumberOfMouse = 0; } else if (GfxInputGetMouseCount() == 1) { iMouseOneX = GfxInputGetMousePositionX(0); iMouseOneY = GfxInputGetMousePositionY(0); iNumberOfMouse = 1; } else { iMouseOneX = GfxInputGetMousePositionX(0); iMouseOneY = GfxInputGetMousePositionY(0); iMouseTwoX = GfxInputGetMousePositionX(1); iMouseTwoY = GfxInputGetMousePositionY(1); iNumberOfMouse = 2; } if (bNextToWallRight == true) { if ((GfxInputIsPressed(EGfxInputID_KeyArrowRight)) || (iNumberOfMouse == 1 && iMouseOneX > 68 && iMouseOneX < 130 && iMouseOneY > 220 && iMouseOneY < 320) || (iNumberOfMouse == 2 && iMouseOneX > 68 && iMouseOneX < 130 && iMouseOneY > 220 && iMouseOneY < 320) || (iNumberOfMouse == 2 && iMouseTwoX > 68 && iMouseTwoX < 130 && iMouseTwoY > 220 && iMouseTwoY < 320) ) { tVelocity += TGfxVec2(5, 0); bInputPressed = true; } } if (bNextToWallLeft == true) { if ((GfxInputIsPressed(EGfxInputID_KeyArrowLeft)) || (iNumberOfMouse == 1 && iMouseOneX > 0 && iMouseOneX < 68 && iMouseOneY > 220 && iMouseOneY < 320) || (iNumberOfMouse == 2 && iMouseOneX > 0 && iMouseOneX < 68 && iMouseOneY > 220 && iMouseOneY < 320) || (iNumberOfMouse == 2 && iMouseTwoX > 0 && iMouseTwoX < 68 && iMouseTwoY > 220 && iMouseTwoY < 320) ) { tVelocity += TGfxVec2(-5, 0); bInputPressed = true; } } if (bInputPressed == true) // Si un bouton est appuyé, on augmente la vitesse, .... { if (fSpeedX > 4) { fSpeedX = 4; } if (fSpeedX < -4) { fSpeedX = -4; } tMove = ((tDirectionX * fSpeedX) + (tVelocity * GfxTimeFrameGetCurrentDurationInSeconds())); } else // sinon on la réduit jusqu'a un certain nombre où on la mets à 0 { if (fSpeedX > 0.5 || fSpeedX < -0.5) { tMove = (tDirectionX * fSpeedX) * 0.9; } else { tMove = (tDirectionX * fSpeedX) * 0; } } for (int i = 0; i < MAX_WALL; i++) { if ((m_tPosition.x) > (tWall[i].tPosition.x - TILE_SIZE) && (m_tPosition.x) < (tWall[i].tPosition.x + (TILE_SIZE)) && (m_tPosition.y) == (tWall[i].tPosition.y - TILE_SIZE) ) { if (tWall[i].bIsTheEnd == true) { bIsGameWin = true; break; } if (tWall[i].bIsBoost == true) { tMove += tWall[i].tBoost; break; } if ((GfxInputIsPressed(EGfxInputID_KeyCharZ)) || (iNumberOfMouse == 1 && iMouseOneX > 410 && iMouseOneX < 480 && iMouseOneY > 250 && iMouseOneY < 320) || (iNumberOfMouse == 2 && iMouseOneX > 410 && iMouseOneX < 480 && iMouseOneY > 250 && iMouseOneY < 320) || (iNumberOfMouse == 2 && iMouseTwoX > 410 && iMouseTwoX < 480 && iMouseTwoY > 250 && iMouseTwoY < 320) ) { tMove += TGfxVec2(0, -5.5); break; } } } for (int i = 0; i < MAX_WALL; i++) { if ((m_tPosition.x) >(tWall[i].tPosition.x - TILE_SIZE) && (m_tPosition.x) < (tWall[i].tPosition.x + (TILE_SIZE)) && (m_tPosition.y) == (tWall[i].tPosition.y - TILE_SIZE) ) { if (tWall[i].bIsKilling == true) { m_fHealth -= GfxTimeFrameGetCurrentDurationInSeconds() * 50; break; } } } for (int i = 0; i < MAX_WALL; i++) { if (tWall[i].bIsWallJumpable == true) { if ((m_tPosition.x + TILE_SIZE) < (tWall[i].tPosition.x + 1) && (m_tPosition.x + TILE_SIZE) > (tWall[i].tPosition.x - 1) && (m_tPosition.y) > (tWall[i].tPosition.y - TILE_SIZE) && (m_tPosition.y) < (tWall[i].tPosition.y + TILE_SIZE) ) { if ((GfxInputIsPressed(EGfxInputID_KeyCharZ)) || (iNumberOfMouse == 1 && iMouseOneX > 410 && iMouseOneX < 480 && iMouseOneY > 250 && iMouseOneY < 320) || (iNumberOfMouse == 2 && iMouseOneX > 410 && iMouseOneX < 480 && iMouseOneY > 250 && iMouseOneY < 320) || (iNumberOfMouse == 2 && iMouseTwoX > 410 && iMouseTwoX < 480 && iMouseTwoY > 250 && iMouseTwoY < 320) ) { tMove += TGfxVec2(-5.5, -5.5); break; } } } if (tWall[i].bIsWallJumpable == true) { if ((m_tPosition.x - TILE_SIZE) < (tWall[i].tPosition.x + 1) && (m_tPosition.x - TILE_SIZE) > (tWall[i].tPosition.x - 1) && (m_tPosition.y) > (tWall[i].tPosition.y - TILE_SIZE) && (m_tPosition.y) < (tWall[i].tPosition.y + TILE_SIZE) ) { if ((GfxInputIsPressed(EGfxInputID_KeyCharZ)) || (iNumberOfMouse == 1 && iMouseOneX > 410 && iMouseOneX < 480 && iMouseOneY > 250 && iMouseOneY < 320) || (iNumberOfMouse == 2 && iMouseOneX > 410 && iMouseOneX < 480 && iMouseOneY > 250 && iMouseOneY < 320) || (iNumberOfMouse == 2 && iMouseTwoX > 410 && iMouseTwoX < 480 && iMouseTwoY > 250 && iMouseTwoY < 320) ) { tMove += TGfxVec2(5.5, -5.5); break; } } } } tMove += (fSpeedY * tDirectionY); bool bInAir = true; for (int i = 0; i < MAX_WALL; i++) { if (m_tPosition.y + TILE_SIZE == tWall[i].tPosition.y && m_tPosition.x > (tWall[i].tPosition.x - TILE_SIZE) + 0.05 && m_tPosition.x < (tWall[i].tPosition.x + TILE_SIZE) - 0.05)// test si un bloc sous le joueur, si oui pas de pesanteur { bInAir = false; break; } } if (bInAir == true) { tMove += (GfxTimeFrameGetCurrentDurationInSeconds() * TGfxVec2(0, 15)); // Attraction terrestre } if (tMove.y > 6) { tMove.y = 6; } if (tMove.y < -6) { tMove.y = -6; } for (int i = 0; i < MAX_WALL; i++) { if ((m_tPosition.x + tMove.x) > (tWall[i].tPosition.x - TILE_SIZE) && (m_tPosition.x + tMove.x) < (tWall[i].tPosition.x + (TILE_SIZE)) && (m_tPosition.y + tMove.y) > (tWall[i].tPosition.y - TILE_SIZE) && (m_tPosition.y + tMove.y) < (tWall[i].tPosition.y + (TILE_SIZE)) ) { //const int iMaxPossibleCollision = 4; //int iCollisionableWall[iMaxPossibleCollision]; //int iCollisionableWallCpt = 0; //int iCloserCollisionableWall = 0; iCollisionableWall[iCollisionableWallCpt] = i; iCollisionableWallCpt++; bCollision = true; } } if (bCollision == true) // SI au moins une collision à été détectée, on regarde laquelle est la plus proche et on lance le code de collision { for (int i = 0; i < iCollisionableWallCpt; i++) { fCollisionableWallLength[i] = ((tWall[iCollisionableWall[i]].tPosition - m_tPosition).Length()); } bool bIsTheSmallest = true; for (int i = 0; i < iCollisionableWallCpt; i++) { bIsTheSmallest = true; for (int e = 0; e < iCollisionableWallCpt; e++) { if (fCollisionableWallLength[i] > fCollisionableWallLength[e]) { bIsTheSmallest = false; } } if (bIsTheSmallest == true) { iCloserCollisionableWall = iCollisionableWall[i]; break; } } int i = iCloserCollisionableWall; TGfxVec2 tWallTopPos = TGfxVec2(tWall[i].tPosition.x, (tWall[i].tPosition.y - TILE_SIZE)); TGfxVec2 tWallLeftPos = TGfxVec2((tWall[i].tPosition.x - TILE_SIZE), tWall[i].tPosition.y); TGfxVec2 tWallBottomPos = TGfxVec2(tWall[i].tPosition.x, (tWall[i].tPosition.y + TILE_SIZE)); TGfxVec2 tWallRightPos = TGfxVec2((tWall[i].tPosition.x + TILE_SIZE), tWall[i].tPosition.y); //TGfxVec2 tPlayerFuturePos = TGfxVec2(m_tPosition.x + tMove.x, m_tPosition.y + tMove.y); TGfxVec2 tPlayerToTop = m_tPosition - tWallTopPos; TGfxVec2 tPlayerToLeft = m_tPosition - tWallLeftPos; TGfxVec2 tPlayerToBottom = m_tPosition - tWallBottomPos; TGfxVec2 tPlayerToRight = m_tPosition - tWallRightPos; float fPlayerToTopLength = tPlayerToTop.Length(); float fPlayerToLeftLength = tPlayerToLeft.Length(); float fPlayerToBottomLength = tPlayerToBottom.Length(); float fPlayerToRightLength = tPlayerToRight.Length(); if (fPlayerToTopLength < fPlayerToLeftLength && fPlayerToTopLength < fPlayerToBottomLength && fPlayerToTopLength < fPlayerToRightLength ) { // Renvoyé à gauche du mur float fPixelInCollision = ((tPlayer.m_tPosition.y + (tMove.y + TILE_SIZE)) - (tWall[i].tPosition.y)); tMove.y -= fPixelInCollision; iCollisionDirection = 1; } else if (fPlayerToLeftLength < fPlayerToTopLength && fPlayerToLeftLength < fPlayerToBottomLength && fPlayerToLeftLength < fPlayerToRightLength ) { float fPixelInCollision = ((tPlayer.m_tPosition.x + (tMove.x + TILE_SIZE)) - (tWall[i].tPosition.x)); tMove.x -= fPixelInCollision; iCollisionDirection = 2; } else if (fPlayerToBottomLength < fPlayerToTopLength && fPlayerToBottomLength < fPlayerToLeftLength && fPlayerToBottomLength < fPlayerToRightLength ) { float fPixelInCollision = (tWall[i].tPosition.y + TILE_SIZE) - (tPlayer.m_tPosition.y + tMove.y); tMove.y += fPixelInCollision; iCollisionDirection = 3; } else { float fPixelInCollision = (tWall[i].tPosition.x + TILE_SIZE) - (tPlayer.m_tPosition.x + tMove.x); tMove.x += fPixelInCollision; iCollisionDirection = 4; } } m_tPosition = TGfxVec2(GfxSpriteGetPositionX(m_pSpritePlayer) + tMove.x, GfxSpriteGetPositionY(m_pSpritePlayer) + tMove.y); GfxSpriteSetPosition(m_pSpritePlayer, m_tPosition.x, m_tPosition.y); m_fSpeed = tMove.Length(); if (m_fSpeed != 0) { m_tDirection = tMove.Normalize(); } //if (iCollisionDirection == 0) //{ // // Stop déplacement haut/bas -> Speed.y = 0 // m_fSpeed = (m_fSpeed * m_tDirection).DotProduct(TGfxVec2(0, 1)); //} //if (iCollisionDirection == 1) //{ // m_fSpeed = (m_fSpeed * m_tDirection).DotProduct(TGfxVec2(1, 0)); //} }
void Move(TGfxVec2 tDest, TGfxVec2 tSrc) { TGfxVec2 Move(tDest.x - tSrc.x, tDest.y - tSrc.y); float Time = (ArcheoStuffs::Absol(Move.x) + ArcheoStuffs::Absol(Move.y)) / g_iSpeed; Move = Move / Time; Move = Move * GfxTimeFrameGetCurrentDurationInSeconds(); MoveX = (tDest.x) - (tSrc.x); MoveY = (tDest.y) - (tSrc.y); RatioX = MoveX / (ArcheoStuffs::Absol(MoveX) + ArcheoStuffs::Absol(MoveY)); RatioY = MoveY / (ArcheoStuffs::Absol(MoveX) + ArcheoStuffs::Absol(MoveY)); MoveX2 = RatioX * g_iSpeed; MoveY2 = RatioY * g_iSpeed; const float X1 = tSrc.x; const float Y1 = tSrc.y; const float X2 = tDest.x; const float Y2 = tDest.y; const float X3 = (tSrc.x + (GfxTimeFrameGetCurrentDurationInSeconds() * MoveX2)); const float Y3 = (tSrc.y + (GfxTimeFrameGetCurrentDurationInSeconds() * MoveY2)); if ( ( X1 < X2 && Y1 > Y2 && X3 > X2 && Y3 < Y2 ) || ( X1 < X2 && Y1 < Y2 && X3 > X2 && Y3 > Y2 ) || ( X1 > X2 && Y1 > Y2 && X3 < X2 && Y3 < Y2 ) || ( X1 > X2 && Y1 < Y2 && X3 < X2 && Y3 > Y2 ) ) { tSrc.x = tDest.x; tSrc.y = tDest.y; g_bMoving = false; int sizeX = (GfxGetDisplaySizeX() / 2); int sizeY = (GfxGetDisplaySizeY() / 2); if (tDest == TGfxVec2(sizeX - 8, sizeY - 8)) { g_TPlayerData.m_ePlayerState = g_TPlayerData.EPlayerState_AtBase; } else { g_TPlayerData.m_ePlayerState = g_TPlayerData.EPlayerState_AtCave; } } else { g_TPlayerData.iPos += Move; g_TPlayerData.iPosX += (GfxTimeFrameGetCurrentDurationInSeconds() * MoveX2); g_TPlayerData.iPosY += (GfxTimeFrameGetCurrentDurationInSeconds() * MoveY2); } }
void Initialize() { g_pSprite = new TSpriteElement( TGfxVec2(0.f, 0.f), TGfxVec2(0.f, 0.f), "train_Station_v1.tga" ); //TSLLRoot grooot; }
void TCamera::updateCam() { m_tPos = TGfxVec2(m_pCaillou->m_tPos.x - SCREEN_WIDTH / 2, 0); TGfxVec2 oldPos; for (int i = 0; i < NB_PARALLAX; i++){ if (m_pParallax[i].getDepth() >= 1){ oldPos = m_pParallax[i].m_tPos; m_pParallax[i].m_tPos = TGfxVec2(oldPos.x, SCREEN_HEIGHT - oldPos.y) - m_tPos; m_pParallax[i].render(); m_pParallax[i].m_tPos = oldPos; } } int heightOmbre = 10; SDL_Rect ombre = { SCREEN_WIDTH / 2 - 10, SCREEN_HEIGHT - (BASE_HAUTEUR + heightOmbre / 2), 20, heightOmbre / 2 }; SDL_SetRenderDrawColor(g_pRenderer, 0x00, 0x00, 0x00, 0xDF); SDL_RenderFillRect(g_pRenderer, &ombre); for (int i = 0; i < TBounceZone::m_iMaxZones; i++){ if (m_pBounce[i] != nullptr){ oldPos = m_pBounce[i]->m_tPos; m_pBounce[i]->m_tPos = TGfxVec2(oldPos.x, SCREEN_HEIGHT - oldPos.y) - m_tPos; m_pBounce[i]->render(); m_pBounce[i]->m_tPos = oldPos; } } oldPos = m_pParticle->getPos(); m_pParticle->setGlobalPos(TGfxVec2(oldPos.x, SCREEN_HEIGHT - oldPos.y) - m_tPos); m_pParticle->render(); m_pParticle->setGlobalPos(oldPos); oldPos = m_pCaillou->m_tPos; m_pCaillou->m_tPos = TGfxVec2(oldPos.x, SCREEN_HEIGHT - oldPos.y) - m_tPos; m_pCaillou->render(); m_pCaillou->m_tPos = oldPos; oldPos = m_pParallax[2].m_tPos; m_pParallax[2].m_tPos = TGfxVec2(oldPos.x, SCREEN_HEIGHT - (oldPos.y-(m_pParallax[2].getHeight() - BASE_HAUTEUR))) - m_tPos; m_pParallax[2].setBlendMode(SDL_BLENDMODE_BLEND); m_pParallax[2].setAlpha(0xA3); SDL_Rect clip = { 0, (m_pParallax[2].getHeight() - BASE_HAUTEUR), m_pParallax[2].getWidth(), BASE_HAUTEUR }; m_pParallax[2].render(&clip); m_pParallax[2].m_tPos = oldPos; m_pParallax[2].setBlendMode(SDL_BLENDMODE_NONE); ombre = { SCREEN_WIDTH / 2 - 10, SCREEN_HEIGHT - (BASE_HAUTEUR), 20, heightOmbre / 2 }; SDL_SetRenderDrawColor(g_pRenderer, 0x00, 0x00, 0x00, 0xDF); //SDL_RenderFillRect(g_pRenderer, &ombre); for (int i = 0; i < NB_PARALLAX; i++){ if (m_pParallax[i].getDepth() < 1){ oldPos = m_pParallax[i].m_tPos; m_pParallax[i].m_tPos = TGfxVec2(oldPos.x, SCREEN_HEIGHT - oldPos.y) - m_tPos; m_pParallax[i].render(); m_pParallax[i].m_tPos = oldPos; } } }
void TBox::SetCollider() { TGfxVec2 tRay(m_fRay_W / 2.0f, m_fRay_H / 2.0f); m_Collider.m_tSpot_LH = TGfxVec2(m_tCenter - tRay); m_Collider.m_tSpot_RD = TGfxVec2(m_tCenter + tRay); }
void TCheckPoint::Initialize(TGfxTexture * pTexture, const TGfxVec2 & tWorldPos) { TTrigger::Initialize(tWorldPos, CHECKPOINT_RADIUS); m_tSprite.Initialize(this, pTexture, CHECKPOINT_INITIAL_CUTOUT, CHECKPOINT_CUTOUT_SIZE, TGfxVec2(SCALE, SCALE)); m_tAnimation.Initialize(&m_tSprite, CHECKPOINT_RESPAWN_CUTOUT, ECutOutIncrement_X_Positive, CHECKPOINT_RESPAWN_TIME_PER_FRAME, CHECKPOINT_RESPAWN_FRAME_NUMBER); m_bActive = false; m_bRespawning = false; m_bEndCheckPoint = false; }
EGame_State TTransition::Update() { switch( m_eState ) { case ETransitionState_DoorClosing: { TDoor * pDoor = nullptr; //get the opposite door to animate if( m_eTransitionType == ERoomResult_EntryDoor ) pDoor = &m_pOtherRoom->GetExitDoor(); else if( m_eTransitionType == ERoomResult_ExitDoor ) pDoor = &m_pOtherRoom->GetEntryDoor(); //check door anim progression int iAnimStep = pDoor->GetAnimStep(); if( iAnimStep == TTextureControler::GetTileCountX( ETextureData_Door ) - 1 )// anim begining { pDoor->SetAnimPlay( true ); } else if( iAnimStep == 0 )//anim ending { pDoor->SetAnimPlay( false ); pDoor->SetAnimReverse( false ); return EGame_State_Playing; } pDoor->PlayAnim(); } break; case ETransitionState_DoorOpening: { TDoor * pDoor = nullptr; //get the door to animate if( m_eTransitionType == ERoomResult_EntryDoor ) pDoor = &m_pCurrentRoom->GetEntryDoor(); else if(m_eTransitionType == ERoomResult_ExitDoor ) pDoor = &m_pCurrentRoom->GetExitDoor(); //check door anim progression int iAnimStep = pDoor->GetAnimStep(); if( iAnimStep == 0 )//anim begining { pDoor->SetAnimPlay( true ); pDoor->SetAnimReverse( false ); } else if( iAnimStep == TTextureControler::GetTileCountX( ETextureData_Door )-1 )// anim ending { pDoor->SetAnimPlay( false ); m_eState = ETransitionState_RoomTransit; int iTime = GfxTimeGetMilliseconds(); m_pTimer->SetStartTime( iTime ); m_pTimer->SetActive( true ); //set opposite door to closing TDoor * OppositepDoor = nullptr; if( m_eTransitionType == ERoomResult_EntryDoor ) OppositepDoor = &m_pOtherRoom->GetExitDoor(); else if( m_eTransitionType == ERoomResult_ExitDoor ) OppositepDoor = &m_pOtherRoom->GetEntryDoor(); OppositepDoor->SetTile( TTextureControler::GetTileCountX( ETextureData_Door ) - 1, OppositepDoor->GetAnimLevel() ); OppositepDoor->SetAnimReverse( true ); } pDoor->PlayAnim(); } break; case ETransitionState_RoomTransit: { //lerp during transition delay if( m_pTimer->Update() == true ) { float fProgression = m_pTimer->GetProgress(); int iDistance = 0; //define the distance of the transition depending of if the transition is vertical or horizontal if (m_tDir.x > 0.f || m_tDir.x < 0.f) iDistance = SCREEN_SIZE_X; else iDistance = SCREEN_SIZE_Y; //set room position float fStep = fProgression * iDistance; m_pOtherRoom->TransitionUpdate( m_tDir * ( fStep - iDistance ) ); m_pCurrentRoom->TransitionUpdate(m_tDir * fStep); } else { //reset room position when transition ends m_pOtherRoom->TransitionUpdate(TGfxVec2(fBACKGROUND_POS_X, fBACKGROUND_POS_Y)); m_pCurrentRoom->TransitionUpdate(TGfxVec2(fBACKGROUND_POS_X, fBACKGROUND_POS_Y)); //reset door sprite TDoor * pDoor = nullptr; if( m_eTransitionType == ERoomResult_EntryDoor ) pDoor = &m_pCurrentRoom->GetEntryDoor(); else if( m_eTransitionType == ERoomResult_ExitDoor ) pDoor = &m_pCurrentRoom->GetExitDoor(); pDoor->SetTile( 0, pDoor->GetAnimLevel() ); m_eState = ETransitionState_DoorClosing; } } break; } return EGame_State_RoomTransition; }