Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Player marker draft #64

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/menu/player_marker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion scenes/game_object/player/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ var can_boost = true
@onready var tank_body: Sprite2D = $TankBody/Sprite2D
@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_marker: Node2D = %PlayerMarker
@export var boost_available: TextureRect
@export var boost_unavailable: TextureRect
@onready var player_name: Label = $PlayerName
@onready var emote = load("res://scenes/game_object/player/emote.tscn")
@export var emote_wheel: Control

Expand All @@ -29,10 +31,13 @@ func _ready():
if multiplayer.get_unique_id() == 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(GameManager.players[player_id].name)

boost_available.visible = false
boost_unavailable.visible = false
emote = emote.instantiate()
Expand Down
9 changes: 8 additions & 1 deletion scenes/game_object/player/player.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[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"]
[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" 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="PackedScene" uid="uid://dbb83yj4h1nw2" path="res://scenes/game_object/ui/emote_wheel.tscn" id="4_vw4ar"]
[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"]
Expand Down Expand Up @@ -111,6 +112,11 @@ 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
player = NodePath("../..")
camera = NodePath("../../Camera2D")

[node name="PanelContainer2" type="PanelContainer" parent="HUD"]
anchors_preset = 8
anchor_left = 0.5
Expand Down Expand Up @@ -210,5 +216,6 @@ frame_progress = 0.217273

[connection signal="timeout" from="BoostTimer" to="." method="_on_boost_timer_timeout"]

[editable path="HUD/PlayerMarker"]
[editable path="HUD/PanelContainer2/EmoteWheel"]
[editable path="TankBody"]
46 changes: 46 additions & 0 deletions scenes/game_object/ui/player_marker.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
extends Node2D

@export var player: Player
@export var camera: Camera2D
@onready var pointer = $Pointer
@onready var player_name = $Pointer/NameMarker
var disabled = false

func enable(name=""):
if 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 _process(delta):
var canvas = get_canvas_transform()
# canvas.get_scale() for adjusting these for camera zoom
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()

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
22 changes: 22 additions & 0 deletions scenes/game_object/ui/player_marker.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[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"]
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