Advertisement
Gerson_Linky

A GD-Script to destroy your pieces

Jan 18th, 2020
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. const GRAVITY = 1
  2. const MAX_SPEED = 3
  3. const EXPLOSION_MIN_HEIGHT = GRAVITY * 1.2
  4. const EXPLOSION_MAX_HEIGHT = EXPLOSION_MIN_HEIGHT * 1.2
  5. const EXPLOSION_LARGER_OFFSET = 10
  6. const ACCELERATION_MODIFIER = .3
  7.  
  8. var force: Vector2
  9. var speed: Vector2
  10.  
  11. func _ready() -> void:
  12.    
  13.     set_process(false)
  14.  
  15.  
  16. func _process(delta: float) -> void:
  17.    
  18.     var acceleration: float = ACCELERATION_MODIFIER * delta
  19.     speed.y += GRAVITY
  20.     speed.x = lerp(speed.x, MAX_SPEED, acceleration)
  21.    
  22.     if force.y > GRAVITY:
  23.         speed.y = lerp(speed.y, MAX_SPEED, acceleration)
  24.        
  25.     else:
  26.         speed.y = lerp(speed.y, speed.y - force.y, acceleration)
  27.    
  28.     position += ((Vector2.DOWN * GRAVITY) + force) * speed
  29.    
  30.     force = Vector2(lerp(force.x, 0, acceleration), lerp(force.y, 0, acceleration))
  31.  
  32.  
  33. func destroy() -> void:
  34.    
  35.     $Tween.interpolate_property($Sprite, "modulate:a", modulate.a, modulate.a * .5, 1, Tween.TRANS_LINEAR)
  36.     $Tween.start()
  37.     $Sprite.z_index += 1
  38.     force = Vector2(
  39.         rand_range(-EXPLOSION_LARGER_OFFSET, EXPLOSION_LARGER_OFFSET),
  40.         -rand_range(EXPLOSION_MIN_HEIGHT, EXPLOSION_MAX_HEIGHT)
  41.     )
  42.     set_process(true)
  43.     matched = true
  44.  
  45.  
  46. func _on_VisibilityNotifier2D_screen_exited() -> void:
  47.     queue_free()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement