Пример #1
0
/*------------------
movement control
-------------------*/
void Movement(BYTE code, BOOL4 value)
{
	//////////////////////////////////////////
	// Homework #01 part 2
	//////////////////////////////////////////
	// note : only hotkey input can trigger this function


	FnCharacter actor;
	FnCharacter badguy;
	//Tang: FX
	vector<char*> FX_FileName;
	//Tang

	float actorPos[3], actorfDir[3], actoruDir[3];
	float badguyPos[3], badguyfDir[3], badguyuDir[3];

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

	// 2. use a global idle_count variable to memorize the action status.
	//    (to prevent the "slide" actor bug)

	if (value)
	{
		idle_count++;

		if (FyCheckHotKeyStatus(FY_Q) && dirCount % SMOOTHINESS == 0)
		{
			actorPos[0] += actorfDir[0] * HATKOFFSET;
			actorPos[1] += actorfDir[1] * HATKOFFSET;

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

				if (FyDistance(badguyPos, actorPos) < HATKRANGE && badguyID[i].blood_remain > 0)
				{
					if (!ActAction(badguyID[i], "Damage1", HATKDAMAGE))
					{
						LyubuID.exp_cur += 50;
						if (LyubuID.exp_cur >= LyubuID.exp_total){
							LyubuID.level++;
							LyubuID.exp_cur -= LyubuID.exp_total;
						}
					}

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

			for (int i = 0; i < NUM_OF_BOSS; i++)
			{
				badguy.ID(BossID[i].actorID);
				badguy.GetPosition(badguyPos);

				if (FyDistance(badguyPos, actorPos) < HATKRANGE && BossID[i].blood_remain > 0)
				{
					ActAction(BossID[i], "Donzo", HATKDAMAGE);

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

		}

		if (FyCheckHotKeyStatus(FY_W) && dirCount % SMOOTHINESS == 0)
		{
			actorPos[0] += actorfDir[0] * NATK1OFFSET;
			actorPos[1] += actorfDir[1] * NATK1OFFSET;

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

				if (FyDistance(badguyPos, actorPos) < NATK1RANGE && badguyID[i].blood_remain > 0)
				{
					if (!ActAction(badguyID[i], "Damage2", NATK1DAMAGE))
					{
						LyubuID.exp_cur += 50;
						if (LyubuID.exp_cur >= LyubuID.exp_total){
							LyubuID.level++;
							LyubuID.exp_cur -= LyubuID.exp_total;
						}
					}

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

			for (int i = 0; i < NUM_OF_BOSS; i++)
			{
				badguy.ID(BossID[i].actorID);
				badguy.GetPosition(badguyPos);

				if (FyDistance(badguyPos, actorPos) < NATK1RANGE && BossID[i].blood_remain > 0)
				{					
					ActAction(BossID[i], "Donzo", NATK1DAMAGE);

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

		}

		if (FyCheckHotKeyStatus(FY_E) && dirCount % SMOOTHINESS == 0)
		{
			actorPos[0] += actorfDir[0] * NATK2OFFSET;
			actorPos[1] += actorfDir[1] * NATK2OFFSET;

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

				if (FyDistance(badguyPos, actorPos) < NATK2RANGE && badguyID[i].blood_remain > 0)
				{
					if (!ActAction(badguyID[i], "Damage2", NATK2DAMAGE))
					{
						LyubuID.exp_cur += 50;
						if (LyubuID.exp_cur >= LyubuID.exp_total){
							LyubuID.level++;
							LyubuID.exp_cur -= LyubuID.exp_total;
						}
					}

					//Tang: FX
					FX_FileName.clear();
					FX_FileName.push_back("Lyubu_atk01 -X");
					GenFX(sID, gFXID, dummyID, badguyPos, FX_FileName);
					//Tang
				}
			}

			for (int i = 0; i < NUM_OF_BOSS; i++)
			{
				badguy.ID(badguyID[i].actorID);
				badguy.GetPosition(badguyPos);

				if (FyDistance(badguyPos, actorPos) < NATK2RANGE && BossID[i].blood_remain > 0)
				{
					ActAction(BossID[i], "Donzo", NATK2DAMAGE);

					//Tang: FX
					FX_FileName.clear();
					FX_FileName.push_back("Lyubu_atk01 -X");
					GenFX(sID, gFXID, dummyID, badguyPos, FX_FileName);
					//Tang
				}
			}


		}
		if ((FyCheckHotKeyStatus(FY_UP) || FyCheckHotKeyStatus(FY_S)) && dirCount % SMOOTHINESS == 0)
		{
			dirCount = 0 - dirState;
			dirState = 0;
		}
		if (FyCheckHotKeyStatus(FY_RIGHT) && dirCount % SMOOTHINESS == 0)
		{
			dirCount = SMOOTHINESS / 4 - dirState;
			dirState = SMOOTHINESS / 4;
		}
		if (FyCheckHotKeyStatus(FY_LEFT) && dirCount % SMOOTHINESS == 0)
		{
			dirCount = SMOOTHINESS * 3 / 4 - dirState;
			dirState = SMOOTHINESS * 3 / 4;
		}
		if (FyCheckHotKeyStatus(FY_DOWN) && dirCount % SMOOTHINESS == 0)
		{
			dirCount = SMOOTHINESS / 2 - dirState;
			dirState = SMOOTHINESS / 2;
		}
	}
	else
	{
		idle_count--;
	}

	// 3. the actor is idle when idle_count is equal to zero.   

	if (idle_count > 0)
	{

		if (FyCheckHotKeyStatus(FY_Q) && dirCount % SMOOTHINESS == 0)
		{
			curPoseID = NormalAttack1ID;

			//Tang: FX
			FX_FileName.clear();
			FX_FileName.push_back("AttacKBasic");
			FX_FileName.push_back("Lyubu_skill01");
			FX_FileName.push_back("LyubuDamege");
			GenFX(sID, gFXID, dummyID, actorPos, FX_FileName);
			//Tang
		}
		else if (FyCheckHotKeyStatus(FY_W) && dirCount % SMOOTHINESS == 0)
		{
			curPoseID = NormalAttack2ID;

			//Tang: FX
			FX_FileName.clear();
			FX_FileName.push_back("AttacKBasic");
			FX_FileName.push_back("Lyubu_skill02");
			FX_FileName.push_back("Lyubu_atk01");
			FX_FileName.push_back("MonGotHit_1");
			GenFX(sID, gFXID, dummyID, actorPos, FX_FileName);
			//Tang
		}
		else if (FyCheckHotKeyStatus(FY_E) && dirCount % SMOOTHINESS == 0)
		{
			curPoseID = HeavyAttack1ID;
			
			//Tang: FX
			FX_FileName.clear();
			FX_FileName.push_back("AttacKBasic");
			FX_FileName.push_back("Lyubu_skill03");
			FX_FileName.push_back("MonGotHit2G04");
			//FX_FileName.push_back("Lyubu_atk01 - X");
			GenFX(sID, gFXID, dummyID, actorPos, FX_FileName);
			//Tang
		}
		else
		{
			curPoseID = runID;

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

		actor.SetCurrentAction(NULL, 0, curPoseID, 5.0f);
	}
	else if (curPoseID == runID)
	{
		curPoseID = idleID;
		actor.SetCurrentAction(NULL, 0, curPoseID, 5.0f);
	}


}
Пример #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();
}
Пример #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
}
Пример #4
0
/*------------------
the main program
C.Wang 1010, 2014
-------------------*/
void FyMain(int argc, char **argv)
{
	// create a new world
	BOOL4 beOK = FyStartFlyWin32("NTU@2015 Homework #02 - Use Fly2", 0, 0, 1024, 768, FALSE);

	// setup the data searching paths
	FySetShaderPath("Data\\NTU6\\Shaders");
	FySetModelPath("Data\\NTU6\\Scenes");
	FySetTexturePath("Data\\NTU6\\Scenes\\Textures");
	FySetScenePath("Data\\NTU6\\Scenes");

	// create a viewport
	vID = FyCreateViewport(0, 0, 1024, 768);
	FnViewport vp;
	vp.ID(vID);

	// create a 3D scene
	sID = FyCreateScene(10);
	FnScene scene;
	scene.ID(sID);

	// load the scene
	scene.Load("gameScene02");
	scene.SetAmbientLights(1.0f, 1.0f, 1.0f, 0.6f, 0.6f, 0.6f);

	// load the terrain
	tID = scene.CreateObject(OBJECT);
	FnObject terrain;
	terrain.ID(tID);
	BOOL beOK1 = terrain.Load("terrain");
	terrain.Show(FALSE);

	// set terrain environment
	terrainRoomID = scene.CreateRoom(SIMPLE_ROOM, 10);
	FnRoom room;
	room.ID(terrainRoomID);
	room.AddObject(tID);

	// load the character
	FySetModelPath("Data\\NTU6\\Characters");
	FySetTexturePath("Data\\NTU6\\Characters");
	FySetCharacterPath("Data\\NTU6\\Characters");
	actorID = scene.LoadCharacter("Lyubu2");

	// put the character on terrain
	float pos[3], fDir[3], uDir[3];
	SetValues(pos, 3569.0f, -3208.0f, 1000.0f);
	SetValues(fDir, 1.0f, 1.0f, 0.0f);
	SetValues(uDir, 0.0f, 0.0f, 1.0f);

	ActorGen(scene, terrainRoomID, LyubuID, "Lyubu2", "Idle", pos, fDir, uDir);
	actorID = LyubuID.actorID;

	FnCharacter actor;
	actor.ID(actorID);

	// Get two character actions pre-defined at Lyubu2
	idleID = actor.GetBodyAction(NULL, "Idle");
	runID = actor.GetBodyAction(NULL, "Run");
	NormalAttack1ID = actor.GetBodyAction(NULL, "NormalAttack1");
	NormalAttack2ID = actor.GetBodyAction(NULL, "NormalAttack2");
	HeavyAttack1ID = actor.GetBodyAction(NULL, "HeavyAttack1");

	// translate the camera
	cID = scene.CreateObject(CAMERA);
	FnCamera camera;
	camera.ID(cID);
	camera.SetNearPlane(5.0f);
	camera.SetFarPlane(100000.0f);

	//hw3 : Donzo and Robber02 initialization
	float temp_pos[3];
	float temp_fDir[3];

	/*
	for (int i = 0; i < NUM_OF_BADGUYS; i++)
	{
		temp_pos[0] = pos[0] + 30 * (rand()%8);
		temp_pos[1] = pos[1] + 30 * (rand()%8);
		temp_pos[2] = pos[2] + 30 * (rand()%8);
		temp_fDir[0] = -1.0f; temp_fDir[1] = -1.0f; temp_fDir[2] = 1.0f;

		ActorGen(scene, terrainRoomID, badguyID[i], "Robber02", "CombatIdle", temp_pos, temp_fDir, uDir);
	}
	*/
	for (int i = 0; i < NUM_OF_BOSS; i++)
	{
		temp_pos[0] = 130.636;  //pos[0] + 30 * (rand()%8);
		temp_pos[1] = 2707.003; //pos[1] + 30 * (rand()%8);
		temp_pos[2] = 70.897;   //pos[2] + 30 * (rand()%8);
		SetValues(temp_fDir, -1.0f, -1.0f, 1.0f);

		ActorGen(scene, terrainRoomID, BossID[i], "Donzo2", "CombatIdle", temp_pos, temp_fDir, uDir);
	}
	

	// hw2 initial : set camera position
	actor.GetPosition(pos);

	pos[0] = pos[0] - SHORTDIST * fDir[0];
	pos[1] = pos[1] - SHORTDIST * fDir[1];
	pos[2] = pos[2] + HEIGHTOFFSET;

	SetValues(fDir, 1.0f, 1.0f, 0.0f);
	SetValues(uDir, 0.0f, 0.0f, 1.0f);

	camera.SetPosition(pos);
	camera.SetDirection(fDir, uDir); // the same as actor

	float mainLightPos[3] = { -4579.0, -714.0, 15530.0 };
	float mainLightFDir[3] = { 0.276, 0.0, -0.961 };
	float mainLightUDir[3] = { 0.961, 0.026, 0.276 };

	FnLight lgt;
	lgt.ID(scene.CreateObject(LIGHT));
	lgt.Translate(mainLightPos[0], mainLightPos[1], mainLightPos[2], REPLACE);
	lgt.SetDirection(mainLightFDir, mainLightUDir);
	lgt.SetLightType(PARALLEL_LIGHT);
	lgt.SetColor(1.0f, 1.0f, 1.0f);
	lgt.SetName("MainLight");
	lgt.SetIntensity(0.4f);

	// create a text object for displaying messages on screen
	textID = FyCreateText("Trebuchet MS", 18, FALSE, FALSE);

	// create a 2D scene for sprite rendering which will be rendered on the top of 3D
	sID2 = FyCreateScene(1);
	scene.ID(sID2);
	scene.SetSpriteWorldSize(800, 600);         // 2D scene size in pixels

	spID0 = scene.CreateObject(SPRITE);
	sp.ID(spID0);
	showPicture(sp, "startTalk_1.png", 780, 180 , 10, 10); //showPicture parameter : FnSprite ,imageName, size, position


	spID_hpFrame = scene.CreateObject(SPRITE);
	sp_hpFrame.ID(spID_hpFrame);
	showPicture(sp_hpFrame, "hp_line.png", 400, 100, 400, 480);

	spID_hpBlood = scene.CreateObject(SPRITE);
	sp_hpBlood.ID(spID_hpBlood);

	spID_hpMana = scene.CreateObject(SPRITE);
	sp_hpMana.ID(spID_hpMana);
	//showPicture(sp_hpBlood, "hp_blood.png", 250, 10, 500, 510);

	spID_headLyu = scene.CreateObject(SPRITE);
	sp_headLyu.ID(spID_headLyu);
	showPicture(sp_headLyu, "headLyu.png", 80, 80, 475, 520);

	spID_wordLyu = scene.CreateObject(SPRITE);
	sp_wordLyu.ID(spID_wordLyu);
	showPicture(sp_wordLyu, "wordLyu.png", 140, 40, 550, 540);

	spID_deadEnd = scene.CreateObject(SPRITE);
	sp_deadEnd.ID(spID_deadEnd);

	spID_trueEnd = scene.CreateObject(SPRITE);
	sp_trueEnd.ID(spID_trueEnd);
	


	// set Hotkeys
	FyDefineHotKey(FY_ESCAPE, QuitGame, FALSE);  // escape for quiting the game
	FyDefineHotKey(FY_UP, Movement, FALSE);      // Up for moving forward
	FyDefineHotKey(FY_RIGHT, Movement, FALSE);   // Right for turning right
	FyDefineHotKey(FY_LEFT, Movement, FALSE);    // Left for turning left
	FyDefineHotKey(FY_DOWN, Movement, FALSE);
	FyDefineHotKey(FY_Q, Movement, FALSE);
	FyDefineHotKey(FY_W, Movement, FALSE);
	FyDefineHotKey(FY_E, Movement, FALSE);

	FyDefineHotKey(FY_A, Movement, FALSE);       // Turn left with camera rotation
	FyDefineHotKey(FY_D, Movement, FALSE);		 // Turn right with camera rotation
	FyDefineHotKey(FY_S, Movement, FALSE);

	FyDefineHotKey(FY_T, Movement, FALSE);   //Talk button
	FyDefineHotKey(FY_M, Movement, FALSE);   //Mission button

	FyDefineHotKey(FY_I, Movement, FALSE);   //Mission button

	// define some mouse functions
	FyBindMouseFunction(LEFT_MOUSE, InitPivot, PivotCam, NULL, NULL);
	FyBindMouseFunction(MIDDLE_MOUSE, InitZoom, ZoomCam, NULL, NULL);
	FyBindMouseFunction(RIGHT_MOUSE, InitMove, MoveCam, NULL, NULL);

	// bind timers, frame rate = 30 fps
	FyBindTimer(0, 30.0f, GameAI, TRUE);
	FyBindTimer(1, 30.0f, RenderIt, TRUE);

	// invoke the system
	FyInvokeFly(TRUE);
}
Пример #5
0
/*------------------
movement control
-------------------*/
void Movement(BYTE code, BOOL4 value)
{
	//////////////////////////////////////////
	// Homework #01 part 2
	//////////////////////////////////////////
	// note : only hotkey input can trigger this function


	FnCharacter actor;
	FnCharacter badguy;

	float actorPos[3], actorfDir[3], actoruDir[3];
	float badguyPos[3], badguyfDir[3], badguyuDir[3];

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

	// 2. use a global idle_count variable to memorize the action status.
	//    (to prevent the "slide" actor bug)

	if (value)
	{
		idle_count++;

		if (FyCheckHotKeyStatus(FY_Q) && dirCount % SMOOTHINESS == 0 && LyubuID.mana_remain > 0)
		{
			actorPos[0] += actorfDir[0] * HATKOFFSET;
			actorPos[1] += actorfDir[1] * HATKOFFSET;

			LyubuID.mana_remain = LyubuID.mana_remain - HATKDAMAGE;

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

				if (FyDistance(badguyPos, actorPos) < HATKRANGE && badguyID[i].blood_remain > 0)
				{
					if (!ActAction(badguyID[i], "Damage1", HATKDAMAGE))
					{
						LyubuID.exp_cur += 50;
						if (LyubuID.exp_cur >= LyubuID.exp_total){
							LyubuID.level++;
							LyubuID.exp_cur -= LyubuID.exp_total;
						}
					}
				}
			}

			for (int i = 0; i < NUM_OF_BOSS; i++)
			{
				badguy.ID(BossID[i].actorID);
				badguy.GetPosition(badguyPos);

				if (FyDistance(badguyPos, actorPos) < HATKRANGE && BossID[i].blood_remain > 0)
				{
					ActAction(BossID[i], "Donzo", HATKDAMAGE);
				}
			}
		

		}

		if (FyCheckHotKeyStatus(FY_W) && dirCount % SMOOTHINESS == 0 && LyubuID.mana_remain > 0)
		{
			actorPos[0] += actorfDir[0] * NATK1OFFSET;
			actorPos[1] += actorfDir[1] * NATK1OFFSET;

			LyubuID.mana_remain = LyubuID.mana_remain - NATK1DAMAGE;

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

				if (FyDistance(badguyPos, actorPos) < NATK1RANGE && badguyID[i].blood_remain > 0)
				{
					if (!ActAction(badguyID[i], "Damage2", NATK1DAMAGE))
					{
						LyubuID.exp_cur += 50;
						if (LyubuID.exp_cur >= LyubuID.exp_total){
							LyubuID.level++;
							LyubuID.exp_cur -= LyubuID.exp_total;
						}
					}
				}
			}

			for (int i = 0; i < NUM_OF_BOSS; i++)
			{
				badguy.ID(BossID[i].actorID);
				badguy.GetPosition(badguyPos);

				if (FyDistance(badguyPos, actorPos) < NATK1RANGE && BossID[i].blood_remain > 0)
				{
					ActAction(BossID[i], "Donzo", NATK1DAMAGE);
				}
			}

		}

		if (FyCheckHotKeyStatus(FY_E) && dirCount % SMOOTHINESS == 0 && LyubuID.mana_remain > 0)
		{
			actorPos[0] += actorfDir[0] * NATK2OFFSET;
			actorPos[1] += actorfDir[1] * NATK2OFFSET;


			LyubuID.mana_remain = LyubuID.mana_remain - NATK2DAMAGE;

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

				if (FyDistance(badguyPos, actorPos) < NATK2RANGE && badguyID[i].blood_remain > 0)
				{
					if (!ActAction(badguyID[i], "Damage2", NATK2DAMAGE))
					{
						LyubuID.exp_cur += 50;
						if (LyubuID.exp_cur >= LyubuID.exp_total){
							LyubuID.level++;
							LyubuID.exp_cur -= LyubuID.exp_total;
						}
					}
				}
			}

			for (int i = 0; i < NUM_OF_BOSS; i++)
			{
				badguy.ID(badguyID[i].actorID);
				badguy.GetPosition(badguyPos);

				if (FyDistance(badguyPos, actorPos) < NATK2RANGE && BossID[i].blood_remain > 0)
				{
					ActAction(BossID[i], "Donzo", NATK2DAMAGE);
				}
			}


		}
		if ((FyCheckHotKeyStatus(FY_UP) || FyCheckHotKeyStatus(FY_S)) && dirCount % SMOOTHINESS == 0)
		{
			dirCount = 0 - dirState;
			dirState = 0;
		}
		if (FyCheckHotKeyStatus(FY_RIGHT) && dirCount % SMOOTHINESS == 0)
		{
			dirCount = SMOOTHINESS / 4 - dirState;
			dirState = SMOOTHINESS / 4;
		}
		if (FyCheckHotKeyStatus(FY_LEFT) && dirCount % SMOOTHINESS == 0)
		{
			dirCount = SMOOTHINESS * 3 / 4 - dirState;
			dirState = SMOOTHINESS * 3 / 4;
		}
		if (FyCheckHotKeyStatus(FY_DOWN) && dirCount % SMOOTHINESS == 0)
		{
			dirCount = SMOOTHINESS / 2 - dirState;
			dirState = SMOOTHINESS / 2;
		}
	}
	else
	{
		idle_count--;
	}

	// 3. the actor is idle when idle_count is equal to zero.   

	
	if (idle_count > 0)
	{

		if (FyCheckHotKeyStatus(FY_Q) && dirCount % SMOOTHINESS == 0 && LyubuID.mana_remain > 0)
		{
			curPoseID = NormalAttack1ID;
		}
		else if (FyCheckHotKeyStatus(FY_W) && dirCount % SMOOTHINESS == 0 && LyubuID.mana_remain > 0)
		{
			curPoseID = NormalAttack2ID;
		}
		else if (FyCheckHotKeyStatus(FY_E) && dirCount % SMOOTHINESS == 0 && LyubuID.mana_remain > 0)
		{
			curPoseID = HeavyAttack1ID;
		}
		else if (!FyCheckHotKeyStatus(FY_T) && !FyCheckHotKeyStatus(FY_M) && 
			     !FyCheckHotKeyStatus(FY_Q) && !FyCheckHotKeyStatus(FY_W) && 
				 !FyCheckHotKeyStatus(FY_E) )
		{
			curPoseID = runID;
		}
		else
		{
			curPoseID = idleID;
		}
		
		actor.SetCurrentAction(NULL, 0, curPoseID, 5.0f);
	}
	else if (curPoseID == runID)
	{
		curPoseID = idleID;
		actor.SetCurrentAction(NULL, 0, curPoseID, 5.0f);
	}








	if (FyCheckHotKeyStatus(FY_T) && picture_count <= 8)
	{
		char str_buf[16];
		itoa(picture_count, str_buf, 10);
		string pic_num(str_buf);

		string picture = "startTalk_" + pic_num + ".png";
		char* chr = strdup(picture.c_str());

		showPicture(sp, chr, 780, 180, 10, 10); //showPicture parameter : FnSprite ,imageName, size, position
	
		free(chr);

		picture_count++;
	}
	else if (FyCheckHotKeyStatus(FY_T) && picture_count == 9){
		showPicture(sp, "mission_transparent.png", 580, 580 , 110, 15);
		picture_count++;
	}
	else if (FyCheckHotKeyStatus(FY_T) && picture_count > 9) {
		showPicture(sp, "", 0, 0, 0, 0);
	}


	

	if (FyCheckHotKeyStatus(FY_M) && missionWindowStatus == FALSE  && picture_count > 9)
	{
		showPicture(sp, "mission_transparent.png", 580, 580, 110, 15);
		missionWindowStatus = TRUE;

	}
	else if(FyCheckHotKeyStatus(FY_M) && missionWindowStatus == TRUE  && picture_count > 9)
	{
		showPicture(sp, "", 0, 0, 0, 0);
		missionWindowStatus = FALSE;
	}
}
Пример #6
0
/*------------------
the main program
C.Wang 1010, 2014
-------------------*/
void FyMain(int argc, char **argv)
{
	// create a new world
	BOOL4 beOK = FyStartFlyWin32("NTU@2014 Homework #01 - Use Fly2", 0, 0, 1024, 768, FALSE);

	// setup the data searching paths
	FySetShaderPath("Data\\NTU6\\Shaders");
	FySetModelPath("Data\\NTU6\\Scenes");
	FySetTexturePath("Data\\NTU6\\Scenes\\Textures");
	FySetScenePath("Data\\NTU6\\Scenes");

	// create a viewport
	vID = FyCreateViewport(0, 0, 1024, 768);
	FnViewport vp;
	vp.ID(vID);

	// create a 3D scene
	sID = FyCreateScene(10);
	FnScene scene;
	scene.ID(sID);

	// load the scene
	scene.Load("gameScene02");
	scene.SetAmbientLights(1.0f, 1.0f, 1.0f, 0.6f, 0.6f, 0.6f);

	// load the terrain
	tID = scene.CreateObject(OBJECT);
	FnObject terrain;
	terrain.ID(tID);
	BOOL beOK1 = terrain.Load("terrain");
	terrain.Show(FALSE);

	// set terrain environment
	terrainRoomID = scene.CreateRoom(SIMPLE_ROOM, 10);
	FnRoom room;
	room.ID(terrainRoomID);
	room.AddObject(tID);

	// load the character
	FySetModelPath("Data\\NTU6\\Characters");
	FySetTexturePath("Data\\NTU6\\Characters");
	FySetCharacterPath("Data\\NTU6\\Characters");
	actorID = scene.LoadCharacter("Lyubu2");

	// put the character on terrain
	float pos[3], fDir[3], uDir[3];
	FnCharacter actor;
	actor.ID(actorID);
	pos[0] = 3569.0f; pos[1] = -3208.0f; pos[2] = 1000.0f;
	fDir[0] = 1.0f; fDir[1] = -1.0f; fDir[2] = 0.0f;
	uDir[0] = 0.0f; uDir[1] = 0.0f; uDir[2] = 1.0f;
	actor.SetDirection(fDir, uDir);

	actor.SetTerrainRoom(terrainRoomID, 10.0f);
	beOK = actor.PutOnTerrain(pos);

	// Get two character actions pre-defined at Lyubu2
	idleID = actor.GetBodyAction(NULL, "Idle");
	runID = actor.GetBodyAction(NULL, "Run");

	// set the character to idle action
	curPoseID = idleID;
	actor.SetCurrentAction(NULL, 0, curPoseID);
	actor.Play(START, 0.0f, FALSE, TRUE);
	actor.TurnRight(90.0f);

	// translate the camera
	cID = scene.CreateObject(CAMERA);
	FnCamera camera;
	camera.ID(cID);
	camera.SetNearPlane(5.0f);
	camera.SetFarPlane(100000.0f);

	// set camera initial position and orientation
	pos[0] = 4069.0f; pos[1] = -3208.0f; pos[2] = 93.046f;
	fDir[0] = -500.0f; fDir[1] = -0.0f; fDir[2] = -0.0f;
	uDir[0] = -0.116f; uDir[1] = -0.031f; uDir[2] = 0.993f;
	camera.SetPosition(pos);
	camera.SetDirection(fDir, uDir);

	float mainLightPos[3] = { -4579.0, -714.0, 15530.0 };
	float mainLightFDir[3] = { 0.276, 0.0, -0.961 };
	float mainLightUDir[3] = { 0.961, 0.026, 0.276 };

	FnLight lgt;
	lgt.ID(scene.CreateObject(LIGHT));
	lgt.Translate(mainLightPos[0], mainLightPos[1], mainLightPos[2], REPLACE);
	lgt.SetDirection(mainLightFDir, mainLightUDir);
	lgt.SetLightType(PARALLEL_LIGHT);
	lgt.SetColor(1.0f, 1.0f, 1.0f);
	lgt.SetName("MainLight");
	lgt.SetIntensity(0.4f);

	// create a text object for displaying messages on screen
	textID = FyCreateText("Trebuchet MS", 18, FALSE, FALSE);

	// set Hotkeys
	FyDefineHotKey(FY_ESCAPE, QuitGame, FALSE);  // escape for quiting the game
	FyDefineHotKey(FY_UP, Movement, FALSE);      // Up for moving forward
	FyDefineHotKey(FY_RIGHT, Movement, FALSE);   // Right for turning right
	FyDefineHotKey(FY_LEFT, Movement, FALSE);    // Left for turning left

	// define some mouse functions
	if (!IsCameraFollow)
	{
		FyBindMouseFunction(LEFT_MOUSE, InitPivot, PivotCam, NULL, NULL);
		FyBindMouseFunction(MIDDLE_MOUSE, InitZoom, ZoomCam, NULL, NULL);
		FyBindMouseFunction(RIGHT_MOUSE, InitMove, MoveCam, NULL, NULL);
	}
	else
	{
		FyBindMouseFunction(LEFT_MOUSE, InitZoom2, ZoomCam2, NULL, NULL);
		FyBindMouseFunction(RIGHT_MOUSE, NULL, RotateCam, NULL, NULL);
	}

	// bind timers, frame rate = 30 fps
	FyBindTimer(0, 30.0f, GameAI, TRUE);
	FyBindTimer(1, 30.0f, RenderIt, TRUE);

	// invoke the system
	FyInvokeFly(TRUE);
}