Init commit
This commit is contained in:
commit
a4452b69c4
59 changed files with 1259 additions and 0 deletions
43
Scripts/utils.gd
Normal file
43
Scripts/utils.gd
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
extends Node2D
|
||||
|
||||
func get_half_size(sprt: Node2D):
|
||||
var half_size: Vector2
|
||||
|
||||
if sprt is Sprite2D:
|
||||
half_size = (sprt.texture.get_size() * sprt.scale) / 2.0
|
||||
elif sprt is AnimatedSprite2D:
|
||||
var tex: Texture2D = sprt.sprite_frames.get_frame_texture(sprt.animation, 0)
|
||||
if tex:
|
||||
half_size = (tex.get_size() * sprt.scale) / 2.0
|
||||
else:
|
||||
half_size = Vector2.ZERO
|
||||
else:
|
||||
half_size = Vector2.ZERO
|
||||
|
||||
return half_size
|
||||
|
||||
func wrap_position(node: Node2D) -> void:
|
||||
var rect = node.get_viewport_rect()
|
||||
var pos = node.position
|
||||
var half_size = get_half_size(node)
|
||||
|
||||
# Horizontal wrap
|
||||
if pos.x < -half_size.x:
|
||||
pos.x = rect.size.x + half_size.x
|
||||
elif pos.x > rect.size.x + half_size.x:
|
||||
pos.x = -half_size.x
|
||||
|
||||
# Vertical wrap
|
||||
if pos.y < -half_size.y:
|
||||
pos.y = rect.size.y + half_size.y
|
||||
elif pos.y > rect.size.y + half_size.y:
|
||||
pos.y = -half_size.y
|
||||
|
||||
node.position = pos
|
||||
|
||||
func play_sound(sound: Resource, parent: Node2D):
|
||||
var player = AudioStreamPlayer.new()
|
||||
parent.add_child(player)
|
||||
player.stream = sound
|
||||
player.play()
|
||||
player.finished.connect(func(): player.queue_free())
|
||||
Loading…
Add table
Add a link
Reference in a new issue