Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Firefly by @PixelChipCode
- // This code controls the movement and glow behavior of a firefly in GameMaker.
- // The firefly follows a Lissajous curve, which creates smooth, looping movement patterns
- // based on sine waves for both the x and y positions. Random values are assigned
- // to the amplitude, frequency, and phase shift of the curve to make each firefly's movement unique.
- // Additionally, the firefly exhibits a soft, glowing effect that fades in and out in cycles.
- // This glow is controlled by a timer, and each firefly's glow intensity and speed of fading
- // are randomized for a more natural and organic feel.
- // Create event
- // Store the origin position based on the spawn location (mouse)
- origin_x = x; // Set the initial x position to mouse_x when spawned
- origin_y = y; // Set the initial y position to mouse_y when spawned
- // Initialize Lissajous curve variables with random values
- amplitude_x = irandom_range(80, 150);
- amplitude_y = irandom_range(40, 100);
- frequency_x = irandom_range(2, 4);
- frequency_y = irandom_range(1, 3);
- phase_shift = random_range(0, 2 * pi);
- speed = random_range(0.001, 0.003);
- time = 0;
- // Glow variables
- glow_timer = 0; // Timer for the glow effect
- glow_duration = irandom_range(60, 120); // Random duration of the glow cycle (in frames)
- glow_intensity = 0; // Intensity of the glow (0 = off, 1 = full glow)
- glow_speed = random_range(0.01, 0.03); // How fast the glow fades in/out
- color = random_range(40,60);
- // Step event
- // Update time and calculate position based on the Lissajous curve
- time += speed;
- // Set x and y relative to the original spawn location (origin_x, origin_y)
- x = origin_x + amplitude_x * sin(frequency_x * time + phase_shift);
- y = origin_y + amplitude_y * sin(frequency_y * time);
- // Handle glow effect
- glow_timer += 1; // Increment the glow timer
- if (glow_timer < glow_duration / 2) {
- // Fade in glow (first half of the glow cycle)
- glow_intensity = min(glow_intensity + glow_speed, 1);
- } else {
- // Fade out glow (second half of the glow cycle)
- glow_intensity = max(glow_intensity - glow_speed, 0);
- }
- // Reset timer when the full glow cycle is complete
- if (glow_timer >= glow_duration) {
- glow_timer = 0;
- glow_duration = irandom_range(60, 120); // Set a new random duration for the next cycle
- }
- // Draw event
- // Set additive blending for the glow effect
- gpu_set_blendmode(bm_add);
- // Set the glow color to a more yellowy-green hue
- var glow_color = make_color_hsv(color, 255, 255); // Shifted hue to 65 for a more yellowy tone
- draw_set_color(glow_color);
- draw_set_alpha(glow_intensity); // Use the glow intensity to control the alpha
- // Draw the glowing firefly as a circle
- draw_circle(x, y, 2 * glow_intensity, false); // The size increases slightly with glow intensity
- // Reset blend mode to normal
- gpu_set_blendmode(bm_normal);
- // Reset color and alpha to default
- draw_set_color(c_white);
- draw_set_alpha(1);
- /////obj_firefly_spawner
- //step event
- if(mouse_check_button(mb_left)) {
- var firefly = instance_create_layer(mouse_x, mouse_y, "Instances", obj_firefly);
- // Set the origin manually, if needed
- firefly.origin_x = mouse_x;
- firefly.origin_y = mouse_y;
- }
- if(keyboard_check_pressed(ord("R"))){
- game_restart();
- }
Advertisement
Add Comment
Please, Sign In to add comment