-
Notifications
You must be signed in to change notification settings - Fork 1
/
thinking_track.tscn
58 lines (41 loc) · 5.48 KB
/
thinking_track.tscn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
[gd_scene load_steps=7 format=1]
[ext_resource path="res://img/grad.png" type="Texture" id=1]
[ext_resource path="res://img/thinking_base.png" type="Texture" id=2]
[ext_resource path="res://thinking_track.tres" type="Animation" id=3]
[ext_resource path="res://music/bad.wav" type="Sample" id=4]
[sub_resource type="GDScript" id=1]
script/source = "extends Node2D\n\nsignal pressed_correct_key\nsignal pressed_wrong_key\nsignal completed_key_sequence\n\nvar IEMANJA_JUMPS = 7\nvar N_BUTTON = 4\nvar MAX_THOUGHT_VISIBLE = 5\nvar consumable_thoughts = null\nvar thought_scene\nvar vp_rect\n\nfunc _ready():\n\trandomize()\n\tthought_scene = load(\"res://thought.tscn\")\n\tset_process_input(true)\n\tvp_rect = get_viewport_rect()\n\nfunc _input(event):\n\tif consumable_thoughts != null:\n\t\tif event.is_action_released(\"thinking_button_0\"):\n\t\t\tif (consumable_thoughts.size() > 0):\n\t\t\t\tif(consumable_thoughts[0].get_key() == 0):\n\t\t\t\t\tconsume_thought()\n\t\t\t\telse:\n\t\t\t\t\temit_signal(\"pressed_wrong_key\")\n\t\t\t\t\tget_node(\"sample_player\").play(\"bad\")\n\t\t\t\t\tget_node(\"animation_player\").play(\"panic_animation\")\n\t\telif event.is_action_released(\"thinking_button_1\"):\n\t\t\tif (consumable_thoughts.size() > 0):\n\t\t\t\tif(consumable_thoughts[0].get_key() == 1):\n\t\t\t\t\tconsume_thought()\n\t\t\t\telse:\n\t\t\t\t\temit_signal(\"pressed_wrong_key\")\n\t\t\t\t\tget_node(\"sample_player\").play(\"bad\")\n\t\t\t\t\tget_node(\"animation_player\").play(\"panic_animation\")\n\t\telif event.is_action_released(\"thinking_button_2\"):\n\t\t\tif (consumable_thoughts.size() > 0):\n\t\t\t\tif(consumable_thoughts[0].get_key() == 2):\n\t\t\t\t\tconsume_thought()\n\t\t\t\telse:\n\t\t\t\t\temit_signal(\"pressed_wrong_key\")\n\t\t\t\t\tget_node(\"sample_player\").play(\"bad\")\n\t\t\t\t\tget_node(\"animation_player\").play(\"panic_animation\")\n\t\telif event.is_action_released(\"thinking_button_3\"):\n\t\t\tif (consumable_thoughts.size() > 0):\n\t\t\t\tif(consumable_thoughts[0].get_key() == 3):\n\t\t\t\t\tconsume_thought()\n\t\t\t\telse:\n\t\t\t\t\temit_signal(\"pressed_wrong_key\")\n\t\t\t\t\tget_node(\"sample_player\").play(\"bad\")\n\t\t\t\t\tget_node(\"animation_player\").play(\"panic_animation\")\n\nfunc randomize_n_thoughts(n_waves):\n\t\"\"\"\n\tReturn the number of thoughts\n\tdefines a static value based on n_waves and a dinamic one\n\tthe static is the minimal and the dinamic is a random sum\n\tto the static number\n\t\"\"\"\n\tvar static_value = int(n_waves/IEMANJA_JUMPS) + 2\n\tvar dinamic_value = static_value - 1\n\t\n\tif (n_waves <= 2):\n\t\treturn static_value\n\treturn static_value + randi()%dinamic_value\n\nfunc generate_new_thoughts(n_waves):\n\t\"\"\"\n\tCreate new thoughts instances and put them in\n\tthinking track\n\t\"\"\"\n\tvar n_thoughts = randomize_n_thoughts(n_waves)\n\t\n\tif consumable_thoughts == null:\n\t\tconsumable_thoughts = []\n\telse:\n\t\tconsumable_thoughts.clear()\n\t\n\tfor i in range(n_thoughts):\n\t\tvar new_thought = thought_scene.instance()\n\t\tif new_thought != null:\n\t\t\tvar k = randi()%N_BUTTON\n\t\t\tnew_thought.init(k)\n\t\t\tnew_thought.hide()\n\t\t\tadd_child(new_thought)\n\t\t\tconsumable_thoughts.push_back(new_thought)\n\t\telse:\n\t\t\tprint(\"new_thought is null!!\")\n\t\n\tput_thoughts_in_place()\n\nfunc put_thoughts_in_place():\n\t\"\"\"\n\twith a list of toughts, put them in place in\n\tthinking track, positioning the first in the bottom\n\tthe second above, etc\n\tand sprite.show() the thoughts\n\t\"\"\"\n\tvar n_thoughts_to_show = min(consumable_thoughts.size(), MAX_THOUGHT_VISIBLE)\n\t\n\tfor i in range(n_thoughts_to_show):\n\t\tvar thought = consumable_thoughts[i]\n\t\tvar k = thought.get_key()\n\t\t\n\t\t# x and y of thinking track\n\t\tvar x = 50*k + 5 + 23\n\t\tvar y = 288 - (50*i + 5) - 23\n\t\t\n\t\tthought.set_pos(Vector2(x, y))\n\t\tthought.set_opacity(1.0 - i*0.20)\n\t\tthought.show()\n\nfunc clear():\n\tif consumable_thoughts != null:\n\t\tfor thought in consumable_thoughts:\n\t\t\tremove_child(thought)\n\nfunc consume_thought():\n\t\"\"\"\n\tconsumes a thought\n\tremoves the front of the list and updates\n\t\"\"\"\n\tif consumable_thoughts.size() > 0:\n\t\tvar child = consumable_thoughts[0]\n\t\tremove_child(child)\n\t\tconsumable_thoughts.pop_front()\n\t\tput_thoughts_in_place()\n\t\temit_signal(\"pressed_correct_key\")\n\t\t\n\t\tif consumable_thoughts.size() <= 0:\n\t\t\temit_signal(\"completed_key_sequence\")"
[sub_resource type="SampleLibrary" id=2]
samples/bad = { "db":0.0, "pitch":1.0, "sample":ExtResource( 4 ) }
[node name="thinking_track" type="Node2D"]
script/script = SubResource( 1 )
[node name="thinking_track_bg" type="Sprite" parent="."]
transform/pos = Vector2( 102.921, 144.184 )
texture = ExtResource( 1 )
[node name="thinking_base" type="Sprite" parent="."]
transform/pos = Vector2( 102.518, 260.712 )
texture = ExtResource( 2 )
[node name="animation_player" type="AnimationPlayer" parent="."]
playback/process_mode = 1
playback/default_blend_time = 0.0
root/root = NodePath("..")
anims/panic_animation = ExtResource( 3 )
playback/active = true
playback/speed = 1.0
blend_times = [ ]
autoplay = ""
[node name="sample_player" type="SamplePlayer" parent="."]
config/polyphony = 1
config/samples = SubResource( 2 )
default/volume_db = 0.0
default/pitch_scale = 1.0
default/pan = 0.0
default/depth = 0.0
default/height = 0.0
default/filter/type = 0
default/filter/cutoff = 5000.0
default/filter/resonance = 1.0
default/filter/gain = 1.0
default/reverb_room = 2
default/reverb_send = 0.0
default/chorus_send = 0.0