PixelChipCode

GML Various 001

Sep 19th, 2024
86
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 4.47 KB | Source Code | 1 0
  1.  _____ _          _  _____ _     _        _____          _      
  2.  |  __ (_)        | |/ ____| |   (_)      / ____|        | |    
  3.  | |__) |__  _____| | |    | |__  _ _ __ | |     ___   __| | ___
  4.  |  ___/ \ \/ / _ \ | |    | '_ \| | '_ \| |    / _ \ / _` |/ _ \
  5.  | |   | |>  <  __/ | |____| | | | | |_) | |___| (_) | (_| |  __/
  6.  |_|   |_/_/\_\___|_|\_____|_| |_|_| .__/ \_____\___/ \__,_|\___|
  7.                                    | |                          
  8.                                    |_|                          
  9. = = = = = obj_sun_particle
  10.  
  11. // Create Event
  12. life = 0; // Initialize life of the particle to 0
  13. life_span = random_range(30, 100); // Set a random lifespan between 30 and 100 steps
  14.  
  15. direction = random(360); // Randomize direction of movement (0-360 degrees)
  16. speed = random_range(0.01, 0.1); // Randomize speed of the particle between 0.01 and 0.1
  17.  
  18. // Step Event
  19. life++; // Increase the particle's life by 1 step
  20. if (life > life_span) {
  21.     instance_destroy(); // Destroy the particle if it has lived longer than its lifespan
  22. }
  23.  
  24. = = = = = obj_sun_particle_emitter
  25.  
  26. // Step Event
  27. var random_angle = irandom_range(0, 359); // Generate a random angle in degrees
  28. var radians = degtorad(random_angle); // Convert the random angle to radians
  29.  
  30. // Calculate the position along the orbit with a radius of 30
  31. var orbit_x = 73 + 30 * cos(radians); // X position based on the random angle
  32. var orbit_y = 90 + 30 * sin(radians); // Y position based on the random angle
  33.  
  34. // Create 50 particles at the calculated orbit position
  35. repeat(50) {
  36.     instance_create_layer(orbit_x, orbit_y, "Instances", obj_sun_particle);
  37. }
  38.  
  39. // Slightly randomize the direction for variation in movement
  40. direction += random_range(-1, 1);
  41.  
  42. = = = = = obj_UI_dial
  43.  
  44. // Create event
  45. image_angle = 0; // Set the initial rotation of the sprite
  46. previous_mouse_angle = 0; // Store the previous mouse angle
  47. mouse_touching = false; // Flag to indicate if mouse is touching the sprite
  48.  
  49. // Step event
  50. if (point_distance(x, y, mouse_x, mouse_y) <= sprite_width / 2) {
  51.     // Mouse is touching the sprite
  52.     mouse_touching = true;
  53. } else {
  54.     // Mouse is not touching the sprite
  55.     mouse_touching = false;
  56. }
  57.  
  58. if (mouse_touching && mouse_check_button_pressed(mb_left)) {
  59.     // Calculate the angle between the sprite and the mouse position
  60.     previous_mouse_angle = point_direction(x, y, mouse_x, mouse_y);
  61. } else if (mouse_touching && mouse_check_button(mb_left)) {
  62.     // Calculate the angle of rotation based on the mouse movement
  63.     var mouse_angle = point_direction(x, y, mouse_x, mouse_y);
  64.     var drag_angle = angle_difference(mouse_angle, previous_mouse_angle);
  65.    
  66.     // Rotate the sprite by the drag angle
  67.     image_angle += drag_angle;
  68.    
  69.     // Store the current mouse angle as the previous mouse angle for the next step
  70.     previous_mouse_angle = mouse_angle;
  71. }
  72.  
  73. = = = = = obj_UI_slider
  74.  
  75. // Create event
  76. slider_x = 100; // Set the initial position of the slider
  77. slider_width = 100; // Set the width of the slider
  78. slider_height = 20; // Set the height of the slider
  79. slider_min = 0; // Set the minimum value of the slider
  80. slider_max = 100; // Set the maximum value of the slider
  81. slider_value = slider_min; // Set the initial value of the slider
  82. slider_dragging = false; // Set dragging flag to false
  83.  
  84. //Step event
  85. if (mouse_check_button_pressed(mb_left)) {
  86.    // Check if the mouse is over the slider
  87.    if (mouse_x > slider_x && mouse_x < slider_x + slider_width &&
  88.        mouse_y > y && mouse_y < y + slider_height) {
  89.       slider_dragging = true; // Set dragging flag to true
  90.    }
  91. } else if (mouse_check_button(mb_left)) {
  92.    // If dragging, update the slider value based on the mouse position
  93.    if (slider_dragging) {
  94.       var percent = (mouse_x - slider_x) / slider_width;
  95.       slider_value = clamp(slider_min + percent * (slider_max - slider_min), slider_min, slider_max);
  96.    }
  97. } else {
  98.    // Set dragging flag to false when mouse is released
  99.    slider_dragging = false;
  100. }
  101.  
  102. // Draw event
  103. draw_set_color(c_gray);
  104. draw_rectangle(slider_x, y, slider_x + slider_width, y + slider_height, false);
  105. draw_set_color(c_lime);
  106. var slider_percent = (slider_value - slider_min) / (slider_max - slider_min);
  107. //draw_rectangle(slider_x, y, slider_x + slider_width * slider_percent, y + slider_height, true); //fills bar
  108. draw_rectangle(slider_x + slider_width * slider_percent, y, slider_x + slider_width * slider_percent, y + slider_height, true);
  109.  
  110.  
  111. draw_text(10,10,slider_percent)
  112.  
  113.  
Advertisement
Add Comment
Please, Sign In to add comment