godot-mota/scripts/MonsterSprite.gd

42 lines
962 B
GDScript

extends AnimatedSprite
class_name MonsterSprite
var monster_info : Dictionary
func _on_Area2D_body_entered(body):
# 查询怪物信息
monster_info = MonsterBook.get_info_by_name(animation)
if monster_info == null:
print("未找到怪物",animation)
return
# 开始播放打斗动画
$AtkSprite.playing = true
# 打斗动画播放完成回调
func _on_AtkSprite_animation_finished():
var atk_sprite =$AtkSprite
atk_sprite.playing = false
var player_info = GameArchiveManager.player_info
monster_info.hp -= get_hurt(player_info.atk - monster_info.def)
if monster_info.hp <= 0:
dead()
return
player_info.hp -= get_hurt(monster_info.atk - player_info.def)
GameArchiveManager.update_hp_view()
if player_info.hp <=0:
print("game over")
else:
atk_sprite.playing = true
func dead():
GameArchiveManager.add_used_item(get_path())
queue_free()
# 计算伤害
func get_hurt(hurt:int) -> int:
if hurt > 0:
return hurt
else:
return 0