More work on combat
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
extends Sprite2D
|
||||
|
||||
@onready var label : Label = $Label
|
||||
|
||||
func _ready():
|
||||
var move_tween = create_tween()
|
||||
move_tween.tween_property(self, "position:y", -40, 1.25)
|
||||
@@ -10,3 +12,6 @@ func _ready():
|
||||
fade_tween.tween_property(self, "modulate:a", 0, .25)
|
||||
fade_tween.tween_callback(queue_free)
|
||||
|
||||
func set_label(string : String) -> void:
|
||||
if label != null:
|
||||
label.text = string
|
||||
|
||||
@@ -1,32 +1,47 @@
|
||||
class_name QuestSprite extends Control
|
||||
|
||||
@onready var damage_banner_template = preload("res://templates/damage_banner.tscn")
|
||||
|
||||
|
||||
@onready var lifebar : TextureProgressBar = $LifeBar
|
||||
|
||||
var life : int = 1
|
||||
var max_life : int = 1
|
||||
var energy : int = 1
|
||||
var max_energy : int = 1
|
||||
@export var life : int = 1
|
||||
@export var max_life : int = 1
|
||||
@export var energy : int = 1
|
||||
@export var max_energy : int = 1
|
||||
var level : int = 1
|
||||
var exp : int = 0
|
||||
@export var exp : int = 0
|
||||
var reset_position : Vector2
|
||||
var melee_range : float = 100
|
||||
var highlight_color : Color = Color(1,1,1,0)
|
||||
var knockback_tween : Tween
|
||||
|
||||
@export var stats : StatBlock
|
||||
var gold : int = 0
|
||||
|
||||
|
||||
@onready var anim_player : AnimationPlayer = $AnimationPlayer
|
||||
@onready var sprite_material : ShaderMaterial = $Sprite.material
|
||||
@onready var banner_offset : Node2D = $BannerOffset
|
||||
signal hitting()
|
||||
signal died(killer :QuestSprite)
|
||||
signal action_complete(requeue : bool)
|
||||
signal busy()
|
||||
signal arrived()
|
||||
|
||||
func _ready() -> void:
|
||||
lifebar.value = life
|
||||
lifebar.max_value = max_life
|
||||
lifebar.visible = false
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
sprite_material.set_shader_parameter("highlight", highlight_color)
|
||||
|
||||
func position_reset() -> void:
|
||||
var tween = create_tween()
|
||||
#TODO: Vary movement animations?
|
||||
tween.tween_callback(anim_player.play.bind("running"))
|
||||
tween.tween_property(self, "position", reset_position,.75)
|
||||
tween.tween_property(self, "position", reset_position,.5)
|
||||
if reset_position.x < position.x:
|
||||
$Sprite.flip_h = true
|
||||
tween.tween_property($Sprite, "flip_h", false, 0)
|
||||
@@ -41,7 +56,7 @@ func approach(target, offset) -> void:
|
||||
#TODO: Vary movement animations?
|
||||
tween.tween_callback(anim_player.play.bind("running"))
|
||||
var target_position = target.position + Vector2(offset, 0)
|
||||
tween.tween_property(self, "position", target_position,.75)
|
||||
tween.tween_property(self, "position", target_position,.5)
|
||||
if target_position.x < position.x:
|
||||
$Sprite.flip_h = true
|
||||
tween.tween_property($Sprite, "flip_h", false, 0)
|
||||
@@ -50,13 +65,24 @@ func approach(target, offset) -> void:
|
||||
|
||||
func attack(target : QuestSprite) -> void:
|
||||
print("Attack by %s to %s" % [name, target.name])
|
||||
target.take_damage(self, 10)
|
||||
action_complete.emit(true)
|
||||
hitting.connect(spear_hit.bind(target), CONNECT_ONE_SHOT)
|
||||
anim_player.play("spear attack")
|
||||
|
||||
func spear_hit(target : QuestSprite) -> void:
|
||||
target.take_damage(self, 5)
|
||||
|
||||
func take_damage(source : QuestSprite, amount : int) -> void:
|
||||
busy.emit()
|
||||
var damage_banner = damage_banner_template.instantiate()
|
||||
damage_banner.position = Vector2.ZERO
|
||||
banner_offset.add_child(damage_banner)
|
||||
damage_banner.set_label(str(-amount))
|
||||
if amount > 0:
|
||||
anim_player.play("hurt")
|
||||
life = clampi(life - amount, 0, max_life)
|
||||
lifebar.value = life * 100 / max_life
|
||||
lifebar.value = life
|
||||
lifebar.max_value = max_life
|
||||
|
||||
if life == 0:
|
||||
print("%s killed %s!" % [source.name, name])
|
||||
die(source)
|
||||
@@ -68,3 +94,26 @@ func take_damage(source : QuestSprite, amount : int) -> void:
|
||||
func die(killer : QuestSprite) -> void:
|
||||
died.emit(killer)
|
||||
queue_free()
|
||||
|
||||
func trigger_hit() -> void:
|
||||
hitting.emit()
|
||||
|
||||
func complete_action(requeue : bool, reset_animation : String) -> void:
|
||||
anim_player.play(reset_animation)
|
||||
action_complete.emit(requeue)
|
||||
|
||||
func show_lifebar(showing : bool) -> void:
|
||||
lifebar.visible = showing
|
||||
|
||||
func flip_h() -> void:
|
||||
$Sprite.flip_h = true
|
||||
|
||||
func knockback(time : float) -> void:
|
||||
knockback_tween = create_tween()
|
||||
var offset : Vector2 = Vector2(-20, 0)
|
||||
if $Sprite.flip_h:
|
||||
offset.x *= -1
|
||||
var knockback_pos = reset_position + offset
|
||||
knockback_tween.tween_property(self, "position", knockback_pos, lerp(0.0, time, (knockback_pos.x - position.x) / offset.x ))
|
||||
knockback_tween.tween_property(self, "position", reset_position, time)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class_name QuestorSprite extends QuestSprite
|
||||
|
||||
@onready var levelup_banner_template = preload("res://templates/levelup_banner.tscn")
|
||||
|
||||
var data : Adventurer = null
|
||||
var banner_lag : float
|
||||
|
||||
@@ -15,7 +16,8 @@ func _ready() -> void:
|
||||
stats = StatBlock.copy(data.stats)
|
||||
gold = data.gold
|
||||
data.changed.connect(_on_questor_changed)
|
||||
|
||||
super._ready()
|
||||
|
||||
func _process(delta) -> void:
|
||||
if banner_lag > 0:
|
||||
banner_lag -= delta
|
||||
@@ -45,13 +47,15 @@ func show_levelup_banner(lagged : bool = false) -> void:
|
||||
return
|
||||
var banner = levelup_banner_template.instantiate()
|
||||
banner.position = Vector2.ZERO
|
||||
$BannerOffset.add_child(banner)
|
||||
banner_offset.add_child(banner)
|
||||
banner_lag = .75
|
||||
|
||||
|
||||
func check_levelup() -> void:
|
||||
data.gain_exp(exp)
|
||||
|
||||
|
||||
|
||||
func _on_level_up() -> void:
|
||||
show_levelup_banner()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user