From 4faeccff102143218b3c58f56dc8dc6cfe5024eb Mon Sep 17 00:00:00 2001 From: James Date: Mon, 4 Dec 2023 16:34:30 +0000 Subject: [PATCH] scroll/zoom --- Camera2D.gd | 37 ++++++++++++++++++++++++ map_select.gd | 12 ++++++++ map_select.tscn | 39 ++++++++++++++----------- maps/map_tools.gd | 11 +++++++ maps/sections.gd | 32 +++++++++++++++++++++ maps/sections.tscn | 6 ++++ project.godot | 8 ++---- sim.gd | 7 +++-- sim.tscn | 20 ++++++++----- test.tscn | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 210 insertions(+), 33 deletions(-) create mode 100644 Camera2D.gd create mode 100644 map_select.gd create mode 100644 maps/map_tools.gd create mode 100644 maps/sections.gd create mode 100644 maps/sections.tscn create mode 100644 test.tscn diff --git a/Camera2D.gd b/Camera2D.gd new file mode 100644 index 0000000..65d39ff --- /dev/null +++ b/Camera2D.gd @@ -0,0 +1,37 @@ +extends Camera2D + +var zoom_speed=Vector2(.2,.2) +var scrolling=false; + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +func _input(event): + if event is InputEventMouseButton: + if event.is_pressed(): + if event.button_index==MOUSE_BUTTON_WHEEL_UP: + zoom+=zoom_speed + if event.button_index==MOUSE_BUTTON_WHEEL_DOWN: + zoom-=zoom_speed + if event.button_index==MOUSE_BUTTON_MIDDLE: + scrolling=true + if event.is_released(): + if event.button_index==MOUSE_BUTTON_MIDDLE: + scrolling=false + if event is InputEventMouseMotion: + if scrolling: + offset-=event.velocity*0.1 + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + if Input.is_action_pressed('move_up'): + offset.y -= 1 + if Input.is_action_pressed('move_down'): + offset.y += 1 + if Input.is_action_pressed('move_left'): + offset.x -= 1 + if Input.is_action_pressed('move_right'): + offset.x += 1 +# if Input.is_action_just_pressed('take'): +# drop() diff --git a/map_select.gd b/map_select.gd new file mode 100644 index 0000000..dc643ab --- /dev/null +++ b/map_select.gd @@ -0,0 +1,12 @@ +extends Node2D + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + if Input.is_action_just_pressed("escape"): + get_tree().quit() # default behavior diff --git a/map_select.tscn b/map_select.tscn index 43a5720..fc014af 100644 --- a/map_select.tscn +++ b/map_select.tscn @@ -1,17 +1,19 @@ -[gd_scene load_steps=3 format=3 uid="uid://iskh4m3ltqul"] +[gd_scene load_steps=4 format=3 uid="uid://iskh4m3ltqul"] +[ext_resource type="Script" path="res://map_select.gd" id="1_f0hdc"] [ext_resource type="Script" path="res://Button.gd" id="1_rygkg"] [sub_resource type="LabelSettings" id="LabelSettings_kd1xo"] font_size = 32 [node name="MapSelect" type="Node2D"] +script = ExtResource("1_f0hdc") [node name="Title" type="Label" parent="."] -offset_left = 27.0 -offset_top = 127.0 -offset_right = 196.0 -offset_bottom = 175.0 +offset_left = 29.0 +offset_top = 17.0 +offset_right = 198.0 +offset_bottom = 65.0 text = "Map Select" label_settings = SubResource("LabelSettings_kd1xo") @@ -69,24 +71,27 @@ text = "RGB Sections" script = ExtResource("1_rygkg") map_path = "res://maps/rgb_sections.tscn" -[node name="Drop" type="CheckBox" parent="."] -offset_left = 33.0 -offset_top = 74.0 -offset_right = 194.0 -offset_bottom = 105.0 -text = "Drop on Collision" - [node name="Title2" type="Label" parent="."] -offset_left = 24.0 -offset_top = 14.0 -offset_right = 193.0 -offset_bottom = 62.0 -text = "Options" +offset_left = 17.0 +offset_top = 133.0 +offset_right = 186.0 +offset_bottom = 181.0 +text = "Archived" label_settings = SubResource("LabelSettings_kd1xo") +[node name="Button7" type="Button" parent="."] +offset_left = 35.0 +offset_top = 71.0 +offset_right = 210.0 +offset_bottom = 134.0 +text = "Sections" +script = ExtResource("1_rygkg") +map_path = "res://maps/sections.tscn" + [connection signal="pressed" from="Button" to="Button" method="_on_pressed"] [connection signal="pressed" from="Button2" to="Button2" method="_on_pressed"] [connection signal="pressed" from="Button3" to="Button3" method="_on_pressed"] [connection signal="pressed" from="Button4" to="Button4" method="_on_pressed"] [connection signal="pressed" from="Button5" to="Button5" method="_on_pressed"] [connection signal="pressed" from="Button6" to="Button6" method="_on_pressed"] +[connection signal="pressed" from="Button7" to="Button7" method="_on_pressed"] diff --git a/maps/map_tools.gd b/maps/map_tools.gd new file mode 100644 index 0000000..58577cf --- /dev/null +++ b/maps/map_tools.gd @@ -0,0 +1,11 @@ +extends Node2D + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass diff --git a/maps/sections.gd b/maps/sections.gd new file mode 100644 index 0000000..bd59f89 --- /dev/null +++ b/maps/sections.gd @@ -0,0 +1,32 @@ +extends Node2D + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + poolcircle(Vector2(0,0),200,32,100,0,0) + poolcircle(Vector2(600,0),200,32,0,100,0) + poolcircle(Vector2(1200,0),200,32,0,0,100) + + poolcircle(Vector2(0,600),200,32,0,50,50) + poolcircle(Vector2(600,600),200,32,50,0,50) + poolcircle(Vector2(1200,600),200,32,50,50,0) + + poolcircle(Vector2(600,200),2000,100,1000,1000,1000) + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass + +func poolcircle(pos: Vector2, radius, count, r,g,b): + + for n in range(1,count+1): + var new_pool: Pool = load("res://pool.tscn").instantiate() + var t=(float(n)/count)*3.141*2 + print(t) + new_pool.position = pos + (Vector2(sin(t),cos(t))*radius) + new_pool.mana_r=r + new_pool.mana_g=g + new_pool.mana_b=b + new_pool.get_node("StaticBody2D/CollisionShape2D2").disabled=true; + get_tree().root.get_node("Sim").call_deferred("add_child",new_pool) diff --git a/maps/sections.tscn b/maps/sections.tscn new file mode 100644 index 0000000..7f86a36 --- /dev/null +++ b/maps/sections.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://bkapistmqmur8"] + +[ext_resource type="Script" path="res://maps/sections.gd" id="1_ihwvy"] + +[node name="Map" type="Node2D"] +script = ExtResource("1_ihwvy") diff --git a/project.godot b/project.godot index 7f2ce72..7976fc7 100644 --- a/project.godot +++ b/project.godot @@ -12,13 +12,9 @@ config_version=5 config/name="RGB Physics Life" run/main_scene="res://map_select.tscn" -config/features=PackedStringArray("4.1", "Mobile") +config/features=PackedStringArray("4.2", "Mobile") config/icon="res://images/icon.svg" -[display] - -window/size/resizable=false - [input] move_up={ @@ -71,4 +67,4 @@ escape={ [rendering] -renderer/rendering_method="mobile" +renderer/rendering_method="gl_compatibility" diff --git a/sim.gd b/sim.gd index f7a36fd..d3f2782 100644 --- a/sim.gd +++ b/sim.gd @@ -4,7 +4,8 @@ var spawn_position=Vector2(100,100); # Called when the node enters the scene tree for the first time. func _ready(): - setup_edge_collisions() + #setup_edge_collisions() + pass func setup_edge_collisions(): var screen_size = get_viewport_rect().size @@ -41,11 +42,11 @@ func _input(event): get_tree().change_scene_to_file("res://map_select.tscn") get_node("/root/Sim").queue_free() if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT: - spawn_position=event.position + spawn_position=get_global_mouse_position() spawn() $Timer.stop() if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_RIGHT: - spawn_position=event.position + spawn_position=get_global_mouse_position() $Timer.start() func _on_timer_timeout(): diff --git a/sim.tscn b/sim.tscn index 38d7224..eda2b32 100644 --- a/sim.tscn +++ b/sim.tscn @@ -1,18 +1,13 @@ -[gd_scene load_steps=4 format=3 uid="uid://bpy475nyq5ea1"] +[gd_scene load_steps=5 format=3 uid="uid://bpy475nyq5ea1"] [ext_resource type="Script" path="res://sim.gd" id="1_wbm7g"] [ext_resource type="Script" path="res://Debug.gd" id="2_iqnjl"] [ext_resource type="Script" path="res://TimerSS.gd" id="3_7b3mn"] +[ext_resource type="Script" path="res://Camera2D.gd" id="4_g4kw0"] [node name="Sim" type="Node2D"] script = ExtResource("1_wbm7g") -[node name="Debug" type="Label" parent="."] -offset_right = 67.0 -offset_bottom = 26.0 -text = "debug" -script = ExtResource("2_iqnjl") - [node name="Timer" type="Timer" parent="."] wait_time = 0.3 @@ -21,5 +16,16 @@ wait_time = 60.0 autostart = true script = ExtResource("3_7b3mn") +[node name="Camera2D" type="Camera2D" parent="."] +script = ExtResource("4_g4kw0") + +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="Debug" type="Label" parent="CanvasLayer"] +offset_right = 67.0 +offset_bottom = 26.0 +text = "debug" +script = ExtResource("2_iqnjl") + [connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"] [connection signal="timeout" from="TimerSS" to="TimerSS" method="_on_timeout"] diff --git a/test.tscn b/test.tscn new file mode 100644 index 0000000..1a71f89 --- /dev/null +++ b/test.tscn @@ -0,0 +1,71 @@ +[gd_scene load_steps=10 format=3 uid="uid://bkjmlky5ihri0"] + +[ext_resource type="Script" path="res://sim.gd" id="1_gqc3c"] +[ext_resource type="Script" path="res://Debug.gd" id="2_gfcm0"] +[ext_resource type="Script" path="res://TimerSS.gd" id="3_gvywt"] +[ext_resource type="Script" path="res://Camera2D.gd" id="4_1cl5t"] +[ext_resource type="PackedScene" uid="uid://65vslfrgjtly" path="res://maps/rgb_sections.tscn" id="5_6ne8u"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_jlloy"] +size = Vector2(1152, 20) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_kvylm"] +size = Vector2(1152, 20) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_ygq31"] +size = Vector2(20, 648) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_piktq"] +size = Vector2(20, 648) + +[node name="Sim" type="Node2D"] +script = ExtResource("1_gqc3c") + +[node name="Debug" type="Label" parent="."] +offset_right = 67.0 +offset_bottom = 26.0 +text = "00:00:22 60 fps" +script = ExtResource("2_gfcm0") + +[node name="Timer" type="Timer" parent="."] +wait_time = 0.3 + +[node name="TimerSS" type="Timer" parent="."] +wait_time = 60.0 +script = ExtResource("3_gvywt") + +[node name="Camera2D" type="Camera2D" parent="."] +script = ExtResource("4_1cl5t") + +[node name="Map" parent="." instance=ExtResource("5_6ne8u")] + +[node name="_StaticBody2D_2" type="StaticBody2D" parent="."] +position = Vector2(576, 0) +collision_layer = 4 + +[node name="_CollisionShape2D_3" type="CollisionShape2D" parent="_StaticBody2D_2"] +shape = SubResource("RectangleShape2D_jlloy") + +[node name="_StaticBody2D_4" type="StaticBody2D" parent="."] +position = Vector2(576, 648) +collision_layer = 4 + +[node name="_CollisionShape2D_5" type="CollisionShape2D" parent="_StaticBody2D_4"] +shape = SubResource("RectangleShape2D_kvylm") + +[node name="_StaticBody2D_6" type="StaticBody2D" parent="."] +position = Vector2(0, 324) +collision_layer = 4 + +[node name="_CollisionShape2D_7" type="CollisionShape2D" parent="_StaticBody2D_6"] +shape = SubResource("RectangleShape2D_ygq31") + +[node name="_StaticBody2D_8" type="StaticBody2D" parent="."] +position = Vector2(1152, 324) +collision_layer = 4 + +[node name="_CollisionShape2D_9" type="CollisionShape2D" parent="_StaticBody2D_8"] +shape = SubResource("RectangleShape2D_piktq") + +[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"] +[connection signal="timeout" from="TimerSS" to="TimerSS" method="_on_timeout"]