Пример #1
0
virtual int render()
{
	STX_TRY;
		// ----- Input update ----

		mI->Input->Update ();

		// ----- Input ----

		mDelta = mI->Render->GetFrameTime() / 1000.0f;

		if (mI->Input->IsKeyPressed (KEY_RIGHT))	mScale += mSpeedScaling * mDelta;
		if (mI->Input->IsKeyPressed (KEY_LEFT))	mScale -= mSpeedScaling * mDelta;
		mAngle += mSpeedRotation * mDelta;
		if (mScale < 0) mScale = 0;

		// ----- Updating entities attributes  -----

		mBack.SetAngleXYZ (0, 0, -mAngle);
		mRocket.SetAngleXYZ (0, 0, mAngle);
		mRocket.SetScale (mScale, mScale);
		mBeetle.SetPosition ((float) mI->Input->GetMouseX(), (float) mI->Input->GetMouseY(), 5);

		// ----- Check collisions -----

		mTextSmallWhite.SetText	("No collision between the groups we are checking");

		if (mI->Entity2dManager->IsCollision (&mRocket, "engines", &mBeetle, "beetle_boy_head"))
			mTextSmallWhite.SetText	("Collision between rocket boy head and engines");

		if (mI->Entity2dManager->IsCollision (&mRocket, "rocket_head", &mBeetle, "beetle_head"))
			mTextSmallWhite.SetText	("Collision between rokect head and beetle head");

		if (mI->Entity2dManager->IsCollision (&mRocket, "rocket_boy_head", &mBeetle, "beetle_boy_head"))
			mTextSmallWhite.SetText	("Collision between rocket boy head and beetle boy head");

		if (mI->Entity2dManager->IsCollision (&mBeetle, "beetle_boy_head", &mSwordMaster, "sword"))
			mTextSmallWhite.SetText	("Collision between beetle boy head and the sword");

		// ----- Render  -----

		mI->Render->BeginScene ();
		mI->Entity2dManager->RenderEntities2d ();
		mI->Entity2dManager->RenderCollisionAreas (255, 0, 0, 255);
		//mI->Entity2dManager->RenderGridAreas (255, 255, 0, 255);
		mI->Render->EndScene ();
		STX_CATCH;
		return 0;
	}
