Add reactions to attacks on AI dummy
This commit is contained in:
parent
8ec0536aec
commit
457bd0e2d7
6 changed files with 1836 additions and 9 deletions
1786
Hiro/hiro_ai.tscn
Normal file
1786
Hiro/hiro_ai.tscn
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1457,11 +1457,11 @@ states/Start/position = Vector2(197, 108)
|
|||
states/idle/node = SubResource("AnimationNodeBlendSpace2D_bd8j1")
|
||||
states/idle/position = Vector2(329, 108)
|
||||
states/melee/node = SubResource("AnimationNodeBlendSpace1D_dc3kp")
|
||||
states/melee/position = Vector2(425, 213)
|
||||
states/melee/position = Vector2(329, 212)
|
||||
states/walk/node = SubResource("AnimationNodeBlendSpace2D_vunsg")
|
||||
states/walk/position = Vector2(520, 108)
|
||||
transitions = ["Start", "idle", SubResource("AnimationNodeStateMachineTransition_akmuq"), "idle", "walk", SubResource("AnimationNodeStateMachineTransition_sn1tm"), "walk", "idle", SubResource("AnimationNodeStateMachineTransition_5i3fu"), "idle", "melee", SubResource("AnimationNodeStateMachineTransition_y8p74"), "melee", "idle", SubResource("AnimationNodeStateMachineTransition_l17k0")]
|
||||
graph_offset = Vector2(-129, 11)
|
||||
graph_offset = Vector2(-159, -33)
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_vm050"]
|
||||
radius = 8.0
|
||||
|
|
15
Scripts/hiro_ai.gd
Normal file
15
Scripts/hiro_ai.gd
Normal file
|
@ -0,0 +1,15 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
@export var health = 100
|
||||
|
||||
signal got_hurt(damage: int, attack_direction: Vector2)
|
||||
signal defeated
|
||||
|
||||
func _on_player_attack_did_hit(other, attack_power, attack_direction: Vector2):
|
||||
if other.get_parent().get_instance_id() == get_instance_id() :
|
||||
got_hurt.emit(attack_power, attack_direction)
|
||||
|
||||
|
||||
func _on_health_depleted():
|
||||
defeated.emit()
|
||||
queue_free()
|
21
Scripts/hiro_brain.gd
Normal file
21
Scripts/hiro_brain.gd
Normal file
|
@ -0,0 +1,21 @@
|
|||
extends Node
|
||||
|
||||
@onready var health = $"..".health
|
||||
@onready var anim_tree: AnimationTree = $".."/AnimationTree
|
||||
@onready var anim_playback: AnimationNodeStateMachinePlayback = anim_tree["parameters/playback"]
|
||||
|
||||
signal health_depleted
|
||||
|
||||
func _on_ai_got_hurt(damage, attack_direction):
|
||||
var facing_direction = attack_direction * -1
|
||||
health = health - damage
|
||||
if health <= 0:
|
||||
health_depleted.emit()
|
||||
else:
|
||||
anim_tree.set("parameters/idle/blend_position", facing_direction)
|
||||
anim_tree.set("parameters/walk/blend_position", facing_direction)
|
||||
anim_tree.set("parameters/melee/0/blend_position", facing_direction)
|
||||
anim_tree.set("parameters/melee/1/blend_position", facing_direction)
|
||||
anim_tree.set("parameters/melee/2/blend_position", facing_direction)
|
||||
anim_tree.set("parameters/hurt/blend_position", facing_direction)
|
||||
anim_playback.travel("hurt")
|
|
@ -4,7 +4,8 @@ extends CharacterBody2D
|
|||
var last_dpad: Array[Vector2] = [Vector2.ZERO,Vector2.ZERO]
|
||||
const FACING_ANGLE_EPSILON = 15
|
||||
|
||||
signal attack_did_hit(other: Area2D)
|
||||
signal attack_did_hit(other: Area2D, power: int, attack_direction: Vector2)
|
||||
signal defeated
|
||||
|
||||
func _process(_delta):
|
||||
if Input.is_action_pressed("melee") and $AnimationTree.get("parameters/conditions/melee") == false:
|
||||
|
@ -56,4 +57,9 @@ func get_input():
|
|||
|
||||
|
||||
func _on_attackbox_area_entered(area: Area2D):
|
||||
attack_did_hit.emit(area)
|
||||
var attack_vector: Vector2 = $AnimationTree.get("parameters/melee/0/blend_position")
|
||||
attack_did_hit.emit(area, 15, attack_vector)
|
||||
|
||||
|
||||
func _on_hiro_dummy_defeated():
|
||||
print("Yaaaaay!!")
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
[ext_resource type="PackedScene" uid="uid://di21xheryhp0k" path="res://Hiro/hiro_player.tscn" id="1_c1gpq"]
|
||||
[ext_resource type="PackedScene" uid="uid://b8sfype1vx5ad" path="res://Nem/nem_npc.tscn" id="1_sqt7d"]
|
||||
[ext_resource type="Texture2D" uid="uid://b40la2vyf4rn6" path="res://world/Fighting Dojo BG.png" id="4_elb6q"]
|
||||
[ext_resource type="Script" path="res://Scripts/reed_player.gd" id="5_df088"]
|
||||
[ext_resource type="PackedScene" uid="uid://dd2km6qhpdicx" path="res://Hiro/hiro_ai.tscn" id="5_r7nw4"]
|
||||
[ext_resource type="PackedScene" uid="uid://bakb5a7xe4qby" path="res://Reed/reed_player.tscn" id="6_cn8e2"]
|
||||
|
||||
[node name="Node2D" type="Node2D"]
|
||||
|
@ -32,10 +32,9 @@ position = Vector2(-1341, -243)
|
|||
scale = Vector2(8.83789, 4.22585)
|
||||
polygon = PackedVector2Array(157.843, 76.9076, 161.464, 75.961, 172.213, 75.7244, 176.513, 76.9076, 179.22, 82.4429, 180.012, 85.7558, 180.238, 91.9084, 180.012, 107.053, 178.549, 113.823, 176.739, 116.426, 175.042, 118.083, 169.497, 118.319, 169.497, 123.525, 164.745, 123.525, 164.858, 118.319, 158.975, 117.846, 157.504, 116.663, 155.806, 114.533, 154.109, 108.617, 154.109, 94.4188, 154.222, 83.2968, 152.186, 83.0602, 152.412, 80.9304, 146.181, 70.3743, 139.513, 85.4266, 135.779, 90.8692, 147.66, 124.945, 187.367, 125.038, 195.514, 91.4351, 192.232, 66.1148, 173.676, 53.3363, 157.382, 53.8096, 152.404, 63.2751, 153.317, 81.6403, 154.222, 83.7701, 155.92, 79.9839)
|
||||
|
||||
[node name="HiroDummy" parent="." instance=ExtResource("1_c1gpq")]
|
||||
modulate = Color(0.603922, 0.603922, 0.603922, 1)
|
||||
position = Vector2(139, 203)
|
||||
script = ExtResource("5_df088")
|
||||
[node name="HiroDummy" parent="." instance=ExtResource("5_r7nw4")]
|
||||
position = Vector2(138, 216)
|
||||
|
||||
[connection signal="attack_did_hit" from="HiroPlayer" to="ReedPlayer" method="_on_player_attack_did_hit"]
|
||||
[connection signal="attack_did_hit" from="HiroPlayer" to="HiroDummy" method="_on_player_attack_did_hit"]
|
||||
[connection signal="defeated" from="HiroDummy" to="HiroPlayer" method="_on_hiro_dummy_defeated"]
|
||||
|
|
Loading…
Reference in a new issue