当前位置: 首页>>代码示例>>C++>>正文


C++ ParticleManager::addRandomParticle方法代码示例

本文整理汇总了C++中ParticleManager::addRandomParticle方法的典型用法代码示例。如果您正苦于以下问题:C++ ParticleManager::addRandomParticle方法的具体用法?C++ ParticleManager::addRandomParticle怎么用?C++ ParticleManager::addRandomParticle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ParticleManager的用法示例。


在下文中一共展示了ParticleManager::addRandomParticle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: checkFoodCollision

	// Check collision between snake and food
	int checkFoodCollision(ParticleGraph& snakeGraph, ParticleManager& snakeManager, ParticleManager& foodManager, ParticleManager& fireworkManager, float step, int init) {
	    for(int i = init; i < foodManager.getCount(); ++i) {

	        if(foodManager.getParticleX(i) - step * foodManager.getParticleMass(i) <= snakeManager.getParticleX(0) 
	            && snakeManager.getParticleX(0) <= foodManager.getParticleX(i) + step * foodManager.getParticleMass(i)
	            && foodManager.getParticleY(i) - step * foodManager.getParticleMass(i) <= snakeManager.getParticleY(0) 
	            && snakeManager.getParticleY(0) <= foodManager.getParticleY(i) + step* foodManager.getParticleMass(i)) {

	        	fireworkManager.addCircleParticlesAtPosition(3, snakeManager.getParticlePosition(0), snakeManager.getParticleColor(1), 25);

	            addParticletoSnake(snakeGraph, i, foodManager, snakeManager);
                foodManager.addRandomParticle(snakeManager.getCount());

                return i;
	        }
	    }

	    return -1;
	}
开发者ID:eprana,项目名称:Zipix,代码行数:20,代码来源:Game.cpp

示例2: main

