Advertisement
mainland_china

Light Code

Dec 18th, 2023 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Game Maker 3.60 KB | Source Code | 0 0
  1. ~flashlight
  2. -------------------------
  3. step event
  4. event_inherited();
  5.  
  6. obj_light_lamp.x = obj_player.x;
  7. obj_light_lamp.y = obj_player.y;
  8.  
  9. image_yscale = 100;
  10. image_xscale = 100;
  11. var pd = point_direction(x, y, mouse_x, mouse_y);
  12. var ad = angle_difference(image_angle, pd);
  13. image_angle -= min(abs(ad), 25) * sign(ad);
  14.  
  15. //Custom
  16. var cos_value = cos(current_time*0.00012 + xstart + ystart + random_range(-0.08,0.08));
  17. if (cos_value > 0.972)
  18. {
  19.     visible = false;
  20. }
  21. else
  22. {
  23.     visible = true;
  24. }
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. ~light torch, player light
  34. -------------------------
  35. create
  36. /// @description Initialize Values
  37.     depth = obj_light_torch.depth + 1;
  38.     //Set up Vertex
  39.     vertex_format_begin();
  40.     vertex_format_add_position();
  41.     vertex_format_add_color();
  42.     VertexFormat = vertex_format_end();
  43.  
  44.     VBuffer = vertex_create_buffer();
  45.    
  46.     //Set up Surface
  47.     image_initial_alpha = image_alpha;
  48.     light_radius = light_initial_radius;
  49.    
  50.     //Creating Surface
  51.     var circle_di = light_radius*2;
  52.     light_surf = surface_create( circle_di*1.25, circle_di*1.25);
  53.    
  54.     //Check if this one is a sprited light
  55.     if (sprite_index != -1)
  56.     {
  57.         light_initial_radius = max( sprite_get_height(sprite_index) * image_yscale, sprite_get_width(sprite_index) * image_xscale);
  58.         light_radius = light_initial_radius;
  59.     }
  60.    
  61.     //Light Values
  62.     Visible = true;
  63. --------------------------------
  64. draw event
  65. /// @description Alter
  66.  
  67. // Inherit the parent event
  68. event_inherited();
  69.  
  70. // Draw brilho
  71. gpu_set_blendmode(bm_add);
  72.    
  73.     //outside light
  74.     var v_radius = 20 * random_range(0.01, 2);
  75.     var v_alpha = 0.0025;
  76.    
  77.     draw_set_alpha(v_alpha);
  78.     draw_circle_color(x, y, v_radius, make_color_rgb(255, 238, 53), c_white, 0);
  79.    
  80.     //inside light
  81.     var v_radius = 20;
  82.     var v_alpha = 0.005 + random_range(0, 0.002);
  83.    
  84.     draw_set_alpha(v_alpha);
  85.     draw_circle_color(x, y, v_radius, make_color_rgb(255, 237, 178), c_white, 0);
  86.    
  87.     draw_set_alpha(1);
  88.  
  89.     if (irandom(4) == 1)
  90.     uls_set_light_alpha(self, 0.6 * random_range(0.8, 0.9))
  91.  
  92. gpu_set_blendmode(bm_normal);
  93. -------------------------------
  94. step event
  95. /// @description Insert description here
  96. // You can write your code in this editor
  97.  
  98. obj_light_torch.x = obj_player.x;
  99. obj_light_torch.y = obj_player.y + 3;
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112. ~enemy light, parent torch, copy draw event, then parent uls_light
  113. ---------------------------
  114. step event
  115. # Update the light's position to match the enemy's position
  116. obj_enemy_light.x = obj_enemy.x;
  117. obj_enemy_light.y = obj_enemy.y;
  118.  
  119. # Adjust the light's visibility and alpha value based on whether it's colliding with a wall
  120. image_alpha = fade_alpha;
  121. if (collision_circle(x, y, 32, obj_player, false, false)){
  122.  if (fade_alpha < 1) {
  123.      fade_alpha += 0.12;
  124.  }
  125.  visible = true;
  126. } else {
  127.  fade_alpha -= 0.12;
  128.  if (fade_alpha <= 0) {
  129.      visible = false;
  130.      fade_alpha = 0;
  131.  }
  132. }
  133. ---------------------------
  134. draw event
  135. /// @description Alter
  136.  
  137. // Inherit the parent event
  138. event_inherited();
  139.  
  140. // Draw brilho
  141. gpu_set_blendmode(bm_add);
  142.    
  143.     //outside light
  144.     var v_radius = 20 * random_range(0.01, 2);
  145.     var v_alpha = 0.0025;
  146.    
  147.     draw_set_alpha(v_alpha);
  148.     draw_circle_color(obj_enemy_light.x, obj_enemy_light.y, v_radius, make_color_rgb(255, 238, 53), c_white, 0);
  149.    
  150.     //inside light
  151.     var v_radius = 20;
  152.     var v_alpha = 0.005 + random_range(0, 0.002);
  153.    
  154.     draw_set_alpha(v_alpha);
  155.     draw_circle_color(obj_enemy_light.x, obj_enemy_light.y, v_radius, make_color_rgb(255, 237, 178), c_white, 0);
  156.    
  157.     draw_set_alpha(1);
  158.  
  159.     if (irandom(4) == 1)
  160.     uls_set_light_alpha(obj_enemy_light, 0.3 * random_range(0.8, 0.9))
  161.  
  162. gpu_set_blendmode(bm_normal);
  163. -----------------------------
  164.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement