control a player! begin health

This commit is contained in:
James 2023-12-07 22:38:33 +00:00
parent 6775649043
commit cffc458f0a
8 changed files with 209 additions and 162 deletions

View File

@ -27,4 +27,4 @@ func zoom_towards_mouse(zoom_factor):
var previous_mouse_position := get_local_mouse_position() var previous_mouse_position := get_local_mouse_position()
zoom *= zoom_factor zoom *= zoom_factor
var diff = previous_mouse_position - get_local_mouse_position() var diff = previous_mouse_position - get_local_mouse_position()
offset += diff position += diff

4
HUD.gd
View File

@ -14,7 +14,9 @@ func _process(delta):
var time_string = "%02d:%02d:%02d" % [hours, minutes, seconds] # Format time as H:M:S 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 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 $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(): func _on_save_pressed():
$"../SaveDialog".popup_centered() $"../SaveDialog".popup_centered()

20
Map.gd
View File

@ -1,6 +1,11 @@
extends Node2D extends Node2D
var mouse_down_position = Vector2() 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): func _unhandled_input(event):
if event is InputEventMouseButton: 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 var results = space_state.intersect_point(query_params, 32) # Adjust max_results as needed
for result in results: for result in results:
result.collider.queue_free() 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): func spawm_pool(pos,red,green,blue):
var new_pool: Pool = load("res://pool.tscn").instantiate() var new_pool: Pool = load("res://pool.tscn").instantiate()
new_pool.position = pos new_pool.position = pos

View File

@ -1,6 +1,8 @@
class_name Player class_name Player
extends RigidBody2D extends RigidBody2D
var health=60
func _integrate_forces(state: PhysicsDirectBodyState2D): func _integrate_forces(state: PhysicsDirectBodyState2D):
var contact_count = state.get_contact_count() var contact_count = state.get_contact_count()
for i in range(contact_count): for i in range(contact_count):
@ -39,18 +41,18 @@ func _process(_delta):
var collision_results = space_state.intersect_shape(query_parameters) var collision_results = space_state.intersect_shape(query_parameters)
if collision_results.size() == 0: if collision_results.size() == 0:
$CollisionShape2D.disabled=false $CollisionShape2D.disabled=false
#func _physics_process(delta): var controlling=get_tree().root.get_node("Sim/Map").controlling
# if Input.is_action_pressed('move_up'): if controlling and is_instance_valid(controlling) and controlling==self:
# velocity.y -= 1 var s=5
# if Input.is_action_pressed('move_down'): if Input.is_action_pressed('move_up'):
# velocity.y += 1 controlling.apply_impulse(Vector2(0,-1)*s)
# if Input.is_action_pressed('move_left'): if Input.is_action_pressed('move_down'):
# velocity.x -= 1 controlling.apply_impulse(Vector2(0,1)*s)
# if Input.is_action_pressed('move_right'): if Input.is_action_pressed('move_left'):
# velocity.x += 1 controlling.apply_impulse(Vector2(-1,0)*s)
# if Input.is_action_just_pressed('take'): if Input.is_action_pressed('move_right'):
# drop() controlling.apply_impulse(Vector2(1,0)*s)
func drop(): func drop():
if not is_carrying(): if not is_carrying():
@ -84,6 +86,7 @@ func doubledrop(player: Player):
player.carrying_b=0 player.carrying_b=0
get_tree().root.get_node("Sim/Map").call_deferred("add_child",new_pool) get_tree().root.get_node("Sim/Map").call_deferred("add_child",new_pool)
update() update()
player.update()
func exchange_with(pool: Pool): func exchange_with(pool: Pool):
if is_carrying(): if is_carrying():
@ -141,6 +144,14 @@ func load_data(data):
carrying_g=data["g"] carrying_g=data["g"]
carrying_b=data["b"] carrying_b=data["b"]
func _on_health_timer_timeout():
func _on_decay_timer_timeout(): if not get_tree().root.get_node("Sim/ScreenOverlay/HUD/HBoxContainer/Right/Health").is_pressed():
pass # Replace with function body. return
if is_carrying():
health+=1
else:
health-=1
if(health<1):
self.queue_free()

View File

@ -27,9 +27,7 @@ func _process(_delta):
var collision_results = space_state.intersect_shape(query_parameters) var collision_results = space_state.intersect_shape(query_parameters)
if collision_results.size() == 0: if collision_results.size() == 0:
$CollisionShape2D2.disabled=false $CollisionShape2D2.disabled=false
update() update()
pass
func update(): func update():
var max_value: float = max(mana_r, mana_g, mana_b) var max_value: float = max(mana_r, mana_g, mana_b)

150
hud.tscn Normal file
View File

@ -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"]

View File

@ -20,3 +20,8 @@ texture = ExtResource("2_cxs7h")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
scale = Vector2(0.8, 0.8) scale = Vector2(0.8, 0.8)
shape = SubResource("CircleShape2D_yt706") shape = SubResource("CircleShape2D_yt706")
[node name="HealthTimer" type="Timer" parent="."]
autostart = true
[connection signal="timeout" from="HealthTimer" to="." method="_on_health_timer_timeout"]

147
sim.tscn
View File

@ -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://Map.gd" id="2_rolej"]
[ext_resource type="Script" path="res://ScreenShots.gd" id="3_7b3mn"] [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="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://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://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"] [ext_resource type="Script" path="res://SaveDialog.gd" id="6_v2wl8"]
[node name="Sim" type="Node2D"] [node name="Sim" type="Node2D"]
[node name="Map" type="Node2D" parent="."] [node name="Map" type="Node2D" parent="."]
unique_name_in_owner = true
script = ExtResource("2_rolej") script = ExtResource("2_rolej")
[node name="Camera2D" type="Camera2D" parent="Map"] [node name="Camera2D" type="Camera2D" parent="Map"]
script = ExtResource("4_g4kw0") script = ExtResource("4_g4kw0")
[node name="Sprite2D" type="Sprite2D" parent="Map"] [node name="OriginSprite" type="Sprite2D" parent="Map"]
scale = Vector2(0.2, 0.2) scale = Vector2(0.2, 0.2)
texture = ExtResource("3_i24br") texture = ExtResource("3_i24br")
[node name="ScreenOverlay" type="CanvasLayer" parent="."] [node name="ScreenOverlay" type="CanvasLayer" parent="."]
[node name="HUD" type="PanelContainer" parent="ScreenOverlay"] [node name="HUD" parent="ScreenOverlay" instance=ExtResource("4_u63sk")]
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="LoadDialog" type="ConfirmationDialog" parent="ScreenOverlay"] [node name="LoadDialog" type="ConfirmationDialog" parent="ScreenOverlay"]
title = "Load" title = "Load"
@ -192,9 +58,6 @@ wait_time = 60.0
autostart = true autostart = true
script = ExtResource("3_7b3mn") 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="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="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"] [connection signal="about_to_popup" from="ScreenOverlay/SaveDialog" to="ScreenOverlay/SaveDialog" method="_on_about_to_popup"]