Пример #1
0
void renderParticles(tEmitter *emitter)
{
	if (emitter->particle != NULL)
	{
		tParticle* particle = emitter->particle;
		while (particle)
		{
			CORE_RenderCenteredSprite(particle->pos, 
				vmake(particle->radius , particle->radius ), particle->index);
			particle = particle->next;
		}
	}
}
Пример #2
0
int Main(void)
{
  // Load resources
  texsmallball  = CORE_LoadBmp("data/tyrian_ball.32.bmp"      , false);
  texcursor  = CORE_LoadBmp("data/cursor.bmp", false);
  
  initCursor();

  initParticlePool(MAX_PARTICLES);

  initEmmiter();

  // Set up rendering
  glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT); // Sets up clipping
  glClearColor( 0.0f, 0.1f, 0.3f, 0.0f );
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho( 0.0, SCR_WIDTH, 0.0, SCR_HEIGHT, 0.0, 1.0);
  glEnable(GL_TEXTURE_2D);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  DWORD start_tick= GetTickCount();

  while (!SYS_GottaQuit())
  {
    // Render
    glClear( GL_COLOR_BUFFER_BIT );
		
	CORE_RenderCenteredSprite(cursor->pos, 
				vmake(cursor->radius , cursor->radius ), cursor->index);

	//fixed substep
	float dt =1.0f/(substep*FPS);
	//add gravity
//	tVector emitterforces=vmake(0.0f,0.0f);
	tVector emitterforces= GRAVITY; //vmake(0,gravityForce);

	updateEmitter( myEmmiter, emitterforces, dt);

	applyDeflectors(myEmmiter);

	renderParticles(myEmmiter);

	SYS_Show();

	start_tick= GetTickCount();
    // Keypress!
	const float scale=2.0f;
    if (SYS_KeyPressed('O'))
    {
		if(cursor)cursor->pos.x-=1.0f*scale;
	}
    if (SYS_KeyPressed('P'))
    {
		if(cursor)cursor->pos.x+=1.0f*scale;
	}
    if (SYS_KeyPressed('Q'))
    {
		if(cursor)cursor->pos.y+=1.0f*scale;
	}
    if (SYS_KeyPressed('A'))
    {
		if(cursor)cursor->pos.y-=1.0f*scale;
	}
    if (SYS_KeyPressed('S'))
    {
		atractorScale*=1.1f;
		if( atractorScale > 1000.0f)atractorScale=1000.0f;
	}
    if (SYS_KeyPressed('W'))
    {
		atractorScale*=0.9f;
	}

    // Keep system running
    SYS_Pump();
    SYS_Sleep(17);
  }

  CORE_UnloadBmp(texsmallball);
  CORE_UnloadBmp(texcursor);

  destroyEmmmiter(myEmmiter);
  destroyParticlePool();
  destroyCursor();

  return 0;
}
int Main(void)
{
  // Load resources
  texsmallball  = CORE_LoadBmp("data/tyrian_ball.32.bmp"      , false);
  texcursor  = CORE_LoadBmp("data/cursor.bmp", false);
  
  initCursor();

  initParticlePool(MAX_PARTICLES);

  //checking pool
  //while(particlePool.current)
  //{
	 // particlePool.current=particlePool.current->next;
  //}
  //particlePool.current = particlePool.head->next;

  initEmmiter();

  //for (int i = 0; i < NUM_PARTICLES; i++)
  //{
		//float radius;
		//radius = 8.f;
		//particle[i]=particlePool.current;
		//particlePool.current=particlePool.current->next;
		//particle[i]->radius = radius;
		//particle[i]->mass = 1.f;
		//particle[i]->index = texsmallball;
		//particle[i]->pos = vmake(CORE_FRand(radius, SCR_WIDTH-radius), CORE_FRand(radius, SCR_HEIGHT-radius));
		//particle[i]->vel = vmake(CORE_FRand(-MAX_BALL_SPEED, +MAX_BALL_SPEED), CORE_FRand(-MAX_BALL_SPEED, +MAX_BALL_SPEED));
  //}


  // Set up rendering
  glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT); // Sets up clipping
  glClearColor( 0.0f, 0.1f, 0.3f, 0.0f );
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho( 0.0, SCR_WIDTH, 0.0, SCR_HEIGHT, 0.0, 1.0);
  glEnable(GL_TEXTURE_2D);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  DWORD start_tick= GetTickCount();

  while (!SYS_GottaQuit())
  {
    // Render
    glClear( GL_COLOR_BUFFER_BIT );
		
	CORE_RenderCenteredSprite(cursor->pos, 
				vmake(cursor->radius , cursor->radius ), cursor->index);

	//fixed substep
	float dt =1.0f/(substep*FPS);
	//adaptive substep
	//DWORD elapsed_ticks= GetTickCount()- start_tick;
	//float elapsed_dt= elapsed_ticks/TICKS_PER_SECOND;

	//float edt_dt = elapsed_dt/dt;
	//int ite = (int)edt_dt;
	//float lastdt= edt_dt - ite;

	tVector forces=vmake(0,-100.0f);

//	for( int i=0; i < ite; i++)
		updateEmitter( myEmmiter, forces, dt);

//	updateEmitter( myEmmiter, forces, lastdt);
	applyDeflectors(myEmmiter);

	renderParticles(myEmmiter);

	SYS_Show();

	start_tick= GetTickCount();
    // Keypress!
    if (SYS_KeyPressed('O'))
    {
		if(cursor)cursor->pos.x-=1.0f;;
	}
    if (SYS_KeyPressed('P'))
    {
		if(cursor)cursor->pos.x+=1.0f;;
	}
    if (SYS_KeyPressed('Q'))
    {
		if(cursor)cursor->pos.y+=1.0f;;
	}
    if (SYS_KeyPressed('A'))
    {
		if(cursor)cursor->pos.y-=1.0f;;
	}

    if (0)//SYS_KeyPressed('I'))
    {
		//start single ball at random
		float radius=16.f;
		GLuint texBall=texsmallball;
		float mass=1.0f;
		int index=(int)CORE_FRand(0, MAX_PARTICLES-1);

		//particle[index]->mass = mass;
		//particle[index]->index = texBall;
		//particle[index]->radius = radius;
	 //   particle[index]->pos = vmake(CORE_FRand(radius, SCR_WIDTH-radius), CORE_FRand(SCR_HEIGHT*.5f, SCR_HEIGHT-radius));
		//particle[index]->vel = vmake(0, 10);
	}
    if (0)//SYS_KeyPressed(' '))
    {
		//give an impulse to all balss

//      for (int i = 0; i < MAX_PARTICLES; i++)
//	  {
          //if (fabs(particle[i]->vel.x) < 0.1f)
          //  particle[i]->vel.x = CORE_FRand(-MAX_BALL_SPEED, +MAX_BALL_SPEED);
          //particle[i]->vel.y = CORE_FRand(0, JUMP_SPEED);
//	  }
    }
    if (0)//SYS_KeyPressed(VK_CONTROL))
    {
	  //reset all
		glClear( GL_COLOR_BUFFER_BIT );

  //    for (int i = 0; i < MAX_PARTICLES; i++)
	 // {
		//float radius=particle[i]->radius;
		//particle[i]->pos = vmake(CORE_FRand(radius, SCR_WIDTH-radius), CORE_FRand(radius, SCR_HEIGHT-radius));
		//particle[i]->vel = vmake(0, 10);
	 // }
	  SYS_Show();
	}
    // Keep system running
    SYS_Pump();
    SYS_Sleep(17);
  }

  CORE_UnloadBmp(texsmallball);
  CORE_UnloadBmp(texcursor);

  destroyEmmmiter(myEmmiter);
  destroyParticlePool();
  destroyCursor();

  return 0;
}
Пример #4
0
void Render()
{
	glClear(GL_COLOR_BUFFER_BIT);

	// Render background, only tiles within camera view
	int first_tile = (int)floorf(g_camera_offset / G_HEIGHT);
	for (int i = first_tile; i < first_tile + 2; i++)
	{
		vec2 pos = vsub(vadd(vmake(G_WIDTH / 2.0f, G_HEIGHT / 2.0f), vmake(0.f, (float)i * G_HEIGHT)), vmake(0.f, g_camera_offset)); // split up, what does it?
		vec2 size = vmake(G_WIDTH, G_HEIGHT);
		CORE_RenderCenteredSprite(pos, size, g_bkg);
	}

	// Draw entities
	for (int i = MAX_ENTITIES - 1; i >= 0; i--)
	{
		if (g_entities[i].type != E_NULL)
		{
			ivec2 size = CORE_GetBmpSize(g_entities[i].gfx);
			vec2 pos = g_entities[i].pos;
			pos.x = (float)((int)pos.x);
			pos.y = (float)((int)pos.y);

			if (g_entities[i].has_shadow) // renders shadows first
			{
				vec2 s_pos = vadd(vsub(pos, vmake(0.f, g_camera_offset)), vmake(0.f, -SHADOW_OFFSET));
				vec2 s_size = vmake(size.x * SPRITE_SCALE * g_entities[i].gfxscale * SHADOW_SCALE, size.y * SPRITE_SCALE * g_entities[i].gfxscale * SHADOW_SCALE);
				int s_texture = g_entities[i].gfx;
				rgba s_color = vmake(0.f, 0.f, 0.f, 0.4f);
				bool s_additive = g_entities[i].gfxadditive;
				CORE_RenderCenteredSprite(s_pos, s_size, s_texture, s_color, s_additive);
			}

			// Render not shadows
			vec2 offset_pos = vsub(pos, vmake(0.f, g_camera_offset)); // Adjust to where camera is at
			vec2 scaled_size = vmake(size.x * SPRITE_SCALE * g_entities[i].gfxscale, size.y * SPRITE_SCALE * g_entities[i].gfxscale);
			int texture = g_entities[i].gfx;
			rgba color = g_entities[i].color;
			bool additive = g_entities[i].gfxadditive;
			CORE_RenderCenteredSprite(offset_pos, scaled_size, texture, color, additive);
		}
	}

	if (g_gs != GS_VICTORY) // if not yet won
	{
		// Draw UI
		// The energy bar
		float energy_ratio = MAIN_SHIP.energy / MAX_ENERGY;
		vec2 e_bar_pos = vmake(ENERGY_BAR_W / 2.f, energy_ratio * ENERGY_BAR_H / 2.f);
		vec2 e_bar_size = vmake(ENERGY_BAR_W, ENERGY_BAR_H * energy_ratio);
		CORE_RenderCenteredSprite(e_bar_pos, e_bar_size, g_energy, COLOR_WHITE, true);

		// The fuel bar
		float fuel_ratio = MAIN_SHIP.fuel / MAX_FUEL;
		vec2 f_bar_pos = vmake(G_WIDTH - FUEL_BAR_W / 2.f, fuel_ratio * FUEL_BAR_H / 2.f);
		vec2 f_bar_size = vmake(FUEL_BAR_W, FUEL_BAR_H * fuel_ratio);
		CORE_RenderCenteredSprite(f_bar_pos, f_bar_size, g_fuel, COLOR_WHITE, true);

		// Draw how long you have lasted
		int num_chunks = (int)((g_current_race_pos / RACE_END) * MAX_CHUNKS);
		for (int i = 0; i < num_chunks; i++)
		{
			vec2 c_pos = vmake(G_WIDTH - 100.f, 50.f + i * 50.f);
			vec2 c_size = vmake(CHUNK_W, CHUNK_H);
			CORE_RenderCenteredSprite(c_pos, c_size, g_pearl);
		}
	}
}