Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
void GameStatePlayUpdate(void)
{
    if (AEInputCheckTriggered(DIK_J))
        SendJoinMessage();

    MsgInput inputMsg;
    if(ProcInput(inputMsg))
    {
        strcpy(inputMsg.data_.username_.name_, client.config_.username_.c_str());
        NetworkMessage netMsg;
        netMsg << inputMsg;
        netMsg.receiverAddress_ = client.remoteAddr_;
        try
        {
            printf("\nSending INPUT message... Input Count = %d\n", inputMsg.data_.key_info_count_);
            client.udpSock_.Send(netMsg);
        }
        catch(iSocket::SockErr& e)
        {
            e.Print();
        }
    }

    char buffer[1000] = { 0 };
    sprintf(buffer, "TIME LEFT: %.2f", time);
    AEGfxPrint(300, 10, 0xFFFFFFFF, buffer);
    sprintf(buffer, "Round: %u", round);
    AEGfxPrint(350, 30, 0xFFFFFFFF, buffer);

    unsigned yPos = 10;
    unsigned xPos = 10;
    for(std::vector<ResultStatus>::iterator it = results.begin(); it != results.end(); ++it)
    {
        sprintf(buffer, "%s:    Score: %u", it->name_.name_, it->score_);
        AEGfxPrint(xPos, yPos, 0xFFFFFFFF, buffer);
        yPos += ROW_HEIGHT;
    }

    client.udpSock_.Resend();

    // check for messages from server
    NetworkMessage netMsg;
    if(client.udpSock_.Receive(netMsg))
        ProcMessage(netMsg);
#if 0
    // ===============
    // update physics
    // ===============

    for (u32 i = 0; i < GAME_OBJ_INST_NUM_MAX; i++)
    {
        GameObjInst* pInst = sGameObjInstList + i;

        // skip non-active object
        if ((pInst->flag & FLAG_ACTIVE) == 0)
            continue;

        // update the position
        AEVec2ScaleAdd(&pInst->posCurr, &pInst->velCurr, &pInst->posCurr, (f32)(gAEFrameTime));
    }

    // ===============
    // update objects
    // ===============

    for (u32 i = 0; i < GAME_OBJ_INST_NUM_MAX; i++)
    {
        GameObjInst* pInst = sGameObjInstList + i;

        // skip non-active object
        if ((pInst->flag & FLAG_ACTIVE) == 0)
            continue;

        // check if the object is a ship
        if (pInst->pObject->type == TYPE_SHIP)
        {
            // warp the ship from one end of the screen to the other
            pInst->posCurr.x = AEWrap(pInst->posCurr.x, gAEWinMinX - SHIP_SIZE, gAEWinMaxX + SHIP_SIZE);
            pInst->posCurr.y = AEWrap(pInst->posCurr.y, gAEWinMinY - SHIP_SIZE, gAEWinMaxY + SHIP_SIZE);
        }
        // check if the object is an asteroid
        else if (pInst->pObject->type == TYPE_ASTEROID)
        {
            AEVec2 u;
            f32    uLen;

            // warp the asteroid from one end of the screen to the other
            pInst->posCurr.x = AEWrap(pInst->posCurr.x, gAEWinMinX - AST_SIZE_MAX, gAEWinMaxX + AST_SIZE_MAX);
            pInst->posCurr.y = AEWrap(pInst->posCurr.y, gAEWinMinY - AST_SIZE_MAX, gAEWinMaxY + AST_SIZE_MAX);

            // pull the asteroid toward the ship a little bit
            if (spShip)
            {
                // apply acceleration propotional to the distance from the asteroid to the ship
                AEVec2Sub	(&u, &spShip->posCurr, &pInst->posCurr);
                AEVec2Scale	(&u, &u, AST_TO_SHIP_ACC * (f32)(gAEFrameTime));
                AEVec2Add	(&pInst->velCurr, &pInst->velCurr, &u);
            }

            // if the asterid velocity is more than its maximum velocity, reduce its speed
            if ((uLen = AEVec2Length(&pInst->velCurr)) > (AST_VEL_MAX * 2.0f))
            {
                AEVec2Scale	(&u, &pInst->velCurr, (1.0f / uLen) * (AST_VEL_MAX * 2.0f - uLen) * pow(AST_VEL_DAMP, (f32)(gAEFrameTime)));
                AEVec2Add	(&pInst->velCurr, &pInst->velCurr, &u);
            }
        }
        // check if the object is a bullet
        else if (pInst->pObject->type == TYPE_BULLET)
        {
            // kill the bullet if it gets out of the screen
            if (!AEInRange(pInst->posCurr.x, gAEWinMinX - AST_SIZE_MAX, gAEWinMaxX + AST_SIZE_MAX) || 
                !AEInRange(pInst->posCurr.y, gAEWinMinY - AST_SIZE_MAX, gAEWinMaxY + AST_SIZE_MAX))
                gameObjInstDestroy(pInst);
        }
        // check if the object is a bomb
        else if (pInst->pObject->type == TYPE_BOMB)
        {
            // adjust the life counter
            pInst->life -= (f32)(gAEFrameTime) / BOMB_LIFE;

            if (pInst->life < 0.0f)
            {
                gameObjInstDestroy(pInst);
            }
            else
            {
                f32    radius = 1.0f - pInst->life;
                AEVec2 u;

                pInst->dirCurr += 2.0f * PI * (f32)(gAEFrameTime);

                radius =   1.0f - radius;
                radius *=  radius;
                radius *=  radius;
                radius *=  radius;
                radius *=  radius;
                radius =   (1.0f - radius) * BOMB_RADIUS;

                // generate the particle ring
                for (u32 j = 0; j < 10; j++)
                {
                    //f32 dir = AERandFloat() * 2.0f * PI;
                    f32 dir = (j / 9.0f) * 2.0f * PI + pInst->life * 1.5f * 2.0f * PI;

                    u.x = AECos(dir) * radius + pInst->posCurr.x;
                    u.y = AESin(dir) * radius + pInst->posCurr.y;

                    //sparkCreate(PTCL_EXHAUST, &u, 1, dir + 0.8f * PI, dir + 0.9f * PI);
                    sparkCreate(PTCL_EXHAUST, &u, 1, dir + 0.40f * PI, dir + 0.60f * PI);
                }
            }
        }
        // check if the object is a missile
        else if (pInst->pObject->type == TYPE_MISSILE)
        {
            // adjust the life counter
            pInst->life -= (f32)(gAEFrameTime) / MISSILE_LIFE;

            if (pInst->life < 0.0f)
            {
                gameObjInstDestroy(pInst);
            }
            else
            {
                AEVec2 dir;

                if (pInst->pUserData == 0)
                {
                    pInst->pUserData = missileAcquireTarget(pInst);
                }
                else
                {
                    GameObjInst* pTarget = (GameObjInst*)(pInst->pUserData);

                    // if the target is no longer valid, reacquire
                    if (((pTarget->flag & FLAG_ACTIVE) == 0) || (pTarget->pObject->type != TYPE_ASTEROID))
                        pInst->pUserData = missileAcquireTarget(pInst);
                }

                if (pInst->pUserData)
                {
                    GameObjInst* pTarget = (GameObjInst*)(pInst->pUserData);
                    AEVec2 u;
                    f32    uLen;

                    // get the vector from the missile to the target and its length
                    AEVec2Sub(&u, &pTarget->posCurr, &pInst->posCurr);
                    uLen = AEVec2Length(&u);

                    // if the missile is 'close' to target, do nothing
                    if (uLen > 0.1f)
                    {
                        // normalize the vector from the missile to the target
                        AEVec2Scale(&u, &u, 1.0f / uLen);

                        // calculate the missile direction vector
                        AEVec2Set(&dir, AECos(pInst->dirCurr), AESin(pInst->dirCurr));

                        // calculate the cos and sin of the angle between the target 
                        // vector and the missile direction vector
                        f32 cosAngle = AEVec2DotProduct(&dir, &u), 
                            sinAngle = AEVec2CrossProductMag(&dir, &u), 
                            rotAngle;

                        // calculate how much to rotate the missile
                        if (cosAngle < AECos(MISSILE_TURN_SPEED * (f32)(gAEFrameTime)))
                            rotAngle = MISSILE_TURN_SPEED * (f32)(gAEFrameTime);
                        else
                            rotAngle = AEACos(AEClamp(cosAngle, -1.0f, 1.0f));

                        // rotate to the left if sine of the angle is positive and vice versa
                        pInst->dirCurr += (sinAngle > 0.0f) ? rotAngle : -rotAngle;
                    }
                }

                // adjust the missile velocity
                AEVec2Set  (&dir, AECos(pInst->dirCurr), AESin(pInst->dirCurr));
                AEVec2Scale(&dir, &dir, MISSILE_ACCEL * (f32)(gAEFrameTime));
                AEVec2Add  (&pInst->velCurr, &pInst->velCurr, &dir);
                AEVec2Scale(&pInst->velCurr, &pInst->velCurr, pow(MISSILE_DAMP, (f32)(gAEFrameTime)));

                sparkCreate(PTCL_EXHAUST, &pInst->posCurr, 1, pInst->dirCurr + 0.8f * PI, pInst->dirCurr + 1.2f * PI);
            }
        }
        // check if the object is a particle
        else if ((TYPE_PTCL_WHITE <= pInst->pObject->type) && (pInst->pObject->type <= TYPE_PTCL_RED))
        {
            pInst->scale   *= pow(PTCL_SCALE_DAMP, (f32)(gAEFrameTime));
            pInst->dirCurr += 0.1f;
            AEVec2Scale(&pInst->velCurr, &pInst->velCurr, pow(PTCL_VEL_DAMP, (f32)(gAEFrameTime)));

            if (pInst->scale < PTCL_SCALE_DAMP)
                gameObjInstDestroy(pInst);
        }
    }

    // ====================
    // check for collision
    // ====================

    for (u32 i = 0; i < GAME_OBJ_INST_NUM_MAX; i++)
    {
        GameObjInst* pSrc = sGameObjInstList + i;

        // skip non-active object
        if ((pSrc->flag & FLAG_ACTIVE) == 0)
            continue;

        if ((pSrc->pObject->type == TYPE_BULLET) || (pSrc->pObject->type == TYPE_MISSILE))
        {
            for (u32 j = 0; j < GAME_OBJ_INST_NUM_MAX; j++)
            {
                GameObjInst* pDst = sGameObjInstList + j;

                // skip no-active and non-asteroid object
                if (((pDst->flag & FLAG_ACTIVE) == 0) || (pDst->pObject->type != TYPE_ASTEROID))
                    continue;

                if (AETestPointToRect(&pSrc->posCurr, &pDst->posCurr, pDst->scale, pDst->scale) == false)
                    continue;

                if (pDst->scale < AST_SIZE_MIN)
                {
                    sparkCreate(PTCL_EXPLOSION_M, &pDst->posCurr, (u32)(pDst->scale * 10), pSrc->dirCurr - 0.05f * PI, pSrc->dirCurr + 0.05f * PI, pDst->scale);
                    sScore++;

                    if ((sScore % AST_SPECIAL_RATIO) == 0)
                        sSpecialCtr++;
                    if ((sScore % AST_SHIP_RATIO) == 0)
                        sShipCtr++;
                    if (sScore == sAstNum * 5)
                        sAstNum = (sAstNum < AST_NUM_MAX) ? (sAstNum * 2) : sAstNum;

                    // destroy the asteroid
                    gameObjInstDestroy(pDst);
                }
                else
                {
                    sparkCreate(PTCL_EXPLOSION_S, &pSrc->posCurr, 10, pSrc->dirCurr + 0.9f * PI, pSrc->dirCurr + 1.1f * PI);

                    // impart some of the bullet/missile velocity to the asteroid
                    AEVec2Scale(&pSrc->velCurr, &pSrc->velCurr, 0.01f * (1.0f - pDst->scale / AST_SIZE_MAX));
                    AEVec2Add  (&pDst->velCurr, &pDst->velCurr, &pSrc->velCurr);

                    // split the asteroid to 4
                    if ((pSrc->pObject->type == TYPE_MISSILE) || ((pDst->life -= 1.0f) < 0.0f))
                        astCreate(pDst);
                }

                // destroy the bullet
                gameObjInstDestroy(pSrc);

                break;
            }
        }
        else if (TYPE_BOMB == pSrc->pObject->type)
        {
            f32 radius = 1.0f - pSrc->life;

            pSrc->dirCurr += 2.0f * PI * (f32)(gAEFrameTime);

            radius =   1.0f - radius;
            radius *=  radius;
            radius *=  radius;
            radius *=  radius;
            radius *=  radius;
            radius *=  radius;
            radius =   (1.0f - radius) * BOMB_RADIUS;

            // check collision
            for (u32 j = 0; j < GAME_OBJ_INST_NUM_MAX; j++)
            {
                GameObjInst* pDst = sGameObjInstList + j;

                if (((pDst->flag & FLAG_ACTIVE) == 0) || (pDst->pObject->type != TYPE_ASTEROID))
                    continue;

                if (AECalcDistPointToRect(&pSrc->posCurr, &pDst->posCurr, pDst->scale, pDst->scale) > radius)
                    continue;

                if (pDst->scale < AST_SIZE_MIN)
                {
                    f32 dir = atan2f(pDst->posCurr.y - pSrc->posCurr.y, pDst->posCurr.x - pSrc->posCurr.x);

                    gameObjInstDestroy(pDst);
                    sparkCreate(PTCL_EXPLOSION_M, &pDst->posCurr, 20, dir + 0.4f * PI, dir + 0.45f * PI);
                    sScore++;

                    if ((sScore % AST_SPECIAL_RATIO) == 0)
                        sSpecialCtr++;
                    if ((sScore % AST_SHIP_RATIO) == 0)
                        sShipCtr++;
                    if (sScore == sAstNum * 5)
                        sAstNum = (sAstNum < AST_NUM_MAX) ? (sAstNum * 2) : sAstNum;
                }
                else
                {
                    // split the asteroid to 4
                    astCreate(pDst);
                }
            }
        }
        else if (pSrc->pObject->type == TYPE_ASTEROID)
        {
            for (u32 j = 0; j < GAME_OBJ_INST_NUM_MAX; j++)
            {
                GameObjInst* pDst = sGameObjInstList + j;
                f32          d;
                AEVec2       nrm, u;

                // skip no-active and non-asteroid object
                if ((pSrc == pDst) || ((pDst->flag & FLAG_ACTIVE) == 0)  || (pDst->pObject->type != TYPE_ASTEROID))
                    continue;

                // check if the object rectangle overlap
                d = AECalcDistRectToRect(
                    &pSrc->posCurr, pSrc->scale, pSrc->scale, 
                    &pDst->posCurr, pDst->scale, pDst->scale, 
                    &nrm);

                if (d >= 0.0f)
                    continue;

                // adjust object position so that they do not overlap
                AEVec2Scale	(&u, &nrm, d * 0.25f);
                AEVec2Sub	(&pSrc->posCurr, &pSrc->posCurr, &u);
                AEVec2Add	(&pDst->posCurr, &pDst->posCurr, &u);

                // calculate new object velocities
                resolveCollision(pSrc, pDst, &nrm);
            }
        }
        else if (pSrc->pObject->type == TYPE_SHIP)
        {
            for (u32 j = 0; j < GAME_OBJ_INST_NUM_MAX; j++)
            {
                GameObjInst* pDst = sGameObjInstList + j;

                // skip no-active and non-asteroid object
                if ((pSrc == pDst) || ((pDst->flag & FLAG_ACTIVE) == 0) || (pDst->pObject->type != TYPE_ASTEROID))
                    continue;

                // check if the object rectangle overlap
                if (AETestRectToRect(
                    &pSrc->posCurr, pSrc->scale, pSrc->scale, 
                    &pDst->posCurr, pDst->scale, pDst->scale) == false)
                    continue;

                // create the big explosion
                sparkCreate(PTCL_EXPLOSION_L, &pSrc->posCurr, 100, 0.0f, 2.0f * PI);

                // reset the ship position and direction
                AEVec2Zero(&spShip->posCurr);
                AEVec2Zero(&spShip->velCurr);
                spShip->dirCurr = 0.0f;

                sSpecialCtr = SHIP_SPECIAL_NUM;

                // destroy all asteroid near the ship so that you do not die as soon as the ship reappear
                for (u32 j = 0; j < GAME_OBJ_INST_NUM_MAX; j++)
                {
                    GameObjInst* pInst = sGameObjInstList + j;
                    AEVec2		 u;

                    // skip no-active and non-asteroid object
                    if (((pInst->flag & FLAG_ACTIVE) == 0) || (pInst->pObject->type != TYPE_ASTEROID))
                        continue;

                    AEVec2Sub(&u, &pInst->posCurr, &spShip->posCurr);

                    if (AEVec2Length(&u) < (spShip->scale * 10.0f))
                    {
                        sparkCreate		  (PTCL_EXPLOSION_M, &pInst->posCurr, 10, -PI, PI);
                        gameObjInstDestroy(pInst);
                    }
                }

                // reduce the ship counter
                sShipCtr--;

                // if counter is less than 0, game over
                if (sShipCtr < 0)
                {
                    sGameStateChangeCtr = 2.0;
                    gameObjInstDestroy(spShip);
                    spShip = 0;
                }

                break;
            }
        }
    }
#endif
    // =====================================
    // calculate the matrix for all objects
    // =====================================

    for (u32 i = 0; i < GAME_OBJ_INST_NUM_MAX; i++)
    {
        GameObjInst* pInst = sGameObjInstList + i;
        AEMtx33		 m;

        // skip non-active object
        if ((pInst->flag & FLAG_ACTIVE) == 0)
            continue;

        AEMtx33Scale		(&pInst->transform, pInst->scale,     pInst->scale);
        AEMtx33Rot			(&m,                pInst->dirCurr);
        AEMtx33Concat		(&pInst->transform, &m,               &pInst->transform);
        AEMtx33Trans		(&m,                pInst->posCurr.x, pInst->posCurr.y);
        AEMtx33Concat		(&pInst->transform, &m,               &pInst->transform);
    }
}
Ejemplo n.º 3
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();
}
Ejemplo n.º 4
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 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;
}