[gd_scene load_steps=7 format=1]

[ext_resource path="res://image/ball.png" type="Texture" id=1]

[sub_resource type="CircleShape2D" id=1]

custom_solver_bias = 0.0
radius = 45.0

[sub_resource type="GDScript" id=2]

script/source = "extends RigidBody2D\n\nvar selfref = preload(\"res://bubble.tscn\");\nvar infected = false;\nvar selfSize = 45;\nvar explodeForce = 0.0;\nvar infectPower = 0;\nvar resistancePower = rand_range(5,15);\nexport var immunitet = false;\n\nfunc _ready():\n\tset_linear_damp(Globals.get(\"game_saver\").savedict.dumping);\n\tif(infected):\n\t\tget_node(\"deathAnimation\").play(\"death\");\n\t\tpass;\n\telse:\n\t\tGlobals.get(\"bubbles_counter\").add();\n\tif (immunitet):\n\t\tget_node(\"node/Sprite\").set_modulate(Color (0,0,1)) ;\n\tpass;\n\nfunc _exit_tree():\n\tif(!infected && !immunitet):\n\t\tGlobals.get(\"bubbles_counter\").decrease();\n\t\nfunc begin_exploding(force):\n\tif(!infected):\n\t\texplodeForce = force;\n\t\tinfected = true;\n\t\tif(!immunitet):\n\t\t\tGlobals.get(\"bubbles_counter\").addInfected();\n\t\t\tget_node(\"animation\").play(\"modulate\");\n\t\telse:\n\t\t\texplodeForce = min(explodeForce*2, 1000);\n\t\t\t_on_AnimationPlayer_finished();\n\nfunc _on_Panel_input_event( ev ):\n\tif(!infected && ev.type == InputEvent.MOUSE_BUTTON && ev.button_index == BUTTON_LEFT && !immunitet):\n\t\tif(ev.pressed):\n\t\t\tGlobals.set(\"curr_pressed_bubble\", self);\n\t\telse:\n\t\t\tclickInfect(Globals.get(\"last_energy_usage_power\"));\n\t\t\tGlobals.set(\"curr_pressed_bubble\", null);\n\nfunc clickInfect(val):\n\tinfectPower = Globals.get(\"game_saver\").savedict.infectPower;\n\tbegin_exploding(val);\n\tGlobals.get(\"bubbles_counter\").discardCombo();\n\tget_node(\"animation\").play(\"blums\");\n\nfunc initShape(size):\n\tselfSize = size;\n\t#remove_child(get_node(\"shape\"));\n\t\n\tvar newShape = CircleShape2D.new();\n\t#var newCollider = CollisionShape2D.new();\n\tget_node(\"shape\").set_shape(newShape);\n\tnewShape.set_radius(selfSize);\n\t#add_child(newCollider);\n\nfunc _on_bubble_body_enter( body ):\n\tif (infected && body extends selfref.instance().get_script()):\n\t\tif(body.resistancePower < infectPower || immunitet):\n\t\t\tbody.infectPower = infectPower - body.resistancePower;\n\t\t\tif(!body.immunitet):\n\t\t\t\tbody.immunitet=immunitet;\n\t\t\tbody.begin_exploding(explodeForce);\n\t\t\t\n\t\telse:\n\t\t\tbody.resistancePower -= infectPower;\n\tpass # replace with function body\n\n\nfunc _on_AnimationPlayer_finished():\n\tvar chunks = rand_range(5,10);\n\tif(selfSize > 5):\n\t\tfor i in range(chunks):\n\t\t\tvar newChild = selfref.instance();\n\t\t\tnewChild.infectPower = infectPower;\n\t\t\tnewChild.set_pos(Vector2(get_pos().x+rand_range(-selfSize, selfSize), get_pos().y+rand_range(-selfSize, selfSize)));\n\t\t\tnewChild.get_node(\"node\").set_scale(get_node(\"node\").get_scale()/chunks);\n\t\t\tvar explode = rand_range(explodeForce*2, explodeForce*5);\n\t\t\tif(randf(1) > 0.5):\n\t\t\t\texplode *= -1;\n\t\t\tnewChild.apply_impulse(Vector2(0,0), Vector2(rand_range(-explodeForce/10, explodeForce/10), explode).rotated(get_rot()));\n\t\t\tnewChild.initShape(selfSize/chunks*2);\n\t\t\tnewChild.get_node(\"node/Sprite\").set_texture(load(\"res://image/Wisp View1.png\"));\n\t\t\tnewChild.explodeForce = explodeForce;\n\t\t\tnewChild.infected = true;\n\t\t\tnewChild.immunitet = immunitet;\n\t\t\tget_parent().add_child(newChild);\n\t\t\n\tget_parent().remove_child(self);\n\tpass # replace with function body\n\nfunc _on_deathAnimation_finished():\n\tget_parent().remove_child(self);\n\tpass # replace with function body\n"

[sub_resource type="Animation" id=3]

resource/name = "death"
length = 3.0
loop = false
step = 0.1
tracks/0/type = "value"
tracks/0/path = NodePath("node/Sprite:transform/scale")
tracks/0/interp = 2
tracks/0/imported = false
tracks/0/keys = { "times":FloatArray( 0, 1, 3 ), "transitions":FloatArray( 1, 1, 1 ), "update":0, "values":[ Vector2( 1, 1 ), Vector2( 1, 1 ), Vector2( 0, 0 ) ] }

[sub_resource type="Animation" id=4]

