Compare commits
2 Commits
3e454f5785
...
48f3e631e6
| Author | SHA1 | Date | |
|---|---|---|---|
| 48f3e631e6 | |||
| 8106474b39 |
|
|
@ -1,7 +1,10 @@
|
|||
[gd_scene load_steps=11 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/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/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]
|
||||
load_path = "res://.import/Spider1.png-85cc52177a93c8766bb76a39a26b9d70.stex"
|
||||
|
|
@ -51,11 +54,12 @@ extents = Vector2( 10, 12 )
|
|||
[sub_resource type="CircleShape2D" id=8]
|
||||
|
||||
[node name="Spider" instance=ExtResource( 1 )]
|
||||
actor_type = "Enemy"
|
||||
|
||||
[node name="AnimatedSprite" parent="." index="0"]
|
||||
frames = SubResource( 6 )
|
||||
animation = "idle"
|
||||
frame = 0
|
||||
animation = "jump"
|
||||
frame = 2
|
||||
__meta__ = {
|
||||
"_aseprite_wizard_config_": {
|
||||
"layer": "",
|
||||
|
|
@ -69,12 +73,25 @@ __meta__ = {
|
|||
}
|
||||
}
|
||||
|
||||
[node name="movement_component" parent="." index="1"]
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="movement_state_machine" parent="." index="2"]
|
||||
debug_state_machine = true
|
||||
|
||||
[node name="idle" parent="movement_state_machine" index="0"]
|
||||
script = ExtResource( 5 )
|
||||
timeout_seconds = 0.5
|
||||
animation_sequence = [ "idle" ]
|
||||
|
||||
[node name="fall" parent="movement_state_machine" index="1"]
|
||||
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"]
|
||||
position = Vector2( 0, -1 )
|
||||
|
||||
|
|
@ -83,9 +100,13 @@ position = Vector2( 0, -2 )
|
|||
shape = SubResource( 7 )
|
||||
|
||||
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="." index="6"]
|
||||
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"]
|
||||
modulate = Color( 1, 0, 0, 1 )
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox_Component" index="0"]
|
||||
position = Vector2( 0, -1 )
|
||||
shape = SubResource( 8 )
|
||||
|
||||
[connection signal="screen_entered" from="VisibilityNotifier2D" to="movement_component" method="_on_VisibilityNotifier2D_screen_entered"]
|
||||
|
|
|
|||
67
src/Actors/Enemies/Spider/spider_movement_component.gd
Normal file
67
src/Actors/Enemies/Spider/spider_movement_component.gd
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
extends MovementComponent
|
||||
|
||||
## Constants available to you
|
||||
# UP = -1.0
|
||||
# DOWN = 1.0
|
||||
# LEFT = -1.0
|
||||
# RIGHT = 1.0
|
||||
|
||||
# Avalable functions to call
|
||||
# A Series of helper functions
|
||||
# go_up():
|
||||
# go_down():
|
||||
# go_left():
|
||||
# go_right():
|
||||
# stop():
|
||||
|
||||
var entered_screen = false
|
||||
var jump_var = false
|
||||
|
||||
var last_player_direction: float
|
||||
|
||||
func process(delta):
|
||||
if entered_screen:
|
||||
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
|
||||
desired_movement_vector.x = last_player_direction
|
||||
else:
|
||||
desired_movement_vector.x = last_player_direction
|
||||
jump_var = false
|
||||
return
|
||||
|
||||
func wants_jump() -> bool:
|
||||
return jump_var
|
||||
|
||||
## Other needed variables
|
||||
# desired_movement_vector: Vector2 - Used to store desired movement depending on the state
|
||||
# current_movement_state:String - The name of the current State
|
||||
|
||||
# Since animactor state machine can actually view properties from this type
|
||||
# I'm thinking about moving the velocity tracker in here instead of player.
|
||||
# velocity: Vector2 - Current velocity, you can change this at will but state may modify it
|
||||
|
||||
# Declare any other member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
# you do not normally need to define this for Actor
|
||||
#func process(delta):
|
||||
# pass
|
||||
|
||||
# For Enemy and NPC Actors:
|
||||
# should be called on the frame process.
|
||||
|
||||
# For Player Actors:
|
||||
# Should be called on the input process
|
||||
|
||||
|
||||
|
||||
|
||||
func _on_VisibilityNotifier2D_screen_entered():
|
||||
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 )
|
||||
shape = SubResource( 9 )
|
||||
|
||||
[node name="movement_state_machine" parent="." index="3"]
|
||||
debug_state_machine = true
|
||||
|
||||
[node name="idle" parent="movement_state_machine" index="0"]
|
||||
script = ExtResource( 3 )
|
||||
debug_state = true
|
||||
timeout_seconds = 2.0
|
||||
move_speed = 0.0
|
||||
|
||||
[node name="move" parent="movement_state_machine" index="2"]
|
||||
script = ExtResource( 2 )
|
||||
debug_state = true
|
||||
timeout_seconds = 1.0
|
||||
move_speed = 30.0
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ extents = Vector2( 8, 53 )
|
|||
script = ExtResource( 10 )
|
||||
|
||||
[node name="PlayerStart" type="Position2D" parent="."]
|
||||
position = Vector2( 493, 291 )
|
||||
position = Vector2( 1047, 111 )
|
||||
|
||||
[node name="CameraBoundaries" type="Area2D" parent="."]
|
||||
collision_layer = 256
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ actor_type = "Enemy"
|
|||
position = Vector2( 11, -7 )
|
||||
frames = SubResource( 20 )
|
||||
animation = "idle"
|
||||
frame = 1
|
||||
frame = 2
|
||||
__meta__ = {
|
||||
"_aseprite_wizard_config_": {
|
||||
"layer": "",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user