10.25
This commit is contained in:
parent
960c397303
commit
19a270cb1e
@ -7,15 +7,15 @@ var init_favour:Dictionary={
|
||||
#测试族群1
|
||||
"test_1":{
|
||||
#对测试族群2的初始好感度为-10
|
||||
"test_1":20,
|
||||
"test_2":-50,
|
||||
"player":-20,
|
||||
"test_1":-100,
|
||||
"test_2":-100,
|
||||
"player":-100,
|
||||
},
|
||||
"test_2":{
|
||||
|
||||
"test_2":100,
|
||||
"test_1":50,
|
||||
"player":-20,
|
||||
"test_2":-100,
|
||||
"test_1":-100,
|
||||
"player":-100,
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,10 @@ func get_unit_instance(id:String):
|
||||
return unit_instance_dic[id]
|
||||
else:
|
||||
return null
|
||||
func delete_unit_instance(id:String):
|
||||
unit_instance_dic.erase(id)
|
||||
|
||||
pass
|
||||
#单位好感度字典
|
||||
var unit_favour_dic:Dictionary={
|
||||
|
||||
|
@ -11,6 +11,7 @@ func tick(actor:Node,black_board:Blackboard):
|
||||
if res:
|
||||
black_board.set_value("target_unit_id",i.unit_id)
|
||||
return SUCCESS
|
||||
black_board.erase_value("target_unit_id")
|
||||
return FAILURE
|
||||
pass
|
||||
|
||||
|
@ -9,10 +9,11 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func _on_animation_finished() -> void:
|
||||
animation_player.play("mddulutehide")
|
||||
animation_player.play("modulutehide")
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
func _on_animation_player_animation_finished(anim_name: StringName) -> void:
|
||||
print("dada")
|
||||
queue_free()
|
||||
pass # Replace with function body.
|
||||
|
@ -5,7 +5,8 @@ func tick(actor:Node,black_board:Blackboard):
|
||||
var unit:Unit=actor
|
||||
if unit.is_attacking():
|
||||
var target_unit:Unit=Global.get_unit_instance(black_board.get_value("target_unit_id"))
|
||||
unit.set_target(target_unit.global_position)
|
||||
if is_instance_valid(target_unit):
|
||||
unit.set_target(target_unit.global_position)
|
||||
return RUNNING
|
||||
if unit.is_attack_finished():
|
||||
black_board.erase_value("target_unit_id")
|
||||
|
@ -13,6 +13,7 @@ func tick(actor:Node,black_board:Blackboard):
|
||||
return FAILURE
|
||||
#获取要移动到的目标实例
|
||||
var target_instance:Unit=Global.get_unit_instance(target_id)
|
||||
|
||||
if not unit.is_unit_instance_in_touch_area(target_instance):
|
||||
unit.set_target_pos(target_instance.global_position)
|
||||
match unit.get_dir():
|
||||
@ -52,7 +53,3 @@ func tick(actor:Node,black_board:Blackboard):
|
||||
unit.play_animation("left_right_idle")
|
||||
return FAILURE
|
||||
|
||||
pass
|
||||
|
||||
|
||||
pass
|
||||
|
20
scene/test/atk.gd
Normal file
20
scene/test/atk.gd
Normal file
@ -0,0 +1,20 @@
|
||||
extends State
|
||||
var target
|
||||
func enter_state(n):
|
||||
if n is Unit:
|
||||
target=n
|
||||
get_player().attack()
|
||||
pass
|
||||
func update_state(delta):
|
||||
pass
|
||||
func update_state_phy(delta):
|
||||
if get_player().is_attack_finished():
|
||||
change_to_state("idle")
|
||||
func exit_state():
|
||||
target=null
|
||||
pass
|
||||
|
||||
func process_message(type:String,n):
|
||||
|
||||
|
||||
pass
|
@ -46,9 +46,10 @@ var action_emoji:Dictionary={
|
||||
"hp_max":100,
|
||||
"hp":100,
|
||||
|
||||
"atk":10,
|
||||
}
|
||||
#允许的状态队列
|
||||
var state_value_array:Array=["hungry","fatigue","rage","tensity","panic","pressure","hp_max","hp"]
|
||||
var state_value_array:Array=["hungry","fatigue","rage","tensity","panic","pressure","hp_max","hp","atk"]
|
||||
#设置状态值
|
||||
func get_state_value(state_value_name:String):
|
||||
if state_value_name in state_value_array:
|
||||
@ -59,7 +60,13 @@ func get_state_value(state_value_name:String):
|
||||
signal state_value_changed(state_value_name:String,value)
|
||||
#设置状态值
|
||||
func set_state_value(state_value_name:String,value)->bool:
|
||||
|
||||
if state_value_name in state_value_array:
|
||||
#对每种属性更改进行特殊设置
|
||||
match state_value_name:
|
||||
"hp":
|
||||
if value<=0:
|
||||
dead()
|
||||
unit_data[state_value_name]=value
|
||||
state_value_changed.emit(state_value_name,value)
|
||||
return true
|
||||
@ -79,6 +86,10 @@ func set_hungry(value):
|
||||
return set_state_value("hungry",value)
|
||||
|
||||
|
||||
func get_atk():
|
||||
return get_state_value("atk")
|
||||
func set_atk(value):
|
||||
return set_state_value("atk",value)
|
||||
|
||||
|
||||
|
||||
@ -133,7 +144,7 @@ func _ready() -> void:
|
||||
new_sprite_animation.position=unit_data["sprite_offset"]
|
||||
new_sprite_animation.scale=unit_data["sprite_scale"]
|
||||
animation=new_sprite_animation
|
||||
|
||||
animation.frame_changed.connect(frame_changed)
|
||||
#state_machine.launch()
|
||||
func set_target_pos(target:Vector2):
|
||||
agent.target_position=target
|
||||
@ -184,6 +195,18 @@ func is_unit_instance_in_touch_area(instance:Node):
|
||||
return instance in touch_area.get_overlapping_bodies()
|
||||
if instance is Area2D:
|
||||
return instance in touch_area.get_overlapping_areas()
|
||||
|
||||
#判断单位是否再攻击范围内
|
||||
func is_unit_instance_in_attack_area(instance:Node):
|
||||
if attack_area==null:
|
||||
return false
|
||||
else:
|
||||
if instance is PhysicsBody2D:
|
||||
return instance in attack_area.get_overlapping_bodies()
|
||||
if instance is Area2D:
|
||||
return instance in attack_area.get_overlapping_areas()
|
||||
|
||||
pass
|
||||
#指责(口角)
|
||||
func accuse(unit_id:String):
|
||||
show_action("指责")
|
||||
@ -225,16 +248,16 @@ func is_attacking():
|
||||
return animation.animation in [&"up_attack",&"down_attack",&"left_right_attack"] and animation.is_playing()
|
||||
#在固定帧使用攻击
|
||||
func use_attack_damage():
|
||||
|
||||
print("使用攻击")
|
||||
for i in attack_area.get_overlapping_bodies():
|
||||
|
||||
if i is Unit and i!=self:
|
||||
i.attacked(unit_id)
|
||||
i.attacked(unit_id,get_atk())
|
||||
|
||||
pass
|
||||
func attacked(by_unit_id:String):
|
||||
func attacked(by_unit_id:String,damage:float):
|
||||
show_action("受伤")
|
||||
Global.set_unit_favour(unit_id,by_unit_id,Global.get_unit_favour(unit_id,by_unit_id)-20)
|
||||
set_state_value("hp",get_state_value("hp")-damage)
|
||||
|
||||
pass
|
||||
func set_target(global_pos:Vector2):
|
||||
@ -282,7 +305,7 @@ func get_dir()->int:
|
||||
|
||||
func second_timer_time_out():
|
||||
|
||||
set_hungry(clamp(get_hungry()+10,0,100))
|
||||
set_hungry(clamp(get_hungry()+1,0,100))
|
||||
|
||||
pass
|
||||
func eat(food:Food):
|
||||
@ -291,3 +314,14 @@ func eat(food:Food):
|
||||
set_hungry(clamp(get_hungry()-food.hungry,0,100))
|
||||
food.eated()
|
||||
pass
|
||||
|
||||
const DEAD_SCENE = preload("res://scene/character/dead_scene_sprite/dead_scene.tscn")
|
||||
func dead():
|
||||
var new_dead_scene=DEAD_SCENE.instantiate()
|
||||
new_dead_scene.sprite_frames=animation.sprite_frames
|
||||
new_dead_scene.global_position=animation.global_position
|
||||
new_dead_scene.scale=animation.scale
|
||||
get_parent().add_child(new_dead_scene)
|
||||
Global.delete_unit_instance(unit_id)
|
||||
queue_free()
|
||||
pass
|
||||
|
@ -1,15 +1,16 @@
|
||||
[gd_scene load_steps=15 format=3 uid="uid://cf2g2urxaukxb"]
|
||||
[gd_scene load_steps=16 format=3 uid="uid://cf2g2urxaukxb"]
|
||||
|
||||
[ext_resource type="Script" path="res://scene/test/self_character.gd" id="1_d0trv"]
|
||||
[ext_resource type="Script" path="res://scene/test/state_machine.gd" id="2_v5m4x"]
|
||||
[ext_resource type="Script" path="res://scene/test/idle.gd" id="3_gcdcj"]
|
||||
[ext_resource type="Script" path="res://scene/test/run.gd" id="4_c7f2w"]
|
||||
[ext_resource type="Texture2D" uid="uid://csk8u15wepd1w" path="res://icon.svg" id="5_lkgch"]
|
||||
[ext_resource type="Script" path="res://scene/test/atk.gd" id="5_ol236"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_740ny"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_7uxj5"]
|
||||
size = Vector2(41, 34)
|
||||
size = Vector2(100, 108)
|
||||
|
||||
[sub_resource type="Animation" id="Animation_tov45"]
|
||||
length = 0.001
|
||||
@ -60,11 +61,12 @@ colors = PackedColorArray(0, 1, 0, 1, 0, 1, 0, 1)
|
||||
[sub_resource type="GradientTexture1D" id="GradientTexture1D_jp0r7"]
|
||||
gradient = SubResource("Gradient_vdy2i")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" node_paths=PackedStringArray("agent", "state_machine", "rotate")]
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" node_paths=PackedStringArray("agent", "state_machine", "rotate", "attack_area")]
|
||||
script = ExtResource("1_d0trv")
|
||||
agent = NodePath("agent")
|
||||
state_machine = NodePath("state_machine")
|
||||
rotate = NodePath("rotate")
|
||||
attack_area = NodePath("rotate/attack_area")
|
||||
|
||||
[node name="agent" type="NavigationAgent2D" parent="."]
|
||||
path_postprocessing = 1
|
||||
@ -89,14 +91,15 @@ script = ExtResource("3_gcdcj")
|
||||
[node name="run" type="Node" parent="state_machine"]
|
||||
script = ExtResource("4_c7f2w")
|
||||
|
||||
[node name="Node3" type="Node" parent="state_machine"]
|
||||
[node name="atk" type="Node" parent="state_machine"]
|
||||
script = ExtResource("5_ol236")
|
||||
|
||||
[node name="rotate" type="Node2D" parent="."]
|
||||
|
||||
[node name="attack_area" type="Area2D" parent="rotate"]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="rotate/attack_area"]
|
||||
position = Vector2(20.5, 0)
|
||||
position = Vector2(50, 1)
|
||||
shape = SubResource("RectangleShape2D_7uxj5")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
|
@ -3,7 +3,7 @@ func tick(actor:Node,black_board:Blackboard):
|
||||
var unit:UnitOther=actor
|
||||
var all_bodys=unit.sense_area.get_overlapping_bodies()
|
||||
for i in all_bodys:
|
||||
if i is Unit:
|
||||
if i is Unit and i !=unit:
|
||||
var favour=Global.get_unit_favour(unit.unit_id,i.unit_id)
|
||||
var res=get_res(favour,unit.get_hungry())
|
||||
if res:
|
||||
|
@ -25,5 +25,8 @@ func process_message(type:String,n):
|
||||
"move":
|
||||
get_player().set_target_pos(n)
|
||||
change_to_state("run")
|
||||
|
||||
"attack":
|
||||
get_player().set_target_pos(n.global_position)
|
||||
change_to_state("run",n)
|
||||
pass
|
||||
pass
|
||||
|
@ -108,7 +108,7 @@ shape = SubResource("RectangleShape2D_lphpm")
|
||||
|
||||
[node name="BeehaveTree" type="Node" parent="." node_paths=PackedStringArray("blackboard", "actor")]
|
||||
script = ExtResource("2_twyt5")
|
||||
blackboard = NodePath("@Node@37976")
|
||||
blackboard = NodePath("@Node@113329")
|
||||
actor = NodePath("..")
|
||||
|
||||
[node name="SelectorComposite" type="Node" parent="BeehaveTree"]
|
||||
|
@ -1,15 +1,12 @@
|
||||
extends State
|
||||
var target
|
||||
func enter_state(n):
|
||||
if n is Unit:
|
||||
target=n
|
||||
pass
|
||||
func update_state(delta):
|
||||
pass
|
||||
func update_state_phy(delta):
|
||||
if get_player().is_move_finished():
|
||||
|
||||
change_to_state("idle")
|
||||
print("切换为idle")
|
||||
return
|
||||
|
||||
match get_player().get_dir():
|
||||
0:
|
||||
get_player().play_animation("up")
|
||||
@ -19,8 +16,25 @@ func update_state_phy(delta):
|
||||
get_player().play_animation("left_right")
|
||||
3:
|
||||
get_player().play_animation("left_right")
|
||||
if target!=null and is_instance_valid(target):
|
||||
if get_player().is_unit_instance_in_attack_area(target):
|
||||
change_to_state("atk",target)
|
||||
get_player().stop_move()
|
||||
return
|
||||
get_player().set_target_pos(target.global_position)
|
||||
|
||||
return
|
||||
|
||||
if get_player().is_move_finished():
|
||||
|
||||
change_to_state("idle")
|
||||
print("切换为idle")
|
||||
return
|
||||
|
||||
|
||||
pass
|
||||
func exit_state():
|
||||
target=null
|
||||
pass
|
||||
|
||||
func process_message(type:String,n):
|
||||
@ -28,5 +42,9 @@ func process_message(type:String,n):
|
||||
"move":
|
||||
get_player().set_target_pos(n)
|
||||
change_to_state("run")
|
||||
|
||||
target=null
|
||||
"attack":
|
||||
get_player().set_target_pos(n.global_position)
|
||||
change_to_state("run",n)
|
||||
pass
|
||||
pass
|
||||
|
@ -9,6 +9,32 @@ func _on_control_gui_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("mouse_right"):
|
||||
if player:
|
||||
player.sent_message("move",player.get_global_mouse_position())
|
||||
|
||||
|
||||
if event.is_action_pressed("mouse_left"):
|
||||
var arr=%mouse_finder.get_overlapping_bodies()
|
||||
print(arr)
|
||||
if arr.size()==0:
|
||||
return
|
||||
var target=get_closest_node(player,arr,Unit)
|
||||
print(target)
|
||||
if target!=null:
|
||||
|
||||
player.sent_message("attack",target)
|
||||
pass
|
||||
|
||||
pass # Replace with function body.
|
||||
|
||||
func get_closest_node(self_node:Node2D,array:Array,target_class):
|
||||
if array.size()==0:
|
||||
return null
|
||||
var length=999999999
|
||||
var node=null
|
||||
for i in range(0,array.size()):
|
||||
print(is_instance_of(i,target_class))
|
||||
if is_instance_of(array[i],target_class):
|
||||
var l=(array[i].global_position-self_node.global_position).length()
|
||||
if l<length:
|
||||
length=l
|
||||
node=array[i]
|
||||
return node
|
||||
|
@ -27,6 +27,7 @@ navigation_layer_0/layers = 1
|
||||
sources/0 = SubResource("TileSetAtlasSource_pe5ig")
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_shajf"]
|
||||
radius = 38.71
|
||||
|
||||
[node name="main" type="Node2D" node_paths=PackedStringArray("player")]
|
||||
script = ExtResource("1_aimp4")
|
||||
@ -73,25 +74,10 @@ unit_id = "test_1_1"
|
||||
unit_type = "test_1"
|
||||
|
||||
[node name="other_character2" parent="CB_add_pos" instance=ExtResource("4_eyxcn")]
|
||||
position = Vector2(548, -436)
|
||||
position = Vector2(-718, 66)
|
||||
unit_id = "test_1_2"
|
||||
unit_type = "test_1"
|
||||
|
||||
[node name="other_character5" parent="CB_add_pos" instance=ExtResource("4_eyxcn")]
|
||||
position = Vector2(-871, 442)
|
||||
unit_id = "test_1_3"
|
||||
unit_type = "test_1"
|
||||
|
||||
[node name="other_character3" parent="CB_add_pos" instance=ExtResource("4_eyxcn")]
|
||||
position = Vector2(-649, 649)
|
||||
unit_id = "test_2_1"
|
||||
unit_type = "test_2"
|
||||
|
||||
[node name="other_character4" parent="CB_add_pos" instance=ExtResource("4_eyxcn")]
|
||||
position = Vector2(-429, -13)
|
||||
unit_id = "test_2_2"
|
||||
unit_type = "test_2"
|
||||
|
||||
[node name="food" parent="CB_add_pos" instance=ExtResource("3_fgsvv")]
|
||||
position = Vector2(-917, -398)
|
||||
|
||||
@ -134,4 +120,9 @@ position = Vector2(1091, 597)
|
||||
[node name="food14" parent="CB_add_pos" instance=ExtResource("3_fgsvv")]
|
||||
position = Vector2(464, 0)
|
||||
|
||||
[node name="other_character3" parent="CB_add_pos" instance=ExtResource("4_eyxcn")]
|
||||
position = Vector2(-121, 423)
|
||||
unit_id = "test_1_3"
|
||||
unit_type = "test_1"
|
||||
|
||||
[connection signal="gui_input" from="CanvasLayer/Control" to="." method="_on_control_gui_input"]
|
||||
|
Loading…
Reference in New Issue
Block a user