Exemple #1
0
int WINAPI WinMain(HINSTANCE instanceH, HINSTANCE prevInstanceH, LPSTR command_line, int show)
{
	// Variable declaration
	unsigned char colors[16];				// 2x2 image
	float obj1X = 0.0f, obj1Y = 0.0f;		// Position variables for object 1
	float obj2X = 0.0f, obj2Y = 0.0f;		// Position variables for object 2
	float obj1texX = 0, obj1texY = 0;		// Texture variables for object 1's texture
	int counter = 0;						// Counter to swap textures
	AEGfxVertexList*	pMesh1;				// Pointer to Mesh (Model)
	AEGfxVertexList*	pMesh2;				// Pointer to Mesh (Model)
	AEGfxVertexList*	pMeshLine;			// Pointer to Mesh (Model)
	AEGfxTexture *pTex1;					// Pointer to Texture (Image)
	AEGfxTexture *pTex2;					// Pointer to Texture (Image)
	char strBuffer[256];					// Character buffer used to print text
	float camX, camY;						// Used to temporary store camera position
	float camZoom;							// USed to temporary store the camera zoom value
	s32 sx, sy;
	float x, y;
	float alpha = 1.0f;




	// Initialize the system 
	AESysInitInfo sysInitInfo;
	sysInitInfo.mCreateWindow			= 1;
	sysInitInfo.mWindowHandle			= NULL;
	sysInitInfo.mAppInstance			= instanceH;
	sysInitInfo.mShow					= show;
	sysInitInfo.mWinWidth				= 1280; 
	sysInitInfo.mWinHeight				= 800;
	sysInitInfo.mCreateConsole			= 1;
	sysInitInfo.mMaxFrameRate			= 60;
	sysInitInfo.mpWinCallBack			= NULL;
	sysInitInfo.mClassStyle				= CS_HREDRAW | CS_VREDRAW;											
	sysInitInfo.mWindowStyle			= WS_OVERLAPPEDWINDOW;
	sysInitInfo.mHandleWindowMessages	= 1;



	if(0 == AESysInit (&sysInitInfo))
		printf("System Init Failed!\n");


	// Changing the window title
	AESysSetWindowTitle("My New Title!");

	// reset the system modules
	AESysReset();

	////////////////////////////////
	// Creating the objects (Shapes)


	// Informing the library that we're about to start adding triangles
	AEGfxMeshStart();

	// 1 triangle at a time
	// X, Y, Color, texU, texV
	AEGfxTriAdd(
		-25.5f, -25.5f, 0xFFFF0000, 0.0f, 0.0f, 
		25.5f,  0.0f, 0xFFFF0000, 0.0f, 0.0f,
		-25.5f,  25.5f, 0xFFFF0000, 0.0f, 0.0f);

	// Saving the mesh (list of triangles) in pMesh1

	pMesh1 = AEGfxMeshEnd();
	AE_ASSERT_MESG(pMesh1, "Failed to create mesh 1!!");

	// Informing the library that we're about to start adding triangles
	AEGfxMeshStart();

	// This shape has 2 triangles

	AEGfxTriAdd(
		-30.0f, -30.0f, 0x00FF00FF, 0.0f, 1.0f, 
		30.0f,  -30.0f, 0x00FFFF00, 1.0f, 1.0f,
		-30.0f,  30.0f, 0x00F00FFF, 0.0f, 0.0f);

	AEGfxTriAdd(
		30.0f, -30.0f, 0x00FFFFFF, 1.0f, 1.0f, 
		30.0f,  30.0f, 0x00FFFFFF, 1.0f, 0.0f,
		-30.0f,  30.0f, 0x00FFFFFF, 0.0f, 0.0f);

	pMesh2 = AEGfxMeshEnd();
	AE_ASSERT_MESG(pMesh2, "Failed to create mesh 2!!");

		
	// Informing the library that we're about to start adding triangles
	AEGfxMeshStart();

	// This shape has 5 vertices

	AEGfxVertexAdd(0.0f, 0.0f, 0xFFFFFFFF, 0.0f, 0.0f);
	AEGfxVertexAdd(100.0f, 0.0f, 0xFFFFFFFF, 0.0f, 0.0f);
	AEGfxVertexAdd(200.0f, 150.0f, 0xFFFFFFFF, 0.0f, 0.0f);
	AEGfxVertexAdd(300.0f, -100.0f, 0xFFFFFFFF, 0.0f, 0.0f);
	AEGfxVertexAdd(100.0f, -250.0f, 0xFFFFFFFF, 0.0f, 0.0f);


	pMeshLine = AEGfxMeshEnd();
	AE_ASSERT_MESG(pMeshLine, "Failed to create mesh 2!!");


	// Creating the objects (Shapes)
	////////////////////////////////

	////////////////////////////
	// Loading textures (images)

	// Texture 1: From file
	pTex1 = AEGfxTextureLoad("PlanetTexture.png");
	AE_ASSERT_MESG(pTex1, "Failed to create texture1!!");




	// Texture 2: From memory
	// RGBA format
	colors[0] = 255;	colors[1] = 0;		colors[2] = 0;		colors[3] = 255;
	colors[4] = 0;		colors[5] = 255;	colors[6] = 0;		colors[7] = 255;
	colors[8] = 0;		colors[9] = 0;		colors[10] = 255;	colors[11] = 255;	
	colors[12] = 255;	colors[13] = 255;	colors[14] = 255;	colors[15] = 255;				

	pTex2 = AEGfxTextureLoadFromMemory(colors, 2, 2);
	AE_ASSERT_MESG(pTex2, "Failed to create texture2!!");

	// Loading a textures (images)
	//////////////////////////////

	
	AEGfxSetBackgroundColor(0.0f, 0.0f, 0.0f);
	AEGfxSetBlendMode(AE_GFX_BM_BLEND);


	// Game Loop
	while(gGameRunning)
	{
		// Informing the system about the loop's start
		AESysFrameStart();

		// Handling Input
		AEInputUpdate();

		///////////////////
		// Game loop update

		// Object Control
		if (AEInputCheckCurr(VK_UP))
			obj1Y += 3.0f;
		else
		if (AEInputCheckCurr(VK_DOWN))
			obj1Y -= 3.0f;

		if (AEInputCheckCurr(VK_LEFT))
			obj1X -= 3.0f;
		else
		if (AEInputCheckCurr(VK_RIGHT))
			obj1X += 3.0f;


		
		//printf("X = %f, Y = %f\n", obj1X, obj1Y);


		// Texture offset
		if (AEInputCheckCurr('L'))
			obj1texX += 0.01f;
		else
		if (AEInputCheckCurr('J'))
			obj1texX -= 0.01f;

		if (AEInputCheckCurr('I'))
			obj1texY += 0.01f;
		else
		if (AEInputCheckCurr('K'))
			obj1texY -= 0.01f;


		// Move the camera
		AEGfxGetCamPosition(&camX, &camY);
		if (AEInputCheckCurr('W'))
			AEGfxSetCamPosition(camX, camY + 2);
		else
		if (AEInputCheckCurr('S'))
			AEGfxSetCamPosition(camX, camY - 2);

		AEGfxGetCamPosition(&camX, &camY);
		if (AEInputCheckCurr('A'))
			AEGfxSetCamPosition(camX - 2, camY);
		else
		if (AEInputCheckCurr('D'))
			AEGfxSetCamPosition(camX + 2, camY);



		// Alpha value
		if (AEInputCheckCurr('Z'))
			alpha -= 0.01f;
		else
		if (AEInputCheckCurr('X'))
			alpha += 0.01f;

		alpha = AEClamp(alpha, 0.0f, 1.0f);


		// Blending mode
		if (AEInputCheckCurr('1'))
			AEGfxSetBlendMode(AE_GFX_BM_NONE);
		else
		if (AEInputCheckCurr('2'))
			AEGfxSetBlendMode(AE_GFX_BM_BLEND);
		else
		if (AEInputCheckCurr('3'))
			AEGfxSetBlendMode(AE_GFX_BM_ADD);


		// Texture mode
		if (AEInputCheckCurr('9'))
			AEGfxSetTextureMode(AE_GFX_TM_PRECISE);
		else
		if (AEInputCheckCurr('0'))
			AEGfxSetTextureMode(AE_GFX_TM_AVERAGE);
		

		// Game loop update
		///////////////////


		//////////////////
		// Game loop draw

		//printf("MinX: %f | MaxX: %f | MinY: %f | MaxY: %f\n", AEGfxGetWinMinX(), AEGfxGetWinMaxX(), AEGfxGetWinMinY(), AEGfxGetWinMaxY());
		printf("FrameTime %f\n", AEFrameRateControllerGetFrameTime());

		
		AEGfxSetRenderMode(AE_GFX_RM_COLOR);
		AEGfxSetPosition(0, 0);
		AEGfxLine(20, 20, 0, 1, 1, 1, 1, 200, 200, 0, 1, 1, 1, 1);
		

		AEGfxSetRenderMode(AE_GFX_RM_COLOR);
		AEGfxSetPosition(0.0f, 0.0f);
		AEGfxMeshDraw(pMeshLine, AE_GFX_MDM_LINES_STRIP);

		
		// Drawing object 1
		AEGfxSetRenderMode(AE_GFX_RM_COLOR);
		//AEGfxSetWorldOriginMode(AE_WOM_TOP_LEFT);
		// Set poisition for object 1
		//AEGfxSetPosition(obj1X, obj1Y);
		AEGfxSetFullTransformWithZOrder(obj1X, obj1Y, 0.0f, 0.0f, 1.0f, 1.0f);
		// No texture for object 1
		AEGfxTextureSet(NULL, 0, 0);
		// Drawing the mesh (list of triangles)
		AEGfxSetTransparency(alpha);
		//AEGfxSetViewportPositionAndDimensions(100, 100, 400, 300);
		AEGfxMeshDraw(pMesh1, AE_GFX_MDM_TRIANGLES);


		AEInputGetCursorPosition(&sx, &sy);


		AEGfxConvertScreenCoordinatesToWorld(sx, sy, &x, &y);
		obj2X = x;
		obj2Y = y;
	
		// Drawing object 2 - NO TINT
		// Set poisition for object 2
		AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
		//AEGfxSetPosition(100.0f, -60.0f);
		AEGfxSetFullTransformWithZOrder(100.0f, -160.0f, -10.0f, 0.0f, 1.0f, 1.0f);
		AEGfxSetTintColor(1.0f, 1.0f, 1.0f, 1.0f);
		// Set texture for object 2
		++counter;
		if(counter < 120)
			AEGfxTextureSet(pTex1, obj1texX, obj1texY);		// Same object, different texture
		else
		if(counter < 240)
			AEGfxTextureSet(pTex2, obj1texX, obj1texY);		// Same object, different texture
		else
		{
			AEGfxTextureSet(pTex1, obj1texX, obj1texY);		// Same object, different texture
			counter = 0;
		}

		AEGfxSetTransparency(alpha);

		// Drawing the mesh (list of triangles)
		AEGfxMeshDraw(pMesh2, AE_GFX_MDM_TRIANGLES);

		// Drawing object 2 - BLUE TINT
		// Set poisition for object 2
		AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
		AEGfxSetPosition(100.0f, 60.0f);
		AEGfxSetTintColor(0.0f, 0.0f, 1.0f, 1.0f);
		AEGfxSetFullTransformWithZOrder(obj2X, obj2Y, 10.0f, 0.0f, 1.0f, 1.0f);
		// Set texture for object 2
		++counter;
		if(counter < 120)
			AEGfxTextureSet(pTex1, obj1texX, obj1texY);		// Same object, different texture
		else
		if(counter < 240)
			AEGfxTextureSet(pTex2, obj1texX, obj1texY);		// Same object, different texture
		else
		{
			AEGfxTextureSet(pTex1, obj1texX, obj1texY);		// Same object, different texture
			counter = 0;
		}

		AEGfxSetTransparency(alpha);

		// Drawing the mesh (list of triangles)
		AEGfxMeshDraw(pMesh2, AE_GFX_MDM_TRIANGLES);
		//


		// Game loop draw
		//////////////////

		// Informing the system about the loop's end
		AESysFrameEnd();

		// check if forcing the application to quit
		if (AEInputCheckTriggered(VK_ESCAPE) || 0 == AESysDoesWindowExist())
			gGameRunning = 0;
	}

	// Freeing the objects and textures
	AEGfxMeshFree(pMesh1);
	AEGfxMeshFree(pMesh2);

	AEGfxTextureUnload(pTex1);
	AEGfxTextureUnload(pTex2);



	// free the system
	AESysExit();
}
Exemple #2
0
void Update_Sarah(void)
{
	float frametime;

	frametime = (float)AEFrameRateControllerGetFrameTime();
}
Exemple #3
0
void UpdatePhysics(PHYSICS * pPhysics, COLLIDER *pCollider)
{
  UNIT * pOwner = pPhysics->pArchetype->pUnit;
  TRANSFORM * pMyTransform = pOwner->pTransform;
  VECTOR * pVelocity = &(pPhysics->Velocity);
  VECTOR * pAcceleration = &(pPhysics->Acceleration);

  float gravityRate = pPhysics->Gravity;
  float gravityMax = 50;
  float friction = pPhysics->Friction;
  int collidingY = 0;
  float maxSpeed = pPhysics->MaxSpeed;
  double frameTime = AEFrameRateControllerGetFrameTime();

  /**************** Gravity *****************/

  //if (pVelocity->y < gravityMax)
  //{
  pAcceleration->y = -gravityRate;
  //}

  ////////////////////////////////////////////


  /******* Apply Friction to Velocity *******/

  pVelocity->x -= (friction * pVelocity->x);
  //pVelocity->y -= (friction * pVelocity->y);

  ////////////////////////////////////////////


  /******* Account for Collision ************/

  if (pCollider && pCollider->Enabled)
  {
    if (pCollider->Grounded)
    {
      if (pAcceleration->y < 0) pAcceleration->y = 0;
      if (pCollider->Grounded < 0.02f)
      {

        if (pVelocity->y < 0) pVelocity->y = 0;
      }
      else
      {
        if (pVelocity->y < 0) pVelocity->y = (pow((pCollider->Grounded - 0.05) * 20, 2)) / 2;
      }
    }

    if (pCollider->LeftBlocked)
    {
      if (pAcceleration->x < 0) pAcceleration->x = 0;
      if (pCollider->LeftBlocked < 0.1f)
      {

        if (pVelocity->x < 0) pVelocity->x = 0;
      }
      else
      {
        if (pVelocity->x < 0) pVelocity->x = (pow(pCollider->LeftBlocked * 15, 2)) / 2;
      }
    }

    if (pCollider->TopBlocked)
    {
      if (pAcceleration->y > 0) pAcceleration->y = 0;
      if (pCollider->TopBlocked < 0.1f)
      {

        if (pVelocity->y > 0) pVelocity->y = 0;
      }
      else
      {
        if (pVelocity->y > 0) pVelocity->y = -(pow(pCollider->TopBlocked * 15, 2)) / 2;
      }
    }

    if (pCollider->RightBlocked)
    {
      if (pAcceleration->x > 0) pAcceleration->x = 0;
      if (pCollider->RightBlocked < 0.1f)
      {

        if (pVelocity->x > 0) pVelocity->x = 0;
      }
      else
      {
        if (pVelocity->x > 0) pVelocity->x = -(pow(pCollider->RightBlocked * 15, 2)) / 2;
      }
    }
  }

  ////////////////////////////////////////////


  /************ Normalize Velocity **********/

  ////////////////////////////////////////////


  /******* Apply Velocity to Player *********/

  pVelocity->x += pAcceleration->x * frameTime;
  pVelocity->y += pAcceleration->y * frameTime;
  if (pVelocity->y > maxSpeed)
  {
    pVelocity->y = maxSpeed;
  }
  else if (pVelocity->y < -maxSpeed)
  {
    pVelocity->y = -maxSpeed;
  }
  if (pVelocity->x < 0.1 && pVelocity->x > -0.1)
  {
    pVelocity->x = 0;
  }

  pMyTransform->Position.x += pVelocity->x * frameTime;
  pMyTransform->Position.y += pVelocity->y * frameTime;

  ////////////////////////////////////////////
}
Exemple #4
0
void Update2(void)
{
	//unsigned long i;
	float winMaxX, winMaxY, winMinX, winMinY;
	double frameTime;



	// ==========================================================================================
	// 获取窗口四条边的坐标,当窗口发生移动或缩放,以下值会发生变化
	// ==========================================================================================
	winMaxX = AEGfxGetWinMaxX();
	winMaxY = AEGfxGetWinMaxY();
	winMinX = AEGfxGetWinMinX();
	winMinY = AEGfxGetWinMinY();

	// ======================
	// 帧时间:相当于zero中的dt
	// ======================
	frameTime = AEFrameRateControllerGetFrameTime();

	// =========================
	// 游戏逻辑响应输入
	// =========================
	// 状态切换
	if (KeyPressed[KeyR])
		Next = GS_Restart;
	if (KeyPressed[KeyESC])
		Next = GS_Quit;
	if (KeyPressed[Key1])
		Next = GS_L1;
	if (KeyPressed[KeyMenu])
		Next = GS_MENU;


	// 主角的移动
	if (KeyPressed[KeyUp])
	{
		obj1Y += 20.0f;

	}
	else
		if (KeyPressed[KeyDown])
		{
			obj1Y -= 20.0f;
		}
	if (KeyPressed[KeyLeft])
	{
		obj1X -= 20.0f;
	}
	else
		if (KeyPressed[KeyRight])
		{
			obj1X += 20.0f;
		}

	//鼠标左键控制石头生成
	if ((KeyPressed[KeyLeftBottom]) && (Burglar->flag& FLAG_ACTIVE))//&& (StoneCount>0))
	{

		pStone = gameObjCreate(TYPE_STONE, 3.0f, 0, 0, 0.0f);;
		AE_ASSERT(pStone);
		// 实例化
		// 初始化: 坐标位置 朝向和尺寸大小
		//在主角位置产生,射向鼠标位置
		pStone->posCurr.x = Burglar->posCurr.x;
		pStone->posCurr.y = Burglar->posCurr.y;

		//石头减一
		StoneCount -= 1;
	}


	//随机产生水果,每隔3秒产生一个,一个界面最多产生10个水果
	TimeTot++;
	if (TimeTot == 180 && Fruit_NUM<10)
	{
		Fruit_NUM++;
		int Xx, Yy;
		Xx = rand();
		Yy = rand();

		//控制水果在界面内产生
		while (Xx > 800.0f) //控制水果在界面宽度内产生
		{
			Xx = (int)rand();
		}
		while (Yy > 600.0f)//控制水果在界面高度度内产生
		{
			Yy = (int)rand();
		}
		Xx = Xx - 400;
		Yy = Yy - 300;

		TimeTot = 0;
		GameObj* pFruit = gameObjCreate(TYPE_WATERMELON, 3.0f, 0, 0, 0.0f);;
		AE_ASSERT(pFruit);
		// 实例化

		// 初始化: 坐标位置 朝向和尺寸大小
		pFruit->posCurr.x = Xx;
		pFruit->posCurr.y = Yy;

		pFruit->scale = 5.0f;
	}
	else if (TimeTot == 200) TimeTot = 0;



	//遍历所有对象以决定操作
	for (int i = 1; i < GAME_OBJ_NUM_MAX; i++)
	{

		GameObj* pObj = sGameObjList + i;

		//石头的发射
		if (pObj->flag && pObj->pObject->type == TYPE_STONE)
		{
			//石头朝着鼠标位置运动
			pStone->velCurr.x = (posX - Burglar->posCurr.x) / 10.0f;
			pStone->velCurr.y = (posY - Burglar->posCurr.y) / 10.0f;

			pObj->posCurr.x += pObj->velCurr.x;
			pObj->posCurr.y += pObj->velCurr.y;

			//碰撞到狗或者boss
			for (int j = 1; j < GAME_OBJ_NUM_MAX; j++)
			{

				GameObj* pObj0 = sGameObjList + j;
				if (pObj0->flag && (pObj0->pObject->type == TYPE_DOG || pObj0->pObject->type == TYPE_BOSS))
				{
					if (StaticPointToStaticCircle(&pObj->posCurr, &pObj0->posCurr, 10.0))
					{
						gameObjDestroy(pObj0);
						gameObjDestroy(pObj);
					}
				}
			}
		}

		//捡石头
		if (pObj->flag&&pObj->pObject->type == TYPE_STONE_STATIC)
		{
			if (StaticRectToStaticRect(&Burglar->posCurr, 33, 30, &pObj->posCurr, 15, 15))
			{
				gameObjDestroy(pObj);
				StoneCount += 1;
			}
		}


		//离陷阱距离近时
		if (pObj->flag && pObj->pObject->type == TYPE_TRAP_IN)
		{
			if (Burglar->flag&FLAG_ACTIVE)
			{
				if (((pObj->posCurr.x - Burglar->posCurr.x)*(pObj->posCurr.x - Burglar->posCurr.x) + (pObj->posCurr.y - Burglar->posCurr.y) *(pObj->posCurr.y - Burglar->posCurr.y)) < 4000)
				{
					pTrap = gameObjCreate(TYPE_TRAP_OUT, 10.0f, 0, 0, 0.0f);
					pTrap->posCurr.x = pObj->posCurr.x;
					pTrap->posCurr.y = pObj->posCurr.y;
					pTrap->scale = 10.0;

					if (StaticRectToStaticRect(&Burglar->posCurr, 30, 30, &pObj->posCurr, 40, 40) && pObj->flag)
					{
						Burglar->scale -= 0.5;
					}
					if (Burglar->scale < 1.0f)
					{
						gameObjDestroy(Burglar);//碰撞了,减少scale,并销毁对象
					}
				}
			}

		}
		//远离陷阱时
		if (pObj->flag && pObj->pObject->type == TYPE_TRAP_OUT)
		{
			if (((pObj->posCurr.x - Burglar->posCurr.x)*(pObj->posCurr.x - Burglar->posCurr.x) + (pObj->posCurr.y - Burglar->posCurr.y) *(pObj->posCurr.y - Burglar->posCurr.y))>40000)
				gameObjDestroy(pObj);
		}

		//Boss 的运动跟碰撞
		if (pObj->flag && pObj->pObject->type == TYPE_BOSS)
		{

			//发生碰撞,主角死亡
			if (StaticRectToStaticRect(&Burglar->posCurr, 15.0f, 15.0f, &pObj->posCurr, 15.0f, 15.0f))
			{
				gameObjDestroy(Burglar);
			}
		}

		//狗的边界控制
		if (pObj->flag&&pObj->pObject->type == TYPE_DOG)
		{

			if (pObj->posCurr.x >= winMaxX || pObj->posCurr.x <= winMinX)
			{
				pObj->posCurr.x = -pObj->posCurr.x;

			}

			if (pObj->posCurr.y <= winMinY || pObj->posCurr.y >= winMaxY)
			{
				pObj->posCurr.y = -pObj->posCurr.y;
			}



			//是否与狗发生碰撞
			if (StaticRectToStaticRect(&Burglar->posCurr, 30, 30, &pObj->posCurr, 30, 30) && pObj->flag)
			{
				Burglar->scale -= 0.5;
			}
			if (Burglar->scale < 1.0f)
			{
				gameObjDestroy(Burglar);//碰撞了,减少scale,并销毁对象
			}
		}

		//捡西瓜
		if (pObj->flag&&pObj->pObject->type == TYPE_WATERMELON)
		{
			if (StaticPointToStaticCircle(&Burglar->posCurr, &pObj->posCurr, 10.0))
			{
				gameObjDestroy(pObj);
				Fruit_NUM -= 1;
				sScore += 10;
			}
		}


		if (pObj->flag && pObj->pObject->type == TYPE_BURGLARBLOOD)
		{
			//更新血量位置
			pObj->posCurr.x = Burglar->posCurr.x;
			pObj->posCurr.y = Burglar->posCurr.y + 35.0f;

			if (!Burglar->flag&FLAG_ACTIVE)
			{
				gameObjDestroy(pObj);   //销毁主角的同时,销毁主角的血量 
			}
		}

	}//for

	//狗运动
	for (int a = 0; a < 5; a++)
	{
		srand(time());
		int PosDogX = (pDog[a]->posCurr.x + 400) / 40;
		int PosDogY = (pDog[a]->posCurr.y + 300) / 15;
		if (mapinfo[PosDogX - 1][PosDogY])
		{
			pDog[a]->posCurr.x += 1;
		}
		else if (mapinfo[PosDogX + 1][PosDogY])
		{
			pDog[a]->posCurr.x -= 1;
		}

		else if (mapinfo[PosDogX][PosDogY + 1])
		{
			pDog[a]->posCurr.y -= 1;
		}
		else  if (mapinfo[PosDogX][PosDogY - 1])
		{
			pDog[a]->posCurr.y += 1;
		}
		//else
		//{
		//	pDog[a]->posCurr.x += 2;
		//}
	}
	
	//狗的运动
	TimeTot1++;
	int x;
	if (TimeTot1 < 300)
	{
		
		pDog[0]->posCurr.x += 1;
		pDog[1]->posCurr.x -= 1;
		pDog[2]->posCurr.y += 1;
		pDog[3]->posCurr.y -= 1;
		pDog[4]->posCurr.x += 1;
	}
	if (TimeTot1 >= 300 && TimeTot1 < 600)
	{
		pDog[0]->posCurr.x -= 1;
		pDog[1]->posCurr.x += 1;
		pDog[2]->posCurr.y -= 1;
		pDog[3]->posCurr.y += 1;
		pDog[4]->posCurr.y -= 1;
	}
	if (TimeTot1 >= 600 && TimeTot1 < 900)
	{
		pDog[0]->posCurr.y += 1;
		pDog[1]->posCurr.y -= 1;
		pDog[2]->posCurr.x += 1;
		pDog[3]->posCurr.x -= 1;
		pDog[4]->posCurr.y += 1;
	}
	if (TimeTot1 >= 900 && TimeTot1 < 1200)
	{
		pDog[0]->posCurr.y -= 1;
		pDog[1]->posCurr.y += 1;
		pDog[2]->posCurr.x -= 1;
		pDog[3]->posCurr.x += 1;
		pDog[4]->posCurr.y -= 1;
	}
	if (TimeTot1 == 1200)
	{
		TimeTot1 = 0;
	}
	
	
		//按空格键
	if (KeyPressed[KeySpace])
	{

	}
	// 输入重置
	Input_Initialize();

	// 签到
	fprintf(fp, "Level2:Update\n");
}
Exemple #5
0
void Draw2(void)
{
	unsigned long i;

	// 画主角,单独画
	if (Burglar->flag& FLAG_ACTIVE)
	{
		//主角移动帧率时间
		float frameTime = AEFrameRateControllerGetFrameTime()*10.0f;

		AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
		AEGfxSetPosition(obj1X, obj1Y);
		AEGfxTextureSet(pTex1, obj1X, obj1Y);//设置猴子位置
		//更新猴子位置,同时更新相机位置
		Burglar->posCurr.x = obj1X;
		Burglar->posCurr.y = obj1Y;
		//相机的移动
		//AEGfxSetCamPosition(obj1X, obj1Y);

		//实现主角的动图效果
		ElapsedTime += frameTime;               // 游戏帧一帧的时间
		if (ElapsedTime < 1.f / AnimationFPS)	// 如果时间还不到动画帧一帧需要的时间
			return;								// 则返回
		else
			ElapsedTime = 0.0f;                 // 否则重置elapsedTime

		AEGfxTextureSet(pTex1, AnimationCounter*0.125f, 0.0f);
		AnimationCounter += 1;
		if (AnimationCounter > 7)
			AnimationCounter = 0;


		AEGfxSetTransparency(1.0f);
		AEGfxSetBlendColor(0.0f, 0.0f, 0.0, 0.0f);
		AEGfxMeshDraw(Burglar->pObject->pMesh, AE_GFX_MDM_TRIANGLES);
	}

	// 逐个绘制对象列表中的所有对象
	for (i = 1; i < GAME_OBJ_NUM_MAX; i++)
	{
		GameObj* pInst = sGameObjList + i;

		// 跳过非活动对象
		if ((pInst->flag & FLAG_ACTIVE) == 0)
			continue;

		//绘制扔出去的石头对象
		if ((pInst->pObject->type == TYPE_STONE) && (Burglar->flag & FLAG_ACTIVE))
		{
			//if (KeyPressed[KeySpace])
			//	{
			// Drawing object stone
			// Set position for object stone
			AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);   // 必须最先设置绘制模式为纹理
			//AEGfxSetPosition(Burglar->posCurr.x+100.0f, Burglar->posCurr.y+10.0f);
			// Set texture for object stone
			AEGfxSetPosition(pInst->posCurr.x, pInst->posCurr.y);
			AEGfxTextureSet(pTexStone, 0.0f, 0.0f); // 参数1:纹理,偏移量(x,y)
			AEGfxSetTransparency(1.0f);
			AEGfxSetBlendColor(0.0f, 0.0f, 0.0, 0.0f);
			// Drawing the mesh (list of triangles)
			AEGfxMeshDraw(pInst->pObject->pMesh, AE_GFX_MDM_TRIANGLES);
			//}
		}

		//绘制被捡起来的石头
		if (pInst->pObject->type == TYPE_STONE_STATIC)
		{
			//if (KeyPressed[KeySpace])
			//	{
			// Drawing object stone
			// Set position for object stone
			AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);   // 必须最先设置绘制模式为纹理
			//AEGfxSetPosition(Burglar->posCurr.x+100.0f, Burglar->posCurr.y+10.0f);
			// Set texture for object stone
			AEGfxSetPosition(pInst->posCurr.x, pInst->posCurr.y);
			AEGfxTextureSet(pTexStone, 0.0f, 0.0f); // 参数1:纹理,偏移量(x,y)
			AEGfxSetTransparency(1.0f);
			AEGfxSetBlendColor(0.0f, 0.0f, 0.0, 0.0f);
			// Drawing the mesh (list of triangles)
			AEGfxMeshDraw(pInst->pObject->pMesh, AE_GFX_MDM_TRIANGLES);
			//}
		}

		//绘制隐藏的陷阱
		if (pInst->pObject->type == TYPE_TRAP_IN)
		{

			//if (KeyPressed[KeySpace])
			//	{
			// Drawing object stone
			// Set position for object stone
			AEGfxSetRenderMode(AE_GFX_RM_COLOR);   // 必须最先设置绘制模式为纹理
			//AEGfxSetPosition(Burglar->posCurr.x+100.0f, Burglar->posCurr.y+10.0f);
			// Set texture for object stone
			AEGfxSetPosition(pInst->posCurr.x, pInst->posCurr.y);
			//AEGfxTextureSet(pTexStone, 0.0f, 0.0f); // 参数1:纹理,偏移量(x,y)
			AEGfxSetTransparency(1.0f);
			AEGfxSetBlendColor(0.0f, 0.0f, 0.0, 0.0f);
			// Drawing the mesh (list of triangles)
			AEGfxMeshDraw(pInst->pObject->pMesh, AE_GFX_MDM_TRIANGLES);
			//}
		}

		//绘制陷阱
		if (pInst->pObject->type == TYPE_TRAP_OUT)
		{
			//if (KeyPressed[KeySpace])
			//	{
			// Drawing object stone
			// Set position for object stone
			AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);   // 必须最先设置绘制模式为纹理
			//AEGfxSetPosition(Burglar->posCurr.x+100.0f, Burglar->posCurr.y+10.0f);
			// Set texture for object stone
			AEGfxSetPosition(pInst->posCurr.x, pInst->posCurr.y);
			AEGfxTextureSet(pTexTrap, 0.0f, 0.0f); // 参数1:纹理,偏移量(x,y)
			AEGfxSetTransparency(1.0f);
			AEGfxSetBlendColor(0.0f, 0.0f, 0.0, 0.0f);
			// Drawing the mesh (list of triangles)
			AEGfxMeshDraw(pInst->pObject->pMesh, AE_GFX_MDM_TRIANGLES);
			//}
		}


		//绘制boss
		if (pInst->pObject->type == TYPE_BOSS)
		{
			// 设置绘制模式(Color or texture)
			AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
			// 设置狗的坐标位置
			AEGfxSetPosition(pInst->posCurr.x, pInst->posCurr.y);
			// 无纹理
			AEGfxTextureSet(pTexStone, 0.0f, 0.0f);
			// 画对象狗
			AEGfxSetTransparency(1);
			AEGfxSetBlendColor(0.0f, 0.0f, 0.0, 0.0f);
			AEGfxMeshDraw(pInst->pObject->pMesh, AE_GFX_MDM_TRIANGLES);
		}

		//绘制狗对象
		if (pInst->pObject->type == TYPE_DOG)
		{
			// 设置绘制模式(Color or texture)
			AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
			// 设置狗的坐标位置
			AEGfxSetPosition(pInst->posCurr.x, pInst->posCurr.y);
			// 无纹理
			AEGfxTextureSet(pTex2, 0.0f, 0.0f);
			// 画对象狗
			AEGfxSetTransparency(1.0f);
			AEGfxSetBlendColor(0.0f, 0.0f, 0.0, 0.0f);
			AEGfxMeshDraw(pInst->pObject->pMesh, AE_GFX_MDM_TRIANGLES);
		}


		//绘制西瓜对象
		if (pInst->pObject->type == TYPE_WATERMELON)
		{
			// 设置绘制模式(Color or texture)
			AEGfxSetRenderMode(AE_GFX_RM_COLOR);
			// 设置西瓜的坐标位置
			AEGfxSetPosition(pInst->posCurr.x, pInst->posCurr.y);
			// 无纹理
			AEGfxTextureSet(NULL, 0.0f, 0.0f);
			AEGfxSetTintColor(1.0f, 1.0f, 1.0f, 1.0f);
			// 画对象西瓜
			//AEGfxSetTransparency(1);
			//AEGfxSetBlendColor(1.0f, 1.0f, 1.0, 1.0f);
			AEGfxMeshDraw(pInst->pObject->pMesh, AE_GFX_MDM_TRIANGLES);
		}

		//绘制主角血量
		if (pInst->pObject->type == TYPE_BURGLARBLOOD)
		{
			// 设置绘制模式(Color or texture)
			AEGfxSetRenderMode(AE_GFX_RM_COLOR);
			// 设置西瓜的坐标位置
			AEGfxSetPosition(pInst->posCurr.x, pInst->posCurr.y);
			// 无纹理
			AEGfxTextureSet(NULL, 0.0f, 0.0f);
			AEGfxSetTintColor(1.0f, 1.0f, 1.0f, 1.0f);
			// 画对象西瓜
			//AEGfxSetTransparency(1);
			//AEGfxSetBlendColor(1.0f, 1.0f, 1.0, 1.0f);
			AEGfxMeshDraw(pInst->pObject->pMesh, AE_GFX_MDM_TRIANGLES);
		}//if

		//画地图对象
		if (pInst->pObject->type == TYPE_MAP)
		{
			//if (KeyPressed[KeySpace])
			//	{
			// Drawing object stone
			// Set position for object stone
			AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);   // 必须最先设置绘制模式为纹理
			//AEGfxSetPosition(Burglar->posCurr.x+100.0f, Burglar->posCurr.y+10.0f);
			// Set texture for object stone
			AEGfxSetPosition(pInst->posCurr.x, pInst->posCurr.y);
			AEGfxTextureSet(pTexMap, 0.0f, 0.0f); // 参数1:纹理,偏移量(x,y)
			AEGfxSetTransparency(1.0f);
			AEGfxSetBlendColor(0.0f, 0.0f, 0.0, 0.0f);
			// Drawing the mesh (list of triangles)
			AEGfxMeshDraw(pInst->pObject->pMesh, AE_GFX_MDM_TRIANGLES);
			//}
		}

	}//for
	// 签到
	fprintf(fp, "Level2:Draw\n");
}
Exemple #6
0
GameInstance* Create_Instance(List *list, int type)
{
	int i;
	Vector2D pos = { DEFAULT_POSITION_X, DEFAULT_POSITION_Y };
	Vector2D vel = { DEFAULT_VELOCITY_X, DEFAULT_VELOCITY_Y };

	float frametime = (float)AEFrameRateControllerGetFrameTime();

	/* Find a game object Instance that is not in use*/
	for (i = 0; i < MAX_INSTANCES; i++) {
		GameInstance *Instance = list->InstanceList[i];

		if (Instance->In_Use_ == FALSE) {
			Instance->object_           =  get_object(list, type);
			Instance->In_Use_           =  TRUE;
			Instance->scale_x_          =  DEFAULT_SCALE_X;
			Instance->scale_y_          =  DEFAULT_SCALE_Y;
			Instance->position_         =  pos;
			Instance->velocity_         =  vel;
            Instance->rotation_         =  DEFAULT_ROTATION;
			Instance->z_order_          =  DEFAULT_Z_ORDER;
			Instance->CurrHealth_		=  DEFAULT_CUR_HEALTH;
			Instance->MaxHealth_		=  DEFAULT_MAX_HEALTH;
			Instance->Lives_			=  DEFAULT_LIVES;

			if (DEFAULT_LIFETIME == NO_LIFETIME) {
				Instance->lifetime_ = NO_LIFETIME;
			} else {
				Instance->lifetime_ = DEFAULT_LIFETIME / frametime;
			}

			if (DEFAULT_RELOAD == NO_RELOAD) {
				Instance->reload_ = NO_RELOAD;
			} else {
				Instance->reload_ = DEFAULT_RELOAD / frametime;
			}

			
			if (type == Player_Bullet) {
				for (int i = 0; i < MAX_INSTANCES; i++) {
					if (list->player_bullets[i] == NULL) {
						list->player_bullets[i] = Instance;
						list->p_bullets++;
						break;
					}
				}
			} else if (type == Enemy_Ship) {
				for (int i = 0; i < MAX_INSTANCES; i++) {
					if (list->enemies[i] == NULL) {
						list->enemies[i] = Instance;
						list->enemy_num++;
						break;
					}
				}
			} else if (type == Enemy_Bullet) {
				for (int i = 0; i < MAX_INSTANCES; i++) {
					if (list->enemy_bullets[i] == NULL) {
						list->enemy_bullets[i] = Instance;
						list->e_bullets++;
						break;
					}
				}
			}
		
            list->Instance_num++;
			LastInstance = Instance;
			return Instance;
		}
	}

	return 0;
}
Exemple #7
0
void SetReload(GameInstance *Instance, float reload)
{
	float frametime = (float)AEFrameRateControllerGetFrameTime();
	Instance->reload_ = reload / frametime;
}
Exemple #8
0
void InitReload(float reload) 
{
	float frametime = (float)AEFrameRateControllerGetFrameTime();
	LastInstance->reload_ = reload / frametime;
}
Exemple #9
0
void SetLifetime(GameInstance *Instance, float lifetime) 
{
	float frametime = (float)AEFrameRateControllerGetFrameTime();
	Instance->lifetime_ = lifetime / frametime;
}
Exemple #10
0
void InitLifetime(float lifetime)
{
	float frametime = (float)AEFrameRateControllerGetFrameTime();
	LastInstance->lifetime_ = lifetime / frametime;
}