Пример #2
0
		virtual int init(unsigned int width, unsigned int height)
		{
			STX_INIT_SEGVCATCH;
			STX_TRY;
			g_pIndieLib = mI = CIndieLib::Instance();

	// ----- IndieLib intialization -----

#if 0
	//CIndieLib * mI = CIndieLib::Instance();
	if (!mI->Init ()) return 0;
#else
	
	mI = g_pIndieLib = CIndieLib::Instance();
	if (!mI->
		Init (
		"IndieLib-TankFollowsMouseFires"
		)) return -1;
#endif

	//////////////////////////////////////IND_Entity2d mTextSmallWhite;

	// Characters animations
	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->SurfaceManager->Add(&surfaceSky, "/IndieLib-TankFollowsMouseFires/images/frigistan_sky.png", IND_OPAQUE, IND_32)) return 0;

	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->SurfaceManager->Add(&surfaceGnd, "/IndieLib-TankFollowsMouseFires/images/frigistan_ground.png", IND_OPAQUE, IND_32)) return 0;

	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->AnimationManager->AddToSurface (&animTank, "/IndieLib-TankFollowsMouseFires/images/tank.xml", IND_ALPHA, IND_32)) return 0;

	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->SurfaceManager->Add(&surfaceBarrel, "/IndieLib-TankFollowsMouseFires/images/barrel.png", IND_ALPHA, IND_32)) return 0;

	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->SurfaceManager->Add(&surfaceCursor, "/IndieLib-TankFollowsMouseFires/images/crosshairs1.png", IND_ALPHA, IND_32)) return 0;

	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->SurfaceManager->Add(&surfaceBullet, "/IndieLib-TankFollowsMouseFires/images/bullet.png", IND_ALPHA, IND_32)) return 0;

	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->SurfaceManager->Add(&surfaceTankShadow, "/IndieLib-TankFollowsMouseFires/images/tankshadow.png", IND_ALPHA, IND_32)) return 0;

	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->SurfaceManager->Add(&surfaceMuzzleFlash, "/IndieLib-TankFollowsMouseFires/images/muzzleflash.png", IND_ALPHA, IND_32)) return 0;


	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	mI->Entity2dManager->Add(&sky);
	sky.SetSurface(&surfaceSky);

	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	mI->Entity2dManager->Add(&ground);
	ground.SetSurface(&surfaceGnd);
	ground.SetPosition(0, mI->Window->GetHeight() - surfaceGnd.GetHeight(), 0);

	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	mI->Entity2dManager->Add(&tank);
	tank.SetAnimation(&animTank);
	tank.SetHotSpot(0.5f, 0.1f);
	tank.SetPosition(g_vecPlayer_Pos.x, g_vecPlayer_Pos.y, 0);  // initial position

	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	mI->Entity2dManager->Add(&barrel);
	barrel.SetSurface(&surfaceBarrel);
	barrel.SetHotSpot(0.5f, 1.0f);
	barrel.SetScale(1.5f, 1.5f);

	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	mI->Entity2dManager->Add(&bullet);
	bullet.SetSurface(&surfaceBullet);
	bullet.SetHotSpot(0.5f, 0.5f);
	bullet.SetShow(false);

	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	mI->Entity2dManager->Add(1, &cursor);		// GUI layer
	cursor.SetSurface(&surfaceCursor);
	cursor.SetHotSpot(0.5f, 0.5f);

	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	mI->Entity2dManager->Add(0, &tankShadow);
	tankShadow.SetSurface(&surfaceTankShadow);
	tankShadow.SetHotSpot(0.5f, 0.7f);

	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	mI->Entity2dManager->Add(0, &muzzleFlash);
	muzzleFlash.SetSurface(&surfaceMuzzleFlash);
	muzzleFlash.SetHotSpot(0.5f, 0.5f);
	muzzleFlash.SetShow(false);


	// Font
	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	if (!mI->FontManager->Add (&FontSmall, "/IndieLib-TankFollowsMouseFires/font_small.png", "/IndieLib-TankFollowsMouseFires/font_small.xml", IND_ALPHA, IND_32)) return 0;

	// ----- Font creation -----

	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	mI->Entity2dManager->Add(1, &mTextSmallWhite);		// Entity adding (Layer 1)
	mTextSmallWhite.SetFont			(&FontSmall);						// Set the font into the entity
	mTextSmallWhite.SetLineSpacing	(18);
	mTextSmallWhite.SetCharSpacing	(-8);
	mTextSmallWhite.SetPosition		(5, 5, 1);
	mTextSmallWhite.SetAlign		(IND_LEFT);


	timer.Start();



	// global audio manager pointer variable automatically set
	//IAudio* pAudioManager = STX_Service::GetAudioInstance()
	STX_Service::GetAudioInstance()->Init();

#if 1
	//------------------------------
	// Load all sounds
	//------------------------------
	for (int i = 0; i < MAX_SOUNDS; i++)
	{
		STX_Service::GetAudioInstance()->Load(g_SoundNames[i].szFilename.c_str(), g_SoundNames[i].szName.c_str());
	}
#endif
	STX_CATCH;
	return 0;


	// ----- Main Loop -----
	}
