AEGfxVertexList* make_triangle_object(float x, float y, int color) { AEGfxMeshStart(); /* 1st argument: X */ /* 2nd argument: Y */ /* 3rd argument: ARGB */ AEGfxTriAdd( -x, -y, color, 0.0f, 0.0f, x, -y, color, 0.0f, 0.0f, -x, y, color, 0.0f, 0.0f); pObj->pMesh = AEGfxMeshEnd(); return AEGfxMeshEnd(); }
void LoadMenuByIntUs(void) { // 开始添加对象1 AEGfxMeshStart(); AEGfxTriAdd( -450.0f, -300.0f, 0x00FF00FF, 0.0f,1.0f, 450.0f, -300.0f, 0x00FFFF00, 1.0f, 1.0f, -450.0f, 300.0f, 0x00F00FFF, 0.0f, 0.0f); AEGfxTriAdd( 450.0f, -300.0f, 0x00FFFFFF, 1.0f, 1.0f, 450.0f, 300.0f, 0x00FFFFFF, 1.0f, 0.0f, -450.0f, 300.0f, 0x00FFFFFF, 0.0f, 0.0f); pMesh1 = AEGfxMeshEnd(); AE_ASSERT_MESG(pMesh1, "Failed to create mesh 1!!"); // 载入纹理 pTex1 = AEGfxTextureLoad("BackGround.PNG"); // 签到 fprintf(fp, "Menu:Load\n"); }
AEGfxVertexList* make half AEGfxVertexList* make_circle_object(int parts, int color) { float CircleAngleStep; int i; AEGfxMeshStart(); /* 1st argument: X */ /* 2nd argument: Y */ /* 3rd argument: ARGB */ /* Creating the circle shape */ CircleAngleStep = PI/12.0f; for(i = 0; i < parts; ++i) { AEGfxTriAdd( 0.0f, 0.0f, color, 0.0f, 0.0f, cosf(i*2*PI/parts)*0.5f, sinf(i*2*PI/parts)*0.5f, color, 0.0f, 0.0f, cosf((i+1)*2*PI/parts)*0.5f, sinf((i+1)*2*PI/parts)*0.5f, color, 0.0f, 0.0f); } return AEGfxMeshEnd(); }
int WINAPI WinMain(HINSTANCE instanceH, HINSTANCE prevInstanceH, LPSTR command_line, int show) { // Variable declaration float obj1X = 0.0f, obj1Y = 0.0f; // Position variables for object 1 AEGfxVertexList* pMesh1; // Pointer to Mesh (Model) float alpha = 1.0f; // Initialize the system AESysInitInfo sysInitInfo; sysInitInfo.mCreateWindow = 1; sysInitInfo.mAppInstance = instanceH; sysInitInfo.mShow = show; sysInitInfo.mWinWidth = 800; sysInitInfo.mWinHeight = 600; sysInitInfo.mCreateConsole = 1; sysInitInfo.mMaxFrameRate = 60; sysInitInfo.mpWinCallBack = NULL;//MyWinCallBack; sysInitInfo.mClassStyle = CS_HREDRAW | CS_VREDRAW; sysInitInfo.mWindowStyle = WS_OVERLAPPEDWINDOW;//WS_POPUP | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;; sysInitInfo.mWindowHandle = NULL; sysInitInfo.mHandleWindowMessages = 1; AESysInit (&sysInitInfo); // reset the system modules AESysReset(); // 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!!"); 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(); // 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; // Alpha value if (AEInputCheckCurr('Z')) alpha -= 0.01f; else if (AEInputCheckCurr('X')) alpha += 0.01f; alpha = AEClamp(alpha, 0.0f, 1.0f); // Drawing object 1 AEGfxSetRenderMode(AE_GFX_RM_COLOR); // Set position for object 1 AEGfxSetPosition(obj1X, obj1Y); // No texture for object 1 AEGfxTextureSet(NULL, 0, 0); // Drawing the mesh (list of triangles) AEGfxSetTransparency(alpha); AEGfxMeshDraw(pMesh1, AE_GFX_MDM_TRIANGLES); // 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); // free the system AESysExit(); return 1; }
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(); }
void Load2(void) { GameObjBase* pObjBase; // 初始化游戏对象基类的实例列表 memset(sGameObjBaseList, 0, sizeof(GameObjBase) * GAME_OBJ_BASE_NUM_MAX); sGameObjBaseNum = 0; // 创建基类的实例 // ===================== //主角 // ===================== pObjBase = sGameObjBaseList + sGameObjBaseNum++; pObjBase->type = TYPE_BURGLAR; AEGfxMeshStart(); AEGfxTriAdd( -15.0f, -15.0f, 0x00FF00FF, 0.0f, 1.0f, 15.0f, -15.0f, 0x00FFFF00, 0.125f, 1.0f, -15.0f, 12.0f, 0x00F00FFF, 0.0f, 0.0f); AEGfxTriAdd( 15.0f, -15.0f, 0x00FFFFFF, 0.125f, 1.0f, 15.0f, 15.0f, 0x00FFFFFF, 0.125f, 0.0f, -15.0f, 15.0f, 0x00FFFFFF, 0.0f, 0.0f); pObjBase->pMesh = AEGfxMeshEnd(); AE_ASSERT_MESG(pObjBase->pMesh, "Failed to create object!!"); pTex1 = AEGfxTextureLoad("PlayerRun.png");//载入纹理 // ======================= // 发射出去的石头:尺寸很小,简化成三角形定义 // ======================= pObjBase = sGameObjBaseList + sGameObjBaseNum++; pObjBase->type = TYPE_STONE; AEGfxMeshStart(); AEGfxTriAdd( -10.0f, -10.0f, 0x00FF00FF, 0.0f, 1.0f, 10.0f, -10.0f, 0x00FFFF00, 1.0f, 1.0f, -10.0f, 10.0f, 0x00F00FFF, 0.0f, 0.0f); AEGfxTriAdd( 10.0f, -10.0f, 0x00FFFFFF, 1.0f, 1.0f, 10.0f, 10.0f, 0x00FFFFFF, 1.0f, 0.0f, -10.0f, 10.0f, 0x00FFFFFF, 0.0f, 0.0f); pObjBase->pMesh = AEGfxMeshEnd(); AE_ASSERT_MESG(pObjBase->pMesh, "Failed to create Bullet object!!"); pTexStone = AEGfxTextureLoad("planetTexture.png"); // ======================= // 静止被捡起的石头:尺寸很小,简化成三角形定义 // ======================= pObjBase = sGameObjBaseList + sGameObjBaseNum++; pObjBase->type = TYPE_STONE_STATIC; AEGfxMeshStart(); AEGfxTriAdd( -10.0f, -10.0f, 0x00FF00FF, 0.0f, 1.0f, 10.0f, -10.0f, 0x00FFFF00, 1.0f, 1.0f, -10.0f, 10.0f, 0x00F00FFF, 0.0f, 0.0f); AEGfxTriAdd( 10.0f, -10.0f, 0x00FFFFFF, 1.0f, 1.0f, 10.0f, 10.0f, 0x00FFFFFF, 1.0f, 0.0f, -10.0f, 10.0f, 0x00FFFFFF, 0.0f, 0.0f); pObjBase->pMesh = AEGfxMeshEnd(); AE_ASSERT_MESG(pObjBase->pMesh, "Failed to create Bullet object!!"); pTexStone = AEGfxTextureLoad("planetTexture.png"); // ========================= // 看得见的陷阱 // ========================= pObjBase = sGameObjBaseList + sGameObjBaseNum++; pObjBase->type = TYPE_TRAP_IN; AEGfxMeshStart(); 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); pObjBase->pMesh = AEGfxMeshEnd(); AE_ASSERT_MESG(pObjBase->pMesh, "Failed to create Asteroid object!!"); pTexTrap = AEGfxTextureLoad("planetTexture.png");; //陷阱纹理 //看不见的陷阱 pObjBase = sGameObjBaseList + sGameObjBaseNum++; pObjBase->type = TYPE_TRAP_OUT; AEGfxMeshStart(); 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); pObjBase->pMesh = AEGfxMeshEnd(); AE_ASSERT_MESG(pObjBase->pMesh, "Failed to create Asteroid object!!"); // ======================== // 农场主:两个三角形拼接的菱形 // ======================== pObjBase = sGameObjBaseList + sGameObjBaseNum++; pObjBase->type = TYPE_BOSS; AEGfxMeshStart(); AEGfxTriAdd( -20.0f, -20.0f, 0x00FF00FF, 0.0f, 1.0f, 20.0f, -20.0f, 0x00FFFF00, 1.0f, 1.0f, -20.0f, 20.0f, 0x00F00FFF, 0.0f, 0.0f); AEGfxTriAdd( 20.0f, -20.0f, 0x00FFFFFF, 1.0f, 1.0f, 20.0f, 20.0f, 0x00FFFFFF, 1.0f, 0.0f, -20.0f, 20.0f, 0x00FFFFFF, 0.0f, 0.0f); pObjBase->pMesh = AEGfxMeshEnd(); AE_ASSERT_MESG(pObjBase->pMesh, "Failed to create Asteroid object!!"); // ======================== // 狗:两个三角形拼接的菱形 // ======================== pObjBase = sGameObjBaseList + sGameObjBaseNum++; pObjBase->type = TYPE_DOG; AEGfxMeshStart(); AEGfxTriAdd( -15.0f, -9.0f, 0x00FF00FF, 0.0f, 1.0f, 15.0f, -9.0f, 0x00FFFF00, 1.0f, 1.0f, -15.0f, 9.0f, 0x00F00FFF, 0.0f, 0.0f); AEGfxTriAdd( 15.0f, -9.0f, 0x00FFFFFF, 1.0f, 1.0f, 15.0f, 9.0f, 0x00FFFFFF, 1.0f, 0.0f, -15.0f, 9.0f, 0x00FFFFFF, 0.0f, 0.0f); pObjBase->pMesh = AEGfxMeshEnd(); AE_ASSERT_MESG(pObjBase->pMesh, "Failed to create Asteroid object!!"); pTex2 = AEGfxTextureLoad("Dog1.png");//载入纹理 // ======================== // 草莓:两个三角形拼接的菱形 // ======================== pObjBase = sGameObjBaseList + sGameObjBaseNum++; pObjBase->type = TYPE_STRAWBERRY; AEGfxMeshStart(); AEGfxTriAdd( 0.5f, 0.0f, 0xFFFFFF00, 0.0f, 0.0f, 0.0f, 0.5f, 0xFFFFFF00, 0.0f, 0.0f, 0.0f, -0.5f, 0xFFFFFF00, 0.0f, 0.0f); AEGfxTriAdd( -0.5f, 0.0f, 0xFFFFFF00, 0.0f, 0.0f, 0.0f, 0.5f, 0xFFFFFF00, 0.0f, 0.0f, 0.0f, -0.5f, 0xFFFFFF00, 0.0f, 0.0f); pObjBase->pMesh = AEGfxMeshEnd(); AE_ASSERT_MESG(pObjBase->pMesh, "Failed to create Asteroid object!!"); // ======================== // 西瓜:圆形 // ======================== pObjBase = sGameObjBaseList + sGameObjBaseNum++; pObjBase->type = TYPE_WATERMELON; AEGfxMeshStart(); float CircleAngleStep = PI / 12.0f; int Parts = 24; for (int i = 0; i < Parts; ++i) { AEGfxTriAdd( 0.0f, 0.0f, 0xFFFFFF00, 0.0f, 0.0f, cosf(i * 2 * PI / Parts)*10.0f, sinf(i * 2 * PI / Parts)*10.0f, 0xFFFFFF00, 0.0f, 0.0f, cosf((i + 1) * 2 * PI / Parts)*10.0f, sinf((i + 1) * 2 * PI / Parts)*10.0f, 0xFFFFFF00, 0.0f, 0.0f); } pObjBase->pMesh = AEGfxMeshEnd(); AE_ASSERT_MESG(pObjBase->pMesh, "Failed to create Asteroid object!!"); // ======================== // BOSS血量:两个三角形拼接的长方形 // ======================== pObjBase = sGameObjBaseList + sGameObjBaseNum++; pObjBase->type = TYPE_BOSSBLOOD; AEGfxMeshStart(); AEGfxTriAdd( -20.0f, 4.0f, 0x01FF0000, 0.0f, 0.0f, //0x01FF0000 黑色 20.0f, 6.0f, 0xFFFF0000, 1.0f, 0.0f, //0xFFFF0000 红色 -20.0f, -4.0f, 0xFFFFFFFF, 0.0f, 1.0f); //0xFFFFFFFF 白色 AEGfxTriAdd( 20.0f, -2.0f, 0x01FF0000, 1.0f, 1.0f, 20.0f, 4.0f, 0xFFFF0000, 1.0f, 0.0f, -20.0f, -4.0f, 0xFFFFFFFF, 0.0f, 1.0f); pObjBase->pMesh = AEGfxMeshEnd(); AE_ASSERT_MESG(pObjBase->pMesh, "Failed to create Asteroid object!!"); // ======================== // 小盗血量:两个三角形拼接的长方形 // ======================== pObjBase = sGameObjBaseList + sGameObjBaseNum++; pObjBase->type = TYPE_BURGLARBLOOD; AEGfxMeshStart(); AEGfxTriAdd( -20.0f, 4.0f, 0x01FF0000, 0.0f, 0.0f, //0x01FF0000 黑色 28.0f, 4.0f, 0xFFFF0000, 1.0f, 0.0f, //0xFFFF0000 红色 -20.0f, -4.0f, 0xFFFFFFFF, 0.0f, 1.0f); //0xFFFFFFFF 白色 AEGfxTriAdd( 16.0f, -4.0f, 0x01FF0000, 1.0f, 1.0f, 20.0f, 4.0f, 0xFFFF0000, 1.0f, 0.0f, -20.0f, -4.0f, 0xFFFFFFFF, 0.0f, 1.0f); pObjBase->pMesh = AEGfxMeshEnd(); AE_ASSERT_MESG(pObjBase->pMesh, "Failed to create Asteroid object!!"); // ======================== // 小盗生命数:两个三角形拼接的长方形 // ======================== pObjBase = sGameObjBaseList + sGameObjBaseNum++; pObjBase->type = TYPE_BURGLARLIVES; AEGfxMeshStart(); AEGfxTriAdd( -30.0f, 4.0f, 0x01FF0000, 0.0f, 0.0f, //0x01FF0000 黑色 30.0f, 4.0f, 0xFFFF0000, 1.0f, 0.0f, //0xFFFF0000 红色 -30.0f, -4.0f, 0xFFFFFFFF, 0.0f, 1.0f); //0xFFFFFFFF 白色 AEGfxTriAdd( 30.0f, -4.0f, 0x01FF0000, 1.0f, 1.0f, 30.0f, 4.0f, 0xFFFF0000, 1.0f, 0.0f, -30.0f, -4.0f, 0xFFFFFFFF, 0.0f, 1.0f); pObjBase->pMesh = AEGfxMeshEnd(); AE_ASSERT_MESG(pObjBase->pMesh, "Failed to create Asteroid object!!"); // ===================== //地图 // ===================== pObjBase = sGameObjBaseList + sGameObjBaseNum++; pObjBase->type = TYPE_MAP; AEGfxMeshStart(); AEGfxTriAdd( -6.0f, -6.0f, 0x00FF00FF, 0.0f, 1.0f, 6.0f, -6.0f, 0x00FFFF00, 1.0f, 1.0f, -6.0f, 6.0f, 0x00F00FFF, 0.0f, 0.0f); AEGfxTriAdd( 7.0f, -7.0f, 0x00FFFFFF, 1.0f, 1.0f, 7.0f, 7.0f, 0x00FFFFFF, 1.0f, 0.0f, -7.0f, 7.0f, 0x00FFFFFF, 0.0f, 0.0f); pObjBase->pMesh = AEGfxMeshEnd(); AE_ASSERT_MESG(pObjBase->pMesh, "Failed to create object!!"); pTexMap = AEGfxTextureLoad("map1.png"); // 签到 fprintf(fp, "Level2:Load\n"); }
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 obj1texX = 0, obj1texY = 0; // Texture variables for object 2's texture 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) float camX, camY; // Used to temporary store camera position float alpha = 1.0f; // Initialize the system AESysInitInfo sysInitInfo; sysInitInfo.mCreateWindow = 1; sysInitInfo.mAppInstance = instanceH; sysInitInfo.mShow = show; sysInitInfo.mWinWidth = 800; sysInitInfo.mWinHeight = 600; sysInitInfo.mCreateConsole = 1; sysInitInfo.mMaxFrameRate = 60; sysInitInfo.mpWinCallBack = NULL;//MyWinCallBack; sysInitInfo.mClassStyle = CS_HREDRAW | CS_VREDRAW; sysInitInfo.mWindowStyle = WS_OVERLAPPEDWINDOW;//WS_POPUP | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;; sysInitInfo.mWindowHandle = NULL; sysInitInfo.mHandleWindowMessages = 1; AESysInit (&sysInitInfo); // reset the system modules AESysReset(); // 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 vertices 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!!"); // 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); // This step is optional, it creates a file from the texture argument AE_ASSERT_MESG(pTex2, "Failed to create texture2!!"); 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(); // 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; // Alpha value if (AEInputCheckCurr('Z')) alpha -= 0.01f; else if (AEInputCheckCurr('X')) alpha += 0.01f; alpha = AEClamp(alpha, 0.0f, 1.0f); // 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); // 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; AEGfxSetRenderMode(AE_GFX_RM_COLOR); AEGfxSetPosition(0.0f, 0.0f); AEGfxSetBlendColor(0.0f, 0.0f, 0.0, 0.0f); AEGfxMeshDraw(pMeshLine, AE_GFX_MDM_LINES_STRIP); // Drawing object 1 AEGfxSetRenderMode(AE_GFX_RM_COLOR); // Set poisition for object 1 AEGfxSetPosition(obj1X, obj1Y); // No texture for object 1 AEGfxTextureSet(NULL, 0, 0); // Drawing the mesh (list of triangles) AEGfxSetTransparency(alpha); AEGfxSetBlendColor(0.0f, 0.0f, 0.0, 0.0f); AEGfxMeshDraw(pMesh1, AE_GFX_MDM_TRIANGLES); // Drawing object 2 // Set position for object 2 AEGfxSetRenderMode(AE_GFX_RM_TEXTURE); AEGfxSetPosition(100.0f, -60.0f); // Set texture for object 2 AEGfxTextureSet(pTex1, obj1texX, obj1texY); AEGfxSetTransparency(1.0f); AEGfxSetBlendColor(0.0f, 0.0f, 0.0, 0.0f); // Drawing the mesh (list of triangles) AEGfxMeshDraw(pMesh2, AE_GFX_MDM_TRIANGLES); // Drawing object 2 again // Set position for object 2 AEGfxSetRenderMode(AE_GFX_RM_TEXTURE); AEGfxSetPosition(-100.0f, -60.0f); // Set texture for object 2 AEGfxTextureSet(pTex2, 0.0f, 0.0f); AEGfxSetTransparency(1.0f); AEGfxSetBlendColor(0.0f, 0.0f, 0.0, 0.0f); // Drawing the mesh (list of triangles) AEGfxMeshDraw(pMesh2, AE_GFX_MDM_TRIANGLES); // Drawing object 2 again and again // Set poisition for object 2 AEGfxSetRenderMode(AE_GFX_RM_TEXTURE); AEGfxSetPosition(100.0f, 100.0f); // Set texture for object 2 AEGfxTextureSet(pTex1, obj1texX, obj1texY); AEGfxSetTransparency(1.0f); AEGfxSetBlendColor(0.5f, 0.0f, 0.0, 0.75f); // Drawing the mesh (list of triangles) AEGfxMeshDraw(pMesh2, AE_GFX_MDM_TRIANGLES); // 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); AEGfxMeshFree(pMeshLine); AEGfxTextureUnload(pTex1); AEGfxTextureUnload(pTex2); // free the system AESysExit(); return 1; }