added enemy health bar and target with markers
This commit is contained in:
@@ -1,7 +1,25 @@
|
||||
extends Control
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
queue_redraw()
|
||||
|
||||
@onready var sub_viewport: SubViewport = $".."
|
||||
@onready var health_bar_sprite: Sprite3D = $"../.."
|
||||
|
||||
var center = Vector2.ZERO
|
||||
var current_health : float
|
||||
|
||||
const MARGIN = 20
|
||||
|
||||
func _ready() -> void:
|
||||
center = Vector2(sub_viewport.size.x/2,sub_viewport.size.y/2)
|
||||
|
||||
func _draw() -> void:
|
||||
draw_circle(Vector2.ZERO,0,Color(1,1,1,1),true,10,true)
|
||||
print("CHARACTER HEALTH : ")
|
||||
var health_percentage : float = health_bar_sprite.character.health/health_bar_sprite.character.start_health
|
||||
#background
|
||||
draw_line(Vector2(0,center.y),Vector2(sub_viewport.size.x,center.y),Color(.5,.5,.5,.75),MARGIN * 2,true)
|
||||
|
||||
#health
|
||||
for i in range(health_bar_sprite.character.health):
|
||||
var width = sub_viewport.size.x / health_bar_sprite.character.start_health
|
||||
var from = width * i + MARGIN/2
|
||||
var to = width * (i+1) - MARGIN/2
|
||||
draw_line(Vector2(from,center.y),Vector2(to,center.y),ColorSwatch.RED_COLOR,30,true)
|
||||
|
||||
@@ -14,7 +14,7 @@ func _ready():
|
||||
|
||||
scale.x = 1 * rand_scale
|
||||
scale.y = 1 * rand_scale
|
||||
text = str(damage_amt)
|
||||
text = str(int(damage_amt))
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
|
||||
@@ -45,6 +45,10 @@ func _physics_process(delta):
|
||||
instance_bullethole.look_at(ray.get_collision_point() + ray.get_collision_normal())
|
||||
instance_bullethole.rotation.z = deg_to_rad(randf_range(0,360))
|
||||
|
||||
#range target
|
||||
if body.is_in_group("range_target"):
|
||||
body.add_marker(ray.get_collision_point(),ray.global_rotation)
|
||||
|
||||
# Leaking effect
|
||||
if body.is_in_group("leak"):
|
||||
var leakspawn = water_leak.instantiate()
|
||||
|
||||
7
scripts/health_bar_sprite.gd
Normal file
7
scripts/health_bar_sprite.gd
Normal file
@@ -0,0 +1,7 @@
|
||||
extends Sprite3D
|
||||
|
||||
@export var character : Node
|
||||
@onready var health_bar: Control = $SubViewport/HealthBar
|
||||
|
||||
func health_update():
|
||||
health_bar.queue_redraw()
|
||||
1
scripts/health_bar_sprite.gd.uid
Normal file
1
scripts/health_bar_sprite.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cjlwdeu1cft4i
|
||||
@@ -33,7 +33,7 @@ func _on_continue_pressed() -> void:
|
||||
|
||||
|
||||
if GameGlobals.current_level == null:
|
||||
level = "res://scenes/HUBWORLD.tscn"
|
||||
level = "res://scenes/blockout_4.tscn"
|
||||
load_to_gamemode = "res://GameModes/hubworld.tres"
|
||||
else:
|
||||
level = GameGlobals.current_level
|
||||
|
||||
@@ -37,6 +37,8 @@ func _on_body_entered(body: Node3D) -> void:
|
||||
SaveLoad.save_game_data(get_tree().current_scene.get_name())
|
||||
SaveLoad.save_user_data()
|
||||
get_tree().change_scene_to_file(scene_path)
|
||||
else:
|
||||
body.velocity = -body.velocity * 2
|
||||
|
||||
|
||||
func _on_start_activation_timeout() -> void:
|
||||
|
||||
@@ -10,6 +10,7 @@ signal money_deposited()
|
||||
signal player_exiting_tree()
|
||||
signal player_hit()
|
||||
signal shot_fired()
|
||||
signal player_reloading()
|
||||
signal enemy_hit()
|
||||
signal enemy_killed()
|
||||
signal king_killed()
|
||||
|
||||
@@ -5,7 +5,7 @@ signal last_enemy_dead()
|
||||
var player
|
||||
var last_enemy : bool = false
|
||||
|
||||
@export var health = 3
|
||||
@export var start_health = 3
|
||||
@export var SPEED = 3.0
|
||||
@export var loot_amount = 2
|
||||
const MAX_LV = 10
|
||||
@@ -58,6 +58,8 @@ $body/leg3/leg3outline,
|
||||
$body/leg4/foot4/foot4outline,
|
||||
$body/leg4/leg4outline,
|
||||
$body/bodyoutline]
|
||||
@onready var health_bar_sprite: Sprite3D = $HealthBarSprite
|
||||
|
||||
|
||||
var gravity = 9.8
|
||||
var particlespawn
|
||||
@@ -73,11 +75,13 @@ var player_in_view = false
|
||||
var player_last_seen
|
||||
var knocked = false
|
||||
var stunned = false
|
||||
var health
|
||||
|
||||
func _ready():
|
||||
health = start_health
|
||||
player = level_control.player
|
||||
#health_bar_sprite.visible = false
|
||||
turret_material.emission_enabled = false
|
||||
|
||||
#randomly start the postfire timer so enemy turrets aren't synced
|
||||
var random_time = randf_range(0,5)
|
||||
await get_tree().create_timer(random_time).timeout
|
||||
@@ -124,6 +128,8 @@ func _process(delta):
|
||||
|
||||
|
||||
func _on_area_3d_body_part_hit(dam,bullet_damage):
|
||||
health_bar_sprite.visible = true
|
||||
health_bar_sprite.health_update()
|
||||
if !dying:
|
||||
health -= dam * bullet_damage
|
||||
if health <= 0:
|
||||
@@ -243,6 +249,7 @@ func save():
|
||||
"rot_x" : rotation.x,
|
||||
"rot_y" : rotation.y,
|
||||
"rot_z" : rotation.z,
|
||||
"start_health" : start_health,
|
||||
"health" : health
|
||||
}
|
||||
return save_dict
|
||||
|
||||
21
scripts/target_1.gd
Normal file
21
scripts/target_1.gd
Normal file
@@ -0,0 +1,21 @@
|
||||
extends StaticBody3D
|
||||
|
||||
@onready var ray_cast_3d: RayCast3D = $RayCast3D
|
||||
|
||||
const TARGET_MARKER = preload("res://assets/target_marker.tscn")
|
||||
|
||||
func _ready() -> void:
|
||||
SignalBus.player_reloading.connect(remove_targets)
|
||||
|
||||
func remove_targets():
|
||||
print("PLAYER RELOADING")
|
||||
for i in get_children():
|
||||
if i.is_in_group("target_marker"):
|
||||
i.queue_free()
|
||||
|
||||
func add_marker(collision_point,bullet_rotation):
|
||||
var instance_marker = TARGET_MARKER.instantiate()
|
||||
add_child(instance_marker)
|
||||
instance_marker.global_position = collision_point
|
||||
instance_marker.global_rotation = bullet_rotation
|
||||
|
||||
1
scripts/target_1.gd.uid
Normal file
1
scripts/target_1.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://xua2jmq16kjc
|
||||
@@ -134,6 +134,7 @@ func shoot():
|
||||
anim_player.play("shoot")
|
||||
|
||||
func reload():
|
||||
SignalBus.emit_signal("player_reloading")
|
||||
match weapon_info.weapon_type:
|
||||
0:
|
||||
match weapon_info.reload_type:
|
||||
|
||||
Reference in New Issue
Block a user