Tutorial 17 Enemy AI and Stats
This commit is contained in:
parent
23a693d4a9
commit
24bc047855
@ -20,6 +20,7 @@ var state = IDLE
|
|||||||
onready var sprite = $AnimatedSprite
|
onready var sprite = $AnimatedSprite
|
||||||
onready var stats = $Stats
|
onready var stats = $Stats
|
||||||
onready var playerDetectionZone = $PlayerDetectionZone
|
onready var playerDetectionZone = $PlayerDetectionZone
|
||||||
|
onready var hurtbox = $Hurtbox
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
knockback = knockback.move_toward(Vector2.ZERO, 200 * delta)
|
knockback = knockback.move_toward(Vector2.ZERO, 200 * delta)
|
||||||
@ -51,6 +52,7 @@ func seek_player():
|
|||||||
func _on_Hurtbox_area_entered(area):
|
func _on_Hurtbox_area_entered(area):
|
||||||
stats.health -= area.damage
|
stats.health -= area.damage
|
||||||
knockback = area.knockback_vector * 120
|
knockback = area.knockback_vector * 120
|
||||||
|
hurtbox.create_hit_effect()
|
||||||
#queue_free() # Replace with function body.
|
#queue_free() # Replace with function body.
|
||||||
|
|
||||||
func _on_Stats_no_health():
|
func _on_Stats_no_health():
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=16 format=2]
|
[gd_scene load_steps=18 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Enemies/Bat.png" type="Texture" id=1]
|
[ext_resource path="res://Enemies/Bat.png" type="Texture" id=1]
|
||||||
[ext_resource path="res://Shadows/SmallShadow.png" type="Texture" id=2]
|
[ext_resource path="res://Shadows/SmallShadow.png" type="Texture" id=2]
|
||||||
@ -6,6 +6,7 @@
|
|||||||
[ext_resource path="res://Enemies/Bat.gd" type="Script" id=4]
|
[ext_resource path="res://Enemies/Bat.gd" type="Script" id=4]
|
||||||
[ext_resource path="res://Stats.tscn" type="PackedScene" id=5]
|
[ext_resource path="res://Stats.tscn" type="PackedScene" id=5]
|
||||||
[ext_resource path="res://Enemies/PlayerDetectionZone.tscn" type="PackedScene" id=6]
|
[ext_resource path="res://Enemies/PlayerDetectionZone.tscn" type="PackedScene" id=6]
|
||||||
|
[ext_resource path="res://Overlap/Hitbox.tscn" type="PackedScene" id=7]
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id=1]
|
[sub_resource type="AtlasTexture" id=1]
|
||||||
atlas = ExtResource( 1 )
|
atlas = ExtResource( 1 )
|
||||||
@ -45,6 +46,9 @@ height = 6.0
|
|||||||
[sub_resource type="CircleShape2D" id=9]
|
[sub_resource type="CircleShape2D" id=9]
|
||||||
radius = 61.0328
|
radius = 61.0328
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id=10]
|
||||||
|
radius = 5.0
|
||||||
|
|
||||||
[node name="Bat" type="KinematicBody2D"]
|
[node name="Bat" type="KinematicBody2D"]
|
||||||
collision_layer = 16
|
collision_layer = 16
|
||||||
script = ExtResource( 4 )
|
script = ExtResource( 4 )
|
||||||
@ -78,8 +82,16 @@ max_health = 2
|
|||||||
modulate = Color( 1, 1, 1, 0.258824 )
|
modulate = Color( 1, 1, 1, 0.258824 )
|
||||||
shape = SubResource( 9 )
|
shape = SubResource( 9 )
|
||||||
|
|
||||||
|
[node name="Hitbox" parent="." instance=ExtResource( 7 )]
|
||||||
|
collision_mask = 4
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" parent="Hitbox" index="0"]
|
||||||
|
position = Vector2( 0, -15 )
|
||||||
|
shape = SubResource( 10 )
|
||||||
|
|
||||||
[connection signal="area_entered" from="Hurtbox" to="." method="_on_Hurtbox_area_entered"]
|
[connection signal="area_entered" from="Hurtbox" to="." method="_on_Hurtbox_area_entered"]
|
||||||
[connection signal="no_health" from="Stats" to="." method="_on_Stats_no_health"]
|
[connection signal="no_health" from="Stats" to="." method="_on_Stats_no_health"]
|
||||||
|
|
||||||
[editable path="Hurtbox"]
|
[editable path="Hurtbox"]
|
||||||
[editable path="PlayerDetectionZone"]
|
[editable path="PlayerDetectionZone"]
|
||||||
|
[editable path="Hitbox"]
|
||||||
|
@ -1,22 +1,36 @@
|
|||||||
extends Area2D
|
extends Area2D
|
||||||
|
|
||||||
export(bool) var show_hit = true
|
|
||||||
|
|
||||||
const HitEffect = preload("res://Effects/HitEffect.tscn")
|
const HitEffect = preload("res://Effects/HitEffect.tscn")
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
var invincible = false setget set_invincible
|
||||||
func _ready():
|
|
||||||
pass # Replace with function body.
|
|
||||||
|
|
||||||
|
onready var timer = $Timer
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
signal invincibility_started
|
||||||
#func _process(delta):
|
signal invincibility_ended
|
||||||
# pass
|
|
||||||
|
|
||||||
|
func set_invincible(value):
|
||||||
|
invincible = value
|
||||||
|
if invincible == true:
|
||||||
|
emit_signal("invincibility_started")
|
||||||
|
else:
|
||||||
|
emit_signal("invincibility_ended")
|
||||||
|
|
||||||
func _on_Hurtbox_area_entered(area):
|
func start_invincibility(duration):
|
||||||
if show_hit:
|
self.invincible = true
|
||||||
var effect = HitEffect.instance()
|
timer.start(duration)
|
||||||
var main = get_tree().current_scene
|
|
||||||
main.add_child(effect)
|
func create_hit_effect():
|
||||||
effect.global_position = global_position
|
var effect = HitEffect.instance()
|
||||||
|
var main = get_tree().current_scene
|
||||||
|
main.add_child(effect)
|
||||||
|
effect.global_position = global_position
|
||||||
|
|
||||||
|
func _on_Timer_timeout():
|
||||||
|
self.invincible = false
|
||||||
|
|
||||||
|
func _on_Hurtbox_invincibility_ended():
|
||||||
|
monitorable = true
|
||||||
|
|
||||||
|
func _on_Hurtbox_invincibility_started():
|
||||||
|
set_deferred("monitorable", false)
|
||||||
|
@ -9,4 +9,8 @@ script = ExtResource( 1 )
|
|||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
|
||||||
[connection signal="area_entered" from="." to="." method="_on_Hurtbox_area_entered"]
|
[node name="Timer" type="Timer" parent="."]
|
||||||
|
|
||||||
|
[connection signal="invincibility_ended" from="." to="." method="_on_Hurtbox_invincibility_ended"]
|
||||||
|
[connection signal="invincibility_started" from="." to="." method="_on_Hurtbox_invincibility_started"]
|
||||||
|
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]
|
||||||
|
@ -3,6 +3,7 @@ extends KinematicBody2D
|
|||||||
var velocity = Vector2.ZERO
|
var velocity = Vector2.ZERO
|
||||||
var input_vector = Vector2.ZERO
|
var input_vector = Vector2.ZERO
|
||||||
var roll_vector = Vector2.DOWN
|
var roll_vector = Vector2.DOWN
|
||||||
|
var stats = PlayerStats
|
||||||
|
|
||||||
const ACCELERATION = 500
|
const ACCELERATION = 500
|
||||||
const MAX_SPEED = 80
|
const MAX_SPEED = 80
|
||||||
@ -21,8 +22,10 @@ onready var animationPlayer = $AnimationPlayer
|
|||||||
onready var animationTree = $AnimationTree
|
onready var animationTree = $AnimationTree
|
||||||
onready var animationState = animationTree.get("parameters/playback")
|
onready var animationState = animationTree.get("parameters/playback")
|
||||||
onready var swordHitbox = $HitboxPivot/SwordHitbox
|
onready var swordHitbox = $HitboxPivot/SwordHitbox
|
||||||
|
onready var hurtBox = $Hurtbox
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
stats.connect("no_health", self, "queue_free")
|
||||||
animationTree.active = true
|
animationTree.active = true
|
||||||
swordHitbox.knockback_vector = roll_vector
|
swordHitbox.knockback_vector = roll_vector
|
||||||
|
|
||||||
@ -90,3 +93,9 @@ func attack_aninimation_finished():
|
|||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
#func _process(delta):
|
#func _process(delta):
|
||||||
# pass
|
# pass
|
||||||
|
|
||||||
|
|
||||||
|
func _on_Hurtbox_area_entered(area):
|
||||||
|
stats.health -= 1
|
||||||
|
hurtBox.start_invincibility(0.5)
|
||||||
|
hurtBox.create_hit_effect()
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
[gd_scene load_steps=54 format=2]
|
[gd_scene load_steps=56 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Player/Player.gd" type="Script" id=1]
|
[ext_resource path="res://Player/Player.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://Player/Player.png" type="Texture" id=2]
|
[ext_resource path="res://Player/Player.png" type="Texture" id=2]
|
||||||
[ext_resource path="res://Overlap/Hitbox.tscn" type="PackedScene" id=3]
|
[ext_resource path="res://Overlap/Hitbox.tscn" type="PackedScene" id=3]
|
||||||
[ext_resource path="res://Player/SwordHitbox.gd" type="Script" id=4]
|
[ext_resource path="res://Player/SwordHitbox.gd" type="Script" id=4]
|
||||||
|
[ext_resource path="res://Overlap/Hurtbox.tscn" type="PackedScene" id=5]
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape2D" id=1]
|
[sub_resource type="CapsuleShape2D" id=1]
|
||||||
radius = 4.0
|
radius = 4.0
|
||||||
@ -641,6 +642,10 @@ graph_offset = Vector2( -10, -78 )
|
|||||||
[sub_resource type="CapsuleShape2D" id=40]
|
[sub_resource type="CapsuleShape2D" id=40]
|
||||||
height = 12.0
|
height = 12.0
|
||||||
|
|
||||||
|
[sub_resource type="CapsuleShape2D" id=52]
|
||||||
|
radius = 5.0
|
||||||
|
height = 6.0
|
||||||
|
|
||||||
[node name="Player" type="KinematicBody2D"]
|
[node name="Player" type="KinematicBody2D"]
|
||||||
collision_layer = 2
|
collision_layer = 2
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
@ -698,4 +703,14 @@ script = ExtResource( 4 )
|
|||||||
shape = SubResource( 40 )
|
shape = SubResource( 40 )
|
||||||
disabled = true
|
disabled = true
|
||||||
|
|
||||||
|
[node name="Hurtbox" parent="." instance=ExtResource( 5 )]
|
||||||
|
collision_layer = 4
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" parent="Hurtbox" index="0"]
|
||||||
|
position = Vector2( 0, -4 )
|
||||||
|
shape = SubResource( 52 )
|
||||||
|
|
||||||
|
[connection signal="area_entered" from="Hurtbox" to="." method="_on_Hurtbox_area_entered"]
|
||||||
|
|
||||||
[editable path="HitboxPivot/SwordHitbox"]
|
[editable path="HitboxPivot/SwordHitbox"]
|
||||||
|
[editable path="Hurtbox"]
|
||||||
|
6
ActionRPG-HeartBeast/Player/PlayerStats.tscn
Normal file
6
ActionRPG-HeartBeast/Player/PlayerStats.tscn
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Stats.tscn" type="PackedScene" id=1]
|
||||||
|
|
||||||
|
[node name="PlayerStats" instance=ExtResource( 1 )]
|
||||||
|
max_health = 4
|
BIN
ActionRPG-HeartBeast/build/.DS_Store
vendored
BIN
ActionRPG-HeartBeast/build/.DS_Store
vendored
Binary file not shown.
BIN
ActionRPG-HeartBeast/build/web/.DS_Store
vendored
BIN
ActionRPG-HeartBeast/build/web/.DS_Store
vendored
Binary file not shown.
Binary file not shown.
@ -139,7 +139,7 @@
|
|||||||
<script type='text/javascript' src='index.js'></script>
|
<script type='text/javascript' src='index.js'></script>
|
||||||
<script type='text/javascript'>//<![CDATA[
|
<script type='text/javascript'>//<![CDATA[
|
||||||
|
|
||||||
const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":2277296,"index.wasm":13790961},"focusCanvas":true,"gdnativeLibs":[]};
|
const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":2283408,"index.wasm":13790961},"focusCanvas":true,"gdnativeLibs":[]};
|
||||||
var engine = new Engine(GODOT_CONFIG);
|
var engine = new Engine(GODOT_CONFIG);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
Binary file not shown.
@ -14,6 +14,10 @@ config/name="ActionRPG-HeartBeast"
|
|||||||
run/main_scene="res://World.tscn"
|
run/main_scene="res://World.tscn"
|
||||||
config/icon="res://icon.png"
|
config/icon="res://icon.png"
|
||||||
|
|
||||||
|
[autoload]
|
||||||
|
|
||||||
|
PlayerStats="*res://Player/PlayerStats.tscn"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
window/size/width=320
|
window/size/width=320
|
||||||
|
@ -10,25 +10,25 @@
|
|||||||
[node name="TouchControls" type="CanvasLayer"]
|
[node name="TouchControls" type="CanvasLayer"]
|
||||||
|
|
||||||
[node name="Left" type="TouchScreenButton" parent="."]
|
[node name="Left" type="TouchScreenButton" parent="."]
|
||||||
position = Vector2( 4, 133 )
|
position = Vector2( 6, 133 )
|
||||||
normal = ExtResource( 4 )
|
normal = ExtResource( 4 )
|
||||||
passby_press = true
|
passby_press = true
|
||||||
action = "ui_left"
|
action = "ui_left"
|
||||||
|
|
||||||
[node name="Right" type="TouchScreenButton" parent="."]
|
[node name="Right" type="TouchScreenButton" parent="."]
|
||||||
position = Vector2( 43, 133 )
|
position = Vector2( 40, 133 )
|
||||||
normal = ExtResource( 2 )
|
normal = ExtResource( 2 )
|
||||||
passby_press = true
|
passby_press = true
|
||||||
action = "ui_right"
|
action = "ui_right"
|
||||||
|
|
||||||
[node name="Up" type="TouchScreenButton" parent="."]
|
[node name="Up" type="TouchScreenButton" parent="."]
|
||||||
position = Vector2( 23, 113 )
|
position = Vector2( 23, 116 )
|
||||||
normal = ExtResource( 5 )
|
normal = ExtResource( 5 )
|
||||||
passby_press = true
|
passby_press = true
|
||||||
action = "ui_up"
|
action = "ui_up"
|
||||||
|
|
||||||
[node name="Down" type="TouchScreenButton" parent="."]
|
[node name="Down" type="TouchScreenButton" parent="."]
|
||||||
position = Vector2( 23, 153 )
|
position = Vector2( 23, 150 )
|
||||||
normal = ExtResource( 6 )
|
normal = ExtResource( 6 )
|
||||||
passby_press = true
|
passby_press = true
|
||||||
action = "ui_down"
|
action = "ui_down"
|
||||||
|
Loading…
Reference in New Issue
Block a user