Skip to content

Commit 599c64d

Browse files
committed
cleanup and version
1 parent 3eebead commit 599c64d

File tree

19 files changed

+65
-54
lines changed

19 files changed

+65
-54
lines changed

client/assets/bullet/bullet.gd

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
extends Area3D
22

3+
34
var from_player : int
4-
#var bullet_state : Array
55

66
func _ready():
77
print("hello world from: " + str(name))
88
# $AudioStreamPlayer3d.play()
9-
#func _physics_process(_delta):
10-
# # if category bullet doesnt exist in global_state add it
11-
# if !get_node("/root/Main").global_state.has("bullet"):
12-
# get_node("/root/Main").global_state["bullet"] = {}
13-
#
14-
# # add global bullet_state into vars
15-
# if get_node("/root/Main").global_state["bullet"].has(name):
16-
# bullet_state = get_node("/root/Main").global_state["bullet"][name]
17-
# position = bullet_state[1]

client/assets/health_bar/health_bar.gd

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,23 @@
11
extends Control
22

33

4+
#TODO: this script needs some work.. just an early prototype
45

5-
6-
#var healthbar_x = 500
7-
#var healthbar_y =40
86
var my_health_bar_size: Vector2 = Vector2(500.0, 40.0)
9-
#
10-
#var otherhealthbar_x = 250
11-
#var otherhealthbar_y =20
127
var other_health_bar_size: Vector2 = Vector2(250.0,20.0)
13-
148
var player_id
15-
@onready var player = get_node("../")
16-
var lbl_nametag
17-
189
var health_bar_size: Vector2
1910

20-
func _ready():
11+
@onready var player = get_node("../")
2112

13+
func _ready():
2214
#if my player
2315
if str(get_parent().name) == str($"/root/main/net".multiplayer.get_unique_id()):
2416
health_bar_size = my_health_bar_size
25-
26-
print("its me :) ---------------")
27-
else: #if other pplayer
28-
#add label
29-
# lbl_nametag = Label.new()
30-
# lbl_nametag.set_name("nametag")
31-
# lbl_nametag.text = "testtext"
32-
# lbl_nametag.set_position(Vector2(0,-20))
33-
# lbl_nametag.hide()
34-
# add_child(lbl_nametag)
17+
#if other player
18+
else:
3519
health_bar_size = other_health_bar_size
36-
37-
# hide()
20+
3821
var image = Image.create(health_bar_size.x,health_bar_size.y,false,Image.FORMAT_RGB8)
3922
image.fill(Color.DIM_GRAY)
4023
var image_texture = ImageTexture.new()
@@ -44,44 +27,54 @@ func _ready():
4427
$vbox/health_bar.set_tint_progress(Color.RED)
4528
set_name("healthbar_" + str(player_id))
4629

30+
4731
func _physics_process(delta):
48-
pass
4932
if str(get_parent().name) == str($"/root/main/net".multiplayer.get_unique_id()):
5033
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
5134
$vbox.set_anchors_and_offsets_preset(Control.PRESET_CENTER_BOTTOM)
52-
5335
else: #if not network master (if otherplayer)
5436
var healthbar_max_distance = 50
5537

38+
#TODO..
5639
var test_id = str(multiplayer.get_unique_id())
5740
var test = get_node("/root/main/players/" + str(test_id) + "/" + str(test_id))
5841

