spncryn

Animated flora

Jun 23rd, 2020
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// CREATE
  2. image_speed      = 0
  3. image_index      = floor(random(sprite_get_number(sprite_index)))
  4. // image_blend      = make_colour_rgb(98, 123, 61)
  5. #region Wind effects
  6. SWAY_INTENSITY = random_range(0.04, 0.07)
  7. SWAY_DURATION  = random_range(1.4, 1.7  ) * room_speed
  8. SWAY_DELTA     = 180 / SWAY_DURATION
  9. SWAY           = true
  10. SWAY_OFFSET    = sprite_get_width(sprite_index) * SWAY_INTENSITY
  11. STEP           = 0
  12.  
  13. ULX  = x - sprite_get_xoffset(sprite_index)
  14. ULY  = y - sprite_get_yoffset(sprite_index)
  15. URX  = x + sprite_get_width  (sprite_index) - sprite_get_xoffset(sprite_index)
  16. URY  = ULY
  17. LRX  = URX
  18. LRY  = y + sprite_get_height (sprite_index) - sprite_get_yoffset(sprite_index)
  19. LLX  = ULX
  20. LLY  = LRY
  21. TOPY = URY
  22. #endregion
  23.  
  24. /// STEP
  25. /// @description Wind effects
  26. if SWAY {
  27.     STEP ++
  28.     var deg = STEP * SWAY_DELTA;
  29.     ULY = TOPY - sin(degtorad(deg)) * SWAY_INTENSITY * sprite_get_height(sprite_index)
  30.     URY = TOPY + sin(degtorad(deg)) * SWAY_INTENSITY * sprite_get_height(sprite_index)
  31.     ULX = LLX  + sin(degtorad(deg)) * SWAY_OFFSET
  32.     URX = LRX  + sin(degtorad(deg)) * SWAY_OFFSET
  33.    
  34.     if STEP > SWAY_DURATION {
  35. //     SWAY = false
  36.        ULY  = lerp(ULY, TOPY, 0.15)
  37.        URY  = lerp(URY, ULY , 0.15)
  38.        ULX  = lerp(ULX, LLX , 0.15)
  39.        URX  = lerp(URX, LRX , 0.15)
  40.     }
  41. }
  42.  
  43. /// DRAW / script: draw_flora()
  44. draw_sprite_pos(sprite_index, image_index, ULX, ULY, URX, URY, LRX, LRY, LLX, LLY, image_alpha)
  45.  
  46. /// script: wind_collision()
  47. /// @desc This is called any time you want the grass to move. I use a collision with a wind object that passes over the entire room,
  48. ///       but you could just as easily put this script in a timer or alarm as well.
  49.  
  50. /// @func wind_collision(intensity)
  51. /// @arg0 int intensity (between 0 and 10)
  52. if not SWAY {
  53.     var SWAY_DEGREE = 0;
  54.     STEP = 0
  55.     SWAY = true
  56.     SWAY_INTENSITY = random_range(0.01, 0.02)
  57.     SWAY_OFFSET    = sprite_get_width(sprite_index) * SWAY_INTENSITY
  58.     SWAY_DURATION  = random_range(1.4, 1.7) * room_speed
  59.     SWAY_DEGREE    = wave(argument0, -0.5, SWAY_DURATION, SWAY_OFFSET)
  60.     SWAY_DELTA     = 180 / SWAY_DURATION * SWAY_DEGREE
  61. }
Add Comment
Please, Sign In to add comment