PixelChipCode

Gamemaker effects snippets

Oct 10th, 2024 (edited)
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.04 KB | Source Code | 0 0
  1. By oliver
  2. @pixelchipcode
  3.  
  4. Some random GML snippets for mini animations
  5.  
  6. = = = = = = = = = = Mini pixel typewriter effect
  7.  
  8. /// Create Event
  9. words = [];
  10. max_width = 35; // Adjusted for a 50px wide window with margins
  11. x_start = 10; // Starting X position for the "text"
  12. y_start = 15; // Starting Y position
  13. line_height = 3; // Adjusted for tighter lines as in the image
  14. word_gap = 1; // Space between blocks (1px gap)
  15. block_height = 1; // Height of each block
  16.  
  17. // Generating random word lengths between 2 to 5
  18. for (var i = 0; i < 60; i++) { // Increased number of words for more content
  19. var word_length = irandom_range(2, 5);
  20. array_push(words, word_length);
  21. }
  22.  
  23. word_index = 0;
  24. char_timer = 0;
  25. char_delay = 5; // Speed of typing effect
  26. pause_timer = 0;
  27. pause_duration = room_speed * 3; // Pause for 3 seconds (adjust as needed)
  28. is_paused = false;
  29. current_x = x_start;
  30. current_y = y_start;
  31.  
  32. /// Step Event
  33. if (!is_paused) {
  34. if (char_timer >= char_delay) {
  35. char_timer = 0;
  36.  
  37. if (word_index < array_length(words)) {
  38. word_index++;
  39. } else {
  40. // Start pause when all words are typed
  41. is_paused = true;
  42. pause_timer = 0;
  43. }
  44. }
  45. char_timer++;
  46. } else {
  47. // Handle pause
  48. pause_timer++;
  49. if (pause_timer >= pause_duration) {
  50. // Reset after pause
  51. is_paused = false;
  52. word_index = 0;
  53. current_x = x_start;
  54. current_y = y_start;
  55. }
  56. }
  57. // Draw Event
  58. draw_clear(c_black);
  59. draw_set_color(c_ltgray);
  60.  
  61. current_x = x_start;
  62. current_y = y_start;
  63.  
  64. for (var i = 0; i < word_index; i++) {
  65. var word_width = words[i];
  66.  
  67. // Check if it exceeds the max width for a new line
  68. if (current_x + word_width > x_start + max_width) {
  69. current_x = x_start;
  70. current_y += line_height;
  71. }
  72.  
  73. // Draw the block (representing a word)
  74. draw_rectangle(current_x, current_y, current_x + word_width - 1, current_y + block_height - 1, false);
  75.  
  76. // Move to the next block position, including the gap
  77. current_x += word_width + word_gap;
  78. }
  79.  
  80. = = = = = = = = = = Mini pixel soundwave erractic
  81.  
  82. /// Create Event
  83. width = 50;
  84. height = 50;
  85. bar_width = 1; // Width of each bar
  86. bar_gap = 1; // Gap between bars
  87. num_bars = floor(width / (bar_width + bar_gap));
  88. amplitudes = array_create(num_bars, 0);
  89. max_height = height / 4; // Maximum height of bars (from center)
  90. min_height = 2; // Minimum height of bars (from center)
  91. update_speed = 0.2;
  92. variance_factor = 0.7; // Controls the amount of height variance
  93.  
  94. /// Draw Event
  95. draw_clear(c_black);
  96. draw_set_color(c_white);
  97.  
  98. // Update amplitudes
  99. for (var i = 0; i < num_bars; i++) {
  100. var base_height = random_range(min_height, max_height);
  101. var variance = (max_height - min_height) * variance_factor;
  102. var target = base_height + random_range(-variance, variance);
  103. target = clamp(target, min_height, max_height);
  104. amplitudes[i] = lerp(amplitudes[i], target, update_speed);
  105. }
  106.  
  107. // Draw bars
  108. for (var i = 0; i < num_bars; i++) {
  109. var x1 = i * (bar_width + bar_gap);
  110. var y1 = height / 2 - amplitudes[i];
  111. var x2 = x1 + bar_width - 1;
  112. var y2 = height / 2 + amplitudes[i];
  113.  
  114. draw_rectangle(x1, y1, x2, y2, false);
  115. }
  116.  
  117. // Draw center line
  118. draw_set_color(c_gray);
  119. draw_line(0, height / 2, width, height / 2);
  120.  
  121. // Reset drawing color
  122. draw_set_color(c_white);
  123.  
  124. = = = = = = = = = = Mini pixel soundwave smooth
  125.  
  126. width = 50;
  127. height = 50;
  128. bar_width = 1; // Width of each bar
  129. bar_gap = 1; // Gap between bars
  130. num_bars = floor(width / (bar_width + bar_gap));
  131. amplitudes = array_create(num_bars, 0);
  132. max_height = height / 4; // Maximum height of bars (from center)
  133. min_height = 2; // Minimum height of bars (from center)
  134. update_speed = 0.1;
  135. time = 0;
  136. frequency = 0.2;
  137. wave_speed = 0.1;
  138.  
  139. /// Draw Event
  140. draw_clear(c_black);
  141. draw_set_color(c_white);
  142.  
  143. time += wave_speed;
  144.  
  145. // Update amplitudes
  146. for (var i = 0; i < num_bars; i++) {
  147. var wave = sin(time + i * frequency);
  148. var range = max_height - min_height;
  149. var target = min_height + (wave + 1) / 2 * range;
  150. amplitudes[i] = lerp(amplitudes[i], target, update_speed);
  151. }
  152.  
  153. // Draw bars
  154. for (var i = 0; i < num_bars; i++) {
  155. var x1 = i * (bar_width + bar_gap);
  156. var y1 = height / 2 - amplitudes[i];
  157. var x2 = x1 + bar_width - 1;
  158. var y2 = height / 2 + amplitudes[i];
  159.  
  160. draw_rectangle(x1, y1, x2, y2, false);
  161. }
  162.  
  163. // Draw center line
  164. draw_set_color(c_gray);
  165. draw_line(0, height / 2, width, height / 2);
  166.  
  167. // Reset drawing color
  168. draw_set_color(c_white);
  169.  
  170. = = = = = = = = = = Mini pixel radar
  171.  
  172. radius = 15;
  173. center_x = room_width / 2;
  174. center_y = room_height / 2;
  175. angle = 0;
  176. radar_speed = -2; // Clockwise movement
  177.  
  178. // Create blips (random locations within radar range)
  179. blips = [];
  180. for (var i = 0; i < 3; i++) { // Create 3 random blips
  181. var blip_angle = irandom_range(0, 360); // Random angle for each blip
  182. var blip_distance = irandom_range(5, 15); // Random distance from the center
  183. blips[i] = {
  184. x: center_x + lengthdir_x(blip_distance, blip_angle),
  185. y: center_y + lengthdir_y(blip_distance, blip_angle),
  186. alpha: 0 // Start with alpha at 0 (invisible)
  187. };
  188. }
  189.  
  190. // Clear the screen to black
  191. draw_clear(c_black);
  192.  
  193. // Draw the circle outline (the radar's range)
  194. draw_set_color(c_white);
  195. draw_circle(center_x, center_y, radius, true); // Outline, not filled
  196.  
  197. // Draw the rotating radar line
  198. angle += radar_speed; // Increment the angle to make the line rotate
  199. if (angle <= -360) angle = 0; // Reset the angle after a full rotation
  200. var line_x = center_x + lengthdir_x(radius, angle); // End X position of the radar line
  201. var line_y = center_y + lengthdir_y(radius, angle); // End Y position of the radar line
  202. draw_line(center_x, center_y, line_x, line_y); // Draw the radar sweeping line
  203.  
  204. // Draw the blips (make them appear when the radar line passes over)
  205. for (var i = 0; i < array_length(blips); i++) {
  206. var blip = blips[i];
  207. var blip_angle = point_direction(center_x, center_y, blip.x, blip.y);
  208. var angle_diff = abs(angle_difference(angle, blip_angle));
  209.  
  210. // Check if the radar line is close to the blip
  211. if (angle_diff < 5) {
  212. blip.alpha = 1; // Make the blip fully visible when the radar arm passes over it
  213. }
  214.  
  215. // Gradually fade out the blip
  216. if (blip.alpha > 0) {
  217. blip.alpha -= 0.02; // Slowly fade out over time
  218. draw_set_alpha(blip.alpha);
  219. draw_circle(blip.x, blip.y, 1, false); // Draw the fading blip
  220. draw_set_alpha(1); // Reset alpha after drawing the blip
  221. }
  222.  
  223. blips[i] = blip; // Update the blip in the array
  224. }
  225.  
  226. draw_point(room_width/2,room_height/2);
  227.  
  228. = = = = = = = = = = Static
  229.  
  230. ///Draw event
  231.  
  232. var scale=random(10);
  233. for (var i=0;i<128;i++){for(var j=0;j<128;j++){var n=(i* scale+j*scale*57)<<13^(i*scale+j*scale*57);var b=(1- ((n*(n*n*15731+789221)+ 1376312589)&0x7fffffff)/1073741824)*127.5+127.5; draw_point_color(i,j,make_color_rgb(b,b,b));}}
  234.  
Advertisement
Add Comment
Please, Sign In to add comment