コード例 #1
0
void NuevoNivel() {
	int prev_nivel = tiempo_nivel;
	tiempo_nivel += 20000;


	for (int n = 0;n < enemigos.size();n++) {
		enemigos[n].activo = true;
		enemigos[n].x = limites.right+1;
		enemigos[n].hp = 5;
		enemigos[n].material[0] = 1.0f;
		enemigos[n].material[1] = 1.0f;
		enemigos[n].material[2] = 1.0f;
		enemigos[n].material[3] = 1.0f;
		enemigos[n].disparos.clear();
		enemigos[n].ultimo_disparo = 0;
		enemigos[n].tiempo_disparo -= 20;
	}
	for (int n = 0;n < asteroides.size();n++) {
		asteroides[n].activo = true;
		asteroides[n].x = limites.right + 0.5;
		asteroides[n].hp = 5;
		asteroides[n].material[0] = 1.0f;
		asteroides[n].material[1] = 1.0f;
		asteroides[n].material[2] = 1.0f;
		asteroides[n].material[3] = 1.0f;
	}
	for (int n = 0;n < powerups.size();n++) {
		powerups[n].activo = true;
		powerups[n].x = limites.right + 0.5;
	}

	tex1 = SOIL_load_OGL_texture(
		"tex1.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO
	);

	tex2 = SOIL_load_OGL_texture(
		"tex2.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO
	);


	tex3 = SOIL_load_OGL_texture(
		"tex3.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_INVERT_Y
	);

	tex4 = SOIL_load_OGL_texture(
		"pantalla2.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO
	);

	tex5 = SOIL_load_OGL_texture(
		"pantalla1.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO
	);

	tex6 = SOIL_load_OGL_texture(
		"pantalla3.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO
	);

	srand(time(NULL));

	powerups.push_back(Powerup(limites.right +3, random(limites.bottom, limites.top), 0, 70, prev_nivel + randomTime(15000)));
	powerups.push_back(Powerup(limites.right +3, random(limites.bottom, limites.top), 50, 0, prev_nivel + randomTime(15000)));

	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), asteroideModel, 0.3));
	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), asteroideModel, 0.4));
	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), asteroideModel, 0.2));
	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), asteroideModel, 0.2));
	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), asteroideModel, 0.3));
	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), asteroideModel, 0.5));
	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), asteroideModel, 0.3));
	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), asteroideModel, 0.4));

	enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), enemigoModel));
	enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), enemigoModel));
	enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), enemigoModel));
	enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), enemigoModel));
	
	player.hp = 100;
	player.municiones = 100;

	ammo_length = limites.right * 2;
	hp_length = limites.right * 2;

	time_begin = glutGet(GLUT_ELAPSED_TIME);
	time_fin = time_begin + tiempo_nivel;

	player.x = limites.left / 2;
	player.y = 0;
	player.z = 1;
	

}
コード例 #2
0
void Init()
{
	glClearColor(1.0,1.0,1.0,1.0);
	glEnable(GL_ALPHA);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHT1);
	glEnable(GL_LIGHT2);
	glEnable(GL_LIGHTING);

	GLfloat lDiff[] = { 1.0f,1.0f,1.0f,1.0f };
	GLfloat lSpec[] = { 0.0f,0.0f,1.0f,1.0f };
	GLfloat lpos[] = { 0.0,2.5,0.0,1 };

	GLfloat lDiff1[] = { 1.0f,1.0f,1.0f,1.0f };
	GLfloat lSpec1[] = { 1.0f,0.0f,0.0f,1.0f };
	GLfloat lpos1[] = {0.0f,-2.5,1.0,1 };

	GLfloat lDiff2[] = { 1.0f,1.0f,1.0f,1.0f };
	GLfloat lSpec2[] = { 1.0f,0.0f,1.0f,1.0f };
	GLfloat lpos2[] = { 1.5f,0.0,1.0,1 };

	glLightfv(GL_LIGHT0, GL_DIFFUSE, lDiff);
	glLightfv(GL_LIGHT0, GL_SPECULAR, lSpec);
	glLightfv(GL_LIGHT0, GL_POSITION, lpos);

	glLightfv(GL_LIGHT1, GL_DIFFUSE, lDiff1);
	glLightfv(GL_LIGHT1, GL_SPECULAR, lSpec1);
	glLightfv(GL_LIGHT1, GL_POSITION, lpos1);

	glLightfv(GL_LIGHT2, GL_DIFFUSE, lDiff2);
	glLightfv(GL_LIGHT2, GL_SPECULAR, lSpec2);
	glLightfv(GL_LIGHT2, GL_POSITION, lpos2);
	

	tex1 = SOIL_load_OGL_texture(
		"tex1.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO
	);

	tex2 = SOIL_load_OGL_texture(
		"tex2.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO
	);


	tex3 = SOIL_load_OGL_texture(
		"tex3.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_INVERT_Y 
	);

	tex4 = SOIL_load_OGL_texture(
		"pantalla2.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO
		);

	tex5 = SOIL_load_OGL_texture(
		"pantalla1.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO
		);

	tex6 = SOIL_load_OGL_texture(
		"pantalla3.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_POWER_OF_TWO
		);

	player.model = glmReadOBJ("ship.obj");
	asteroideModel = glmReadOBJ("Asteroid.obj");
	enemigoModel = glmReadOBJ("rtm_metroid_v2.obj");

	time_begin = glutGet(GLUT_ELAPSED_TIME);

	srand(time(NULL));

	powerups.push_back(Powerup(limites.right +3, random(limites.bottom,limites.top), 0, 70, time_begin + randomTime(tiempo_nivel - 5000)));
	powerups.push_back(Powerup(limites.right +3, random(limites.bottom, limites.top), 50, 0, time_begin + randomTime(tiempo_nivel - 5000)));

	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000),asteroideModel,0.3));
	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), asteroideModel,0.4));
	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), asteroideModel, 0.3));
	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), asteroideModel, 0.5));
	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), asteroideModel, 0.3));
	asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), asteroideModel, 0.4));

	enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel-5000), enemigoModel));
	enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), enemigoModel));
	enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), enemigoModel));
	enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), enemigoModel));

	ammo_length = limites.right * 2;
	hp_length = limites.right * 2;

	time_fin = time_begin + tiempo_nivel;

	player.x = limites.left/2;
	player.y = 0;
	player.z = 1;

	glutReportErrors();
}
コード例 #3
0
char getIv(){
	char Iv=1;
	Iv*=randomTime();
	if (Iv!=0x13)Iv=Iv*0xa;
	return Iv;
}
コード例 #4
0
char getKey(){
	char Key=0;
	Key+=randomTime();
	if (Key!=0x12)Key=Key*4;
	return Key;
};
コード例 #5
0
ファイル: UnitTest.cpp プロジェクト: itsthejb/HotPants
  void UnitTest::run()
  {
    // local vars
    clock_t begin, end;
    double dur = 0.0;
    unsigned int overloadCount = 0;
    double total = 0.0;
    bool error = false;

    // data
    printf("HotPants Output Test\n");
    printf("--------------------\n");
    printf("Sampling rate = %.2fHz\n", s);
    printf("Wavetable length = %d\n", kTableLength);
    printf("Buffer size = %d\n\n", blockSize);

#ifdef EXPECT_NO_PARAM_CHANGES
    printf("Refresh checking is ON\n");
    printf("There should be no module refresh messages in this test\n\n");
#endif

    // instrument construction
    printf("Constructing instrument...");
    fflush(stdout);
    begin = clock();
    HotPantsCore c;
    printf(" done\n");
    printf("Object size is %lukb\n", sizeof(c) / kK);
    printf("Attempting start note without initialisation... ");
    if(!c.startNote(1, 10, 10)) {
      printf(" operation failed as expected\n");
    } else {
      printf(" ERROR: operation incorrectly succeeded!\n");
      exit(EXIT_FAILURE);
    }

    printf("Initialising instrument at sampling rate %.2f... ", s);
    c.initialise(s);
    end = clock();
    dur = static_cast<double>(end - begin) / CLOCKS_PER_SEC;
    printf("done\n");
    printf(">> TIME: %.2e secs\n", dur);

    // generate some notes
    printf("\nStarting and then stopping %d random notes\n", randomNotes);
    printf("Test runs %d times... ", noteCycles);
    fflush(stdout);
    srand(time(NULL));
    begin = clock();
    for(int j = 0; j < noteCycles; ++j)
    {
      // start notes
      for(int i = 0; i < randomNotes; ++i)
      {
        c.startNote(i, randomNote(), rand() % kMidiMaxVelocity);
      }
      // stop notes
      for(int i = 0; i < randomNotes; ++i)
      {
        c.stopNote(i);
      }
    }
    end = clock();
    printf(" done\n");
    // should now be zero active notes
    printf("Should now be ZERO active voices... ");
    fflush(stdout);
    assert(c._countActiveVoices() == 0);
    printf("OK\n");
    dur = static_cast<double>(end - begin) / CLOCKS_PER_SEC;
    printf(">> TIME: %.2e secs, %.2e s/note\n", dur, dur/randomNotes/noteCycles);

    if(reinit) {
      // reinitialise the instrument
      printf("\nRe-initialising the instrument at %.2fHz... ", 2*s);
      fflush(stdout);
      c.initialise(2 * s);
      printf("done\n");
    }

    // real notes
    printf("\nStarting buffer output test notes (x %d)... ", randomNotes);
    fflush(stdout);
    for(int i = 0; i < randomNotes; ++i)
    {
      c.startNote(i, randomNote(), rand() % kMidiMaxVelocity);
    }
    printf("done\n");

    printf("Rendering output...");
    float bufferL[blockSize] = { 0.0 };
    float bufferR[blockSize] = { 0.0 };

    c.render(bufferL, bufferR, blockSize);
    printf(" done\n");

    // check the output
    bool output = false;
    for(unsigned int i = 0; i < blockSize; ++i)
    {
      // overload check
      if(bufferL[i] > kAmpMax || bufferR[i] > kAmpMax)
        overloadCount++;

      if(bufferL[i] > 0.0) { output = true; total += bufferL[i]; }
      if(bufferR[i] > 0.0) { output = true; total += bufferR[i]; }
    }

    if(output)
    {
      if(display_buffer) {
        printf("Buffer contents:\n");
        for(unsigned int i = 0; i < blockSize; ++i) {
          printf("%3d :\t%.2e\t\t%.2e\n", i, bufferL[i], bufferR[i]);
        }
      } else {
        printf("Buffer produced output OK (+ve sum %.2e)\n", total);
        if(overloadCount) {
          printf("WARNING: Output produced %d overloaded frames\n", overloadCount);
          error = true;
        }
      }
    } else {
      printf(">> ERROR: NO AUDIBLE OUTPUT PRODUCED! <<\n");
      exit(EXIT_FAILURE);
    }

#ifdef SYNTH_SIMULATION
    int randRange = 10;
    printf("\nStopping all notes...");
    for(int i = 0; i < randomNotes; ++i)
    {
      c.stopNote(i);
    }
    printf("done\n");
#endif

#ifndef SYNTH_SIMULATION
    printf("\nDoing %d silent render cycles and timing, %d active notes... ",
        renderCycles, (int) c._countActiveVoices());
    fflush(stdout);
#else
    printf("\nSynth simulation test:\n----------------------\nDoing %d cycles with random notes and param changes\n", renderCycles);
    printf("Notes active at start of test = %d\n", (int) c._countActiveVoices());
#endif

    /*
     * Main test cycle
     */
    begin = clock();
    for(int i = 0; i < renderCycles; ++i)
    {
#ifdef SYNTH_SIMULATION
      printf("\n>> Cycle %d/%d:\n", i+1, renderCycles);

      // start random notes and set random parameters
      if(randomTime(randRange)) {
        int id = rand() % 10;
        MidiNote note = rand() % std::numeric_limits<uint8_t>::max();
        MidiVelocity v = rand() % kMidiMaxVelocity;
        printf("Trying to start a note with ID %d, Midi note %d, velocity %d... ", id, note, v);
        if(c.startNote(id, note, v))
          printf("OK\n");
        else
          printf("note pitch invalid or ID already active\n");
      }
      if(randomTime(randRange/2)) {
        int id = rand() % 10;
        printf("Trying to stop a note with id %d... ", id);

        if(c.stopNote(id))
          printf("OK\n");
        else
          printf("this ID isn't active\n");
      }
      if(true) {
        // always try parameters
        eParameter p = static_cast<eParameter>(rand() % kNumOfParams);
        const _parameterMap m = c.getParamMap(p);
        ParamValue v = randFPRange(m.maxValue, m.minValue);
        printf("Trying to set parameter %d with value %.2f... ", p, v);
        if(c.setParam(p, v))
          printf("OK\n");
        else
          printf("param invalid or value out of range\n");
      }
#endif

      c.render(bufferL, bufferR, blockSize);
    }

    end = clock();

#ifdef SYNTH_SIMULATION
    printf("\nTest complete.\n");
#else
    printf("Done\n");
#endif

    dur = static_cast<double>(end - begin) / CLOCKS_PER_SEC;
    printf("Notes active at end of test = %d\n", (int) c._countActiveVoices());
    printf(">> TIME: %.2e secs, %.2e secs/cycle\n\n", dur, dur/renderCycles);

    if(!error)
      printf("No errors encountered\n");

    printf("\bUnit Test main end\n\n");
    return;
  }