diff --git a/Camera2D.gd b/Camera2D.gd index 7d6b174..b72b178 100644 --- a/Camera2D.gd +++ b/Camera2D.gd @@ -27,4 +27,4 @@ func zoom_towards_mouse(zoom_factor): var previous_mouse_position := get_local_mouse_position() zoom *= zoom_factor var diff = previous_mouse_position - get_local_mouse_position() - offset += diff + position += diff diff --git a/HUD.gd b/HUD.gd index 66a52ad..77a243b 100644 --- a/HUD.gd +++ b/HUD.gd @@ -14,7 +14,9 @@ func _process(delta): var time_string = "%02d:%02d:%02d" % [hours, minutes, seconds] # Format time as H:M:S var fps = Engine.get_frames_per_second() # Get the current FPS $HBoxContainer/Debug.text = time_string+" "+str(fps) + " fps" # Combine FPS and runtime into one string - + if %Map.controlling and is_instance_valid(%Map.controlling) and %Map.controlling==self: + $HBoxContainer/Debug.text += str(%Map.controlling.health) # Combine FPS and runtime into one string + func _on_save_pressed(): $"../SaveDialog".popup_centered() diff --git a/Map.gd b/Map.gd index 31ed186..d59020e 100644 --- a/Map.gd +++ b/Map.gd @@ -1,6 +1,11 @@ extends Node2D var mouse_down_position = Vector2() +var controlling=null + +func _process(_delta): + if controlling and is_instance_valid(controlling): + $Camera2D.position=controlling.position func _unhandled_input(event): if event is InputEventMouseButton: @@ -47,7 +52,20 @@ func spawn(pos,vol): var results = space_state.intersect_point(query_params, 32) # Adjust max_results as needed for result in results: result.collider.queue_free() - + if tool.name=="Control": + var space_state = get_world_2d().direct_space_state + var query_params = PhysicsPointQueryParameters2D.new() + query_params.position = pos + query_params.collide_with_areas = true # Set to false if you only want to check collision with bodies + query_params.collide_with_bodies = true # Set to false if you only want to check collision with areas + query_params.collision_mask = 1 # players + + var results = space_state.intersect_point(query_params, 32) # Adjust max_results as needed + for result in results: + controlling=result.collider + print("gotit") + break + func spawm_pool(pos,red,green,blue): var new_pool: Pool = load("res://pool.tscn").instantiate() new_pool.position = pos diff --git a/Player.gd b/Player.gd index f9b73fe..38f0dec 100644 --- a/Player.gd +++ b/Player.gd @@ -1,6 +1,8 @@ class_name Player extends RigidBody2D +var health=60 + func _integrate_forces(state: PhysicsDirectBodyState2D): var contact_count = state.get_contact_count() for i in range(contact_count): @@ -39,18 +41,18 @@ func _process(_delta): var collision_results = space_state.intersect_shape(query_parameters) if collision_results.size() == 0: $CollisionShape2D.disabled=false - -#func _physics_process(delta): -# if Input.is_action_pressed('move_up'): -# velocity.y -= 1 -# if Input.is_action_pressed('move_down'): -# velocity.y += 1 -# if Input.is_action_pressed('move_left'): -# velocity.x -= 1 -# if Input.is_action_pressed('move_right'): -# velocity.x += 1 -# if Input.is_action_just_pressed('take'): -# drop() + + var controlling=get_tree().root.get_node("Sim/Map").controlling + if controlling and is_instance_valid(controlling) and controlling==self: + var s=5 + if Input.is_action_pressed('move_up'): + controlling.apply_impulse(Vector2(0,-1)*s) + if Input.is_action_pressed('move_down'): + controlling.apply_impulse(Vector2(0,1)*s) + if Input.is_action_pressed('move_left'): + controlling.apply_impulse(Vector2(-1,0)*s) + if Input.is_action_pressed('move_right'): + controlling.apply_impulse(Vector2(1,0)*s) func drop(): if not is_carrying(): @@ -84,6 +86,7 @@ func doubledrop(player: Player): player.carrying_b=0 get_tree().root.get_node("Sim/Map").call_deferred("add_child",new_pool) update() + player.update() func exchange_with(pool: Pool): if is_carrying(): @@ -141,6 +144,14 @@ func load_data(data): carrying_g=data["g"] carrying_b=data["b"] - -func _on_decay_timer_timeout(): - pass # Replace with function body. +func _on_health_timer_timeout(): + if not get_tree().root.get_node("Sim/ScreenOverlay/HUD/HBoxContainer/Right/Health").is_pressed(): + return + + if is_carrying(): + health+=1 + else: + health-=1 + + if(health<1): + self.queue_free() diff --git a/Pool.gd b/Pool.gd index bf6067b..677778f 100644 --- a/Pool.gd +++ b/Pool.gd @@ -27,9 +27,7 @@ func _process(_delta): var collision_results = space_state.intersect_shape(query_parameters) if collision_results.size() == 0: $CollisionShape2D2.disabled=false - update() - pass func update(): var max_value: float = max(mana_r, mana_g, mana_b) diff --git a/hud.tscn b/hud.tscn new file mode 100644 index 0000000..2770f22 --- /dev/null +++ b/hud.tscn @@ -0,0 +1,150 @@ +[gd_scene load_steps=3 format=3 uid="uid://i5hw0qow332a"] + +[ext_resource type="Script" path="res://HUD.gd" id="1_4qotk"] +[ext_resource type="Script" path="res://ToolSelect.gd" id="2_m1iu2"] + +[node name="HUD" type="PanelContainer"] +anchors_preset = 10 +anchor_right = 1.0 +grow_horizontal = 2 +script = ExtResource("1_4qotk") + +[node name="HBoxContainer" type="HBoxContainer" parent="."] +layout_mode = 2 + +[node name="ToolSelect" type="HBoxContainer" parent="HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 2 +script = ExtResource("2_m1iu2") + +[node name="VBoxContainer" type="HBoxContainer" parent="HBoxContainer/ToolSelect"] +layout_mode = 2 + +[node name="OptionButton" type="OptionButton" parent="HBoxContainer/ToolSelect/VBoxContainer"] +layout_mode = 2 + +[node name="Create Player" type="VBoxContainer" parent="HBoxContainer/ToolSelect/VBoxContainer"] +layout_mode = 2 + +[node name="Create Pool" type="HBoxContainer" parent="HBoxContainer/ToolSelect/VBoxContainer"] +layout_mode = 2 + +[node name="Label" type="Label" parent="HBoxContainer/ToolSelect/VBoxContainer/Create Pool"] +layout_mode = 2 +text = "R:" + +[node name="Red" type="LineEdit" parent="HBoxContainer/ToolSelect/VBoxContainer/Create Pool"] +layout_mode = 2 +text = "100" +placeholder_text = "0" + +[node name="Label5" type="Label" parent="HBoxContainer/ToolSelect/VBoxContainer/Create Pool"] +layout_mode = 2 +text = "G:" + +[node name="Green" type="LineEdit" parent="HBoxContainer/ToolSelect/VBoxContainer/Create Pool"] +layout_mode = 2 +text = "100" +placeholder_text = "0" +max_length = 5 + +[node name="Label4" type="Label" parent="HBoxContainer/ToolSelect/VBoxContainer/Create Pool"] +layout_mode = 2 +text = "B:" + +[node name="Blue" type="LineEdit" parent="HBoxContainer/ToolSelect/VBoxContainer/Create Pool"] +layout_mode = 2 +text = "100" +placeholder_text = "0" +max_length = 5 + +[node name="Create Pool Circle" type="HBoxContainer" parent="HBoxContainer/ToolSelect/VBoxContainer"] +layout_mode = 2 + +[node name="Label" type="Label" parent="HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] +layout_mode = 2 +text = "R:" + +[node name="Red" type="LineEdit" parent="HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] +layout_mode = 2 +text = "100" +placeholder_text = "0" +max_length = 5 + +[node name="Label5" type="Label" parent="HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] +layout_mode = 2 +text = "G:" + +[node name="Green" type="LineEdit" parent="HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] +layout_mode = 2 +text = "100" +placeholder_text = "0" +max_length = 5 + +[node name="Label4" type="Label" parent="HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] +layout_mode = 2 +text = "B:" + +[node name="Blue" type="LineEdit" parent="HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] +layout_mode = 2 +text = "100" +placeholder_text = "0" +max_length = 5 + +[node name="Label2" type="Label" parent="HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] +layout_mode = 2 +text = "Radius:" + +[node name="Radius" type="LineEdit" parent="HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] +layout_mode = 2 +text = "200" +placeholder_text = "0" +max_length = 5 + +[node name="Label3" type="Label" parent="HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] +layout_mode = 2 +text = "Count:" + +[node name="Count" type="LineEdit" parent="HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] +layout_mode = 2 +text = "16" +placeholder_text = "0" +max_length = 5 + +[node name="Paste" type="OptionButton" parent="HBoxContainer/ToolSelect/VBoxContainer"] +layout_mode = 2 + +[node name="Delete" type="VBoxContainer" parent="HBoxContainer/ToolSelect/VBoxContainer"] +layout_mode = 2 + +[node name="Control" type="VBoxContainer" parent="HBoxContainer/ToolSelect/VBoxContainer"] +layout_mode = 2 + +[node name="Debug" type="Label" parent="HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 6 +text = "debug" + +[node name="Right" type="HBoxContainer" parent="HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 10 + +[node name="Decay" type="CheckBox" parent="HBoxContainer/Right"] +layout_mode = 2 +text = "Decay" + +[node name="Health" type="CheckBox" parent="HBoxContainer/Right"] +layout_mode = 2 +text = "Health" + +[node name="Load" type="Button" parent="HBoxContainer/Right"] +layout_mode = 2 +text = "Load..." + +[node name="Save" type="Button" parent="HBoxContainer/Right"] +layout_mode = 2 +text = "Save..." + +[connection signal="item_selected" from="HBoxContainer/ToolSelect/VBoxContainer/OptionButton" to="HBoxContainer/ToolSelect" method="_on_option_button_item_selected"] +[connection signal="pressed" from="HBoxContainer/Right/Load" to="." method="_on_load_pressed"] +[connection signal="pressed" from="HBoxContainer/Right/Save" to="." method="_on_save_pressed"] diff --git a/player.tscn b/player.tscn index 4b5ef82..6783eec 100644 --- a/player.tscn +++ b/player.tscn @@ -20,3 +20,8 @@ texture = ExtResource("2_cxs7h") [node name="CollisionShape2D" type="CollisionShape2D" parent="."] scale = Vector2(0.8, 0.8) shape = SubResource("CircleShape2D_yt706") + +[node name="HealthTimer" type="Timer" parent="."] +autostart = true + +[connection signal="timeout" from="HealthTimer" to="." method="_on_health_timer_timeout"] diff --git a/sim.tscn b/sim.tscn index c815d82..0e6c6ad 100644 --- a/sim.tscn +++ b/sim.tscn @@ -1,163 +1,29 @@ -[gd_scene load_steps=9 format=3 uid="uid://bpy475nyq5ea1"] +[gd_scene load_steps=8 format=3 uid="uid://bpy475nyq5ea1"] [ext_resource type="Script" path="res://Map.gd" id="2_rolej"] [ext_resource type="Script" path="res://ScreenShots.gd" id="3_7b3mn"] [ext_resource type="Texture2D" uid="uid://1g54esg7yd35" path="res://images/crosshair.png" id="3_i24br"] [ext_resource type="Script" path="res://Camera2D.gd" id="4_g4kw0"] -[ext_resource type="Script" path="res://HUD.gd" id="5_pfkj4"] +[ext_resource type="PackedScene" uid="uid://i5hw0qow332a" path="res://hud.tscn" id="4_u63sk"] [ext_resource type="Script" path="res://LoadDialog.gd" id="6_0mayr"] -[ext_resource type="Script" path="res://ToolSelect.gd" id="6_hswn6"] [ext_resource type="Script" path="res://SaveDialog.gd" id="6_v2wl8"] [node name="Sim" type="Node2D"] [node name="Map" type="Node2D" parent="."] +unique_name_in_owner = true script = ExtResource("2_rolej") [node name="Camera2D" type="Camera2D" parent="Map"] script = ExtResource("4_g4kw0") -[node name="Sprite2D" type="Sprite2D" parent="Map"] +[node name="OriginSprite" type="Sprite2D" parent="Map"] scale = Vector2(0.2, 0.2) texture = ExtResource("3_i24br") [node name="ScreenOverlay" type="CanvasLayer" parent="."] -[node name="HUD" type="PanelContainer" parent="ScreenOverlay"] -anchors_preset = 10 -anchor_right = 1.0 -grow_horizontal = 2 -script = ExtResource("5_pfkj4") - -[node name="HBoxContainer" type="HBoxContainer" parent="ScreenOverlay/HUD"] -layout_mode = 2 - -[node name="ToolSelect" type="HBoxContainer" parent="ScreenOverlay/HUD/HBoxContainer"] -layout_mode = 2 -size_flags_horizontal = 2 -script = ExtResource("6_hswn6") - -[node name="VBoxContainer" type="HBoxContainer" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect"] -layout_mode = 2 - -[node name="OptionButton" type="OptionButton" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer"] -layout_mode = 2 - -[node name="Create Player" type="VBoxContainer" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer"] -layout_mode = 2 - -[node name="Create Pool" type="HBoxContainer" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer"] -layout_mode = 2 - -[node name="Label" type="Label" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer/Create Pool"] -layout_mode = 2 -text = "R:" - -[node name="Red" type="LineEdit" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer/Create Pool"] -layout_mode = 2 -text = "100" -placeholder_text = "0" - -[node name="Label5" type="Label" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer/Create Pool"] -layout_mode = 2 -text = "G:" - -[node name="Green" type="LineEdit" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer/Create Pool"] -layout_mode = 2 -text = "100" -placeholder_text = "0" -max_length = 5 - -[node name="Label4" type="Label" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer/Create Pool"] -layout_mode = 2 -text = "B:" - -[node name="Blue" type="LineEdit" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer/Create Pool"] -layout_mode = 2 -text = "100" -placeholder_text = "0" -max_length = 5 - -[node name="Create Pool Circle" type="HBoxContainer" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer"] -layout_mode = 2 - -[node name="Label" type="Label" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] -layout_mode = 2 -text = "R:" - -[node name="Red" type="LineEdit" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] -layout_mode = 2 -text = "100" -placeholder_text = "0" -max_length = 5 - -[node name="Label5" type="Label" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] -layout_mode = 2 -text = "G:" - -[node name="Green" type="LineEdit" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] -layout_mode = 2 -text = "100" -placeholder_text = "0" -max_length = 5 - -[node name="Label4" type="Label" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] -layout_mode = 2 -text = "B:" - -[node name="Blue" type="LineEdit" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] -layout_mode = 2 -text = "100" -placeholder_text = "0" -max_length = 5 - -[node name="Label2" type="Label" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] -layout_mode = 2 -text = "Radius:" - -[node name="Radius" type="LineEdit" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] -layout_mode = 2 -text = "200" -placeholder_text = "0" -max_length = 5 - -[node name="Label3" type="Label" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] -layout_mode = 2 -text = "Count:" - -[node name="Count" type="LineEdit" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer/Create Pool Circle"] -layout_mode = 2 -text = "16" -placeholder_text = "0" -max_length = 5 - -[node name="Paste" type="OptionButton" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer"] -layout_mode = 2 - -[node name="Delete" type="VBoxContainer" parent="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer"] -layout_mode = 2 - -[node name="Debug" type="Label" parent="ScreenOverlay/HUD/HBoxContainer"] -layout_mode = 2 -size_flags_horizontal = 6 -text = "debug" - -[node name="Right" type="HBoxContainer" parent="ScreenOverlay/HUD/HBoxContainer"] -layout_mode = 2 -size_flags_horizontal = 10 - -[node name="Decay" type="CheckBox" parent="ScreenOverlay/HUD/HBoxContainer/Right"] -visible = false -layout_mode = 2 -text = "Decay" - -[node name="Load" type="Button" parent="ScreenOverlay/HUD/HBoxContainer/Right"] -layout_mode = 2 -text = "Load..." - -[node name="Save" type="Button" parent="ScreenOverlay/HUD/HBoxContainer/Right"] -layout_mode = 2 -text = "Save..." +[node name="HUD" parent="ScreenOverlay" instance=ExtResource("4_u63sk")] [node name="LoadDialog" type="ConfirmationDialog" parent="ScreenOverlay"] title = "Load" @@ -192,9 +58,6 @@ wait_time = 60.0 autostart = true script = ExtResource("3_7b3mn") -[connection signal="item_selected" from="ScreenOverlay/HUD/HBoxContainer/ToolSelect/VBoxContainer/OptionButton" to="ScreenOverlay/HUD/HBoxContainer/ToolSelect" method="_on_option_button_item_selected"] -[connection signal="pressed" from="ScreenOverlay/HUD/HBoxContainer/Right/Load" to="ScreenOverlay/HUD" method="_on_load_pressed"] -[connection signal="pressed" from="ScreenOverlay/HUD/HBoxContainer/Right/Save" to="ScreenOverlay/HUD" method="_on_save_pressed"] [connection signal="about_to_popup" from="ScreenOverlay/LoadDialog" to="ScreenOverlay/LoadDialog" method="_on_about_to_popup"] [connection signal="confirmed" from="ScreenOverlay/LoadDialog" to="ScreenOverlay/LoadDialog" method="_on_confirmed"] [connection signal="about_to_popup" from="ScreenOverlay/SaveDialog" to="ScreenOverlay/SaveDialog" method="_on_about_to_popup"]