Exemple #1
0
void PlayerState_Searching()
{
	if (g_bSearchingLaunch == false)
	{
		g_iTime = GfxMathGetRandomInteger(1, 3);
		g_bSearchingLaunch = true;
	}
	if (g_iTime > 0)
	{
		g_iTime -= GfxTimeFrameGetCurrentDurationInSeconds();
	}
	if (g_iTime <= 0)
	{
		g_pCave[g_iCurrentCaveTarget].bIsSearched = true;
		g_iPlayerInventory = GfxMathGetRandomInteger(0, 3);
		GfxDbgPrintf("You finished searching and you found %d artefacts\n", g_iPlayerInventory);
		g_iTime = 0;
		g_bSearchingLaunch = false;
		if (g_iPlayerInventory > 0)
		{
			g_TPlayerData.m_ePlayerState = g_TPlayerData.EPlayerState_GoingToBase;
		}
		else
		{
			g_TPlayerData.m_ePlayerState = g_TPlayerData.EPlayerState_GoingToCave;
		}
	}
}
float UnscaleDeltaTime(){

	return GfxTimeFrameGetCurrentDurationInSeconds() ;


}
float DeltaTime(){

	return GfxTimeFrameGetCurrentDurationInSeconds() * TTime::GetTimeScale();


}
Exemple #4
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);
		}
	}
Exemple #5
0
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));
	//}


}