// Drawing a line void DrawLine(int newx, int newy, int oldx, int oldy) { if(newx == oldx && newy == oldy) { DrawParticles(newx,newy); } else { float step = 1.0f / ((abs(newx-oldx)>abs(newy-oldy)) ? abs(newx-oldx) : abs(newy-oldy)); for (float a = 0; a < 1; a+=step) DrawParticles(a*newx+(1-a)*oldx,a*newy+(1-a)*oldy); } }
void Forward(float distance) { nMotorPIDSpeedCtrl[motorC] = mtrSpeedReg; nMotorPIDSpeedCtrl[motorB] = mtrSpeedReg; motor[motorC] = FORWARD_SPEED; motor[motorB] = FORWARD_SPEED; int timeLeft = (int) (distance*FORWARD_CONST/(float)FORWARD_SPEED); int timeToTravelEdge = timeLeft; float distPerTimeSplit = distance/timeToTravelEdge; int timeFor10cms = (int) (10*FORWARD_CONST/(float)FORWARD_SPEED); for (; timeLeft > TIME_SPLIT; timeLeft -= TIME_SPLIT) { Wait(); x+=cos(angle)*distPerTimeSplit; y+=sin(angle)*distPerTimeSplit; if (timeLeft % timeFor10cms == 0) { updateParticlesForward(); DrawParticles(); } //nxtDisplayStringAt(20, 40, "%f, %f", x, y); Draw(); } motor[motorC] = 0; motor[motorB] = 0; }
void Render() { UINT passes = 0; effect->Begin(&passes, 0); for(UINT i = 0; i < passes; ++i) { effect->BeginPass(i); if(i == 0) { device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); device->SetRenderTarget(0, renderTarget); device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); DrawParticles(); } else if(i == 1) { device->SetRenderTarget(0, orig); DrawRect(); } effect->EndPass(); } effect->End(); device->Present(NULL, NULL, NULL, NULL); }
/* * Animate() handles the animation and the redrawing of the * graphics window contents. */ static void Animate(void) { // Clear the redering window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the current matrix (Modelview) glLoadIdentity(); // Back off eight units to be able to view from the origin. glTranslatef ( 0.0, 0.0, 0.0); // Rotate the plane of the elliptic // (rotate the model's plane about the x axis by fifteen degrees) glRotatef( 0.0, 0.0, 0.0, 0.0 ); DrawBox(); DetectCollision(); DrawParticles(); // Flush the pipeline, and swap the buffers glFlush(); glutSwapBuffers(); if ( singleStep ) { spinMode = GL_FALSE; } glutPostRedisplay(); // Request a re-draw for animation purposes }
void CPowerMode::ShowParticles() { ::EnterCriticalSection(&m_cs); if(m_hAttachWnd != NULL) { ClearParticles(m_hAttachWnd); UpdateParticles(); DrawParticles(m_hAttachWnd); } ::LeaveCriticalSection(&m_cs); }
void RenderTick(SDL_Surface *screen, GameState *gs) { static const Uint32 bg_color = 0x666666; ClearSurfaceTo(screen, bg_color); DrawBoardGrids(screen, gs); DrawPuyos(screen, gs); DrawParticles(screen, gs->particles); DrawImpendingDoom(screen, gs); DrawWinnerBanner(screen, gs); DrawLoserBanner(screen, gs); }
void WindFlow::Draw() const { DrawParticles(); //for (Vector3 i : dashPositions) //{ // Vector3 top = i; // top.y = HeightMax; // Vector3 bottom = i; // bottom.y = HeightMin; // //DrawCapsule3D(bottom.ToVECTOR(), top.ToVECTOR(), parameter.radius, 10, 1, 1, 0); //} }
void Tornado::Draw() const { DrawParticles(); //Vector3 TopPos, BottomPos; //BottomPos = Matrix4::GetPosition(parameter.mat); //TopPos = BottomPos + velocity * 1000.0f; ////DrawCapsule3D((position + parameter.height).ToVECTOR(), position, parameter.radius, 20, Vector3::Red.ToColor(), Vector3::Red.ToColor(), false); //DrawFormatString(10, 70, GetColor(255, 255, 255), "TopPoint : %f %f %f", TopPos.x, TopPos.y, TopPos.z); //DrawFormatString(10, 90, GetColor(255, 255, 255), "BottomPoint: %f %f %f", BottomPos.x, BottomPos.y, BottomPos.z); //DrawFormatString(10, 130, GetColor(255, 255, 255), "isHit : %d", isHit); }
/*========================================================================= // Name: DrawScene() // Desc: Draws the whole scene! //=======================================================================*/ static void DrawScene() { char chScore[30], chLines[30], chLevel[30]; /* Black background */ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0,0,0)); DrawStars(); /* Starfield */ if (bCrazy) WriteText(font, 250, 30+(boxdraw.box_x), "Cr4zY m0d3!"); /* woo hoo! */ if (!bGameOver) { /* Draw border of the box */ PutRect(boxdraw.box_x-5, boxdraw.box_y-5, boxdraw.box_width + 2*5, boxdraw.box_height + 2*5, 150,150,150); PutRect(boxdraw.box_x, boxdraw.box_y, boxdraw.box_width, boxdraw.box_height, 90,90,90); DrawCluster(); /* Draw cluster */ sprintf(chScore, "%d", score); sprintf(chLines, "%d", lines); sprintf(chLevel, "%d", level); WriteText(font, 490, 80, "Score"); /* Show SCORE */ WriteText(font, 490, 105, chScore); WriteText(font, 495, 180, "Next"); /* Show NEXT piece */ DrawNextPiece(490, 220); WriteText(font, 490, 350, "Lines"); /* Show number of killed LINES */ WriteText(font, 490, 375, chLines); WriteText(font, 95, 350, "Level"); /* Show current LEVEL */ WriteText(font, 95, 375, chLevel); } DrawBox(); /* Draw box bricks */ DrawParticles(); if (bPause) WriteText(font, 265, 20, "- PAUSE -"); if (bGameOver && !bExplode) { WriteTextCenter(font, 120, "GAME OVER"); sprintf(chScore, "Your Score: %d", score); WriteTextCenter(font, 250, chScore); } SDL_Flip(screen); /* Let's flip! */ }
void RenderCommand::Execute( void ) const { switch ( type ) { case CommandType::DrawQuad: { DrawQuad( drawQuad ); } break; case CommandType::DrawModel: { DrawModel( drawModel ); } break; case CommandType::DrawParticles: { DrawParticles( drawParticles ); } break; case CommandType::Screenshot: { Screenshot( screenshot ); } break; default: { } break; } }
static void PlayGame() { Uint8 *keystate; int quit = 0; int turn; int prev_ticks = 0, cur_ticks = 0; /* for keeping track of timing */ int awaiting_respawn = 0; /* framerate counter variables */ int start_time, end_time; int frames_drawn = 0; /* respawn timer */ int respawn_timer = -1; prev_ticks = SDL_GetTicks(); start_time = time(NULL); /* Reset the score counters. */ player.score = 0; opponent.score = 0; /* Start sound playback. */ StartAudio(); StartMusic(); /* Start the music update thread. */ music_update_thread = SDL_CreateThread(UpdateMusicThread, NULL); if (music_update_thread == NULL) { printf("Unable to start music update thread.\n"); } /* Start the game! */ while ((quit == 0) && network_ok) { /* Determine how many milliseconds have passed since the last frame, and update our motion scaling. */ prev_ticks = cur_ticks; cur_ticks = SDL_GetTicks(); time_scale = (double)(cur_ticks-prev_ticks)/30.0; /* Update SDL's internal input state information. */ SDL_PumpEvents(); /* Grab a snapshot of the keyboard. */ keystate = SDL_GetKeyState(NULL); /* Lock the mutex so we can access the player's data. */ SDL_LockMutex(player_mutex); /* If this is a network game, take note of variables set by the network thread. These are handled differently for a scripted opponent. */ if (opponent_type == OPP_NETWORK) { /* Has the opponent respawned? */ if (network_opponent_respawn) { printf("Remote player has respawned.\n"); opponent.shields = 100; network_opponent_respawn = 0; awaiting_respawn = 0; } /* Has the local player been hit? */ if (local_player_hit) { local_player_hit--; player.shields -= PHASER_DAMAGE; ShowPhaserHit(&player); /* No need to check for death, the other computer will tell us. */ } } /* Update phasers. */ player.firing -= time_scale; if (player.firing < 0) player.firing = 0; opponent.firing -= time_scale; if (opponent.firing < 0) opponent.firing = 0; ChargePhasers(&player); /* If the local player is destroyed, the respawn timer will start counting. During this time the controls are disabled and explosion sequence occurs. */ if (respawn_timer >= 0) { respawn_timer++; if (respawn_timer >= ((double)RESPAWN_TIME / time_scale)) { respawn_timer = -1; InitPlayer(&player); /* Set the local_player_respawn flag so the network thread will notify the opponent of the respawn. */ local_player_respawn = 1; SetStatusMessage("GOOD LUCK, WARRIOR!"); } } /* Respond to input and network events, but not if we're in a respawn. */ if (respawn_timer == -1) { if (keystate[SDLK_q] || keystate[SDLK_ESCAPE]) quit = 1; /* Left and right arrow keys control turning. */ turn = 0; if (keystate[SDLK_LEFT]) turn += 10; if (keystate[SDLK_RIGHT]) turn -= 10; /* Forward and back arrow keys activate thrusters. */ player.accel = 0; if (keystate[SDLK_UP]) player.accel = PLAYER_FORWARD_THRUST; if (keystate[SDLK_DOWN]) player.accel = PLAYER_REVERSE_THRUST; /* Spacebar fires phasers. */ if (keystate[SDLK_SPACE]) { if (CanPlayerFire(&player)) { FirePhasers(&player); /* If it's a hit, either notify the opponent or exact the damage. Create a satisfying particle burst. */ if (!awaiting_respawn && CheckPhaserHit(&player,&opponent)) { ShowPhaserHit(&opponent); DamageOpponent(); /* If that killed the opponent, set the "awaiting respawn" state, to prevent multiple kills. */ if (opponent.shields <= 0 && opponent_type == OPP_NETWORK) awaiting_respawn = 1; } } } /* Turn. */ player.angle += turn * time_scale; if (player.angle < 0) player.angle += 360; if (player.angle >= 360) player.angle -= 360; /* If this is a network game, the remote player will tell us if we've died. Otherwise we have to check for failed shields. */ if (((opponent_type == OPP_NETWORK) && local_player_dead) || (player.shields <= 0)) { printf("Local player has been destroyed.\n"); local_player_dead = 0; /* Kaboom! */ KillPlayer(); /* Respawn. */ respawn_timer = 0; } } /* If this is a player vs. computer game, give the computer a chance. */ if (opponent_type == OPP_COMPUTER) { if (RunGameScript() != 0) { fprintf(stderr, "Ending game due to script error.\n"); quit = 1; } /* Check for phaser hits against the player. */ if (opponent.firing) { if (CheckPhaserHit(&opponent,&player)) { ShowPhaserHit(&player); player.shields -= PHASER_DAMAGE; /* Did that destroy the player? */ if (respawn_timer < 0 && player.shields <= 0) { KillPlayer(); respawn_timer = 0; } } } ChargePhasers(&opponent); UpdatePlayer(&opponent); } /* Update the player's position. */ UpdatePlayer(&player); /* Update the status information. */ SetPlayerStatusInfo(player.score, player.shields, player.charge); SetOpponentStatusInfo(opponent.score, opponent.shields); /* Make the camera follow the player (but impose limits). */ camera_x = player.world_x - SCREEN_WIDTH/2; camera_y = player.world_y - SCREEN_HEIGHT/2; if (camera_x < 0) camera_x = 0; if (camera_x >= WORLD_WIDTH-SCREEN_WIDTH) camera_x = WORLD_WIDTH-SCREEN_WIDTH-1; if (camera_y < 0) camera_y = 0; if (camera_y >= WORLD_HEIGHT-SCREEN_HEIGHT) camera_y = WORLD_HEIGHT-SCREEN_HEIGHT-1; /* Update the particle system. */ UpdateParticles(); /* Keep OpenAL happy. */ UpdateAudio(&player, &opponent); /* Redraw everything. */ DrawBackground(screen, camera_x, camera_y); DrawParallax(screen, camera_x, camera_y); DrawParticles(screen, camera_x, camera_y); if (opponent.firing) DrawPhaserBeam(&opponent, screen, camera_x, camera_y); if (player.firing) DrawPhaserBeam(&player, screen, camera_x, camera_y); if (respawn_timer < 0) DrawPlayer(&player); if (!awaiting_respawn) DrawPlayer(&opponent); UpdateStatusDisplay(screen); /* Release the mutex so the networking system can get it. It doesn't stay unlocked for very long, but the networking system should still have plenty of time. */ SDL_UnlockMutex(player_mutex); /* Flip the page. */ SDL_Flip(screen); frames_drawn++; } end_time = time(NULL); if (start_time == end_time) end_time++; /* Display the average framerate. */ printf("Drew %i frames in %i seconds, for a framerate of %.2f fps.\n", frames_drawn, end_time-start_time, (float)frames_drawn/(float)(end_time-start_time)); /* Terminate the music update thread. */ if (music_update_thread != NULL) { SDL_KillThread(music_update_thread); music_update_thread = NULL; } /* Stop audio playback. */ StopAudio(); StopMusic(); }
void GLUTRedraw(void) { // Initialize OpenGL drawing modes glEnable(GL_LIGHTING); glDisable(GL_BLEND); glBlendFunc(GL_ONE, GL_ZERO); glDepthMask(true); // Clear window R3Rgb background = scene->background; glClearColor(background[0], background[1], background[2], background[3]); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Load camera LoadCamera(&camera); // Load scene lights LoadLights(scene); // Draw scene camera DrawCamera(scene); // Draw scene lights DrawLights(scene); // Draw particles DrawParticles(scene); // Draw particle sources DrawParticleSources(scene); // Draw particle sinks DrawParticleSinks(scene); // Draw particle springs DrawParticleSprings(scene); // Draw scene surfaces if (show_faces) { glEnable(GL_LIGHTING); DrawScene(scene); } // Draw scene edges if (show_edges) { glDisable(GL_LIGHTING); glColor3d(1 - background[0], 1 - background[1], 1 - background[2]); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); DrawScene(scene); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } // Save image if (save_image) { char image_name[256]; static int image_number = 1; for (;;) { sprintf(image_name, "image%d.jpg", image_number++); FILE *fp = fopen(image_name, "r"); if (!fp) break; else fclose(fp); } GLUTSaveImage(image_name); printf("Saved %s\n", image_name); save_image = 0; } // Save video if (save_video) { char frame_name[512]; static int next_frame = 0; static int num_frames_recorded = 0; for (;;) { sprintf(frame_name, "%sframe%04d.jpg", video_prefix, next_frame++); FILE *fp = fopen(frame_name, "r"); if (!fp) break; else fclose(fp); } GLUTSaveImage(frame_name); if (next_frame % 100 == 1) { printf("Saved %s\n", frame_name); } if (num_frames_to_record == ++num_frames_recorded) { save_video = 0; printf("Recorded %d frames, stopping as instructed.\n", num_frames_recorded); quit = 1; } } // Quit here so that can save image before exit if (quit) { if (output_image_name) GLUTSaveImage(output_image_name); GLUTStop(); } // Swap buffers glutSwapBuffers(); }
void Draw( double t ) { double xpos, ypos, zpos, angle_x, angle_y, angle_z; static double t_old = 0.0; float dt; // Calculate frame-to-frame delta time dt = (float)(t-t_old); t_old = t; // Setup viewport glViewport( 0, 0, width, height ); // Clear color and Z-buffer glClearColor( 0.1f, 0.1f, 0.1f, 1.0f ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Setup projection glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 65.0, (double)width/(double)height, 1.0, 60.0 ); // Setup camera glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); // Rotate camera angle_x = 90.0 - 10.0; angle_y = 10.0 * sin( 0.3 * t ); angle_z = 10.0 * t; glRotated( -angle_x, 1.0, 0.0, 0.0 ); glRotated( -angle_y, 0.0, 1.0, 0.0 ); glRotated( -angle_z, 0.0, 0.0, 1.0 ); // Translate camera xpos = 15.0 * sin( (M_PI/180.0) * angle_z ) + 2.0 * sin( (M_PI/180.0) * 3.1 * t ); ypos = -15.0 * cos( (M_PI/180.0) * angle_z ) + 2.0 * cos( (M_PI/180.0) * 2.9 * t ); zpos = 4.0 + 2.0 * cos( (M_PI/180.0) * 4.9 * t ); glTranslated( -xpos, -ypos, -zpos ); // Enable face culling glFrontFace( GL_CCW ); glCullFace( GL_BACK ); glEnable( GL_CULL_FACE ); // Enable lighting SetupLights(); glEnable( GL_LIGHTING ); // Enable fog (dim details far away) glEnable( GL_FOG ); glFogi( GL_FOG_MODE, GL_EXP ); glFogf( GL_FOG_DENSITY, 0.05f ); glFogfv( GL_FOG_COLOR, fog_color ); // Draw floor DrawFloor(); // Enable Z-buffering glEnable( GL_DEPTH_TEST ); glDepthFunc( GL_LEQUAL ); glDepthMask( GL_TRUE ); // Draw fountain DrawFountain(); // Disable fog & lighting glDisable( GL_LIGHTING ); glDisable( GL_FOG ); // Draw all particles (must be drawn after all solid objects have been // drawn!) DrawParticles( t, dt ); // Z-buffer not needed anymore glDisable( GL_DEPTH_TEST ); }
void InClassProj::DrawScene() { md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::White)); md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0); md3dImmediateContext->IASetInputLayout(Vertex::GetNormalTexVertLayout()); md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); XMVECTOR ambient = XMLoadFloat4(&mAmbientColour); XMVECTOR eyePos = XMVectorSet(m2DCam->GetPos().m128_f32[0], m2DCam->GetPos().m128_f32[1], m2DCam->GetPos().m128_f32[2], 0.0f); XMMATRIX proj = XMLoadFloat4x4(&mProj); XMMATRIX view = m2DCam->GetView(); mLitTexEffect->SetPerFrameParams(ambient, eyePos, mPointLight, mSpotLight); XMMATRIX vp = view * proj; vp = XMMatrixIdentity(); proj = XMLoadFloat4x4(&m2DProj); view = m2DCam->GetView(); vp = vp * view * proj; md3dImmediateContext->IASetInputLayout(Vertex::GetNormalTexVertLayout()); md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); float blendFactor[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; md3dImmediateContext->OMSetBlendState(mTransparentBS, blendFactor, 0xffffffff); md3dImmediateContext->OMSetDepthStencilState(mFontDS, 0); vp = XMMatrixIdentity(); proj = XMLoadFloat4x4(&m2DProj); view = m2DCam->GetView(); vp = vp * view * proj; mBG->Draw(vp, md3dImmediateContext, mLitTexEffect); //draw player if (isFacingRight) { mPlayer->SetScale(XMVectorSet(1.0f, 1.0f, 0.0f, 0.0f)); } else if (!isFacingRight) { mPlayer->SetScale(XMVectorSet(-1.0f, 1.0f, 0.0f, 0.0f)); } mPlayer->Draw(vp, md3dImmediateContext, mLitTexEffect); md3dImmediateContext->RSSetState(0); //draw enemies for (int i = 0; i < enemies.size(); ++i) { enemies[i]->Draw(vp, md3dImmediateContext, mLitTexEffect); //draw enemy health bars greenBarVec[i]->Draw(vp, md3dImmediateContext, mLitTexEffect); redBarVec[i]->Draw(vp, md3dImmediateContext, mLitTexEffect); } //draw arrow projectiles for (int i = 0; i < mProjectiles.size(); ++i) { mProjectiles[i]->Draw(vp, md3dImmediateContext, mLitTexEffect); } //draw end of level object if (EOLobjActive) { EOLobj->Draw(vp, md3dImmediateContext, mLitTexEffect); //EOLobj->Play(true); } DrawParticles(); md3dImmediateContext->OMSetDepthStencilState(0, 0); md3dImmediateContext->OMSetBlendState(0, blendFactor, 0xffffffff); //mFont->DrawFont(md3dImmediateContext, XMVectorSet(10.0f, 500.0f, 0.0f, 0.0f), 50, 75, 10, "Hi Brandon, you are a good student"); HR(mSwapChain->Present(1, 0)); }
static void PlayGame() { Uint8 *keystate; int quit = 0; int turn; int prev_ticks = 0, cur_ticks = 0; /* for keeping track of timing */ /* framerate counter variables */ int start_time, end_time; int frames_drawn = 0; /* Start audio playback. */ StartAudio(); StartMusic(); /* Start the music update thread. */ music_update_thread = SDL_CreateThread(UpdateMusicThread, NULL); if (music_update_thread == NULL) { printf("Unable to start music update thread.\n"); } prev_ticks = SDL_GetTicks(); start_time = time(NULL); while (quit == 0) { /* Determine how many milliseconds have passed since the last frame, and update our motion scaling. */ prev_ticks = cur_ticks; cur_ticks = SDL_GetTicks(); time_scale = (double)(cur_ticks-prev_ticks)/30.0; /* Update SDL's internal input state information. */ SDL_PumpEvents(); /* Grab a snapshot of the keyboard. */ keystate = SDL_GetKeyState(NULL); /* Respond to input. */ if (keystate[SDLK_q] || keystate[SDLK_ESCAPE]) quit = 1; /* Left and right arrow keys control turning. */ turn = 0; if (keystate[SDLK_LEFT]) turn += 15; if (keystate[SDLK_RIGHT]) turn -= 15; /* Forward and back arrow keys activate thrusters. */ player.accel = 0; if (keystate[SDLK_UP]) player.accel = PLAYER_FORWARD_THRUST; if (keystate[SDLK_DOWN]) player.accel = PLAYER_REVERSE_THRUST; /* Spacebar slows the ship down. */ if (keystate[SDLK_SPACE]) { player.velocity *= 0.8; } /* Just an amusing way to test the particle system. */ if (keystate[SDLK_e]) { CreateParticleExplosion( player.world_x, player.world_y, 255, 255, 255, 10, 300); CreateParticleExplosion( player.world_x, player.world_y, 255, 0, 0, 5, 100); CreateParticleExplosion( player.world_x, player.world_y, 255, 255, 0, 2, 50); } /* Allow a turn of four degrees per frame. */ player.angle += turn * time_scale; if (player.angle < 0) player.angle += 360; if (player.angle >= 360) player.angle -= 360; /* Update the player's position. */ UpdatePlayer(&player); UpdatePlayer(&opponent); /* Make the camera follow the player (but impose limits). */ camera_x = player.world_x - SCREEN_WIDTH/2; camera_y = player.world_y - SCREEN_HEIGHT/2; if (camera_x < 0) camera_x = 0; if (camera_x >= WORLD_WIDTH-SCREEN_WIDTH) camera_x = WORLD_WIDTH-SCREEN_WIDTH-1; if (camera_y < 0) camera_y = 0; if (camera_y >= WORLD_HEIGHT-SCREEN_HEIGHT) camera_y = WORLD_HEIGHT-SCREEN_HEIGHT-1; /* Update the particle system. */ UpdateParticles(); /* Keep OpenAL happy. */ UpdateAudio(&player, &opponent); /* Redraw everything. */ DrawBackground(screen, camera_x, camera_y); DrawParallax(screen, camera_x, camera_y); DrawParticles(screen, camera_x, camera_y); DrawPlayer(&player); DrawPlayer(&opponent); /* Flip the page. */ SDL_Flip(screen); frames_drawn++; } end_time = time(NULL); if (start_time == end_time) end_time++; /* Display the average framerate. */ printf("Drew %i frames in %i seconds, for a framerate of %.2f fps.\n", frames_drawn, end_time-start_time, (float)frames_drawn/(float)(end_time-start_time)); /* Terminate the music update thread. */ if (music_update_thread != NULL) { SDL_KillThread(music_update_thread); music_update_thread = NULL; } /* Stop audio playback. */ StopAudio(); StopMusic(); }
void CBE_ExplosionSmoke::Draw(CCopyEntity* pCopyEnt) { DrawParticles( pCopyEnt ); }
void GForce::RecordSample( long inCurTime ) { long intensity; float t; if ( &mPortA == mCurPort ) mCurPort = &mPortB; else mCurPort = &mPortA; // All the waveshape virtual machines are linked to our time index mT_MS = inCurTime - mT_MS_Base; mT = ( (float) inCurTime ) / 1000.0; // Don't bother doing mouse or kybd poll if sceeen saver mode is disabled if ( mScrnSaverDelay > 0 ) IdleMonitor(); ManageColorChanges(); ManageShapeChanges(); ManageFieldChanges(); ManageParticleChanges(); // Do the blur operation, a fcn of what's oqn the screen, and the current delta field if ( mCurPort == &mPortA ) mPortB.Fade( mPortA, mField -> GetField() ); else mPortA.Fade( mPortB, mField -> GetField() ); /* This redraws the image */ // Draw all the current particles DrawParticles( *mCurPort ); // Draw the current wave shape for the current music sample playing // If there's a morph going, drawing is a mix of both waves if ( mShapeTransTime > 0 ) { float morphPct = (float) ( mShapeTransEnd - mT_MS ) / ( (float) mShapeTransTime ); mWave -> Draw( mNum_S_Steps, *mCurPort, 1, mNextWave, morphPct ); } else mWave -> Draw( mNum_S_Steps, *mCurPort, 1, 0, 0 ); // If we're not currently drawing track text, check to see if we start new text if ( mTrackTextDur == 0 && mTrackTextPosMode ) { if ( mTrackTextStartFcn.Evaluate() > 0 ) StartTrackText(); } // If we already have a t.t. draw in progress, draw the text in the (full) foreground color if ( mTrackTextDur > 0 ) { // From 0 to 1, how far are we into the text display interval? t = ( mT - mTrackTextStartTime ) / mTrackTextDur; // Decrease the text intensity thru time intensity = 255 * ( 1.2 - .3*t ); if ( intensity > 255 ) intensity = 255; mCurPort -> SetTextColor( mPalette[ intensity ] ); mCurPort -> SetTrackTextFont(); mCurPort -> DrawText( mTrackTextPos.h, mTrackTextPos.v, mTrackText ); } // Draw the console text to the offscreen image. Then copy the image to the OS out port if ( mT_MS < mConsoleExpireTime ) { // To ensure the console text is readable, we erase it when we're done mCurPort -> SetTextMode( SRC_XOR ); mCurPort -> SetTextColor( mPalette[ 255 ] ); mCurPort -> SetConsoleFont(); DrawConsole(); DrawFrame(); mCurPort -> SetTextColor( mPalette[ 0 ] ); DrawConsole(); mCurPort -> SetTextMode( SRC_OR ); } else DrawFrame(); // We need to avoid text all bluring together so we overwrite the foreground text we just drew // with text of a lower intensity... if ( mTrackTextDur > 0 ) { // Is the text is about to expire? if not, continue drawing. if ( t <= 1 ) { intensity = 255.5 * pow( t, 1.5 ); mCurPort -> SetTextColor( mPalette[ intensity ] ); mCurPort -> SetTrackTextFont(); mCurPort -> DrawText( mTrackTextPos.h, mTrackTextPos.v, mTrackText ); } else { // The text's duration is up so turn the draw flag off mTrackTextDur = 0; } } // Maintain the frame rate mFrameCount++; if ( mT_MS - mFrameCountStart >= 1500 ) { mCurFrameRate = 10000 * mFrameCount / ( mT_MS - mFrameCountStart ); mFrameCountStart = mT_MS; mFrameCount = 0; } if ( mT_MS - mLastCursorUpdate > 3000 ) { mLastCursorUpdate = mT_MS; if ( IsFullscreen() ) EgOSUtils::HideCursor(); } }