Пример #3
0
virtual int render()
{
	STX_TRY;
		mI->Input->Update ();

		// ----- Delta Time -----
		fElapsedTime = mI->Render->GetFrameTime() / 1000.0f;

			// ----- Text -----
		stx_strlcpy (szText, "Move the mouse left and right and watch the tank try to follow!\n", 2048);
		stx_strlcat (szText, "Press Left Mouse button to fire!\n", 2048);
		stx_strlcat (szText, "Press 'f' to toggle freezing the tank movement (debug)\n", 2048);
		stx_snprintf(szBuf, 2048, "%d, %d\n", mI->Input->GetMouseX(), mI->Input->GetMouseY() );
		stx_strlcat (szText, szBuf, 2048);
		stx_snprintf(szBuf, 2048, "%.3f, %.3f\n", g_vecPlayer_Pos.x, g_vecPlayer_Pos.y);
		stx_strlcat (szText, szBuf, 2048);
		stx_snprintf(szBuf, 2048, "Muzzle angle %.3f\n", g_fGunAngle);
		stx_strlcat (szText, szBuf, 2048);
		stx_snprintf(szBuf, 2048, "Tank velocity %.3f\n", g_vecPlayer_Velocity.x);
		stx_strlcat (szText, szBuf, 2048);
		mTextSmallWhite.SetText	 (szText);

		// Position the mouse cursor
		cursor.SetPosition((float)mI->Input->GetMouseX(), (float)mI->Input->GetMouseY(), 1);

		// "Freeze" tank except allow gun to rotate
		if (mI->Input->OnKeyPress(KEY_f))
			g_bToggleFreezeTank = !g_bToggleFreezeTank;


		ULONG        Direction = 0;

		float deltaX = g_vecPlayer_Pos.x - mI->Input->GetMouseX();

		if (!g_bToggleFreezeTank && fabs(deltaX) > g_Epsilon)
		{
			if (deltaX < 0)
			{
				Direction |= DIR_RIGHT;
				tank.SetSequence(1);
			}
			else
			if (deltaX > 0)
			{
				Direction |= DIR_LEFT;
				tank.SetSequence(2);
			}
		}
		else
		{
			// Stop the animation if not moving
			tank.SetSequence(0);
		}

		// Any movement?
		if ( Direction && !g_bToggleFreezeTank )
		{
			Player_Move( Direction, g_fSpeed * fElapsedTime, true );
		}

		//---------------------------
		// Update the player
		//---------------------------
		Player_Update( fElapsedTime );

		//---------------------------
		// Move and rotate the barrel
		// Note: there would normally be a class representing the whole tank
		//---------------------------
		float fMouse2TankX = tank.GetPosX() - mI->Input->GetMouseX();
		float fMouse2TankY = tank.GetPosY() - mI->Input->GetMouseY();	// y position going down

		// Clamp. Mouse is below tank
		if (fMouse2TankY < 0.0f)
			fMouse2TankY = 0.0f;
		g_fGunAngle = atan2(fMouse2TankY, fMouse2TankX) * 180.0f / fPI;			// in degrees
		g_fGunAngle -= 90.0f;	// barrel is initially pointing up (in image).  atan2() w.r.t x-axis (pointing right)
		barrel.SetAngleXYZ(0.0f, 0.0f, g_fGunAngle);

		// Set position of barrel (child) on the tank (parent)
		g_vecBarrel.x = tank.GetPosX();
		g_vecBarrel.y = tank.GetPosY();
		barrel.SetPosition(g_vecBarrel.x, g_vecBarrel.y, 0);

		// Move the tank (player)
		tank.SetPosition(g_vecPlayer_Pos.x, g_vecPlayer_Pos.y, 1);
		tankShadow.SetPosition(tank.GetPosX(), tank.GetPosY() + 50, 0);	// location is tank HotSpot plus an offset of 50


		//---------------------------
		// Fire weapon!!
		//---------------------------
		if (5 && mI->Input->OnMouseButtonPress(MBUTTON_LEFT))
		{
			// Initial bullet position (following code is rather verbose and could be combined into less lines
			// but did it that way to explain the math.
			float angleDegrees = barrel.GetAngleZ() + 90.0f;
			float angleRadians = angleDegrees * fPI / 180.0f;
			float fX = barrel.GetPosX() - cosf(angleRadians) * BARREL_LENGTH;
			float fY = barrel.GetPosY() - sinf(angleRadians) * BARREL_LENGTH;
			bullet.SetAngleXYZ(0, 0, angleDegrees - 90.0f);
			g_vecBullet_Pos = D3DXFROMWINEVECTOR3(fX, fY, 0.0f);
			bullet.SetPosition(g_vecBullet_Pos.x, g_vecBullet_Pos.y, 0);

			// Initial bullet velocity
			D3DXFROMWINEMATRIX mtxRotate;
			D3DXFROMWINEVECTOR3 vecVelDir = D3DXFROMWINEVECTOR3(-1.0f, 0.0f, 0.0f);
			D3DXFROMWINEMatrixRotationZ( &mtxRotate, angleRadians);
			D3DXFROMWINEVec3TransformNormal( &vecVelDir, &vecVelDir, &mtxRotate );
			g_vecBullet_Velocity = vecVelDir * BULLET_SPEED;

			// Show blast!
			g_fMuzzleFlashTimer = 0.05f;
			muzzleFlash.SetPosition(g_vecBullet_Pos.x, g_vecBullet_Pos.y, 0);
			g_bBulletDead = false;

			// Make sound! (no sound lib hooked up but this is where you would do it.
			STX_Service::GetAudioInstance()->Play("tankfire1");
		}

		// Update the single bullet
		if (!g_bBulletDead)
		{
			bullet.SetShow(true);
			Bullet_Update( fElapsedTime, &bullet );
			bullet.SetPosition(g_vecBullet_Pos.x, g_vecBullet_Pos.y, 0);
		}
		else
		{
			bullet.SetShow(false);
		}

		//---------------------------
		// Render muzzle flash effect
		//---------------------------
		g_fMuzzleFlashTimer -= fElapsedTime;
		if (g_fMuzzleFlashTimer > 0.0f)
		{
			muzzleFlash.SetShow(true);
		}
		else
		{
			muzzleFlash.SetShow(false);
			g_fMuzzleFlashTimer = 0.0f;
		}


		//-----------------
		// Render the scene
		//-----------------
		mI->Render->BeginScene ();

		mI->Render->ClearViewPort (160, 160, 160);

		mI->Render->SetViewPort2d (0, 0, mI->Window->GetWidth(), mI->Window->GetHeight());

		mI->Entity2dManager->RenderEntities2d ( );

		// Render GUI layer
		mI->Entity2dManager->RenderEntities2d (1);
		//???mI->Render->ShowFpsInWindowTitle();

		// MUST call this to update FMOD
		STX_Service::GetAudioInstance()->Update();

		mI->Render->EndScene ();
		STX_CATCH;
		return 0;


	}
