From 7ad01682063ca366e5a90f65cfc22a5e18ae520c Mon Sep 17 00:00:00 2001 From: justinorringer Date: Thu, 21 Dec 2023 02:09:11 -0500 Subject: [PATCH 1/3] Removing old scoreboard --- scenes/main.tscn | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/scenes/main.tscn b/scenes/main.tscn index 52529cf..20dc5c1 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -1,11 +1,10 @@ -[gd_scene load_steps=8 format=3 uid="uid://cnoe7lwarfttu"] +[gd_scene load_steps=7 format=3 uid="uid://cnoe7lwarfttu"] [ext_resource type="PackedScene" path="res://scenes/signal_server.tscn" id="1_1os64"] [ext_resource type="Script" path="res://scenes/manager/multiplayer_manager.gd" id="1_2jebv"] [ext_resource type="Script" path="res://scenes/manager/scene_manager.gd" id="1_22ckq"] [ext_resource type="Script" path="res://scenes/socket/client.gd" id="2_j1by0"] [ext_resource type="PackedScene" uid="uid://c7re7lky8g0bl" path="res://scenes/start.tscn" id="3_k5fwe"] -[ext_resource type="PackedScene" uid="uid://dttuc30vkk7yh" path="res://scenes/scoreboard.tscn" id="4_cgdun"] [ext_resource type="Texture2D" uid="uid://cmwqrwqwbkkh5" path="res://assets/menu/logo.png" id="7_la3mv"] [node name="Main" type="Node2D"] @@ -76,15 +75,6 @@ offset_right = 298.0 offset_bottom = 560.0 placeholder_text = "Code" -[node name="CanvasLayer" type="CanvasLayer" parent="."] - -[node name="Scoreboard" parent="CanvasLayer" instance=ExtResource("4_cgdun")] -visible = true -offset_left = 371.0 -offset_top = 63.0 -offset_right = -310.0 -offset_bottom = -58.0 - [node name="logo" type="Sprite2D" parent="."] position = Vector2(159.625, 107) scale = Vector2(1.125, 1.125) From 583e9cb1dc026b9018fac4d3821c6e77879ca071 Mon Sep 17 00:00:00 2001 From: justinorringer Date: Thu, 21 Dec 2023 03:31:28 -0500 Subject: [PATCH 2/3] Drafting player_marker; moving on lol --- assets/menu/player_marker.png | Bin 0 -> 650 bytes scenes/game_object/player/player.gd | 6 ++- scenes/game_object/player/player.tscn | 14 +++++-- scenes/game_object/ui/player_marker.gd | 48 +++++++++++++++++++++++ scenes/game_object/ui/player_marker.tscn | 23 +++++++++++ 5 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 assets/menu/player_marker.png create mode 100644 scenes/game_object/ui/player_marker.gd create mode 100644 scenes/game_object/ui/player_marker.tscn diff --git a/assets/menu/player_marker.png b/assets/menu/player_marker.png new file mode 100644 index 0000000000000000000000000000000000000000..0d9490886a3bceb8458690db1c7d177c910e56ee GIT binary patch literal 650 zcmV;50(Jd~P)Px%L`g(JRA_UEf`Zz(0HlPMEsJB?=9^!L6LP zhX2@HEV-OB@ZNyDuWv0kBVuOuAy$4y2dD5oN8VdP$xi#)b6u|2gip$}rk?GR4K3=? zE~lY^4fuU?^GfZKm1#}8ImcRb)Ggw)$jW)?xD*kkd#-*y$zNB5mSaN>l?4nJa7D>)SbKN7|Bh~e$(12Zw0G8CaG>b>5 zGecK5Xdv1y7pq;e=II(bGNX5O+Sie|3Z92bNXik=qV2RfFEk@7YhXN~R?aHGqM_PFrzsXL-feN-?LMyLTa27eLS;kOsO$;UXDKrOFHbZ=9763b#F5md7eVPII%AJSzHU2G0dDF6Tf07*qoM6N<$f^q*g@Bjb+ literal 0 HcmV?d00001 diff --git a/scenes/game_object/player/player.gd b/scenes/game_object/player/player.gd index b034b6e..7982e73 100644 --- a/scenes/game_object/player/player.gd +++ b/scenes/game_object/player/player.gd @@ -11,7 +11,8 @@ var can_boost = true @onready var barrel_color: Sprite2D = $Barrel/Sprite2D @onready var boost_timer: Timer = $BoostTimer @export var boost_icons: Array[TextureRect] -@onready var player_name : Label = $PlayerName +@onready var player_name: Label = $PlayerName +@onready var player_marker: Node2D = %PlayerMarker @onready var previous_movement: Vector2 = Vector2.ZERO @@ -22,9 +23,12 @@ func _ready(): if $MultiplayerSynchronizer.get_multiplayer_authority() == player_id: $Camera2D.make_current() health_component.health_changed.connect(on_health_changed) + player_marker.disable() var tank_color = GameManager.players[player_id].color set_tank_texture.rpc(player_id, tank_color) set_player_name.rpc(player_id) + else: + player_marker.enable(player_id, GameManager.players[player_id].name) @rpc("any_peer", "call_local") func set_player_name(player_id): diff --git a/scenes/game_object/player/player.tscn b/scenes/game_object/player/player.tscn index 24a5344..f88faa7 100644 --- a/scenes/game_object/player/player.tscn +++ b/scenes/game_object/player/player.tscn @@ -1,11 +1,12 @@ -[gd_scene load_steps=20 format=3 uid="uid://bam04hog13mtt"] +[gd_scene load_steps=21 format=3 uid="uid://bam04hog13mtt"] [ext_resource type="Script" path="res://scenes/game_object/player/player.gd" id="1_hkal2"] [ext_resource type="PackedScene" uid="uid://73lr8fqud4" path="res://scenes/component/health_component.tscn" id="2_gt4m0"] -[ext_resource type="Texture2D" path="res://assets/menu/boost.png" id="2_mn8cc"] +[ext_resource type="Texture2D" uid="uid://bev0i3hblaggj" path="res://assets/menu/boost.png" id="2_mn8cc"] [ext_resource type="PackedScene" uid="uid://drybknwrows3o" path="res://scenes/game_object/player/tank_body.tscn" id="3_1e010"] -[ext_resource type="Texture2D" path="res://assets/menu/boost_dark.png" id="3_ciky0"] +[ext_resource type="Texture2D" uid="uid://cjgsa7jtfnoms" path="res://assets/menu/boost_dark.png" id="3_ciky0"] [ext_resource type="Texture2D" uid="uid://8ip3d3virahl" path="res://scenes/game_object/player/tankGreen_barrel3_outline.png" id="3_vvwhs"] +[ext_resource type="PackedScene" uid="uid://cqxs0jej1q5jn" path="res://scenes/game_object/ui/player_marker.tscn" id="4_m3oq3"] [ext_resource type="Script" path="res://scenes/game_object/player/Barrel.gd" id="4_yiyg3"] [ext_resource type="PackedScene" uid="uid://dp7s6opobih82" path="res://scenes/component/hurtbox_component.tscn" id="5_fvhfs"] [ext_resource type="PackedScene" uid="uid://dubcod0jv5c7t" path="res://scenes/game_object/player/health_bar.tscn" id="7_p6dmh"] @@ -105,6 +106,12 @@ layout_mode = 2 texture = ExtResource("3_ciky0") stretch_mode = 2 +[node name="PlayerMarker" parent="HUD" node_paths=PackedStringArray("player", "camera") instance=ExtResource("4_m3oq3")] +unique_name_in_owner = true +visible = false +player = NodePath("../..") +camera = NodePath("../../Camera2D") + [node name="HealthComponent" parent="." instance=ExtResource("2_gt4m0")] max_health = 50.0 @@ -189,4 +196,5 @@ frame_progress = 0.217273 [connection signal="timeout" from="BoostTimer" to="." method="_on_boost_timer_timeout"] +[editable path="HUD/PlayerMarker"] [editable path="TankBody"] diff --git a/scenes/game_object/ui/player_marker.gd b/scenes/game_object/ui/player_marker.gd new file mode 100644 index 0000000..68159fa --- /dev/null +++ b/scenes/game_object/ui/player_marker.gd @@ -0,0 +1,48 @@ +extends Node2D + +@export var player: Player +@export var camera: Camera2D +@onready var pointer = $Pointer +@onready var player_name = $Pointer/NameMarker +var disabled = false + +func _ready(): + #if player_id == GameManager.ENVIRONMENT: + #disable() + pass + +func enable(id, name): + player_name.text = name + +func disable(): + disabled = false + set_process(false) + visible = false + +# base from this tutorial +# https://youtu.be/Sw9Iiejkae4?si=VPpL7UNA6UTAvfOl +func _physics_process(delta): + if disabled: + return + var canvas = get_canvas_transform() + # canvas.get_scale() for adjusting these for camera zoom + var top_left = -camera.get_screen_center_position() / canvas.get_scale() + var size = get_viewport_rect().size / canvas.get_scale() + + set_marker_position(Rect2(top_left, size)) + set_marker_rotation() + +func set_marker_position(bounds : Rect2): + pointer.global_position.x = clamp(global_position.x, bounds.position.x, bounds.end.x) + pointer.global_position.y = clamp(global_position.y, bounds.position.y, bounds.end.y) + + # object is on screen + if bounds.has_point(global_position): + hide() + return + show() + +func set_marker_rotation(): + var angle = (global_position - pointer.global_position).angle() + pointer.global_rotation = angle + player_name.rotation = 0.0 diff --git a/scenes/game_object/ui/player_marker.tscn b/scenes/game_object/ui/player_marker.tscn new file mode 100644 index 0000000..44652b0 --- /dev/null +++ b/scenes/game_object/ui/player_marker.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=3 format=3 uid="uid://cqxs0jej1q5jn"] + +[ext_resource type="Script" path="res://scenes/game_object/ui/player_marker.gd" id="1_7q3vp"] +[ext_resource type="Texture2D" uid="uid://b03swukpu7v84" path="res://assets/menu/player_marker.png" id="2_pf83w"] + +[node name="PlayerMarker" type="Node2D"] +position = Vector2(-1, 1) +script = ExtResource("1_7q3vp") + +[node name="Pointer" type="Sprite2D" parent="."] +texture = ExtResource("2_pf83w") +offset = Vector2(-21.16, 0) + +[node name="NameMarker" type="RichTextLabel" parent="Pointer"] +offset_left = -107.0 +offset_top = -13.0 +offset_right = -60.0 +offset_bottom = 27.0 +pivot_offset = Vector2(20.8, 12.37) +text = "NAME" +fit_content = true +scroll_active = false +autowrap_mode = 0 From 14c6418d6f45160dd70ad7ca37c6f93f470c3990 Mon Sep 17 00:00:00 2001 From: justinorringer Date: Thu, 21 Dec 2023 15:01:49 -0500 Subject: [PATCH 3/3] Updating with main, still doesn't work --- scenes/game_object/player/player.gd | 2 +- scenes/game_object/player/player.tscn | 4 ++-- scenes/game_object/ui/player_marker.gd | 20 +++++++++----------- scenes/game_object/ui/player_marker.tscn | 1 - 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/scenes/game_object/player/player.gd b/scenes/game_object/player/player.gd index e9bb190..705eaa5 100644 --- a/scenes/game_object/player/player.gd +++ b/scenes/game_object/player/player.gd @@ -36,7 +36,7 @@ func _ready(): set_tank_texture.rpc(player_id, tank_color) set_player_name.rpc(player_id) else: - player_marker.enable(player_id, GameManager.players[player_id].name) + player_marker.enable(GameManager.players[player_id].name) boost_available.visible = false boost_unavailable.visible = false diff --git a/scenes/game_object/player/player.tscn b/scenes/game_object/player/player.tscn index c619529..b1504b9 100644 --- a/scenes/game_object/player/player.tscn +++ b/scenes/game_object/player/player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=21 format=3 uid="uid://bam04hog13mtt"] +[gd_scene load_steps=22 format=3 uid="uid://bam04hog13mtt"] [ext_resource type="Script" path="res://scenes/game_object/player/player.gd" id="1_hkal2"] [ext_resource type="PackedScene" uid="uid://73lr8fqud4" path="res://scenes/component/health_component.tscn" id="2_gt4m0"] @@ -114,9 +114,9 @@ stretch_mode = 2 [node name="PlayerMarker" parent="HUD" node_paths=PackedStringArray("player", "camera") instance=ExtResource("4_m3oq3")] unique_name_in_owner = true -visible = false player = NodePath("../..") camera = NodePath("../../Camera2D") + [node name="PanelContainer2" type="PanelContainer" parent="HUD"] anchors_preset = 8 anchor_left = 0.5 diff --git a/scenes/game_object/ui/player_marker.gd b/scenes/game_object/ui/player_marker.gd index 68159fa..0b6e8b3 100644 --- a/scenes/game_object/ui/player_marker.gd +++ b/scenes/game_object/ui/player_marker.gd @@ -6,13 +6,9 @@ extends Node2D @onready var player_name = $Pointer/NameMarker var disabled = false -func _ready(): - #if player_id == GameManager.ENVIRONMENT: - #disable() - pass - -func enable(id, name): - player_name.text = name +func enable(name=""): + if name != "": + player_name.text = name func disable(): disabled = false @@ -21,14 +17,16 @@ func disable(): # base from this tutorial # https://youtu.be/Sw9Iiejkae4?si=VPpL7UNA6UTAvfOl -func _physics_process(delta): - if disabled: - return +func _process(delta): var canvas = get_canvas_transform() # canvas.get_scale() for adjusting these for camera zoom - var top_left = -camera.get_screen_center_position() / canvas.get_scale() + var top_left = -canvas.origin / canvas.get_scale() var size = get_viewport_rect().size / canvas.get_scale() + print("canvas") + print(canvas) + print("top_left") + print(top_left) set_marker_position(Rect2(top_left, size)) set_marker_rotation() diff --git a/scenes/game_object/ui/player_marker.tscn b/scenes/game_object/ui/player_marker.tscn index 44652b0..71653d2 100644 --- a/scenes/game_object/ui/player_marker.tscn +++ b/scenes/game_object/ui/player_marker.tscn @@ -4,7 +4,6 @@ [ext_resource type="Texture2D" uid="uid://b03swukpu7v84" path="res://assets/menu/player_marker.png" id="2_pf83w"] [node name="PlayerMarker" type="Node2D"] -position = Vector2(-1, 1) script = ExtResource("1_7q3vp") [node name="Pointer" type="Sprite2D" parent="."]