void L_ExplosionEffect::howto_emit_particle(void) { static L_REAL radian; static int num_particles; static int j; num_particles = min_particles + rand() % (max_particles - min_particles + 1); for( j=0; j<num_particles; j++ ) { radian = L_RAND_REAL_2()*L_2PI; static L_REAL current_speed_dis; if(speed_dis == 0) current_speed_dis = 0; else current_speed_dis = ( L_RAND_REAL_1()*2.0f - 1.0f ) * speed_dis; CL_Vec2f v_t; linear_set2(v_t, explosion_level+current_speed_dis, radian ); create_particle(x_pos,y_pos,&v_t); } }
static void snow_move(void) { int i; if (!(rb->rand()%2)) create_particle(); for (i=0; i<NUM_PARTICLES; i++) { if (particle_exists(i)) { mylcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); #ifdef HAVE_LCD_BITMAP rb->lcd_fillrect(particles[i][0],particles[i][1], FLAKE_WIDTH,FLAKE_WIDTH); #else pgfx_drawpixel(particles[i][0],particles[i][1]); #endif mylcd_set_drawmode(DRMODE_SOLID); #ifdef HAVE_REMOTE_LCD if (particles[i][0] <= LCD_REMOTE_WIDTH && particles[i][1] <= LCD_REMOTE_HEIGHT) { rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); rb->lcd_remote_fillrect(particles[i][0],particles[i][1], FLAKE_WIDTH,FLAKE_WIDTH); rb->lcd_remote_set_drawmode(DRMODE_SOLID); } #endif switch ((rb->rand()%7)) { case 0: particles[i][0]++; break; case 1: particles[i][0]--; break; case 2: break; default: particles[i][1]++; break; } if (particle_exists(i)) #ifdef HAVE_LCD_BITMAP rb->lcd_mono_bitmap(flake,particles[i][0],particles[i][1], FLAKE_WIDTH,FLAKE_WIDTH); #else pgfx_drawpixel(particles[i][0],particles[i][1]); #endif #ifdef HAVE_REMOTE_LCD if (particles[i][0] <= LCD_REMOTE_WIDTH && particles[i][1] <= LCD_REMOTE_HEIGHT) { rb->lcd_remote_mono_bitmap(flake,particles[i][0],particles[i][1], FLAKE_WIDTH,FLAKE_WIDTH); } #endif } } }
void L_ShootingEffect::howto_emit_particle(void) { static L_REAL radian_t; static L_REAL current_speed_dis; static L_REAL width_t; static L_REAL x_shift; static L_REAL y_shift; static int j; shooting_angle_cache = shooting_vector.get_angle(); for(j=0;j<particle_per_period;j++) { // === shooting interval(angle) === if(angle_interval == 0) radian_t =0; else radian_t = ( L_RAND_REAL_1() - 0.5f ) * angle_interval; // === end === // === speed distortion === if(speed_dis == 0) current_speed_dis = 0; else current_speed_dis = ( L_RAND_REAL_1()*2.0f - 1.0f ) * speed_dis; // === end === // === shooting interval(width) === if(width_interval == 0) { x_shift = 0; y_shift = 0; } else { width_t = ( L_RAND_REAL_1() - 0.5f ) * width_interval; x_shift = width_t * L_SIN(shooting_angle_cache); y_shift = width_t * L_COS(shooting_angle_cache); } // === end === L_Vector v_t = shooting_vector; v_t.set2(shooting_magnitude_cache+current_speed_dis, shooting_angle_cache+radian_t); create_particle(x_pos+x_shift, y_pos+y_shift, &v_t); } }
void PlasmaBunch::propagate_bunch(){ int i; double actdn=dnb+dnrest; for(i=0;i<nb;i++){ xb[i][0]+=vb*dt; if(xb[i][0]>=L/2){ // goes out of the cell create_particle(i); actdn-=1; } } if(actdn<=1)dnrest=actdn; else{ int ncr=(int)actdn; dnrest=actdn-ncr; if(nb+ncr>limnb){ msg_error("Too many bunch particles: %d, adding %d?\n",nb,ncr); return; } for(i=0;i<ncr;i++){ create_particle(nb+i); } nb+=ncr; } }
void init_particles(int ***Flag,double dx,double dy,double dz,int imax,int jmax,int kmax,int ppc,struct particleline *Partlines){ int i,j,k; int pi = 0; /*todo multiple partlines*/ Partlines[pi].length = 0; Partlines[pi].Particles = create_particle(-1,-1,-1); for(i = 0; i <= imax+1; i++) { for(j = 0; j <= jmax+1; j++) { for(k = 0; k <= kmax+1; k++) { if(isfluid(Flag[i][j][k])){ add_cell_particles(&Partlines[pi], i, j, k,dx,dy,dz,ppc); } } } } }
void create_battleshot(int type, int ox, int oy, int dx, int dy, int delay, int sound) { const float tconst = 10.0; const float gravity = 0.9; _battleshot b; ox += -3 + rand()%6; oy += -3 + rand()%6; b.type = type; b.x = float(ox); b.y = float(oy); b.dx = float(dx); b.dy = float(dy); b.delay = delay; b.exists = true; b.time = int(tconst); b.sound = sound; b.playedsound = false; switch (type) { case B_CANNON: create_particle(ox, oy, P_SMOKE, WHITE); b.xv = float(dx - ox) / (tconst / 2); b.yv = float(dy - oy) / (tconst / 2); b.xa = 0; b.ya = 0; b.striplen = 3; b.start = ol::Rgba(1.0, 1.0, 1.0, 1.0); b.end = b.start; b.time /= 2; break; case B_BULLET: b.xv = float(dx - ox) / tconst; b.yv = float(dy - oy) / tconst; b.xa = 0; b.ya = 0; b.striplen = 3; b.start = ol::Rgba(1.0, 1.0, 0.0, 1.0); b.end = ol::Rgba(1.0, 1.0, 1.0, 1.0); break; case B_BALLISTIC: create_particle(ox, oy, P_SMOKE); b.xv = float(dx - ox) / (tconst * 2); b.yv = (float(dy - oy) / (tconst * 2)) + (-gravity * tconst); b.xa = 0; b.ya = gravity; b.striplen = 3; b.time *= 2; b.start = ol::Rgba(1.0, 1.0, 1.0, 1.0); b.end = ol::Rgba(0.0, 0.0, 0.0, 0.0); break; case B_NUKE: create_particle(ox, oy, P_SMOKE); b.xv = float(dx - ox) / (tconst * 4); b.yv = (float(dy - oy) / (tconst * 4)) + (-gravity * tconst); b.xa = 0; b.ya = gravity / 2; b.striplen = 3; b.time *= 4; b.start = ol::Rgba(1.0, 1.0, 1.0, 1.0); b.end = ol::Rgba(0.0, 0.0, 0.0, 0.0); break; case B_BALTRAIL: create_particle(ox, oy, P_SMOKE); b.xv = float(dx - ox) / (tconst * 2); b.yv = (float(dy - oy) / (tconst * 2)) + (-gravity * tconst); b.xa = 0; b.ya = gravity; b.striplen = 20; b.time *= 2; b.start = ol::Rgba(1.0, 1.0, 1.0, 1.0); b.end = ol::Rgba(0.0, 0.0, 0.0, 0.0); break; case B_ROCKET: create_particle(ox, oy, P_SMOKE); b.xv = float(dx - ox) / (tconst * 2); b.yv = float(dy - oy) / (tconst * 2); b.xa = 0; b.ya = 0; b.striplen = 5; b.time *= 2; b.start = ol::Rgba(1.0, 1.0, 0.0, 1.0); b.end = ol::Rgba(1.0, 0.0, 0.0, 0.5); break; case B_BOMB: b.xv = float(dx - ox) / tconst; b.yv = float(dy - oy) / tconst; b.xa = 0; b.ya = gravity / 4; b.striplen = 2; b.start = ol::Rgba(0.8, 0.8, 0.8, 1.0); b.end = b.start; break; case B_TORPEDO: b.xv = float(dx - ox) / (tconst * 3); b.yv = float(dy - oy) / (tconst * 3); b.xa = 0; b.ya = 0; b.striplen = 10; b.start = ol::Rgba(1.0, 1.0, 1.0, 0.9); b.end = ol::Rgba(1.0, 1.0, 1.0, 0.0); b.time *= 3; break; case B_SNIPER: b.xv = float(dx - ox) / (tconst / 2); b.yv = float(dy - oy) / (tconst / 2); b.xa = 0; b.ya = 0; b.striplen = 6; b.start = ol::Rgba(1.0, 1.0, 1.0, 0.9); b.end = ol::Rgba(1.0, 1.0, 1.0, 0.0); b.time /= 2; break; } bshot.push_back(b); }
bool do_battleshots() { //returns true when finished bool alldone = true; unsigned int i = 0; float screenx, screeny; i = 0; while (i < bshot.size()) { if (bshot[i].exists) { alldone = false; if (bshot[i].delay > 0) { bshot[i].delay--; } else { if (!bshot[i].playedsound) { play_sound(bshot[i].sound); bshot[i].playedsound = true; } bshot[i].time--; bshot[i].x += bshot[i].xv; bshot[i].y += bshot[i].yv; bshot[i].xv += bshot[i].xa; bshot[i].yv += bshot[i].ya; screenx = bshot[i].x - (worldmap.scroll_x * MAP_TILE_SIZE) + worldmap.offset_x; screeny = bshot[i].y - (worldmap.scroll_y * MAP_TILE_SIZE) + worldmap.offset_y; if (bshot[i].strip.GetNumOfVertices() > bshot[i].striplen) { bshot[i].strip.DeleteLast(); } bshot[i].strip.AddToBegin(ol::Vec2D(screenx, screeny)); if (bshot[i].time <= 0) { //if the particle has finished, create different explosion effects switch(bshot[i].type) { case B_BALLISTIC: create_particle(int(bshot[i].x), int(bshot[i].y) + 6, P_SHOTHIT); break; case B_BOMB: create_particle(int(bshot[i].x) - 4 + rand()%8, int(bshot[i].y) - rand()%7, P_SHOTHIT); create_particle(int(bshot[i].x) - 4 + rand()%8, int(bshot[i].y) - rand()%7, P_SHOTHIT); create_particle(int(bshot[i].x) - 4 + rand()%8, int(bshot[i].y) - rand()%7, P_SHOTHIT); break; case B_TORPEDO: create_particle(int(bshot[i].x), int(bshot[i].y), P_SHOTHIT); break; case B_NUKE: create_particle(int(bshot[i].x), int(bshot[i].y), P_NUKEBOOM); break; } bshot[i].exists = false; play_sound(S_SHOTHIT1); } else { //or, if it's still going, create whatever movement-related particles it should have switch(bshot[i].type) { case B_TORPEDO: //create_particle(int(bshot[i].x), int(bshot[i].y), P_SEATRAIL); break; } } if (bshot[i].exists) { if (bshot[i].strip.GetNumOfVertices() > 1) { buffer_linestrip(&bshot[i].strip, bshot[i].start, bshot[i].end); } } if (bshot[i].type == B_NUKE) { buffer_rotate_sprite(glb.bmp(37), int(screenx), int(screeny), 64 + int(atan2(bshot[i].yv, bshot[i].xv) * 255 / (2 * AL_PI))); } } } i++; } if (alldone) { bshot.clear(); return true; } return false; }
struct mesh *init_thrust_mesh(int streaks, double h, double r1, double r2) { struct mesh *my_mesh = malloc(sizeof(*my_mesh)); if (!my_mesh) return my_mesh; memset(my_mesh, 0, sizeof(*my_mesh)); my_mesh->geometry_mode = MESH_GEOMETRY_PARTICLE_ANIMATION; my_mesh->nlines = streaks * 50; my_mesh->nvertices = my_mesh->nlines * 2; my_mesh->ntriangles = 0; my_mesh->t = 0; my_mesh->v = malloc(sizeof(*my_mesh->v) * my_mesh->nvertices); my_mesh->l = malloc(sizeof(*my_mesh->l) * my_mesh->nlines); my_mesh->tex = 0; my_mesh->radius = h; my_mesh->graph_ptr = 0; int maxparticle = streaks; struct particle particles[maxparticle]; int i; for (i = 0; i < maxparticle; i++) create_particle(h, r1, particles, i); int line_index = 0; while (1) { int one_is_active = 0; for (i = 0; i < maxparticle; i++) { if (!particles[i].active) continue; float x1 = particles[i].xpos; float y1 = particles[i].ypos; float z1 = particles[i].zpos; evolve_particle(h, particles, i); if (particles[i].lifetime < 0) { particles[i].active = 0; continue; } one_is_active = 1; float x2 = particles[i].xpos; float y2 = particles[i].ypos; float z2 = particles[i].zpos; int v_index = line_index * 2; my_mesh->v[v_index + 0].x = x1; my_mesh->v[v_index + 0].y = y1; my_mesh->v[v_index + 0].z = z1; my_mesh->v[v_index + 1].x = x2; my_mesh->v[v_index + 1].y = y2; my_mesh->v[v_index + 1].z = z2; my_mesh->l[line_index].start = &my_mesh->v[v_index + 0]; my_mesh->l[line_index].end = &my_mesh->v[v_index + 1]; my_mesh->l[line_index].flag = 0; my_mesh->l[line_index].additivity = 1.0; my_mesh->l[line_index].opacity = particles[i].lifetime; my_mesh->l[line_index].tint_color.red = 1.0; my_mesh->l[line_index].tint_color.green = 1.0; my_mesh->l[line_index].tint_color.blue = 1.0; my_mesh->l[line_index].time_offset = particles[i].offset; line_index++; if (line_index >= my_mesh->nlines) { one_is_active = 0; break; } } if (!one_is_active) break; } my_mesh->nlines = line_index; my_mesh->nvertices = line_index * 2; struct mesh *optimized_mesh = mesh_duplicate(my_mesh); mesh_free(my_mesh); return optimized_mesh; }
void L_DroppingEffect::howto_emit_particle(void) { create_particle(x_pos,y_pos); }