Spider now tracks player and delays jump. Exit animation modifier works too!
This commit is contained in:
parent
8106474b39
commit
48f3e631e6
|
|
@ -1,8 +1,10 @@
|
||||||
[gd_scene load_steps=12 format=2]
|
[gd_scene load_steps=14 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
|
[ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://src/components/Hurtbox_Component.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://src/components/Hitbox_Component.tscn" type="PackedScene" id=2]
|
||||||
[ext_resource path="res://src/Actors/Enemies/Spider/spider_movement_component.gd" type="Script" id=3]
|
[ext_resource path="res://src/Actors/Enemies/Spider/spider_movement_component.gd" type="Script" id=3]
|
||||||
|
[ext_resource path="res://src/Actors/Enemies/Spider/states/move.gd" type="Script" id=4]
|
||||||
|
[ext_resource path="res://src/Actors/Enemies/Spider/states/idle.gd" type="Script" id=5]
|
||||||
|
|
||||||
[sub_resource type="StreamTexture" id=1]
|
[sub_resource type="StreamTexture" id=1]
|
||||||
load_path = "res://.import/Spider1.png-85cc52177a93c8766bb76a39a26b9d70.stex"
|
load_path = "res://.import/Spider1.png-85cc52177a93c8766bb76a39a26b9d70.stex"
|
||||||
|
|
@ -52,11 +54,12 @@ extents = Vector2( 10, 12 )
|
||||||
[sub_resource type="CircleShape2D" id=8]
|
[sub_resource type="CircleShape2D" id=8]
|
||||||
|
|
||||||
[node name="Spider" instance=ExtResource( 1 )]
|
[node name="Spider" instance=ExtResource( 1 )]
|
||||||
|
actor_type = "Enemy"
|
||||||
|
|
||||||
[node name="AnimatedSprite" parent="." index="0"]
|
[node name="AnimatedSprite" parent="." index="0"]
|
||||||
frames = SubResource( 6 )
|
frames = SubResource( 6 )
|
||||||
animation = "idle"
|
animation = "jump"
|
||||||
frame = 0
|
frame = 2
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_aseprite_wizard_config_": {
|
"_aseprite_wizard_config_": {
|
||||||
"layer": "",
|
"layer": "",
|
||||||
|
|
@ -73,12 +76,22 @@ __meta__ = {
|
||||||
[node name="movement_component" parent="." index="1"]
|
[node name="movement_component" parent="." index="1"]
|
||||||
script = ExtResource( 3 )
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
|
[node name="movement_state_machine" parent="." index="2"]
|
||||||
|
debug_state_machine = true
|
||||||
|
|
||||||
[node name="idle" parent="movement_state_machine" index="0"]
|
[node name="idle" parent="movement_state_machine" index="0"]
|
||||||
|
script = ExtResource( 5 )
|
||||||
|
timeout_seconds = 0.5
|
||||||
animation_sequence = [ "idle" ]
|
animation_sequence = [ "idle" ]
|
||||||
|
|
||||||
[node name="fall" parent="movement_state_machine" index="1"]
|
[node name="fall" parent="movement_state_machine" index="1"]
|
||||||
animation_sequence = [ "land" ]
|
animation_sequence = [ "land" ]
|
||||||
|
|
||||||
|
[node name="move" parent="movement_state_machine" index="2"]
|
||||||
|
script = ExtResource( 4 )
|
||||||
|
animation_sequence = [ "jump" ]
|
||||||
|
jump_force = 200.0
|
||||||
|
|
||||||
[node name="CollisionShape2D" parent="Hurtbox_Component" index="0"]
|
[node name="CollisionShape2D" parent="Hurtbox_Component" index="0"]
|
||||||
position = Vector2( 0, -1 )
|
position = Vector2( 0, -1 )
|
||||||
|
|
||||||
|
|
@ -89,10 +102,11 @@ shape = SubResource( 7 )
|
||||||
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="." index="6"]
|
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="." index="6"]
|
||||||
position = Vector2( 0, 1 )
|
position = Vector2( 0, 1 )
|
||||||
|
|
||||||
[node name="Hurtbox_Component2" parent="." index="7" instance=ExtResource( 2 )]
|
[node name="Hitbox_Component" parent="." index="7" instance=ExtResource( 2 )]
|
||||||
|
damage_amount = 5
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hurtbox_Component2" index="0"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox_Component" index="0"]
|
||||||
modulate = Color( 1, 0, 0, 1 )
|
position = Vector2( 0, -1 )
|
||||||
shape = SubResource( 8 )
|
shape = SubResource( 8 )
|
||||||
|
|
||||||
[connection signal="screen_entered" from="VisibilityNotifier2D" to="movement_component" method="_on_VisibilityNotifier2D_screen_entered"]
|
[connection signal="screen_entered" from="VisibilityNotifier2D" to="movement_component" method="_on_VisibilityNotifier2D_screen_entered"]
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,18 @@ extends MovementComponent
|
||||||
var entered_screen = false
|
var entered_screen = false
|
||||||
var jump_var = false
|
var jump_var = false
|
||||||
|
|
||||||
|
var last_player_direction: float
|
||||||
|
|
||||||
func process(delta):
|
func process(delta):
|
||||||
if entered_screen:
|
if entered_screen:
|
||||||
if current_movement_state == "idle":
|
if current_movement_state == "idle":
|
||||||
|
# Only check the player direction in idle because we don't want to track the player during jump
|
||||||
|
if owner is Actor:
|
||||||
|
last_player_direction = sign((owner.global_position.direction_to(PlayerInfo.player_position)).x)
|
||||||
jump_var = true
|
jump_var = true
|
||||||
|
desired_movement_vector.x = last_player_direction
|
||||||
else:
|
else:
|
||||||
|
desired_movement_vector.x = last_player_direction
|
||||||
jump_var = false
|
jump_var = false
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -57,3 +64,4 @@ func wants_jump() -> bool:
|
||||||
|
|
||||||
func _on_VisibilityNotifier2D_screen_entered():
|
func _on_VisibilityNotifier2D_screen_entered():
|
||||||
entered_screen = true
|
entered_screen = true
|
||||||
|
print("Spider wants to play!!!")
|
||||||
|
|
|
||||||
26
src/Actors/Enemies/Spider/states/idle.gd
Normal file
26
src/Actors/Enemies/Spider/states/idle.gd
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
extends "res://src/templates/Actor/states/idle.gd"
|
||||||
|
|
||||||
|
|
||||||
|
func enter() -> void:
|
||||||
|
.enter()
|
||||||
|
# parent.set_hurtbox(true)
|
||||||
|
move_component.velocity.x = 0
|
||||||
|
state_timeout.start()
|
||||||
|
|
||||||
|
|
||||||
|
func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
|
# parent.velocity.y += gravity * delta
|
||||||
|
# #parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||||
|
# parent.velocity.x = move_component.desired_movement_vector.x * move_speed
|
||||||
|
# parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||||
|
|
||||||
|
if state_timeout.time_left == 0:
|
||||||
|
move_actor_as_desired(delta)
|
||||||
|
|
||||||
|
if move_component.velocity.x != 0.0:
|
||||||
|
return move_state
|
||||||
|
|
||||||
|
if !parent.is_on_floor():
|
||||||
|
return fall_state
|
||||||
|
return null
|
||||||
36
src/Actors/Enemies/Spider/states/move.gd
Normal file
36
src/Actors/Enemies/Spider/states/move.gd
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
extends "res://src/templates/Actor/states/move.gd"
|
||||||
|
|
||||||
|
export var jump_force: float = 200.0
|
||||||
|
|
||||||
|
var landing_modifier: StateModifier
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
landing_modifier= StateModifier.new()
|
||||||
|
#add_child(modifier)
|
||||||
|
#modifier.init_ref()
|
||||||
|
landing_modifier.ready( "landing", "jump" , landing_modifier.TYPE.EXIT_ANIMATION)
|
||||||
|
#print("ready! MOD")
|
||||||
|
|
||||||
|
|
||||||
|
func enter() -> void:
|
||||||
|
.enter()
|
||||||
|
# Apply initial jump velocity on state enter
|
||||||
|
move_component.velocity.y = -jump_force
|
||||||
|
|
||||||
|
func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
|
# if move_component.velocity.y > 0:
|
||||||
|
# return fall_state
|
||||||
|
|
||||||
|
# First allow horizontal movement.
|
||||||
|
move_actor_as_desired(delta)
|
||||||
|
|
||||||
|
#Flip the character before tha actual move maybe.
|
||||||
|
if move_component.get_movement_direction() != 0.0:
|
||||||
|
parent.transform.x.x = move_component.get_movement_direction()
|
||||||
|
|
||||||
|
if parent.is_on_floor():
|
||||||
|
idle_state.modifier = landing_modifier
|
||||||
|
return idle_state
|
||||||
|
|
||||||
|
return null
|
||||||
|
|
@ -68,17 +68,12 @@ __meta__ = {
|
||||||
position = Vector2( 0, -3.5 )
|
position = Vector2( 0, -3.5 )
|
||||||
shape = SubResource( 9 )
|
shape = SubResource( 9 )
|
||||||
|
|
||||||
[node name="movement_state_machine" parent="." index="3"]
|
|
||||||
debug_state_machine = true
|
|
||||||
|
|
||||||
[node name="idle" parent="movement_state_machine" index="0"]
|
[node name="idle" parent="movement_state_machine" index="0"]
|
||||||
script = ExtResource( 3 )
|
script = ExtResource( 3 )
|
||||||
debug_state = true
|
|
||||||
timeout_seconds = 2.0
|
timeout_seconds = 2.0
|
||||||
move_speed = 0.0
|
move_speed = 0.0
|
||||||
|
|
||||||
[node name="move" parent="movement_state_machine" index="2"]
|
[node name="move" parent="movement_state_machine" index="2"]
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
debug_state = true
|
|
||||||
timeout_seconds = 1.0
|
timeout_seconds = 1.0
|
||||||
move_speed = 30.0
|
move_speed = 30.0
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ extents = Vector2( 8, 53 )
|
||||||
script = ExtResource( 10 )
|
script = ExtResource( 10 )
|
||||||
|
|
||||||
[node name="PlayerStart" type="Position2D" parent="."]
|
[node name="PlayerStart" type="Position2D" parent="."]
|
||||||
position = Vector2( 316, 73 )
|
position = Vector2( 1047, 111 )
|
||||||
|
|
||||||
[node name="CameraBoundaries" type="Area2D" parent="."]
|
[node name="CameraBoundaries" type="Area2D" parent="."]
|
||||||
collision_layer = 256
|
collision_layer = 256
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user