From f5161186c7b2c6701906084860642d5400f0c011 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 5 Oct 2020 14:31:00 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9D=87=EF=B8=8F=20Add=20loop=20clock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Objects/Main.tscn | 40 +++++++++++++++++-------------- Objects/SpecialObjects/Clock.gd | 22 +++++++++++++++++ Objects/SpecialObjects/Clock.tscn | 37 ++++++++++++++++++++++++++++ project.godot | 7 ++++++ 4 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 Objects/SpecialObjects/Clock.gd create mode 100644 Objects/SpecialObjects/Clock.tscn diff --git a/Objects/Main.tscn b/Objects/Main.tscn index f131899..e5c73d5 100644 --- a/Objects/Main.tscn +++ b/Objects/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=11 format=2] +[gd_scene load_steps=12 format=2] [ext_resource path="res://Objects/SpecialObjects/Player.tscn" type="PackedScene" id=1] [ext_resource path="res://Objects/SpecialObjects/Conductor.tscn" type="PackedScene" id=2] @@ -9,6 +9,7 @@ [ext_resource path="res://Objects/ScrollingObjects/Loop.tscn" type="PackedScene" id=7] [ext_resource path="res://Objects/ScrollingObjects/Buttons/GameButton.tscn" type="PackedScene" id=8] [ext_resource path="res://Objects/ScrollingObjects/Buttons/GameButtonChain.tscn" type="PackedScene" id=9] +[ext_resource path="res://Objects/SpecialObjects/Clock.tscn" type="PackedScene" id=10] [ext_resource path="res://Objects/ScrollingObjects/Laser.tscn" type="PackedScene" id=11] [node name="Main" type="Node2D"] @@ -30,55 +31,55 @@ position = Vector2( 640, 700 ) position = Vector2( 360, 640 ) [node name="ScrollingBlock" parent="." instance=ExtResource( 6 )] -position = Vector2( 1040, 480 ) +position = Vector2( 660, 480 ) [node name="ScrollingBlock2" parent="." instance=ExtResource( 6 )] -position = Vector2( 1080, 480 ) +position = Vector2( 700, 480 ) [node name="ScrollingBlock3" parent="." instance=ExtResource( 6 )] -position = Vector2( 920, 480 ) +position = Vector2( 540, 480 ) [node name="ScrollingBlock4" parent="." instance=ExtResource( 6 )] -position = Vector2( 1000, 480 ) +position = Vector2( 620, 480 ) [node name="ScrollingBlock5" parent="." instance=ExtResource( 6 )] -position = Vector2( 1120, 480 ) +position = Vector2( 740, 480 ) [node name="ScrollingBlock6" parent="." instance=ExtResource( 6 )] -position = Vector2( 960, 480 ) +position = Vector2( 580, 480 ) [node name="Loop" parent="." instance=ExtResource( 7 )] -position = Vector2( 1200, 580 ) +position = Vector2( 520, 560 ) [node name="Loop2" parent="." instance=ExtResource( 7 )] -position = Vector2( 1260, 580 ) +position = Vector2( 580, 560 ) [node name="Loop3" parent="." instance=ExtResource( 7 )] -position = Vector2( 1320, 580 ) +position = Vector2( 640, 560 ) [node name="Loop4" parent="." instance=ExtResource( 7 )] -position = Vector2( 1380, 580 ) +position = Vector2( 700, 560 ) [node name="Loop5" parent="." instance=ExtResource( 7 )] -position = Vector2( 1440, 580 ) +position = Vector2( 760, 560 ) [node name="Loop6" parent="." instance=ExtResource( 7 )] -position = Vector2( 1200, 640 ) +position = Vector2( 520, 620 ) [node name="Loop7" parent="." instance=ExtResource( 7 )] -position = Vector2( 1260, 640 ) +position = Vector2( 580, 620 ) [node name="Loop8" parent="." instance=ExtResource( 7 )] -position = Vector2( 1320, 640 ) +position = Vector2( 640, 620 ) [node name="Loop9" parent="." instance=ExtResource( 7 )] -position = Vector2( 1380, 640 ) +position = Vector2( 700, 620 ) [node name="Loop10" parent="." instance=ExtResource( 7 )] -position = Vector2( 1440, 640 ) +position = Vector2( 760, 620 ) [node name="GameButtonChain" parent="." instance=ExtResource( 9 )] -position = Vector2( 1160, 480 ) +position = Vector2( 860, 660 ) [node name="GameButton" parent="GameButtonChain" instance=ExtResource( 8 )] @@ -94,4 +95,7 @@ color = Color( 0.956863, 0.196078, 0.0941176, 1 ) [node name="Laser2" parent="." instance=ExtResource( 11 )] position = Vector2( 640, 300 ) + +[node name="Clock" parent="." instance=ExtResource( 10 )] +position = Vector2( 40, 40 ) [connection signal="clicked" from="GameButtonChain/GameButton4" to="Laser2" method="deactivate"] diff --git a/Objects/SpecialObjects/Clock.gd b/Objects/SpecialObjects/Clock.gd new file mode 100644 index 0000000..0aa435f --- /dev/null +++ b/Objects/SpecialObjects/Clock.gd @@ -0,0 +1,22 @@ +extends Node2D +class_name Clock + + +var conveyor_belt: ConveyorBelt = null +var wrapper: Wrapper = null +var current_position: float = 0 + + +func _ready(): + conveyor_belt = get_tree().current_scene.get_node("ConveyorBelt") + wrapper = get_tree().current_scene.get_node("Wrapper") + _on_ConveyorBelt_cb_speed_changed(0, conveyor_belt.cb_speed) + conveyor_belt.connect("cb_speed_changed", self, "_on_ConveyorBelt_cb_speed_changed") + +func _physics_process(delta): + current_position += delta * conveyor_belt.cb_speed + $Hand.rotation = int(current_position) % int(wrapper.total_length) / wrapper.total_length * TAU + +func _on_ConveyorBelt_cb_speed_changed(old, new): + $AnimationPlayer.playback_speed = new / 400 + $AnimationPlayer.play("SpinCCW") diff --git a/Objects/SpecialObjects/Clock.tscn b/Objects/SpecialObjects/Clock.tscn new file mode 100644 index 0000000..1f8e817 --- /dev/null +++ b/Objects/SpecialObjects/Clock.tscn @@ -0,0 +1,37 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://Sprites/clock.png" type="Texture" id=1] +[ext_resource path="res://Objects/SpecialObjects/Clock.gd" type="Script" id=2] +[ext_resource path="res://Sprites/clock_lancetta.png" type="Texture" id=3] + +[sub_resource type="Animation" id=1] +resource_name = "SpinCCW" +loop = true +tracks/0/type = "value" +tracks/0/path = NodePath("Sprite:rotation_degrees") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0, 1 ), +"transitions": PoolRealArray( 1, 1 ), +"update": 0, +"values": [ 0.0, -360.0 ] +} + +[node name="Clock" type="Node2D"] +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +rotation = -3.50922 +texture = ExtResource( 1 ) + +[node name="Hand" type="Sprite" parent="."] +rotation = -6.28319 +texture = ExtResource( 3 ) +centered = false +offset = Vector2( -5, -40 ) + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +anims/SpinCCW = SubResource( 1 ) diff --git a/project.godot b/project.godot index ed25091..0eeba73 100644 --- a/project.godot +++ b/project.godot @@ -19,6 +19,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://Objects/ScrollingObjects/Buttons/CBSpeedChangeButton.gd" }, { +"base": "Node2D", +"class": "Clock", +"language": "GDScript", +"path": "res://Objects/SpecialObjects/Clock.gd" +}, { "base": "Node", "class": "Conductor", "language": "GDScript", @@ -87,6 +92,7 @@ _global_script_classes=[ { _global_script_class_icons={ "Buzzsaw": "", "CBSpeedChangeButton": "", +"Clock": "", "Conductor": "", "ConveyorBelt": "", "ConveyorScrollParent": "", @@ -106,6 +112,7 @@ _global_script_class_icons={ config/name="ld47" run/main_scene="res://Objects/Menu.tscn" +config/icon="res://Sprites/clock.png" [display]