fuzzyworld

godot-shooter / commit

Fixed some errors about variable usages.

8c2ffd3fc0d933d2c500a4e6da293dd8c78727fe · Pavel Safronov · 2023-11-01 22:27:25 -0700 · parents a261d90c51f7

Fixed some errors about variable usages.
Adding a debug label, so it's possible to get some debug info on mobile.
 Enemy.gd   |  2 +-
 HUD.gd     |  2 ++
 HUD.tscn   | 18 +++++++++++++++---
 Player.gd  | 16 ++--------------
 Theme.tres |  2 +-
 World.gd   |  6 ++++--
 6 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/Enemy.gd b/Enemy.gd
index 1dc0986..8626ba4 100644
--- a/Enemy.gd
+++ b/Enemy.gd
@@ -21,7 +21,7 @@ func _process(_delta: float) -> void:
 	$Graphics/Alive/Container/HealthLabel.text = "%s / %s" % [health, max_health]
 	$Graphics/Alive/Container.global_rotation = 0
 
-func _physics_process(delta: float) -> void:
+func _physics_process(_delta: float) -> void:
 	if dead:
 		return
 	var players = get_tree().get_nodes_in_group("player")
diff --git a/HUD.gd b/HUD.gd
index 02cee1f..6522f9b 100644
--- a/HUD.gd
+++ b/HUD.gd
@@ -1,9 +1,11 @@
 extends Control
 
 export var score = 0
+export var debug_text = ""
 
 func _ready() -> void:
 	$AnimationPlayer.play("instructions fade")
 
 func _process(_delta: float) -> void:
 	$VBoxContainer/HBoxContainer/Score.text = "%s" % score
+	$VBoxContainer/HBoxContainer2/DebugText.text = debug_text
diff --git a/HUD.tscn b/HUD.tscn
index c44d76c..e9f9be6 100644
--- a/HUD.tscn
+++ b/HUD.tscn
@@ -57,10 +57,20 @@ script = ExtResource( 2 )
 margin_right = 40.0
 margin_bottom = 40.0
 
-[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
+[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"]
 margin_right = 617.0
 margin_bottom = 74.0
 
+[node name="DebugText" type="Label" parent="VBoxContainer/HBoxContainer2"]
+margin_right = 190.0
+margin_bottom = 74.0
+text = "DEBUG"
+
+[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
+margin_top = 78.0
+margin_right = 617.0
+margin_bottom = 152.0
+
 [node name="ScoreText" type="Label" parent="VBoxContainer/HBoxContainer"]
 margin_right = 192.0
 margin_bottom = 74.0
@@ -74,11 +84,13 @@ text = "100"
 uppercase = true
 
 [node name="CenterContainer" type="CenterContainer" parent="VBoxContainer"]
-margin_top = 78.0
+margin_top = 156.0
 margin_right = 617.0
-margin_bottom = 152.0
+margin_bottom = 230.0
+theme = ExtResource( 1 )
 
 [node name="Label" type="Label" parent="VBoxContainer/CenterContainer"]
+modulate = Color( 1, 1, 1, 0 )
 margin_right = 617.0
 margin_bottom = 74.0
 theme = ExtResource( 1 )
diff --git a/Player.gd b/Player.gd
index c2751f7..9d5924f 100644
--- a/Player.gd
+++ b/Player.gd
@@ -25,30 +25,18 @@ func _process(_delta: float) -> void:
 		restart()
 	if dead:
 		return
-	if Input.is_action_pressed("shoot"):
-		shoot()
 	$Graphics/Alive/Control/HealthLabel.text = "%s / %s" % [health, max_health]
 	$Graphics/Alive/Control.global_rotation = 0
 
-func _physics_process(delta: float) -> void:
+func _physics_process(_delta: float) -> void:
 	if dead:
 		return
-	handle_mouse_controls(delta)
+	global_rotation = global_position.direction_to(get_global_mouse_position()).angle() + PI/2.0
 	velocity = move_and_slide(velocity)
 
 func restart():
 	var _error = get_tree().reload_current_scene()
 
-func handle_mouse_controls(delta: float) -> void:
-	global_rotation = global_position.direction_to(get_global_mouse_position()).angle() + PI/2.0
-	var turn_dir = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
-	global_rotation += turn_dir * delta
-	var direction = Vector2.UP.rotated(global_rotation)
-	var forward_dir = Input.get_action_strength("move_up") - Input.get_action_strength("move_down")
-	if forward_dir != 0:
-		var diff = direction * forward_dir * move_speed * delta
-		position += diff
-
 func kill():
 	if dead:
 		return
diff --git a/Theme.tres b/Theme.tres
index 2667149..9f65931 100644
--- a/Theme.tres
+++ b/Theme.tres
@@ -4,7 +4,7 @@
 
 [sub_resource type="DynamicFont" id=1]
 size = 64
-outline_size = 1
+outline_size = 2
 outline_color = Color( 1, 0, 0, 1 )
 font_data = ExtResource( 1 )
 
diff --git a/World.gd b/World.gd
index 5cfdf94..b254518 100644
--- a/World.gd
+++ b/World.gd
@@ -28,24 +28,26 @@ func add_new_enemy(should_be_visible: bool = false) -> void:
 	enemy.add_to_group("enemies")
 	add_child(enemy)
 
-func _process(delta: float) -> void:
+func _process(_delta: float) -> void:
 	if Input.is_action_just_pressed("click") and !$Player.dead:
 		var pos = get_global_mouse_position()
 		destination = pos
 		is_destination_set = true
 		$Destination.position = pos
 		$Destination.visible = true
+		$Player.	global_rotation = global_position.direction_to(get_global_mouse_position()).angle() + PI/2.0
 
 	if is_destination_set:
 		var diff = destination - $Player.position
 		var unit = diff.normalized()
 		$Player.velocity = unit * $Player.move_speed
 		$Destination.visible = true
+		$CanvasLayer/HUD.debug_text = "player velocity = %s, %s" % [($Player.velocity.x), ($Player.velocity.y)]
 	else:
 		$Destination.visible = false
 		$Player.velocity = Vector2.ZERO
 
-func _on_Destination_body_entered(body: Node) -> void:
+func _on_Destination_body_entered(_body: Node) -> void:
 	is_destination_set = false
 
 func sort_enemies_ascending_distance(a: Enemy,b: Enemy):