Пример #4
0
/*
==================
Main
==================
*/
int IndieLib()
{
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::Instance();
	if (!mI->Init ()) return 0;			

	// ----- Surface loading -----

	// 3d Dino loading
	IND_3dMesh mMeshDino;
	if (!mI->MeshManager->Add (&mMeshDino, "..\\resources\\trex dx\\dino videogame.x", "..\\resources\\trex dx")) return 0;

	// Font
	IND_Font mFontSmall;
	if (!mI->FontManager->Add (&mFontSmall, "..\\resources\\font_small.png", "..\\resources\\font_small.xml", IND_ALPHA, IND_32)) return 0;

	// ----- Font creation -----

	IND_Entity2d mTextSmallWhite;					
	mI->Entity2dManager->Add		(&mTextSmallWhite);			// Entity adding
	mTextSmallWhite.SetFont			(&mFontSmall);				// Set the font into the entity
	mTextSmallWhite.SetLineSpacing	(18);
	mTextSmallWhite.SetCharSpacing	(-8);
	mTextSmallWhite.SetPosition		(5, 5, 1);
	mTextSmallWhite.SetAlign		(IND_LEFT);

	// ----- Set the mesh into 3d entity -----

	// Creating 3d entity
	IND_Entity3d mDino;					
	mI->Entity3dManager->Add (&mDino);						// Entity adding
	mDino.Set3dMesh (&mMeshDino);							// Set the 3d mesh into the entity

	// ----- Cameras ------

	IND_Camera2d mCamera2d (mI->Window->GetWidth () / 2, mI->Window->GetHeight() / 2);
	IND_Camera3d mCamera3d (0.0f, 0.0f, -2.0f);
	mCamera3d.SetAspect ((float) mI->Window->GetWidth () / mI->Window->GetHeight());

	// ----- Light -----

	IND_Light mLight0;
	mI->LightManager->Add (&mLight0, IND_AMBIENT_LIGHT);
	mLight0.SetColor (1.0f, 1.0f, 1.0f, 1.0f);

	// Light 1 (Direction light)
	IND_Light mLight1;
	mI->LightManager->Add (&mLight1, IND_DIRECTIONAL_LIGHT);
	mLight1.SetColor (1.0f, 1.0f, 1.0f, 1.0f);
	mLight1.SetDirection (0.0f, -0.3f, 0.5f);
	mLight1.SetRange (1000.0f);

	// Light 2 (Point light)
	IND_Light mLight2;
	mI->LightManager->Add (&mLight2, IND_POINT_LIGHT);
	mLight2.SetPosition (3, 3, 3);
	mLight2.SetColor (0.4f, 1.0f, 0.4f, 1.0f);
	mLight2.SetRange (200);
	mLight2.SetAttenuation (0.5f);

	// Light 3 (Spot light)
	IND_Light mLight3;
	mI->LightManager->Add (&mLight3, IND_SPOT_LIGHT);
	mLight3.SetPosition (5, 5, 5);
	mLight3.SetColor (1.0f, 1.0f, 1.0f, 1.0f);
	mLight3.SetDirection (0.0f, -0.3f, 0.5f);
	mLight3.SetRange (1000);
	mLight3.SetAttenuation (0.2f);
	mLight3.SetFalloff (1.0f);
	mLight3.SetPhi (8.0f);
	mLight3.SetTheta (7);

	// ----- Main Loop -----

	mI->LightManager->Disable(&mLight2);
	mI->LightManager->Disable(&mLight3);
	float	mAngle = 0;
	char	mText [2048]; mText [0] = 0;
	int		mSpeed = 25;
	float	mDelta;

	while (!mI->Input->OnKeyPress (IND_ESCAPE) && !mI->Input->Quit())
	{
		// ----- Input update ----

		mI->Input->Update ();

		// ----- Text -----

		strcpy (mText, "Press 1, 2 or 3 in order to toggle between different lights\n");
		mTextSmallWhite.SetText	 (mText);	

		// ----- Input -----

		mDelta = mI->Render->GetFrameTime() / 1000.0f;

		// Activate only light 1
		if (mI->Input->IsKeyPressed (IND_1))
		{
			mI->LightManager->Disable(&mLight2);
			mI->LightManager->Disable(&mLight3);
			mI->LightManager->Enable(&mLight1);
		}

		// Activate only light 2
		if (mI->Input->IsKeyPressed (IND_2))
		{
			mI->LightManager->Disable(&mLight1);
			mI->LightManager->Disable(&mLight3);
			mI->LightManager->Enable(&mLight2);
		}

		// Activate only light 3
		if (mI->Input->IsKeyPressed (IND_3))
		{
			mI->LightManager->Disable(&mLight1);
			mI->LightManager->Disable(&mLight2);
			mI->LightManager->Enable(&mLight3);
		}

		// ----- Updating entities attributes  -----

		mAngle += mDelta * mSpeed;
		mDino.SetAngleXYZ (0, mAngle, 0);

		// ----- Render  -----

		mI->Render->ClearViewPort (60, 60, 60);
		mI->Render->BeginScene ();

		mI->Render->SetViewPort3d (0, 0, mI->Window->GetWidth (), mI->Window->GetHeight());
		mI->Render->SetCamera3d (&mCamera3d);
		mI->LightManager->Update ();
		mI->Entity3dManager->RenderEntities3d ();

		mI->Render->SetViewPort2d (0, 0, mI->Window->GetWidth (), mI->Window->GetHeight ());
		mI->Render->SetCamera2d (&mCamera2d);
		mI->Entity2dManager->RenderEntities2d ();

		mI->Render->EndScene ();	
	}

	// ----- Free -----

	mI->End ();

	return 0;
}
Пример #5
0
		virtual int init(unsigned int width, unsigned int height)
		{
			STX_INIT_SEGVCATCH;
			STX_TRY;
			g_pIndieLib = mI = CIndieLib::Instance();
	// ----- IndieLib intialization -----
#if 0
	//CIndieLib * mI = CIndieLib::Instance();
	if (!mI->Init ()) return 0;
#else
	
//CIndieLib * mI = CIndieLib::Instance();
	if (!CIndieLib::Instance()->
		Init (
		"a_08_Collisions"
		)) return -1;
#endif
	// ----- Surface loading -----

	// Loading Background
	////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->SurfaceManager->Add (&mSurfaceBack, "/twist.jpg", IND_OPAQUE, IND_32)) return 0;

	// Loading Rocket
	////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->SurfaceManager->Add (&mSurfaceRocket, "/rocket.png", IND_ALPHA, IND_32)) return 0;

	// Loading Beetleship
	////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->SurfaceManager->Add (&mSurfaceBeetle, "/beetleship.png", IND_ALPHA, IND_32)) return 0;

	// Sword Master animation, we apply a color key of (0, 255, 0)
	////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->AnimationManager->AddToSurface (&mSwordMasterAnimation, "/animations/sword_master.xml", IND_ALPHA, IND_16, 0, 255, 0)) return 0;

	// ----- Font loading -----

	// Font
	////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->FontManager->Add (&mFontSmall, "/font_small.png", "/font_small.xml", IND_ALPHA, IND_32)) return 0;

	// ----- Set the surfaces into 2d entities -----

	// Creating 2d entity for the background
	////////////////////IND_Entity2d mTextSmallWhite;
	mI->Entity2dManager->Add (&mBack);						// Entity adding
	mBack.SetSurface (&mSurfaceBack);						// Set the surface into the entity

	// Creating 2d entity for the Rocket
	////////////////////IND_Entity2d mTextSmallWhite;
	mI->Entity2dManager->Add (&mRocket);					// Entity adding
	mRocket.SetSurface (&mSurfaceRocket);					// Set the surface into the entity

	// Creating 2d entity for the Beetleship
	////////////////////IND_Entity2d mTextSmallWhite;
	mI->Entity2dManager->Add (&mBeetle);					// Entity adding
	mBeetle.SetSurface (&mSurfaceBeetle);					// Set the surface into the entity

	// Creating 2d entity for the Sword Master animation
	////////////////////IND_Entity2d mTextSmallWhite;
	mI->Entity2dManager->Add (&mSwordMaster);				// Entity adding
	mSwordMaster.SetAnimation (&mSwordMasterAnimation);		// Set the animation into the entity

	// Text small white
	////////////////////IND_Entity2d mTextSmallWhite;
	mI->Entity2dManager->Add (&mTextSmallWhite);			// Entity adding
	mTextSmallWhite.SetFont (&mFontSmall);					// Set the font into the entity

	// ----- Changing the attributes of the 2d entities -----

	// Background
	mBack.SetHotSpot (0.5f, 0.5f);
	mBack.SetPosition (400, 300, 0);
	mBack.SetScale (1.7f, 1.7f);

	// Beetle
	mBeetle.SetHotSpot (0.5f, 0.5f);
	mBeetle.SetMirrorX (1);
	mBeetle.SetBoundingTriangle ("beetle_head", 160, 105, 160, 170, 190, 135);
	mBeetle.SetBoundingCircle ("beetle_boy_head", 85, 52, 55);

	// Rocket
	mRocket.SetHotSpot (0.5f, 0.5f);
	mRocket.SetPosition (200, 450, 1);
	mRocket.SetBoundingAreas ("/rocket_collisions.xml");
	//mRocket.DeleteBoundingAreas ("engines");

	// Sword Master Animation
	mSwordMaster.SetHotSpot (0.5f, 0.5f);
	mSwordMaster.SetPosition (400, 220, 3);

	// Text
	mTextSmallWhite.SetLineSpacing	(18);
	mTextSmallWhite.SetCharSpacing	(-7);
	mTextSmallWhite.SetPosition		(400, 30, 10);
	mTextSmallWhite.SetAlign		(IND_CENTER);

	// ----- Main Loop -----
	STX_CATCH;
	return 0;



	}
