add shields and tiers on ui

This commit is contained in:
2026-04-23 11:36:01 +03:00
parent bec9389bb8
commit c9489321ae
14 changed files with 163 additions and 10 deletions
+35 -5
View File
@@ -16,6 +16,10 @@ var toughness_tier: int = 0
var has_stick_armor: bool = false
var has_leather_armor: bool = false
var has_plate_armor: bool = false
var has_wooden_shield: bool = false
var has_iron_shield: bool = false
var shield_tier: int = 0
var is_shielding: bool = false
var kick_timer: float = 0.0
var invincible_timer: float = 0.0
var is_alive: bool = true
@@ -81,6 +85,7 @@ func _input(event: InputEvent) -> void:
func _physics_process(delta: float) -> void:
if not is_alive:
return
is_shielding = shield_tier > 0 and Input.is_key_pressed(KEY_SHIFT)
_handle_movement(delta)
_handle_kick(delta)
_handle_iframes(delta)
@@ -88,6 +93,7 @@ func _physics_process(delta: float) -> void:
_do_kick()
func _handle_movement(delta: float) -> void:
var effective_speed := move_speed * (0.2 if is_shielding else 1.0)
var input_x: float = (
float(Input.is_key_pressed(KEY_D) or Input.is_key_pressed(KEY_RIGHT)) -
float(Input.is_key_pressed(KEY_A) or Input.is_key_pressed(KEY_LEFT))
@@ -107,15 +113,15 @@ func _handle_movement(delta: float) -> void:
var move := cam_fwd * (-input_z) + cam_right * input_x
if move.length() > 0.01:
move = move.normalized()
velocity.x = move.x * move_speed
velocity.z = move.z * move_speed
velocity.x = move.x * effective_speed
velocity.z = move.z * effective_speed
last_move_dir = move
if not _is_aiming:
var target_y: float = atan2(-move.x, -move.z)
rotation.y = lerp_angle(rotation.y, target_y, 16.0 * delta)
else:
velocity.x = move_toward(velocity.x, 0.0, move_speed * 12.0 * delta)
velocity.z = move_toward(velocity.z, 0.0, move_speed * 12.0 * delta)
velocity.x = move_toward(velocity.x, 0.0, effective_speed * 12.0 * delta)
velocity.z = move_toward(velocity.z, 0.0, effective_speed * 12.0 * delta)
if _is_aiming:
rotation.y = lerp_angle(rotation.y, _aim_yaw, 14.0 * delta)
_is_aiming = false
@@ -221,10 +227,14 @@ func receive_kick(direction: Vector3, force: float) -> void:
invincible_timer = IFRAMES_DURATION * 0.5
_squish_effect()
func take_damage(amount: int) -> void:
func take_damage(amount: int, attacker_toughness: int = 0) -> void:
if not is_alive or invincible_timer > 0.0:
return
invincible_timer = IFRAMES_DURATION
if is_shielding and shield_tier > 0:
var diff := shield_tier - attacker_toughness
var mod: float = 0.15 if diff >= 2 else (0.30 if diff == 1 else 0.50)
amount = int(amount * mod)
_squish_effect()
func heal(amount: int) -> void:
@@ -303,3 +313,23 @@ func apply_plate_armor() -> bool:
tw.tween_property(player_mat, "albedo_color", Color(0.6, 0.7, 1.0), 0.1)
tw.tween_property(player_mat, "albedo_color", BASE_COLOR, 0.5)
return true
func apply_wooden_shield() -> bool:
if has_wooden_shield:
return false
has_wooden_shield = true
shield_tier = max(shield_tier, 1)
var tw := create_tween()
tw.tween_property(player_mat, "albedo_color", Color(0.55, 0.38, 0.18), 0.1)
tw.tween_property(player_mat, "albedo_color", BASE_COLOR, 0.4)
return true
func apply_iron_shield() -> bool:
if has_iron_shield:
return false
has_iron_shield = true
shield_tier = max(shield_tier, 2)
var tw := create_tween()
tw.tween_property(player_mat, "albedo_color", Color(0.55, 0.58, 0.62), 0.1)
tw.tween_property(player_mat, "albedo_color", BASE_COLOR, 0.5)
return true