Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const GRAVITY = 1
- const MAX_SPEED = 3
- const EXPLOSION_MIN_HEIGHT = GRAVITY * 1.2
- const EXPLOSION_MAX_HEIGHT = EXPLOSION_MIN_HEIGHT * 1.2
- const EXPLOSION_LARGER_OFFSET = 10
- const ACCELERATION_MODIFIER = .3
- var force: Vector2
- var speed: Vector2
- func _ready() -> void:
- set_process(false)
- func _process(delta: float) -> void:
- var acceleration: float = ACCELERATION_MODIFIER * delta
- speed.y += GRAVITY
- speed.x = lerp(speed.x, MAX_SPEED, acceleration)
- if force.y > GRAVITY:
- speed.y = lerp(speed.y, MAX_SPEED, acceleration)
- else:
- speed.y = lerp(speed.y, speed.y - force.y, acceleration)
- position += ((Vector2.DOWN * GRAVITY) + force) * speed
- force = Vector2(lerp(force.x, 0, acceleration), lerp(force.y, 0, acceleration))
- func destroy() -> void:
- $Tween.interpolate_property($Sprite, "modulate:a", modulate.a, modulate.a * .5, 1, Tween.TRANS_LINEAR)
- $Tween.start()
- $Sprite.z_index += 1
- force = Vector2(
- rand_range(-EXPLOSION_LARGER_OFFSET, EXPLOSION_LARGER_OFFSET),
- -rand_range(EXPLOSION_MIN_HEIGHT, EXPLOSION_MAX_HEIGHT)
- )
- set_process(true)
- matched = true
- func _on_VisibilityNotifier2D_screen_exited() -> void:
- queue_free()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement