diff --git a/2dWorld.tscn b/2dWorld.tscn index c8ac6a1..4644ab8 100644 --- a/2dWorld.tscn +++ b/2dWorld.tscn @@ -1,23 +1,27 @@ [gd_scene load_steps=6 format=3 uid="uid://biu528mgexdyp"] -[ext_resource type="Texture2D" uid="uid://b48ofysofsffi" path="res://icon.svg" id="1_2uw02"] [ext_resource type="Script" uid="uid://bdc53dgnhonif" path="res://worldManager.gd" id="1_gy87s"] +[ext_resource type="Texture2D" uid="uid://c4auuun5q0gjy" path="res://Sprites/captains_flat.png" id="2_u230a"] [ext_resource type="PackedScene" uid="uid://vv75ycmtipn7" path="res://Prefabs/cyclone.tscn" id="3_u230a"] [ext_resource type="Script" uid="uid://b1w10iwwhm5bj" path="res://addons/Fantail-Interactive.top_down_camera/td_camera_2d.gd" id="4_u230a"] -[sub_resource type="RectangleShape2D" id="RectangleShape2D_xr6w1"] -size = Vector2(674, 28) +[sub_resource type="RectangleShape2D" id="RectangleShape2D_u230a"] +size = Vector2(1292, 34) -[node name="2dWorld" type="Node2D" node_paths=PackedStringArray("camera", "map")] +[node name="2dWorld" type="Node2D" node_paths=PackedStringArray("camera", "map", "cyclone_holder", "speed_slider", "speed_label", "file_picker")] script = ExtResource("1_gy87s") camera = NodePath("TDCamera2D") map = NodePath("WorldMap") +cyclone_holder = NodePath("Cyclones") +speed_slider = NodePath("UI/Control/VBoxContainer/TheControls/HSlider") +speed_label = NodePath("UI/Control/VBoxContainer/TheControls/Speed label") +file_picker = NodePath("FileDialog") [node name="WorldMap" type="Sprite2D" parent="."] -modulate = Color(1.8049e-07, 0.391665, 0.150329, 1) +texture_filter = 1 position = Vector2(589, 319) -scale = Vector2(5, 5) -texture = ExtResource("1_2uw02") +scale = Vector2(2.5, 2.5) +texture = ExtResource("2_u230a") [node name="Cyclones" type="Node2D" parent="."] @@ -30,36 +34,125 @@ position = Vector2(746, 473) [node name="Cyclone3" parent="Cyclones" instance=ExtResource("3_u230a")] position = Vector2(463, 494) -[node name="Background" type="CanvasLayer" parent="."] -layer = -1 +[node name="UI" type="CanvasLayer" parent="."] -[node name="wall" type="StaticBody2D" parent="."] -position = Vector2(581, -12) +[node name="Control" type="Control" parent="UI"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 1 -[node name="CollisionShape2D" type="CollisionShape2D" parent="wall"] -shape = SubResource("RectangleShape2D_xr6w1") +[node name="VBoxContainer" type="VBoxContainer" parent="UI/Control"] +custom_minimum_size = Vector2(250, 0) +layout_mode = 1 +anchors_preset = 9 +anchor_bottom = 1.0 +offset_right = 128.0 +grow_vertical = 2 -[node name="wall2" type="StaticBody2D" parent="."] -position = Vector2(592, 647) +[node name="Button" type="Button" parent="UI/Control/VBoxContainer"] +layout_mode = 2 +text = "Toggle Controls" -[node name="CollisionShape2D" type="CollisionShape2D" parent="wall2"] -shape = SubResource("RectangleShape2D_xr6w1") +[node name="TheControls" type="VBoxContainer" parent="UI/Control/VBoxContainer"] +layout_mode = 2 -[node name="wall3" type="StaticBody2D" parent="."] -position = Vector2(259, 317) -rotation = 1.5708 +[node name="Speed label" type="Label" parent="UI/Control/VBoxContainer/TheControls"] +layout_mode = 2 +text = "Speed: 1.0x" -[node name="CollisionShape2D" type="CollisionShape2D" parent="wall3"] -shape = SubResource("RectangleShape2D_xr6w1") +[node name="HSlider" type="HSlider" parent="UI/Control/VBoxContainer/TheControls"] +layout_mode = 2 +max_value = 6.0 +value = 3.0 +tick_count = 7 +ticks_on_borders = true -[node name="wall4" type="StaticBody2D" parent="."] -position = Vector2(909, 326) -rotation = 1.5708 +[node name="TabContainer" type="TabContainer" parent="UI/Control/VBoxContainer"] +layout_mode = 2 +current_tab = 0 -[node name="CollisionShape2D" type="CollisionShape2D" parent="wall4"] -shape = SubResource("RectangleShape2D_xr6w1") +[node name="Tools" type="VBoxContainer" parent="UI/Control/VBoxContainer/TabContainer"] +layout_mode = 2 +metadata/_tab_index = 0 + +[node name="meow" type="Label" parent="UI/Control/VBoxContainer/TabContainer/Tools"] +layout_mode = 2 +text = "meow" + +[node name="LoadImage" type="Button" parent="UI/Control/VBoxContainer/TabContainer/Tools"] +layout_mode = 2 +text = "Change Image" + +[node name="Spawn" type="Button" parent="UI/Control/VBoxContainer/TabContainer/Tools"] +layout_mode = 2 +text = "Spawn Cyclone" + +[node name="Spawn2" type="Button" parent="UI/Control/VBoxContainer/TabContainer/Tools"] +layout_mode = 2 +text = "Toggle Walls" + +[node name="Exit" type="Button" parent="UI/Control/VBoxContainer/TabContainer/Tools"] +layout_mode = 2 +text = "Close Program" + +[node name="Settings" type="VBoxContainer" parent="UI/Control/VBoxContainer/TabContainer"] +visible = false +layout_mode = 2 +metadata/_tab_index = 1 + +[node name="meow" type="Label" parent="UI/Control/VBoxContainer/TabContainer/Settings"] +layout_mode = 2 +text = "meow" [node name="TDCamera2D" type="Camera2D" parent="."] position = Vector2(579, 330) script = ExtResource("4_u230a") +min_zoom = 6.0 metadata/_custom_type_script = "uid://b1w10iwwhm5bj" + +[node name="Walls" type="Node2D" parent="."] + +[node name="StaticBody2D" type="StaticBody2D" parent="Walls"] +position = Vector2(-46, -343) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls/StaticBody2D"] +position = Vector2(636, 7) +shape = SubResource("RectangleShape2D_u230a") + +[node name="StaticBody2D2" type="StaticBody2D" parent="Walls"] +position = Vector2(268, 968) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls/StaticBody2D2"] +position = Vector2(319, 7) +shape = SubResource("RectangleShape2D_u230a") + +[node name="StaticBody2D3" type="StaticBody2D" parent="Walls"] +position = Vector2(-57, 1) +rotation = 1.57079 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls/StaticBody2D3"] +position = Vector2(319, 7) +shape = SubResource("RectangleShape2D_u230a") + +[node name="StaticBody2D4" type="StaticBody2D" parent="Walls"] +position = Vector2(1251, 4) +rotation = 1.57079 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls/StaticBody2D4"] +position = Vector2(319, 7) +shape = SubResource("RectangleShape2D_u230a") + +[node name="FileDialog" type="FileDialog" parent="."] +title = "Open a File" +ok_button_text = "Open" +file_mode = 0 +access = 2 +filters = PackedStringArray("*.png") +use_native_dialog = true + +[connection signal="pressed" from="UI/Control/VBoxContainer/TabContainer/Tools/LoadImage" to="." method="_on_load_image_pressed"] +[connection signal="file_selected" from="FileDialog" to="." method="_on_file_dialog_file_selected"] diff --git a/Prefabs/cyclone.tscn b/Prefabs/cyclone.tscn index ca5bfc8..322326a 100644 --- a/Prefabs/cyclone.tscn +++ b/Prefabs/cyclone.tscn @@ -1,50 +1,61 @@ -[gd_scene load_steps=4 format=3 uid="uid://vv75ycmtipn7"] +[gd_scene load_steps=6 format=3 uid="uid://vv75ycmtipn7"] [ext_resource type="Script" uid="uid://u353j4q7l26d" path="res://cyclone.gd" id="1_khbba"] [ext_resource type="Texture2D" uid="uid://cdw1vlidvg2yt" path="res://Sprites/Cyclone.png" id="2_7e2hf"] -[sub_resource type="CircleShape2D" id="CircleShape2D_xr6w1"] -radius = 32.0 +[sub_resource type="LabelSettings" id="LabelSettings_khbba"] +font_color = Color(0, 0, 0, 1) -[node name="Cyclone" type="RigidBody2D" node_paths=PackedStringArray("sprite", "label", "wind_speed_label", "line")] +[sub_resource type="LabelSettings" id="LabelSettings_7e2hf"] +font_color = Color(0, 0, 0, 1) + +[sub_resource type="CircleShape2D" id="CircleShape2D_xr6w1"] +radius = 4.0 + +[node name="Cyclone" type="RigidBody2D" node_paths=PackedStringArray("sprite", "label", "wind_speed_label", "line", "visuals")] gravity_scale = 0.0 lock_rotation = true script = ExtResource("1_khbba") -sprite = NodePath("Sprite2D") -label = NodePath("cLabel") -wind_speed_label = NodePath("wsLabel") +sprite = NodePath("Visuals/Sprite2D") +label = NodePath("Visuals/cLabel") +wind_speed_label = NodePath("Visuals/wsLabel") line = NodePath("Line2D") +visuals = NodePath("Visuals") -[node name="Sprite2D" type="Sprite2D" parent="."] +[node name="Visuals" type="Node2D" parent="."] + +[node name="Sprite2D" type="Sprite2D" parent="Visuals"] scale = Vector2(0.2, 0.2) texture = ExtResource("2_7e2hf") -[node name="Line2D" type="Line2D" parent="."] -position = Vector2(-572, -229) -width = 2.0 -default_color = Color(0.656747, 0, 0.0830602, 1) -joint_mode = 2 - -[node name="cLabel" type="Label" parent="."] +[node name="cLabel" type="Label" parent="Visuals"] offset_left = -21.0 offset_top = -11.0 offset_right = 19.0 offset_bottom = 12.0 size_flags_horizontal = 4 text = "1" +label_settings = SubResource("LabelSettings_khbba") horizontal_alignment = 1 vertical_alignment = 1 -[node name="wsLabel" type="Label" parent="."] +[node name="wsLabel" type="Label" parent="Visuals"] offset_left = -21.0 offset_top = -66.0 offset_right = 19.0 offset_bottom = -43.0 size_flags_horizontal = 4 text = "1" +label_settings = SubResource("LabelSettings_7e2hf") horizontal_alignment = 1 vertical_alignment = 1 +[node name="Line2D" type="Line2D" parent="."] +position = Vector2(-572, -229) +width = 2.0 +default_color = Color(0.654902, 0, 0.0823529, 0.572549) +joint_mode = 2 + [node name="changeTimer" type="Timer" parent="."] wait_time = 5.0 autostart = true diff --git a/Sprites/captains_flat.png b/Sprites/captains_flat.png new file mode 100644 index 0000000..15e6a76 Binary files /dev/null and b/Sprites/captains_flat.png differ diff --git a/Sprites/captains_flat.png.import b/Sprites/captains_flat.png.import new file mode 100644 index 0000000..74e9b92 --- /dev/null +++ b/Sprites/captains_flat.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c4auuun5q0gjy" +path="res://.godot/imported/captains_flat.png-d86faacacebd497f2a1071198ea8f2ab.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/captains_flat.png" +dest_files=["res://.godot/imported/captains_flat.png-d86faacacebd497f2a1071198ea8f2ab.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/cyclone.gd b/cyclone.gd index 3e9ec91..602504f 100644 --- a/cyclone.gd +++ b/cyclone.gd @@ -5,6 +5,7 @@ extends RigidBody2D @export var label : Label @export var wind_speed_label : Label @export var line : Line2D +@export var visuals : Node2D var wind_speed : float = 0.1 #var move_speed : float = 20 var wind_acceleration : float = 5 diff --git a/readme.md b/readme.md index 7b9f0e7..3f38c20 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,8 @@ # Todo -- [ ] Make cyclones loop around edges -- [ ] simulation speed control +- [x] Make cyclones loop around edges - nah dont, they should just leave i think +- [x] simulation speed control - [ ] create cyclones by picking a point on the map - [ ] load custom images - [ ] recalculate bounds based on custom images +- [ ] landfall effect? +- [x] scale culones depending on camera zoom diff --git a/worldManager.gd b/worldManager.gd index b175f85..94f3816 100644 --- a/worldManager.gd +++ b/worldManager.gd @@ -2,7 +2,11 @@ extends Node2D @export var camera : Camera2D @export var map : Sprite2D -@export var cyclones : Array[RigidBody2D] +@export var cyclone_holder : Node2D + +@export var speed_slider : HSlider +@export var speed_label : Label +@export var file_picker : FileDialog # Called when the node enters the scene tree for the first time. func _ready() -> void: @@ -11,7 +15,9 @@ func _ready() -> void: # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: - check_edges() + #check_edges() + update_zoom() + update_ui() func check_edges(): #var right_center = map.global_position + Vector2(map.texture.get_width(), 0) @@ -20,12 +26,51 @@ func check_edges(): var map_bottom : float = map.global_position.y - map.texture.get_height() var map_right : float = map.global_position.x + map.texture.get_width() var map_left : float = map.global_position.x - map.texture.get_width() - print("Top: " + str(map_top)) - print("Bottom: " + str(map_top)) - print("Left: " + str(map_top)) - print("Right: " + str(map_top)) + #print("Top: " + str(map_top)) + #print("Bottom: " + str(map_top)) + #print("Left: " + str(map_top)) + #print("Right: " + str(map_top)) - for cyclone in cyclones: - pass + #for cyclone in cyclones: + #pass pass + +func update_zoom(): + #print(1/camera.zoom.x) + var scale_level : float = clampf(1/camera.zoom.x,0,1) + for cyclone in cyclone_holder.get_children(): + cyclone.visuals.scale = Vector2(scale_level,scale_level) + +func update_ui(): + var selected_speed : float = speed_slider.value + var actual_speed : float + # 3=1.0x, 2=0.5x, 1=0.25x, 0=0.0x, 4=2x 5=3x 6=4x + match int(selected_speed): + 0: + actual_speed = 0.0001 + 1: + actual_speed = 0.25 + 2: + actual_speed = 0.5 + 3: + actual_speed = 1 + 4: + actual_speed = 2 + 5: + actual_speed = 4 + 6: + actual_speed = 8 + speed_label.text = "Speed: " + str(round(actual_speed*100)/100) + "x" + Engine.time_scale = actual_speed + + + +func _on_load_image_pressed() -> void: + file_picker.show() + + +func _on_file_dialog_file_selected(path: String) -> void: + var new_image : Image = Image.load_from_file(path) + var image_texture : ImageTexture = ImageTexture.create_from_image(new_image) + map.texture = image_texture