Пример #6
0
		virtual int init(unsigned int width, unsigned int height)
		{
			STX_INIT_SEGVCATCH;
			STX_TRY;
			g_pIndieLib = mI = CIndieLib::Instance();
	// ----- IndieLib intialization -----

#if 0
	//CIndieLib * mI = CIndieLib::Instance();
	if (!mI->Init ()) return 0;
#else
	
//CIndieLib * mI = CIndieLib::Instance();
	if (!mI->
		Init (
		"IndieLib-Animation-Collision"
		)) return -1;
#endif
	//IND_Entity2d Beetle

	// Loading Background
	//IND_Entity2d Beetle
	if (!mI->SurfaceManager->Add (&mSurfaceBack, "/IndieLib-Animation-Collision/cave.png", IND_ALPHA, IND_32))
		return 0;

	// Loading Beetleship
	//IND_Entity2d Beetle
	if (!mI->SurfaceManager->Add (&mSurfaceBeetle, "/IndieLib-Animation-Collision/beetleship.png", IND_ALPHA, IND_32))
		return 0;

	// ----- Animations loading -----

	// Characters animations
	//IND_Entity2d Beetle
	if (!mI->AnimationManager->AddToSurface (&AnimationCharacter, "/IndieLib-Animation-Collision/mario.xml", IND_ALPHA, IND_32))
		return 0;



	// ----- Set the surface and animations into 2d entities -----

	// Creating 2d entity for the background
	//IND_Entity2d Beetle
	mI->Entity2dManager->Add (&mBack);						// Entity adding (layer 0)
	mBack.SetSurface (&mSurfaceBack);						// Set the surface into the entity

	// Character 1
	//IND_Entity2d Beetle
	mI->Entity2dManager->Add (1, &Player);					// Entity adding (layer 1)
	Player.SetAnimation (&AnimationCharacter);				// Set the animation into the entity

	// Beetle
	//IND_Entity2d Beetle
	mI->Entity2dManager->Add (0, &Beetle);					// (layer 1)
	Beetle.SetSurface (&mSurfaceBeetle);					// Set the surface into the entity
	Beetle.SetPosition(500, 460, 0);
	Beetle.SetHotSpot (0.5f, 0.5f);
	Beetle.SetMirrorX (1);
	Beetle.SetBoundingTriangle ("beetle_head", 160, 105, 160, 170, 190, 135);
	Beetle.SetBoundingCircle ("beetle_boy_head", 85, 52, 55);



	MiddleScreenX = mI->Window->GetWidth() / 2;
	MiddleScreenY = mI->Window->GetHeight() / 2;
	CamPosX = MiddleScreenX;
	Cameras2d=IND_Camera2d(MiddleScreenX, MiddleScreenY);

	// ----- Main Loop -----

	timer.Start();



	// Init Player
	Player.SetSequence (0);			// standing
	Player.SetPosition (x , y, 0);
	Player.SetHotSpot (0.5f, 0.5f);
	Player.SetMirrorX (0);
	Player.SetBoundingRectangle("entire", 0, 0, 48, 48);
	STX_CATCH;
	return 0;

	}