length = 1.0
loop = false
step = 0.1
tracks/0/type = "value"
tracks/0/path = NodePath("node/Sprite:transform/scale")
tracks/0/interp = 2
tracks/0/imported = false
tracks/0/keys = { "times":FloatArray( 0, 0.05, 0.15, 0.3, 0.6, 1 ), "transitions":FloatArray( 1, 1, 1, 1, 1, 1 ), "update":0, "values":[ Vector2( 1, 1 ), Vector2( 0.85, 0.85 ), Vector2( 1.1, 1.1 ), Vector2( 1, 1 ), Vector2( 1, 1 ), Vector2( 1.5, 1.5 ) ] }
tracks/1/type = "value"
tracks/1/path = NodePath("node/Sprite:modulate")
tracks/1/interp = 1
tracks/1/imported = false
tracks/1/keys = { "times":FloatArray( 0, 1 ), "transitions":FloatArray( 1, 1 ), "update":0, "values":[ Color( 1, 1, 1, 1 ), Color( 1, 0, 0, 1 ) ] }

[sub_resource type="Animation" id=5]

length = 1.0
loop = false
step = 0.1
tracks/0/type = "value"
tracks/0/path = NodePath("node/Sprite:modulate")
tracks/0/interp = 1
tracks/0/imported = false
tracks/0/keys = { "times":FloatArray( 0, 1 ), "transitions":FloatArray( 1, 1 ), "update":0, "values":[ Color( 1, 1, 1, 1 ), Color( 1, 0, 0, 1 ) ] }

[node name="bubble" type="RigidBody2D"]

input/pickable = true
shapes/0/shape = SubResource( 1 )
shapes/0/transform = Matrix32( 1, 0, 0, 1, -0.291969, 0.291992 )
shapes/0/trigger = false
collision/layers = 1
collision/mask = 1
mode = 0
mass = 1.0
friction = 1.0
bounce = 0.0
gravity_scale = 1.0
custom_integrator = false
continuous_cd = 0
contacts_reported = 1
contact_monitor = true
sleeping = false
can_sleep = true
velocity/linear = Vector2( 0, 0 )
velocity/angular = 0.0
damp_override/linear = 2.0
damp_override/angular = -1.0
script/script = SubResource( 2 )
immunitet = false

[node name="shape" type="CollisionShape2D" parent="."]

transform/pos = Vector2( -0.291969, 0.291992 )
shape = SubResource( 1 )
trigger = false
_update_shape_index = 0

[node name="node" type="Node2D" parent="."]

[node name="Particles2D" type="Particles2D" parent="node"]

transform/scale = Vector2( 2, 2 )
z/z = -1
config/amount = 32
config/lifetime = 1.0
config/preprocess = 1.0
params/direction = 0.0
params/spread = 10.0
params/linear_velocity = 70.0
params/spin_velocity = 0.0
params/orbit_velocity = 0.0
params/gravity_direction = 0.0
params/gravity_strength = 9.8
params/radial_accel = 1.0
params/tangential_accel = 1.0
params/damping = 0.0
params/initial_angle = 0.0
params/initial_size = 3.0
params/final_size = 0.0
params/hue_variation = 0.0
params/anim_speed_scale = 1.0
params/anim_initial_pos = 0.0
randomness/direction = 0.1
randomness/spread = 0.1

[node name="Particles2D1" type="Particles2D" parent="node"]

transform/rot = 180.0
transform/scale = Vector2( 2, 2 )
z/z = -1
config/amount = 32
config/lifetime = 1.0
config/preprocess = 1.0
params/direction = 0.0
params/spread = 10.0
params/linear_velocity = 70.0
params/spin_velocity = 0.0
params/orbit_velocity = 0.0
params/gravity_direction = 0.0
params/gravity_strength = 9.8
params/radial_accel = 1.0
params/tangential_accel = 1.0
params/damping = 0.0
params/initial_angle = 0.0
params/initial_size = 3.0
params/final_size = 0.0
params/hue_variation = 0.0
params/anim_speed_scale = 1.0
params/anim_initial_pos = 0.0
randomness/direction = 0.1
randomness/spread = 0.1

[node name="Sprite" type="Sprite" parent="node"]

visibility/opacity = 0.7
transform/pos = Vector2( 2.5424, 1.10168 )
texture = ExtResource( 1 )
modulate = Color( 0.863708, 1, 0.207031, 1 )

[node name="Panel" type="Panel" parent="node"]

visibility/opacity = 0.0
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
margin/left = -29.0
margin/top = -30.0
margin/right = 31.0
margin/bottom = 28.0

[node name="deathAnimation" type="AnimationPlayer" parent="."]

playback/process_mode = 1
playback/default_blend_time = 0.0
root/root = NodePath("..")
anims/death = SubResource( 3 )
playback/active = true
playback/speed = 1.0
blend_times = [  ]
autoplay = ""

[node name="animation" type="AnimationPlayer" parent="."]

playback/process_mode = 1
playback/default_blend_time = 0.0
root/root = NodePath("..")
anims/blums = SubResource( 4 )
anims/modulate = SubResource( 5 )
playback/active = true
playback/speed = 1.0
blend_times = [  ]
autoplay = ""

[node name="sleepTimer" type="Timer" parent="."]

process_mode = 1
wait_time = 1.0
one_shot = true
autostart = false

[connection signal="body_enter" from="." to="." method="_on_bubble_body_enter"]

[connection signal="input_event" from="node/Panel" to="." method="_on_Panel_input_event"]

[connection signal="finished" from="deathAnimation" to="." method="_on_deathAnimation_finished"]

[connection signal="finished" from="animation" to="." method="_on_AnimationPlayer_finished"]

[connection signal="timeout" from="sleepTimer" to="." method="_on_sleepTimer_timeout"]


