Helath bar working, crosshair ported.

remotes/1705382094874458415/tmp_refs/heads/godot4-port
unfa 2020-09-29 00:17:19 +02:00
parent 6218910363
commit 15f9859b35
6 changed files with 180 additions and 36 deletions

125
Assets/HUD/Crosshair.tscn Normal file
View File

@ -0,0 +1,125 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://GUI/HitConfirmation.gd" type="Script" id=1]
[ext_resource path="res://Assets/SFX/UI-HitConfirmation.wav" type="AudioStream" id=2]
[node name="CrosshairContainer" type="CenterContainer"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -511.401
margin_top = -301.225
margin_right = 512.599
margin_bottom = 298.775
__meta__ = {
"_edit_use_anchors_": false
}
[node name="CrosshairCenter" type="Control" parent="."]
margin_left = 512.0
margin_top = 300.0
margin_right = 512.0
margin_bottom = 300.0
[node name="Line1" type="ColorRect" parent="CrosshairCenter"]
margin_left = 8.0
margin_top = -1.0
margin_right = 20.0
margin_bottom = 1.0
rect_pivot_offset = Vector2( -8, 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Line2" type="ColorRect" parent="CrosshairCenter"]
margin_left = 8.0
margin_top = -1.0
margin_right = 20.0
margin_bottom = 1.0
rect_rotation = 90.0
rect_pivot_offset = Vector2( -8, 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Line3" type="ColorRect" parent="CrosshairCenter"]
margin_left = 8.0
margin_top = -1.0
margin_right = 20.0
margin_bottom = 1.0
rect_rotation = 180.0
rect_pivot_offset = Vector2( -8, 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Line4" type="ColorRect" parent="CrosshairCenter"]
margin_left = 8.0
margin_top = -1.0
margin_right = 20.0
margin_bottom = 1.0
rect_rotation = -90.0
rect_pivot_offset = Vector2( -8, 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HitConfirmation" type="Control" parent="."]
light_mask = -2147483647
margin_left = 512.0
margin_top = 300.0
margin_right = 512.0
margin_bottom = 300.0
script = ExtResource( 1 )
[node name="HitConfirmationSound" type="AudioStreamPlayer" parent="HitConfirmation"]
stream = ExtResource( 2 )
[node name="Line1" type="ColorRect" parent="HitConfirmation"]
margin_left = 8.0
margin_top = -1.0
margin_right = 16.0
margin_bottom = 1.0
rect_rotation = 45.3067
rect_scale = Vector2( 1, 0.5 )
rect_pivot_offset = Vector2( -8, 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Line2" type="ColorRect" parent="HitConfirmation"]
margin_left = 8.0
margin_top = -1.0
margin_right = 16.0
margin_bottom = 1.0
rect_rotation = 135.307
rect_scale = Vector2( 1, 0.5 )
rect_pivot_offset = Vector2( -8, 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Line3" type="ColorRect" parent="HitConfirmation"]
margin_left = 8.0
margin_top = -1.0
margin_right = 16.0
margin_bottom = 1.0
rect_rotation = 225.306
rect_scale = Vector2( 1, 0.5 )
rect_pivot_offset = Vector2( -8, 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Line4" type="ColorRect" parent="HitConfirmation"]
margin_left = 8.0
margin_top = -1.0
margin_right = 16.0
margin_bottom = 1.0
rect_rotation = -44.6931
rect_scale = Vector2( 1, 0.5 )
rect_pivot_offset = Vector2( -8, 1 )
__meta__ = {
"_edit_use_anchors_": false
}

24
Assets/HUD/HUD.gd Normal file
View File

@ -0,0 +1,24 @@
extends Control
func updateHealth(health: int):
$Health/HealthBar.value = health
$Health/HealthBar/HealthText.text = String(health)
func updateCrosshair(visible: bool, hit: bool):
$Crosshair.visible = visible
if hit:
$Crosshair/HitConfirmation.activate(0.2)
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=11 format=2]
[ext_resource path="res://Assets/HUD/HealthBarOver.svg" type="Texture" id=1]
[ext_resource path="res://Assets/HUD/HealthBarProgress.svg" type="Texture" id=2]
@ -6,6 +6,7 @@
[ext_resource path="res://Assets/HUD/Panel.svg" type="Texture" id=4]
[ext_resource path="res://GUI/HitConfirmation.gd" type="Script" id=5]
[ext_resource path="res://Assets/SFX/UI-HitConfirmation.wav" type="AudioStream" id=6]
[ext_resource path="res://Assets/HUD/HUD.gd" type="Script" id=7]
[sub_resource type="VisualShaderNodeColorConstant" id=1]
constant = Color( 0, 0, 0, 0.176471 )
@ -51,6 +52,7 @@ anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 0.610558
margin_right = 0.610596
script = ExtResource( 7 )
__meta__ = {
"_edit_use_anchors_": false
}

View File

@ -1,6 +1,5 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=5 format=2]
[ext_resource path="res://Assets/HUD/HUD.tscn" type="PackedScene" id=1]
[ext_resource path="res://Game.gd" type="Script" id=2]
[ext_resource path="res://Level.tscn" type="PackedScene" id=3]
@ -39,8 +38,6 @@ glow_bicubic_upscale = true
script = ExtResource( 2 )
SERVER_IP = "127.0.0.1"
[node name="HUD" parent="." instance=ExtResource( 1 )]
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 2 )

View File

@ -12,7 +12,7 @@ const WALK_DECEL = 0.1
const MOUSE_SENSITIVITY = 1.0 / 1000
export var max_health = 150
onready var health = max_health
onready var health = max_health setget set_health
onready var camera = $Camera
onready var debug = $Debug
@ -49,6 +49,11 @@ var bodyHitEffect = preload("res://Assets/Effects/BodyHit.tscn")
# yield(get_tree().create_timer(sfx_footsteps_delay),"timeout")
# sfx_footsteps_play = false
func set_health(value):
health = value
print("Set health")
$HUD.updateHealth(value)
func gravity():
if not is_on_floor():
self.velocity.y -= GRAVITY
@ -158,7 +163,8 @@ func _physics_process(delta):
rset("translation", translation)
master func on_hit(damage, location):
health -= 30
set_health(health - 30)
rpc("blood_splatter", location)
@ -183,7 +189,7 @@ master func kill():
#print ("set as dead")
health = 0
set_health(0)
#print ("health:", health)
$CollisionShapeBody.disabled = true
@ -193,16 +199,16 @@ master func kill():
# spawn gibs
var gibs = $Player/Gibs.duplicate()
get_tree().root.add_child(gibs)
gibs.global_transform = global_transform
gibs.show()
#var gibs = $Player/Gibs.duplicate()
#get_tree().root.add_child(gibs)
#gibs.global_transform = global_transform
#gibs.show()
#print ("gibs spawned")
# enable the ragdoll colliders
for i in gibs.get_children():
i.get_child(1).disabled = false
#for i in gibs.get_children():
# i.get_child(1).disabled = false
#print ("gibs enabled")
@ -210,7 +216,7 @@ master func kill():
#print ("set as dead")
$MeshInstance.hide()
$Camera/Hand.hide()
$CrosshairContainer.hide()
$HUD.updateCrosshair(false, false)
yield(get_tree().create_timer(3), "timeout")
@ -221,15 +227,15 @@ master func kill():
yield(get_tree().create_timer(3), "timeout")
for i in gibs.get_children():
i.queue_free()
yield(get_tree().create_timer(rand_range(0.1, 1)), "timeout")
# for i in gibs.get_children():
# i.queue_free()
# yield(get_tree().create_timer(rand_range(0.1, 1)), "timeout")
gibs.queue_free()
# gibs.queue_free()
func spawn():
is_dead = false
health = 150
set_health(150)
velocity = Vector3()
walkDirection = Vector2.ZERO
@ -239,7 +245,7 @@ func spawn():
$MeshInstance.show()
$Camera/Hand.show()
$CrosshairContainer.show()
$HUD.updateCrosshair(true, false)
$CollisionShapeBody.disabled = false
$CollisionShapeFeet.disabled = false
@ -250,7 +256,6 @@ func spawn():
func shoot():
var gun = find_node("Weapon")
gun.shoot()
var space_state = get_world().direct_space_state
@ -270,7 +275,7 @@ func shoot():
if hit is get_script():
print("Is a live player")
$CrosshairContainer/HitConfirmation.activate(.2)
$HUD.updateCrosshair(true, true)
func _input(event):
@ -318,9 +323,10 @@ func _input(event):
# Called when the node enters the scene tree for the first time.
func _ready():
set_health(150)
# disabled the ragdoll collider
for i in $Player/Gibs.get_children():
i.get_child(1).disabled = true
#for i in $Player/Gibs.get_children():
# i.get_child(1).disabled = true
#disabled = true
#$"Player/Gibs/PlayerGibs _cell /shape0".set_disabled(true)

View File

@ -1,9 +1,8 @@
[gd_scene load_steps=9 format=2]
[gd_scene load_steps=8 format=2]
[ext_resource path="res://Player.gd" type="Script" id=1]
[ext_resource path="res://Assets/Weapons/Handgun/Handgun.tscn" type="PackedScene" id=2]
[ext_resource path="res://Assets/HUD/HUD.tscn" type="PackedScene" id=3]
[ext_resource path="res://Assets/Player/Player.gltf" type="PackedScene" id=4]
[ext_resource path="res://Audio/SoundPlayer.tscn" type="PackedScene" id=7]
[sub_resource type="CapsuleShape" id=1]
@ -39,7 +38,6 @@ shape = SubResource( 2 )
[node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0.882822, 0 )
visible = false
mesh = SubResource( 3 )
material/0 = null
@ -72,11 +70,3 @@ SoundClip = "res://Assets/SFX/Player-Pain-01.wav"
MinDelay = 0.2
[node name="HUD" parent="." instance=ExtResource( 3 )]
[node name="Player" parent="." instance=ExtResource( 4 )]
visible = false
[node name="shape0" parent="Player/Alive/Player /static_collision" index="0"]
disabled = true
[editable path="Player"]