5942
var distance = player.transform.origin.distance_to(test.transform.origin)
6043
# #TODO offset based on distance??????????????????????????????????????????????????????????????
6144
if distance < healthbar_max_distance:
6245
var camera: Camera3D = test.get_node("SpringArm3D/Camera3D")
46+
47+
#TODO offset based on distance
48+
# var healthbar_offset_y=clamp(healthbar_max_offset_y-distance*4,50,180) #I dont know how to calculate the offset based on distance...TODO pls help xD
6349
var healthbar_max_offset_y = 180
64-
var healthbar_offset_y=healthbar_max_offset_y-distance
65-
## var nametag_healthbar_offset = 5
66-
var offset = Vector2(size.x/2*get_scale().x/2, healthbar_offset_y) #TODO offset based on distance
67-
## var offset_nametag = Vector2(lbl_nametag.get_size().x * lbl_nametag.get_scale().x/2, healthbar_offset_y + get_node("healthbar_" + get_name()).get_size().y*get_node("healthbar_" + get_name()).get_scale().y/2 + nametag_healthbar_offset) #TODO offset based on distance
68-
# # if( get_node("../../ui/healthbar_" + get_name()).get_position().x in (camera.unproject_position(get_translation()) - offset).x):
50+
var zwischenresultat1 = float(1) / healthbar_max_distance
51+
var distanceinprozent1 = distance * zwischenresultat1 #dreisatz 1=100%
52+
var healthbar_offset_y = clamp(180 - 180 * distanceinprozent1,50,180)
53+
var offset = Vector2(size.x/2*get_scale().x/2, healthbar_offset_y)
54+
55+
#TODO: only show if player is infront of my players camera
56+
# if( get_node("../../ui/healthbar_" + get_name()).get_position().x in (camera.unproject_position(get_translation()) - offset).x):
6957
var fovx = get_node("../SpringArm3D/Camera3D").position.x
7058
var fovy = get_node("../SpringArm3D/Camera3D").position.y
7159
var hbx = (get_node("../SpringArm3D/Camera3D").unproject_position(test.position) - offset).x
7260
var hby = (get_node("../SpringArm3D/Camera3D").unproject_position(test.position) - offset).y
73-
if(hby > 0 and hby > fovy) or (hbx > 0 and hbx > fovx) :
61+
62+
if(hby > 0 and hby > fovy) or (hbx > 0 and hbx > fovx):
7463
## # healthbar.set_scale(Vector2(0.5, 0.5)) #scale 50%
7564
if distance < 40:
7665
var zwischenresultat = float(1) / healthbar_max_distance
7766
var distanceinprozent = distance * zwischenresultat #dreisatz 1=100%
7867
set_scale(Vector2(1,1) - Vector2(distanceinprozent, distanceinprozent)) # Set scale based on distance
7968
show()
69+
70+
#show label
8071
# lbl_nametag.text="<" + str(player.charname) + "@" + str(player.username) + ">"
8172
$vbox/name_tag.text="<" + str(player.player_name) + ">"
8273
$vbox/name_tag.show()
83-
# set_position(camera.unproject_position(player.position) - offset)
84-
set_position(camera.unproject_position(player.position))
74+
75+
# set position with offset
76+
set_position(camera.unproject_position(player.position) - offset)
77+
# set_position(camera.unproject_position(player.position))
8578
else:
8679
hide()
8780
else:

client/assets/health_bar/health_bar.tscn

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@ script = ExtResource("1_a6ycr")
99

1010
[node name="vbox" type="VBoxContainer" parent="."]
1111
layout_mode = 1
12-
offset_right = 149.0
13-
offset_bottom = 40.0
12+
anchors_preset = 8
13+
anchor_left = 0.5
14+
anchor_top = 0.5
15+
anchor_right = 0.5
16+
anchor_bottom = 0.5
17+
offset_left = -74.5
18+
offset_top = -20.0
19+
offset_right = 74.5
20+
offset_bottom = 20.0
21+
grow_horizontal = 2
22+
grow_vertical = 2
1423

1524
[node name="name_tag" type="Label" parent="vbox"]
1625
visible = false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
extends StaticBody3D
22

3+
34
func _physics_process(_delta):
45
pass

client/assets/net/client_to_server.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ extends Node
44
func _enter_tree():
55
set_multiplayer_authority(int(str($"..".name)))
66

7+
78
@rpc("reliable")
89
func done_preconfig():
910
pass
1011

12+
1113
@rpc("unreliable_ordered")
1214
func send_input_unreliable():
1315
pass
1416

17+
1518
@rpc("reliable")
1619
func send_input_reliable():
1720
pass

client/assets/net/net.gd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ var last_sv_tickid: int
2323
var statebuffer: Array
2424
var cl_interp_time: float = float(cl_interp_ratio) / float(cl_updaterate)
2525

26-
2726
func _ready():
2827
Engine.physics_jitter_fix = 0.0
2928
Engine.physics_ticks_per_second=cl_tickrate

client/assets/net/server_to_client.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
extends Node
22

3+
34
@onready var b_res := preload("res://../assets/bullet/bullet.tscn")
45

56
@rpc("call_remote", "reliable")

client/assets/player/player.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func _ready():
3535

3636
#add healthbar
3737
var max_health=100
38-
var health=max_health
38+
health=max_health
3939
health_bar = preload("res://assets/health_bar/health_bar.tscn").instantiate()
4040
health_bar.get_node("vbox/health_bar").max_value=max_health
4141
health_bar.get_node("vbox/health_bar").set_value(max_health)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
extends RigidBody3D
22

3+
34
func _physics_process(_delta):
45
pass

client/assets/ui/launcher/launcher.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
extends CanvasLayer
22

3+
34
func _on_connect_pressed():
45
get_node("/root/main/net").server.ip = $panel/vbox/server_ip.text
56
get_node("/root/main/net").server.port = $panel/vbox/server_port.value

0 commit comments

Comments
 (0)