Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create Event
- surface_mirror = -1;
- pool_size = 150; // Maximum number of particles
- active_particles = 0;
- particle_sprite = spr_sprite; //your sprite here
- // Animation speed controls
- min_speed = 0.3; // Minimum animation speed
- max_speed = 0.5; // Maximum animation speed
- // Initialize arrays for object pooling
- particle_active = array_create(pool_size, false);
- particle_x = array_create(pool_size, 0);
- particle_y = array_create(pool_size, 0);
- particle_scale = array_create(pool_size, 0);
- particle_angle = array_create(pool_size, 0);
- particle_frame = array_create(pool_size, 0);
- particle_speed = array_create(pool_size, 0);
- // Clean up Event
- if (surface_exists(surface_mirror)) {
- surface_free(surface_mirror);
- }
- // Step Event
- if (!surface_exists(surface_mirror)) {
- surface_mirror = surface_create(room_width, room_height);
- }
- // Spawn particles
- if (mouse_check_button(mb_left)) {
- repeat(4) {
- // Find inactive particle slot
- var slot = -1;
- for (var i = 0; i < pool_size; i++) {
- if (!particle_active[i]) {
- slot = i;
- break;
- }
- }
- if (slot != -1) {
- particle_active[slot] = true;
- particle_x[slot] = mouse_x;
- particle_y[slot] = mouse_y;
- particle_scale[slot] = random_range(0.5, 0.7);
- particle_angle[slot] = random(360);
- particle_frame[slot] = 0;
- particle_speed[slot] = random_range(min_speed, max_speed); // Using the new speed range
- active_particles++;
- }
- }
- }
- // Update particles
- for (var i = 0; i < pool_size; i++) {
- if (particle_active[i]) {
- // Update animation frame
- particle_frame[i] += particle_speed[i];
- // Check if animation is complete (17 frames in my animation but change it to however many yours has)
- if (particle_frame[i] >= 17) {
- particle_active[i] = false;
- active_particles--;
- particle_frame[i] = 0;
- }
- }
- }
- // Draw Event
- surface_set_target(surface_mirror);
- draw_clear_alpha(c_black, 0);
- // Draw all active particles
- for (var i = 0; i < pool_size; i++) {
- if (particle_active[i]) {
- draw_sprite_ext(
- particle_sprite,
- floor(particle_frame[i]),
- particle_x[i],
- particle_y[i],
- particle_scale[i],
- particle_scale[i],
- particle_angle[i],
- c_white,
- 1
- );
- }
- }
- surface_reset_target();
- // Draw the mirrored surfaces
- draw_surface_ext(surface_mirror, room_width, 0, -1, 1, 0, c_white, 1);
- draw_surface_ext(surface_mirror, 0, room_height, 1, -1, 0, c_white, 1);
- draw_surface_ext(surface_mirror, room_width, room_height, -1, -1, 0, c_white, 1);
- draw_surface(surface_mirror, 0, 0);
- //draw_text(10, 10, string(active_particles));
Advertisement
Add Comment
Please, Sign In to add comment