//----------------------------------------------------------------------------- void ProcessInput() { /* //old if (SYS_KeyPressed(SYS_KEY_LEFT)) g_entities[MAINSHIP_ENTITY].vel.x = -HORIZONTAL_SHIP_VEL; else if (SYS_KeyPressed(SYS_KEY_RIGHT)) g_entities[MAINSHIP_ENTITY].vel.x = HORIZONTAL_SHIP_VEL; else g_entities[MAINSHIP_ENTITY].vel.x = 0.f;*/ bool left = SYS_KeyPressed(SYS_KEY_LEFT); bool right = SYS_KeyPressed(SYS_KEY_RIGHT); if (left && !right) { MAIN_SHIP.fuel = SAFESUB(MAIN_SHIP.fuel, TILT_FUEL_COST); // Steering consumes more fuel MAIN_SHIP.tilt -= SHIP_TILT_INC; // For sprite animation } if (right && !left) { MAIN_SHIP.fuel = SAFESUB(MAIN_SHIP.fuel, TILT_FUEL_COST); MAIN_SHIP.tilt += SHIP_TILT_INC; } if (!right && !left) { MAIN_SHIP.tilt *= (1.f - SHIP_TILT_FRICTION); } if (MAIN_SHIP.tilt <= -SHIP_MAX_TILT) MAIN_SHIP.tilt = -SHIP_MAX_TILT; if (MAIN_SHIP.tilt >= SHIP_MAX_TILT) MAIN_SHIP.tilt = SHIP_MAX_TILT; MAIN_SHIP.vel.x += MAIN_SHIP.tilt; MAIN_SHIP.vel.x *= (1.f - SHIP_HVEL_FRICTION); // Tilt animation float tilt = MAIN_SHIP.tilt; if (tilt < -0.6f * SHIP_MAX_TILT) MAIN_SHIP.gfx = g_ship_LL; else if (tilt < -0.2f * SHIP_MAX_TILT) MAIN_SHIP.gfx = g_ship_L; else if (tilt < 0.2f * SHIP_MAX_TILT) MAIN_SHIP.gfx = g_ship_C; else if (tilt < 0.6f * SHIP_MAX_TILT) MAIN_SHIP.gfx = g_ship_R; else MAIN_SHIP.gfx = g_ship_RR; }
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; }