/* ----------------------
perform the rendering
C.Wang 0720, 2006
---------------------- - /
/ ----------------------
perform the rendering
C.Wang 0720, 2006
---------------------- - */
void RenderIt(int skip)
{
	FnViewport vp;

	// render the whole scene
	vp.ID(vID);
	vp.Render3D(cID, TRUE, TRUE);

	// get camera's data
	FnCamera camera;
	camera.ID(cID);

	float pos[3], fDir[3], uDir[3];
	camera.GetPosition(pos);
	camera.GetDirection(fDir, uDir);

	// show frame rate
	static char string[128];
	if (frame == 0) {
		FyTimerReset(0);
	}

	if (frame / 10 * 10 == frame) {
		float curTime;

		curTime = FyTimerCheckTime(0);
		sprintf(string, "Fps: %6.2f", frame / curTime);
	}

	frame += skip;
	if (frame >= 1000) {
		frame = 0;
	}

	FnText text;
	text.ID(textID);

	text.Begin(vID);
	text.Write(string, 20, 20, 255, 0, 0);

	char posS[256], fDirS[256], uDirS[256];
	float cpos[3], apos[3], distance, height, length;//
	FnCharacter actor;
	actor.ID(actorID);

	FnObject terrain;
	terrain.ID(tID);

	sprintf(posS, "pos: %8.3f %8.3f %8.3f", pos[0], pos[1], pos[2]);
	sprintf(fDirS, "facing: %8.3f %8.3f %8.3f", fDir[0], fDir[1], fDir[2]);
	sprintf(uDirS, "up: %8.3f %8.3f %8.3f", uDir[0], uDir[1], uDir[2]);
	text.Write(posS, 20, 35, 255, 255, 0);
	text.Write(fDirS, 20, 50, 255, 255, 0);
	text.Write(uDirS, 20, 65, 255, 255, 0);

	text.End();

	// swap buffer
	FySwapBuffers();
}
Beispiel #2
0
/*----------------------
perform the rendering
C.Wang 0720, 2006
-----------------------*/
void RenderIt(int skip)
{
	FnViewport vp;

	// render the whole scene
	vp.ID(vID);
	vp.Render3D(cID, TRUE, TRUE);

	// render the sprites
	vp.RenderSprites(sID2, FALSE, TRUE);  // no clear the background but clear the z buffer
	FySwapBuffers();

	// get camera's data
	FnCamera camera;
	camera.ID(cID);

	FnObject terrain;
	terrain.ID(tID);

	float pos[3], fDir[3], uDir[3];

	//-----------------HW2 added-----------------------//

	float actorPos[3], actorfDir[3], actoruDir[3];
	FnCharacter actor;
	actor.ID(actorID);

	actor.GetPosition(actorPos);
	actor.GetDirection(actorfDir, actoruDir);

	camera.GetPosition(pos);
	camera.GetDirection(fDir, uDir);

	// Initialze probing ray direction
	float dir[3], charDir[3];

	dir[0] = -fDir[0] / CAMERAPROBE;
	dir[1] = -fDir[1] / CAMERAPROBE;
	dir[2] = -1;

	charDir[0] = actorfDir[0] / ACTORPROBE;
	charDir[1] = actorfDir[1] / ACTORPROBE;
	charDir[2] = -1;

	if ((FyCheckHotKeyStatus(FY_A) || FyCheckHotKeyStatus(FY_D)) && dirCount % SMOOTHINESS == 0)
	{
		int tempHeight = pos[2];
		pos[2] = actorPos[2];
		int theDistance = FyDistance(pos, actorPos);

		pos[0] = actorPos[0] - theDistance * actorfDir[0];
		pos[1] = actorPos[1] - theDistance * actorfDir[1];
		pos[2] = tempHeight;

		fDir[0] = actorfDir[0];
		fDir[1] = actorfDir[1];

		uDir[0] = fDir[0] / abs(fDir[0] * fDir[1]);
		uDir[1] = fDir[1] / abs(fDir[0] * fDir[1]);
		uDir[2] = -abs(uDir[0] * fDir[0] + uDir[1] * fDir[1]) / fDir[2];
	}
	if ((FyCheckHotKeyStatus(FY_UP) || FyCheckHotKeyStatus(FY_S)) && dirCount % SMOOTHINESS == 0)
	{
		if (pos[2] > actorPos[2] + HEIGHTOFFSET)
		{
			pos[2] = actorPos[2];
			pos[2] = actorPos[2] + HEIGHTBOUND + HEIGHTOFFSET - FyDistance(pos, actorPos);

			fDir[0] = actorPos[0] - pos[0];
			fDir[1] = actorPos[1] - pos[1];
			fDir[2] = -pos[2];

			uDir[0] = fDir[0] / abs(fDir[0] * fDir[1]);
			uDir[1] = fDir[1] / abs(fDir[0] * fDir[1]);
			uDir[2] = -abs(uDir[0] * fDir[0] + uDir[1] * fDir[1]) / fDir[2];
		}
		else  // Reset the up direction 
		{
			pos[2] = actorPos[2] + HEIGHTOFFSET;
			fDir[0] = actorfDir[0];		fDir[1] = actorfDir[1];		fDir[2] = 0;
			uDir[0] = 0;	            uDir[1] = 0;	            uDir[2] = 1;
		}

		if (FyDistance(pos, actorPos) > LONGDIST)
		{
			pos[0] = actorPos[0] - LONGDIST * actorfDir[0];
			pos[1] = actorPos[1] - LONGDIST * actorfDir[1];
			pos[2] = actorPos[2] + HEIGHTOFFSET;

			fDir[0] = actorfDir[0];
			fDir[1] = actorfDir[1];
			fDir[2] = -0.0f;

			uDir[0] = actoruDir[0];
			uDir[1] = actoruDir[1];
			uDir[2] = actoruDir[2];

		}
	}

	if (FyCheckHotKeyStatus(FY_RIGHT) && dirCount % SMOOTHINESS == 0)
	{
		actorPos[2] += HEIGHTOFFSET;
		if (terrain.HitTest(actorPos, charDir) <= 0)
		{
			camera.MoveRight(-CAMERASPEED, FALSE, FALSE, 0, FALSE);
			camera.GetPosition(pos);
		}

		fDir[0] = actorPos[0] - pos[0];
		fDir[1] = actorPos[1] - pos[1];
		fDir[2] = 0.0f;
	}
	if (FyCheckHotKeyStatus(FY_LEFT) && dirCount % SMOOTHINESS == 0)
	{
		actorPos[2] += HEIGHTOFFSET;
		if (terrain.HitTest(actorPos, charDir) <= 0)
		{
			camera.MoveRight(CAMERASPEED, FALSE, FALSE, 0, FALSE);
			camera.GetPosition(pos);
		}

		fDir[0] = actorPos[0] - pos[0];
		fDir[1] = actorPos[1] - pos[1];
		fDir[2] = 0.0f;
	}
	if (FyCheckHotKeyStatus(FY_DOWN) && dirCount % SMOOTHINESS == 0)
	{
		if (FyDistance(pos, actorPos) < SHORTDIST)
		{
			if (terrain.HitTest(pos, dir) > 0)
			{
				pos[0] = actorPos[0] + SHORTDIST * actorfDir[0];
				pos[1] = actorPos[1] + SHORTDIST * actorfDir[1];
				pos[2] = actorPos[2] + HEIGHTOFFSET;

				fDir[0] = -actorfDir[0];
				fDir[1] = -actorfDir[1];
				fDir[2] = 0.0f;

				uDir[0] = actoruDir[0];
				uDir[1] = actoruDir[1];
				uDir[2] = actoruDir[2];
			}
			else
			{
				// go back and hit Obstacle : camera look down at the actor

				pos[2] = actorPos[2];
				pos[2] = actorPos[2] + HEIGHTBOUND + HEIGHTOFFSET - FyDistance(pos, actorPos);

				fDir[0] = actorPos[0] - pos[0];
				fDir[1] = actorPos[1] - pos[1];
				fDir[2] = -pos[2];

				uDir[0] = fDir[0] / abs(fDir[0] * fDir[1]);
				uDir[1] = fDir[1] / abs(fDir[0] * fDir[1]);
				uDir[2] = -abs(uDir[0] * fDir[0] + uDir[1] * fDir[1]) / fDir[2];
			}
		}
	}

	//-----------------HW2 end-------------------------//


	if (dirCount % SMOOTHINESS == 0)
	{
		camera.SetPosition(pos);
		camera.SetDirection(fDir, uDir);
	}
	// show frame rate
	static char string[128];
	if (frame == 0) {
		FyTimerReset(0);
	}

	if (frame / 10 * 10 == frame) {
		float curTime;

		curTime = FyTimerCheckTime(0);
		sprintf(string, "Fps: %6.2f", frame / curTime);
	}

	frame += skip;
	if (frame >= 1000) {
		frame = 0;
	}

	FnText text;
	text.ID(textID);

	text.Begin(vID);
	text.Write(string, 20, 20, 255, 0, 0);

	char posS[256], fDirS[256], uDirS[256], debug[256];
	sprintf(posS, "pos: %8.3f %8.3f %8.3f", pos[0], pos[1], pos[2]);
	sprintf(fDirS, "facing: %8.3f %8.3f %8.3f", fDir[0], fDir[1], fDir[2]);
	sprintf(uDirS, "up: %8.3f %8.3f %8.3f", uDir[0], uDir[1], uDir[2]);
	sprintf(debug, "debug: %d %d %d", LyubuID.level, LyubuID.exp_cur, LyubuID.blood_remain);

	text.Write(posS, 20, 35, 255, 255, 0);
	text.Write(fDirS, 20, 50, 255, 255, 0);
	text.Write(uDirS, 20, 65, 255, 255, 0);
	text.Write(debug, 20, 90, 255, 255, 0);

	text.End();

	// swap buffer
	FySwapBuffers();
}
Beispiel #3
0
/*-------------------------------------------------------------
30fps timer callback in fixed frame rate for major game loop
--------------------------------------------------------------*/
void GameAI(int skip)
{



	// play character pose
	FnCharacter actor;
	FnCharacter cur_actor;
	FnObject terrain;
	terrain.ID(tID);
	FnScene scene;
	scene.ID(sID);
	LyubuID.actorID = actorID;
	//Tang: FX
	float actorPos[3];
	vector<char*> FX_FileName;
	//Tang

	actor.ID(actorID);
	//Tang: FX
	actor.GetPosition(actorPos);
	//Tang

	if (curPoseID == runID || curPoseID == idleID)
		actor.Play(LOOP, (float)skip, FALSE, TRUE);
	else if (actor.Play(ONCE, (float)skip, FALSE, TRUE) == 0)
		actor.SetCurrentAction(NULL, 0, idleID, 10.0f);

	
	for (int i = 0; i < NUM_OF_BADGUYS; i++)
	{
		cur_actor.ID(badguyID[i].actorID);

		if (badguyID[i].blood_remain > 0)
		{
			bool checkMove = MoveToTargetLocation(badguyID[i], LyubuID, badguyID, terrain);

			
			if (cur_actor.Play(ONCE, (float)skip, FALSE, TRUE) == 0)
			{
				if (checkMove)
				{
					ACTIONid CombatIdleID = cur_actor.GetBodyAction(NULL, "Run");
					cur_actor.SetCurrentAction(NULL, 0, CombatIdleID);
				}
				else
				{
					ACTIONid CombatIdleID = cur_actor.GetBodyAction(NULL, "NormalAttack2");
					cur_actor.SetCurrentAction(NULL, 0, CombatIdleID);

					//Tang: FX
					FX_FileName.clear();
					FX_FileName.push_back("HitForRobber");
					GenFX(sID, gFXID, dummyID, actorPos, FX_FileName);
					//Tang
				}
			}
		}
	}

	for (int i = 0; i < NUM_OF_BOSS; i++)
	{
		cur_actor.ID(BossID[i].actorID);
		ACTIONid cur_action = cur_actor.GetCurrentAction(NULL, 0);
		ACTIONid DieID = cur_actor.GetBodyAction(NULL, "Die");

		if (cur_action == DieID)
			cur_actor.Play(ONCE, (float)skip, FALSE, TRUE);
		else if (BossID[i].blood_remain > 0)
		{
			bool checkMove = MoveToTargetLocation(BossID[i], LyubuID, BossID, terrain);

			if (cur_actor.Play(ONCE, (float)skip, FALSE, TRUE) == 0)
			{
				if (checkMove)
				{
					ACTIONid CombatIdleID = cur_actor.GetBodyAction(NULL, "Run");
					cur_actor.SetCurrentAction(NULL, 0, CombatIdleID);
				}
				else
				{
					ACTIONid CombatIdleID = cur_actor.GetBodyAction(NULL, "HeavyAttack");
					cur_actor.SetCurrentAction(NULL, 0, CombatIdleID);

					//Tang: FX
					FX_FileName.clear();
					FX_FileName.push_back("HitForRobber");
					GenFX(sID, gFXID, dummyID, actorPos, FX_FileName);
					//Tang
				}
			}
		}
	}




	// Camera's position and direction as a standard for character's location setting
	FnCamera camera;
	camera.ID(cID);
	float cameraPos[3], camerafDir[3], camerauDir[3];
	camera.GetPosition(cameraPos); // not used
	camera.GetDirection(camerafDir, camerauDir);

	float camVertical = camerafDir[2];
	camerafDir[2] = 0; // Guaranteed up direction be 1
	camerauDir[0] = 0; camerauDir[1] = 0; camerauDir[2] = 1;


	float dir[3], origin[3], actorfDir[3], actoruDir[3];// origin is the actor's position      
	actor.GetPosition(origin);
	actor.GetDirection(actorfDir, actoruDir);

	//Generator location 
	genSpot[0][0] = 2905.724;
	genSpot[0][1] = -2856.196;
	genSpot[1][0] = 729.288;
	genSpot[1][1] = -2472.88;

	// Bad guys generator
	for (int i = 0; i < NUM_OF_GENERATOR; i++)
	{
		if (!InArea(origin, genSpot[i], generator[i].range))
		{
			generator[i].in = 0;
			generator[i].double_in = 0;
		}
		if (generator[i].in && InArea(origin, genSpot[i], generator[i].range))
		{
			generator[i].double_in = 1;
		}
		if (InArea(origin, genSpot[i], generator[i].range))
		{
			generator[i].in = 1;
		}

		if (generator[i].in == 1 && generator[i].double_in == 0)
			generator[i].produce(origin, actoruDir, scene, i, NUM_OF_GENERATOR);
	}

	origin[2] = origin[2] + HEIGHTOFFSET; // need an offset to probe the hit
	dir[0] = actorfDir[0] / ACTORPROBE;
	dir[1] = actorfDir[1] / ACTORPROBE;
	dir[2] = -1.0f;

	//////////////////////////////////////////
	// Homework #01 part 1
	//////////////////////////////////////////

	if (dirCount % SMOOTHINESS != 0)
	{
		if ((dirCount + SMOOTHINESS) % SMOOTHINESS < SMOOTHINESS / 2 + 1)
		{
			dirCount--;
			actor.TurnRight(360 / SMOOTHINESS);
		}
		else
		{
			dirCount++;
			actor.TurnRight(360 - 360 / SMOOTHINESS);
		}
	}

	if ((FyCheckHotKeyStatus(FY_UP) || FyCheckHotKeyStatus(FY_S)) && dirCount % SMOOTHINESS == 0)
	{
		actor.SetDirection(camerafDir, camerauDir);
		if (terrain.HitTest(origin, dir) > 0)
			actor.MoveForward(RUNSPEED, FALSE, FALSE, 0, FALSE);
	}
	if (FyCheckHotKeyStatus(FY_D) && dirCount % SMOOTHINESS == 0)
		actor.TurnRight(TURNSPEED);
	if (FyCheckHotKeyStatus(FY_A) && dirCount % SMOOTHINESS == 0)
		actor.TurnRight(360 - TURNSPEED);
	else if (FyCheckHotKeyStatus(FY_RIGHT) && dirCount % SMOOTHINESS == 0)
	{
		actorfDir[0] = camerafDir[1];
		actorfDir[1] = -camerafDir[0];
		actor.SetDirection(actorfDir, actoruDir);
		if (terrain.HitTest(origin, dir) > 0)
		{
			//actor.MoveRight(CALLIBRATION, FALSE, FALSE, 0, FALSE); 
			actor.MoveForward(RUNSPEED / 2, FALSE, FALSE, 0, FALSE);
		}
	}
	else if (FyCheckHotKeyStatus(FY_LEFT) && dirCount % SMOOTHINESS == 0)
	{
		actorfDir[0] = -camerafDir[1];
		actorfDir[1] = camerafDir[0];
		actor.SetDirection(actorfDir, actoruDir);
		if (terrain.HitTest(origin, dir) > 0)
		{
			//actor.MoveRight(CALLIBRATION, FALSE, FALSE, 0, FALSE); 
			actor.MoveForward(RUNSPEED / 2, FALSE, FALSE, 0, FALSE);
		}
	}
	else if (FyCheckHotKeyStatus(FY_DOWN) && dirCount % SMOOTHINESS == 0)
	{
		actor.SetDirection(camerafDir, camerauDir);
		actor.TurnRight(180.0f);
		if (terrain.HitTest(origin, dir) > 0 && camVertical > MAXCAMANGLE)
			actor.MoveForward(RUNSPEED, FALSE, FALSE, 0, FALSE);
	}


	//Tang: FX
	if (gFXID != FAILED_ID) {
		FnGameFXSystem gxS(gFXID);
		BOOL4 beOK = gxS.Play((float)skip, ONCE);
		if (!beOK) {
			FnScene scene(sID);
			scene.DeleteGameFXSystem(gFXID);
			gFXID = FAILED_ID;
		}
	}
	//Tang
}