Tutorials completed.
This commit is contained in:
@ -5,6 +5,7 @@ const EnemyDeathEffect = preload("res://Effects/EnemyDeathEffect.tscn")
|
||||
export var ACCELERATION = 300
|
||||
export var MAX_SPEED = 50
|
||||
export var FRICTION = 200
|
||||
export var WANDER_TARGET_RANGE = 4
|
||||
|
||||
enum {
|
||||
IDLE,
|
||||
@ -22,6 +23,11 @@ onready var stats = $Stats
|
||||
onready var playerDetectionZone = $PlayerDetectionZone
|
||||
onready var hurtbox = $Hurtbox
|
||||
onready var softCollision = $SoftCollision
|
||||
onready var wanderController = $WanderController
|
||||
onready var animationPlayer = $AnimationPlayer
|
||||
|
||||
func _ready():
|
||||
state = pick_new_state([IDLE,WANDER])
|
||||
|
||||
func _physics_process(delta):
|
||||
knockback = knockback.move_toward(Vector2.ZERO, 200 * delta)
|
||||
@ -31,15 +37,21 @@ func _physics_process(delta):
|
||||
IDLE:
|
||||
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
|
||||
seek_player()
|
||||
|
||||
if wanderController.get_time_left() == 0:
|
||||
update_wander()
|
||||
|
||||
WANDER:
|
||||
pass
|
||||
|
||||
seek_player()
|
||||
if wanderController.get_time_left() == 0:
|
||||
update_wander()
|
||||
accelerate_towards_point(wanderController.target_position,delta)
|
||||
if global_position.distance_to(wanderController.target_position) <= WANDER_TARGET_RANGE:
|
||||
update_wander()
|
||||
|
||||
CHASE:
|
||||
var player = playerDetectionZone.player
|
||||
if player != null:
|
||||
var direction = (player.global_position - global_position).normalized()
|
||||
velocity = velocity.move_toward(direction * MAX_SPEED, ACCELERATION * delta)
|
||||
accelerate_towards_point(player.global_position,delta)
|
||||
else:
|
||||
state = IDLE
|
||||
sprite.flip_h = velocity.x < 0
|
||||
@ -48,15 +60,29 @@ func _physics_process(delta):
|
||||
velocity += softCollision.get_push_vector() * delta * 400
|
||||
velocity = move_and_slide(velocity)
|
||||
|
||||
|
||||
func accelerate_towards_point(point,delta):
|
||||
var direction = global_position.direction_to(point)
|
||||
sprite.flip_h = velocity.x < 0
|
||||
velocity = velocity.move_toward(direction * MAX_SPEED, ACCELERATION * delta)
|
||||
|
||||
func update_wander():
|
||||
state = pick_new_state([IDLE, WANDER])
|
||||
wanderController.start_wander_timer(rand_range(1,3))
|
||||
|
||||
func seek_player():
|
||||
if playerDetectionZone.can_see_player():
|
||||
state = CHASE
|
||||
|
||||
func pick_new_state(state_list):
|
||||
#return state_list.pick_random()
|
||||
state_list.shuffle()
|
||||
return state_list.pop_front()
|
||||
|
||||
func _on_Hurtbox_area_entered(area):
|
||||
stats.health -= area.damage
|
||||
knockback = area.knockback_vector * 120
|
||||
hurtbox.create_hit_effect()
|
||||
hurtbox.start_invincibility(0.4)
|
||||
#queue_free() # Replace with function body.
|
||||
|
||||
func _on_Stats_no_health():
|
||||
@ -64,3 +90,10 @@ func _on_Stats_no_health():
|
||||
var enemyDeathEffect = EnemyDeathEffect.instance()
|
||||
get_parent().add_child(enemyDeathEffect)
|
||||
enemyDeathEffect.global_position = global_position
|
||||
|
||||
|
||||
func _on_Hurtbox_invincibility_started():
|
||||
animationPlayer.play("Start")
|
||||
|
||||
func _on_Hurtbox_invincibility_ended():
|
||||
animationPlayer.play("Stop")
|
||||
|
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=20 format=2]
|
||||
[gd_scene load_steps=26 format=2]
|
||||
|
||||
[ext_resource path="res://Enemies/Bat.png" type="Texture" id=1]
|
||||
[ext_resource path="res://Shadows/SmallShadow.png" type="Texture" id=2]
|
||||
@ -8,6 +8,13 @@
|
||||
[ext_resource path="res://Enemies/PlayerDetectionZone.tscn" type="PackedScene" id=6]
|
||||
[ext_resource path="res://Overlap/Hitbox.tscn" type="PackedScene" id=7]
|
||||
[ext_resource path="res://Overlap/SoftCollision.tscn" type="PackedScene" id=8]
|
||||
[ext_resource path="res://Overlap/WanderController.tscn" type="PackedScene" id=9]
|
||||
[ext_resource path="res://WhiteColor_shader.tres" type="Shader" id=10]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id=12]
|
||||
resource_local_to_scene = true
|
||||
shader = ExtResource( 10 )
|
||||
shader_param/active = false
|
||||
|
||||
[sub_resource type="AtlasTexture" id=1]
|
||||
atlas = ExtResource( 1 )
|
||||
@ -53,13 +60,63 @@ radius = 5.0
|
||||
[sub_resource type="CircleShape2D" id=11]
|
||||
radius = 5.0
|
||||
|
||||
[sub_resource type="Animation" id=13]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("AnimatedSprite:material:shader_param/active")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 0,
|
||||
"values": [ false ]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id=14]
|
||||
resource_name = "Start"
|
||||
length = 0.2
|
||||
loop = true
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("AnimatedSprite:material:shader_param/active")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0, 0.1 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 1,
|
||||
"values": [ true, false ]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id=15]
|
||||
resource_name = "Stop"
|
||||
length = 0.1
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("AnimatedSprite:material:shader_param/active")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 1,
|
||||
"values": [ false ]
|
||||
}
|
||||
|
||||
[node name="Bat" type="KinematicBody2D"]
|
||||
collision_layer = 16
|
||||
script = ExtResource( 4 )
|
||||
|
||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
||||
material = SubResource( 12 )
|
||||
frames = SubResource( 6 )
|
||||
animation = "Fly"
|
||||
frame = 3
|
||||
playing = true
|
||||
offset = Vector2( 0, -12 )
|
||||
|
||||
@ -101,7 +158,16 @@ shape = SubResource( 10 )
|
||||
[node name="CollisionShape2D" parent="SoftCollision" index="0"]
|
||||
shape = SubResource( 11 )
|
||||
|
||||
[node name="WanderController" parent="." instance=ExtResource( 9 )]
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
anims/RESET = SubResource( 13 )
|
||||
anims/Start = SubResource( 14 )
|
||||
anims/Stop = SubResource( 15 )
|
||||
|
||||
[connection signal="area_entered" from="Hurtbox" to="." method="_on_Hurtbox_area_entered"]
|
||||
[connection signal="invincibility_ended" from="Hurtbox" to="." method="_on_Hurtbox_invincibility_ended"]
|
||||
[connection signal="invincibility_started" from="Hurtbox" to="." method="_on_Hurtbox_invincibility_started"]
|
||||
[connection signal="no_health" from="Stats" to="." method="_on_Stats_no_health"]
|
||||
|
||||
[editable path="Hurtbox"]
|
||||
|
@ -9,5 +9,5 @@ func can_see_player():
|
||||
func _on_PlayerDetectionZone_body_entered(body):
|
||||
player = body
|
||||
|
||||
func _on_PlayerDetectionZone_body_exited(body):
|
||||
func _on_PlayerDetectionZone_body_exited(_body):
|
||||
player = null
|
||||
|
Reference in New Issue
Block a user