Пример #7
0
virtual int render()
{
		STX_TRY;
		mI->Input->Update ();

		// ----- Delta Time -----
		fElapsedTime = mI->Render->GetFrameTime() / 1000.0f;

		// Toggle show bounding boxes
		if (mI->Input->OnKeyPress(KEY_p))
			bShowBoundsToggle = !bShowBoundsToggle;

		// Walk Left!
		if (mI->Input->IsKeyPressed(KEY_LEFT))
		{
			VelocityX -= speed * fElapsedTime;
			if (!playerJumping)
				Player.SetSequence(0);		//walk
			Player.SetMirrorX(1);
		}
		// Walk Right!
		else
		if (mI->Input->IsKeyPressed(KEY_RIGHT))
		{
			VelocityX += speed * fElapsedTime;
			if (!playerJumping)
				Player.SetSequence(0);		//walk
			Player.SetMirrorX(0);

		}
		else
		{
			if (!playerJumping)
				Player.SetSequence(1);		// stand
			VelocityX = 0.0f;			// 0 = no slide
		}

		// JUMP!
		if(mI->Input->OnKeyPress(KEY_SPACE) && !playerJumping)
		{
			VelocityY -= fJumpForce;	// jump force (minus is up)
			Player.SetSequence(2);		// jump
			playerJumping = true;
		}

		// TODO - if no key press then apply friction.  We want the player to move instantly
		// yet slide to a stop.

		VelocityY += gravity * fElapsedTime;	// apply gravity (value is gravity)
		y += VelocityY * fElapsedTime;			// position

		// Check falling limits (poor man collision detection!)
		if (y > 500)
		{
			VelocityY = 0;
			y = 500;
			playerJumping = false;
		}

		// Clamp walking velocity
		float Length = sqrtf(VelocityX * VelocityX);
		if ( Length > MaxVelocityX )
		{
			VelocityX *= ( MaxVelocityX / Length );
		} // End if clamp X velocity

		x += VelocityX * fElapsedTime;
		if (x < 0)
			x = 0;

		// Move the player
		Player.SetPosition(x, y, 0);

		// Apply slide friction
		float Dec = -Dir * slideFriction * fElapsedTime;

		if (mI->Entity2dManager->IsCollision (&Player, "/IndieLib-Animation-Collision/entire", &Beetle, "/IndieLib-Animation-Collision/beetle_boy_head"))
		{
			VelocityY = 80;	// force him downward
			VelocityX = 0;
		}

		if (x > mI->Window->GetWidth() / 2)
			Cameras2d.SetPosition((int)x, MiddleScreenY);


		mI->Render->BeginScene ();
		mI->Render->ClearViewPort (60, 60, 60);
		mI->Render->SetViewPort2d (0, 0, mI->Window->GetWidth(), mI->Window->GetHeight());
		mI->Render->SetCamera2d (&Cameras2d);

		for (int i = 0; i < 16; i++)
		{
			mI->Entity2dManager->RenderEntities2d ( i );
			if (bShowBoundsToggle)
				mI->Entity2dManager->RenderCollisionAreas (i, 255, 0, 0, 255);
		}
		//???mI->Render->ShowFpsInWindowTitle("");
		mI->Render->EndScene ();
		STX_CATCH;
		return 0;
	}
