Exemple #1
0
//==================================
//  函数:Render()
//  目的:渲染图形并显示
//
void Render()
{
    if( NULL == g_pd3dD )
        return;

	//清空后台缓存
	g_pd3dD->Clear(0,NULL,D3DCLEAR_TARGET && D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,0),1.0f,0);

	if(SUCCEEDED(g_pd3dD->BeginScene()))
	{
		//在后台缓存绘制图形
		graphicRender();
		textRender();
		btnRender();

		//结束在后台缓存渲染图形
		g_pd3dD->EndScene();
	}
	//将在后台缓存绘制的图形提交到前台缓存显示
	g_pd3dD->Present(NULL,NULL,NULL,NULL);
}
Exemple #2
0
void EXPORT_THIS d_text_surface_draw(void *surface) {
	textRender(surface);
	
	return;
}
Exemple #3
0
bool PlayGame(Map &map, ResourceManager &resourceManager, const unsigned int livesIn)
{
    bool nextMap(true), menu(true);

    SoundPlayer soundPlayer(alcGetCurrentContext());

    unsigned int lives(livesIn);
    unsigned int specialItemScoreRequired(1000);
    unsigned int score(0), changedScore(score);
    TextRenderer textRender(resourceManager.GetTexture("text.png"));

    std::vector<std::string> stringVec{"Score:", "0"};
    std::vector<std::string> livesVec{"Lives: ", std::to_string(lives)};

    textRender.AddTextVerticalAlign(stringVec, TextRenderer::Alignment::Right, TextRenderer::Alignment::Top, 20.0f);
    textRender.AddTextHorizontalAlign(livesVec, TextRenderer::Alignment::Right, TextRenderer::Alignment::Bottom, 20.0f);

    glm::mat4 view(glm::ortho(0.0f, 40.0f, 0.0f, 30.0f, 1.0f, -1.0f));
    std::vector<std::shared_ptr<VisibleObject>> objectVec;
    std::vector<Movement> movementVec;
    std::vector<std::shared_ptr<AI>> aiVec;
    std::vector<float> aiStateSwitchTimes;
    std::vector<DeadPlayers> deadPlayerVec;

    int level(0);
    int timesToChange(7);

    while(nextMap && !glfwWindowShouldClose(glfwGetCurrentContext()))
    {
        ++level;
        timesToChange = UpdateAiSwitchVec(aiStateSwitchTimes, timesToChange, level);
        bool playing = true;
        map.LoadNextMap();

        GetVecFullOfObjects(objectVec, map, resourceManager, aiVec);
        textRender.AddTextHorizontalAlign(livesVec, TextRenderer::Alignment::Right, TextRenderer::Alignment::Bottom, 20.0f);

        CollisionDetection collisionDetect;
        collisionDetect.AddPlayersAndEnemys(objectVec);
        map.HideSpecialObj();

        double currTime = glfwGetTime(), prevTime = glfwGetTime(),
                mapStartTime = glfwGetTime(), enemyKillFinish(0.0);

        while(playing && !glfwWindowShouldClose(glfwGetCurrentContext()))
        {

            glClear(GL_COLOR_BUFFER_BIT);

            if(AISwitchModes(aiVec, currTime - mapStartTime, aiStateSwitchTimes.back()))
            {
                soundPlayer.AddToPlay(*(resourceManager.GetSound("wolfhowl.ogg")));
                aiStateSwitchTimes.erase(aiStateSwitchTimes.end() - 1);
            }
            if(score >= specialItemScoreRequired)
                specialItemScoreRequired = UpdateSpecialItem(objectVec, map, specialItemScoreRequired, resourceManager);
            if(enemyKillFinish != 0.0)
            {
                if(currTime >= enemyKillFinish)
                {
                    UpdateEnemysDieStatus(objectVec, resourceManager);
                    enemyKillFinish = 0.0;
                }
            }
            if(!deadPlayerVec.empty())
            {
                for(auto player(deadPlayerVec.begin()); player != deadPlayerVec.end();)
                {
                    if((*player).timeEnemyShouldLive <= currTime)
                    {
                        (*player).player->SwitchDeathVao();
                        (*player).player->ResetToOriginalSquare();
                        player = deadPlayerVec.erase(player);
                    }
                    else
                        ++player;
                }
            }

            if(GetInput(movementVec, aiVec, map))
            {
                if(PauseMenu(resourceManager, menu))
                {
                    playing = false;
                    nextMap = false;
                    break;
                }
                glfwSetTime(currTime);
            }

            for(auto & obj : objectVec)
            {
                if(obj->GetPlayer() > 0)
                {
                    UpdatePlayerMovement(obj, movementVec, map, currTime - prevTime);
                    if(obj->GetPlayer() == 1)
                    {
                        if(UpdateMap(obj, objectVec, map, changedScore, soundPlayer, resourceManager))
                        {
                            if(enemyKillFinish == 0.0f)
                            {
                                enemyKillFinish = currTime;
                                UpdateEnemysDieStatus(objectVec, resourceManager);
                            }
                            currTime -= 5.0;
                            glfwSetTime(currTime);
                        }
                        if(score != changedScore)
                        {
                            UpdateScore(changedScore, textRender, stringVec);
                            score = changedScore;

                            if(map.HasFinished())
                            {
                                playing = false;
                                nextMap = true;
                            }
                        }
                    }
                }
                obj->Draw(view);
            }
            textRender.DrawAll();

            if(collisionDetect.DetectCollisions(lives, changedScore, deadPlayerVec, resourceManager, soundPlayer))
            {
                soundPlayer.AddToPlay(*(resourceManager.GetSound("death.ogg")));
                if(UpdateLives(lives, textRender, livesVec))
                {
                    playing = false;
                    nextMap = false;
                    UpdateHighscore(score, resourceManager);
                }
            }

            glfwSwapBuffers(glfwGetCurrentContext());
            glfwPollEvents();

            prevTime = currTime;
            currTime = glfwGetTime();
        }
    }
    if(glfwWindowShouldClose(glfwGetCurrentContext()))
        nextMap = false;

    return menu;
}