int main() {
    WindowManager wm(WINDOW_WIDTH, WINDOW_HEIGHT, "ZIPIX");
    wm.setFramerate(30);

    // FMOD
    FMOD_SYSTEM *system;

    /* Création et initialisation d'un objet système */
    FMOD_System_Create(&system);
    FMOD_System_Init(system, 2, FMOD_INIT_NORMAL, NULL);

    FMOD_SOUND* background = NULL;
    FMOD_SOUND* firework = NULL;

    FMOD_RESULT check;

    check = FMOD_System_CreateSound(system, "../music/firework_explode_and_crackle.mp3", FMOD_CREATESAMPLE, 0, &firework);
    if (check != FMOD_OK)
    {
        fprintf(stderr, "Impossible de lire le fichier firework_explode_and_crackle.mp3\n");
        exit(EXIT_FAILURE);
    }
    check = FMOD_System_CreateSound(system, "../music/Timer.mp3", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &background);
    
    if (check != FMOD_OK)
    {
        fprintf(stderr, "Impossible de lire le fichier Timer.mp3\n");
        exit(EXIT_FAILURE);
    }
    
    FMOD_CHANNEL *backgroundChannel = NULL;
    FMOD_CHANNEL *fireworkChannel = NULL;
    FMOD_System_GetChannel(system, 0, &backgroundChannel);
    FMOD_System_GetChannel(system, 1, &fireworkChannel);
    FMOD_Sound_SetLoopCount(background, -1);


    FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, background, 0, &backgroundChannel);

    // Time
    time_t beginTime;
    time_t currentTime;
    time(&beginTime);

    // Managers and Renderer
    ParticleRenderer2D renderer;

    ParticleManager snakeManager;
    snakeManager.setHeadColor(glm::vec3(0.4f, 0.8f, 0.3f));
    ParticleManager redManager;
    redManager.setHeadColor(glm::vec3(0.9f, 0.4f, 0.3f));
    ParticleManager blueManager;
    blueManager.setHeadColor(glm::vec3(0.2f, 0.4f, 0.9f));

    ParticleManager foodManager;
    ParticleManager bonusManager;
    ParticleManager fireworkManager;

    ParticleManager autoManager;

    // Graph Forces
    GraphHookForce graphHook = GraphHookForce(1.f, 0.15f/4.f);
    GraphBrakeForce graphBrake = GraphBrakeForce(0.3f, 10.f); // 0.5 = viscosité max 
    
    GraphHookForce redGraphHook = GraphHookForce(1.f, 0.15f/4.f);
    GraphBrakeForce redGraphBrake = GraphBrakeForce(0.3f, 0.0001f);

    GraphHookForce blueGraphHook = GraphHookForce(1.f, 0.15f/4.f);
    GraphBrakeForce blueGraphBrake = GraphBrakeForce(0.3f, 0.0001f);

    // Box
    Polygon box = buildBox(glm::vec3(1.f, 1.f, 1.f), glm::vec2(-1.f, -1.f), 2, 2, true);

    // // Ajout des particules
    int id = foodManager.addRandomParticle(1);
    bonusManager.addParticle(1.5f, glm::vec2(0.5, 0.5), glm::vec2(0, 0), glm::vec2(0, 0), glm::vec3(0.619f, 0.05f, 0.25f));
    bonusManager.addParticle(1.5f, glm::vec2(-0.2, 0.6), glm::vec2(0, 0), glm::vec2(0, 0), glm::vec3(0.619f, 0.05f, 0.25f));
    bonusManager.addParticle(1.5f, glm::vec2(0.8, -0.7), glm::vec2(0, 0), glm::vec2(0, 0), glm::vec3(0.619f, 0.05f, 0.25f));
    bonusManager.addParticle(1.5f, glm::vec2(-0.7, -0.5), glm::vec2(0, 0), glm::vec2(0, 0), glm::vec3(0.619f, 0.05f, 0.25f));
    bonusManager.addParticle(1.5f, glm::vec2(0.3, -0.1), glm::vec2(0, 0), glm::vec2(0, 0), glm::vec3(0.619f, 0.05f, 0.25f));

    // Copy the food to the autoManager
    copyParticle(foodManager, autoManager, id);

    // Forces
    ConstantForce mg(glm::vec2(0.f, -0.005));

    // LeapfrogSolver
    LeapfrogSolver leapfrog;
    PolygonForce boxForce(box, 1.5f, leapfrog);

    // Snake's creation
    ParticleGraph snakeGraph = createString(glm::vec2(0.f, 0.0f), glm::vec2(0.f, -0.15f), glm::vec3(0.2f, 0.6f, 0.2f), glm::vec3(0.4f, 0.8f, 0.3f), 4.f, snakeManager);
    ParticleGraph redGraph = createString(glm::vec2(0.f, 0.2f), glm::vec2(0.15f, 0.2f), glm::vec3(0.9f, 0.2f, 0.2f), glm::vec3(0.9f, 0.4f, 0.3f), 4.f, redManager);
    ParticleGraph blueGraph = createString(glm::vec2(0.f, -0.2f), glm::vec2(-0.15f, -0.2f), glm::vec3(0.2f, 0.2f, 0.6f), glm::vec3(0.2f, 0.4f, 0.9f), 4.f, blueManager);

    copyParticle(snakeManager, autoManager, 0);
    copyParticle(redManager, autoManager, 0);
    copyParticle(blueManager, autoManager, 0);

//.........这里部分代码省略.........
开发者ID:eprana,项目名称:Zipix,代码行数:101,代码来源:main.cpp

示例3: addBonus

	// Create bonus
	void addBonus(ParticleManager& bonusManager) {
		bonusManager.removeParticle(0);
		bonusManager.addRandomParticle(1, ParticleManager::Type::P_BONUS);

	}
开发者ID:eprana,项目名称:Zipix,代码行数:6,代码来源:Game.cpp


注:本文中的ParticleManager::addRandomParticle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。