Пример #8
0
		virtual int init(unsigned int width, unsigned int height)
		{
			STX_INIT_SEGVCATCH;
			STX_TRY;
			g_pIndieLib = mI = CIndieLib::Instance();
	// ----- IndieLib intialization -----

#if 0
	//CIndieLib * mI = CIndieLib::Instance();
	if (!CIndieLib::Instance()->Init ()) return 0;
#else
	
	mI = CIndieLib::Instance();
	if (!CIndieLib::Instance()->
		Init (
		"IndieLib-Transitions"
		)) return -1;
#endif

	// Loading layer 1
	//////////IND_Timer timer;
	if (!mI->SurfaceManager->Add (&SurfaceSnake, "/IndieLib-Transitions/snake_512.jpg", IND_ALPHA, IND_32)) return 0;

	// Loading layer 1
	//////////IND_Timer timer;
	if (!mI->SurfaceManager->Add (&SurfacePool, "/IndieLib-Transitions/pool_512.jpg", IND_ALPHA, IND_32)) return 0;

	// ----- Font creation -----
	// Font (layer 3)
	//////////IND_Timer timer;
	if (!mI->FontManager->Add (&FontSmall, "/IndieLib-Transitions/font_small.png", "/IndieLib-Transitions/font_small.xml", IND_ALPHA, IND_32)) return 0;

	// Create the Font
	//////////IND_Timer timer;
	mI->Entity2dManager->Add		(1, &TextSmallWhite);		// Entity adding (Layer 3)
	TextSmallWhite.SetFont			(&FontSmall);				// Set the font into the entity
	TextSmallWhite.SetLineSpacing	(18);
	TextSmallWhite.SetCharSpacing	(-8);
	TextSmallWhite.SetPosition		(5, 5, 1);
	TextSmallWhite.SetAlign		(IND_LEFT);

	// Creating 2d entity for the pool
	g_pSourceEntity2d = new IND_Entity2d();
	mI->Entity2dManager->Add (0, g_pSourceEntity2d);			// Entity adding !!! Note the first parameter is layer #
	g_pSourceEntity2d->SetSurface (&SurfacePool);				// Set the surface into the entity

	// Creating 2d entity for the snake
	g_pDestEntity2d	= new IND_Entity2d();
	mI->Entity2dManager->Add (0, g_pDestEntity2d);			// Entity adding !!! Note the first parameter is layer #
	g_pDestEntity2d->SetSurface (&SurfaceSnake);			// Set the surface into the entity
	g_pDestEntity2d->SetPosition(0, 0, 0);


	//////////IND_Timer timer;

	g_szTitle = "ALPHA2";
	
	// ----- Main Loop -----

	timer.Start();

	// Create the first transition
	g_pMainTransition = new Transition(g_pSourceEntity2d, g_pDestEntity2d, ALPHA2, g_pSourceEntity2d->GetSurface()->GetWidth(), g_pSourceEntity2d->GetSurface()->GetHeight());
	STX_CATCH;
	return 0;


	}