Continue adding Player based on inherited actor template.
This commit is contained in:
parent
385d722b78
commit
b510927667
|
|
@ -130,7 +130,7 @@ actor_type = "Enemy"
|
||||||
position = Vector2( 11, -7 )
|
position = Vector2( 11, -7 )
|
||||||
frames = SubResource( 20 )
|
frames = SubResource( 20 )
|
||||||
animation = "idle"
|
animation = "idle"
|
||||||
frame = 2
|
frame = 0
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_aseprite_wizard_config_": {
|
"_aseprite_wizard_config_": {
|
||||||
"layer": "",
|
"layer": "",
|
||||||
|
|
|
||||||
|
|
@ -17,3 +17,7 @@ func hit_Receiver(damage):
|
||||||
PlayerInfo.player_health = $Health_Component.health
|
PlayerInfo.player_health = $Health_Component.health
|
||||||
yield( get_tree().create_timer(2 + $movement_state_machine/hurt.timeout_seconds), "timeout")
|
yield( get_tree().create_timer(2 + $movement_state_machine/hurt.timeout_seconds), "timeout")
|
||||||
$Hurtbox_Component.set_hurtbox(true)
|
$Hurtbox_Component.set_hurtbox(true)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_attack_do_attack():
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=97 format=2]
|
[gd_scene load_steps=100 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/playerD/movement_component.gd" type="Script" id=2]
|
[ext_resource path="res://src/playerD/movement_component.gd" type="Script" id=2]
|
||||||
|
|
@ -7,6 +7,9 @@
|
||||||
[ext_resource path="res://src/playerD/states/move.gd" type="Script" id=5]
|
[ext_resource path="res://src/playerD/states/move.gd" type="Script" id=5]
|
||||||
[ext_resource path="res://src/playerD/states/fall.gd" type="Script" id=6]
|
[ext_resource path="res://src/playerD/states/fall.gd" type="Script" id=6]
|
||||||
[ext_resource path="res://src/components/Health_Component.tscn" type="PackedScene" id=7]
|
[ext_resource path="res://src/components/Health_Component.tscn" type="PackedScene" id=7]
|
||||||
|
[ext_resource path="res://src/playerD/states/jump.gd" type="Script" id=8]
|
||||||
|
[ext_resource path="res://src/state_modifier.gd" type="Script" id=9]
|
||||||
|
[ext_resource path="res://src/playerD/states/attack.gd" type="Script" id=10]
|
||||||
|
|
||||||
[sub_resource type="StreamTexture" id=1]
|
[sub_resource type="StreamTexture" id=1]
|
||||||
load_path = "res://.import/Mega.png-93dfe0790902b932f7b46f7b23c5d4e7.stex"
|
load_path = "res://.import/Mega.png-93dfe0790902b932f7b46f7b23c5d4e7.stex"
|
||||||
|
|
@ -388,7 +391,7 @@ animations = [ {
|
||||||
"speed": 10.0
|
"speed": 10.0
|
||||||
}, {
|
}, {
|
||||||
"frames": [ SubResource( 59 ), SubResource( 60 ), SubResource( 61 ), SubResource( 62 ) ],
|
"frames": [ SubResource( 59 ), SubResource( 60 ), SubResource( 61 ), SubResource( 62 ) ],
|
||||||
"loop": true,
|
"loop": false,
|
||||||
"name": "shoot",
|
"name": "shoot",
|
||||||
"speed": 10.0
|
"speed": 10.0
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -420,7 +423,7 @@ player_number = 1
|
||||||
position = Vector2( -1, -51 )
|
position = Vector2( -1, -51 )
|
||||||
frames = SubResource( 88 )
|
frames = SubResource( 88 )
|
||||||
animation = "idle"
|
animation = "idle"
|
||||||
frame = 22
|
frame = 0
|
||||||
flip_h = false
|
flip_h = false
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_aseprite_wizard_config_": {
|
"_aseprite_wizard_config_": {
|
||||||
|
|
@ -439,9 +442,14 @@ __meta__ = {
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
player_number = 1
|
player_number = 1
|
||||||
|
|
||||||
|
[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( 4 )
|
script = ExtResource( 4 )
|
||||||
animation_sequence = [ "idle" ]
|
animation_sequence = [ "idle" ]
|
||||||
|
jump_node = NodePath("../jump")
|
||||||
|
attack_node = NodePath("../attack")
|
||||||
|
|
||||||
[node name="fall" parent="movement_state_machine" index="1"]
|
[node name="fall" parent="movement_state_machine" index="1"]
|
||||||
script = ExtResource( 6 )
|
script = ExtResource( 6 )
|
||||||
|
|
@ -449,7 +457,36 @@ animation_sequence = [ "jump" ]
|
||||||
|
|
||||||
[node name="move" parent="movement_state_machine" index="2"]
|
[node name="move" parent="movement_state_machine" index="2"]
|
||||||
script = ExtResource( 5 )
|
script = ExtResource( 5 )
|
||||||
animation_sequence = [ "run" ]
|
animation_sequence = [ "step", "run" ]
|
||||||
|
jump_node = NodePath("../jump")
|
||||||
|
|
||||||
|
[node name="jump" type="Node" parent="movement_state_machine" index="3"]
|
||||||
|
script = ExtResource( 8 )
|
||||||
|
animation_sequence = [ "jump" ]
|
||||||
|
idle_node = NodePath("../idle")
|
||||||
|
fall_node = NodePath("../fall")
|
||||||
|
jump_force = 300.0
|
||||||
|
|
||||||
|
[node name="attack" type="Node" parent="movement_state_machine" index="4"]
|
||||||
|
script = ExtResource( 10 )
|
||||||
|
timeout_seconds = 2.0
|
||||||
|
animation_sequence = [ "shoot" ]
|
||||||
|
jump_node = NodePath("../jump")
|
||||||
|
idle_node = NodePath("../idle")
|
||||||
|
fall_node = NodePath("../fall")
|
||||||
|
move_node = NodePath("../move")
|
||||||
|
|
||||||
|
[node name="landing" type="Node" parent="movement_state_machine" index="5"]
|
||||||
|
script = ExtResource( 9 )
|
||||||
|
animation_name = "jump"
|
||||||
|
starting_frame = 6
|
||||||
|
timeout_seconds = 0.1
|
||||||
|
|
||||||
|
[node name="draw_weapon" type="Node" parent="movement_state_machine" index="6"]
|
||||||
|
script = ExtResource( 9 )
|
||||||
|
animation_name = "_shoot"
|
||||||
|
timeout_seconds = 2.2
|
||||||
|
animation_suffix = true
|
||||||
|
|
||||||
[node name="Hurtbox_Component" parent="." index="4"]
|
[node name="Hurtbox_Component" parent="." index="4"]
|
||||||
collision_layer = 16
|
collision_layer = 16
|
||||||
|
|
@ -462,3 +499,5 @@ shape = SubResource( 89 )
|
||||||
|
|
||||||
[node name="Health_Component" parent="." index="6" instance=ExtResource( 7 )]
|
[node name="Health_Component" parent="." index="6" instance=ExtResource( 7 )]
|
||||||
max_health = 100
|
max_health = 100
|
||||||
|
|
||||||
|
[connection signal="do_attack" from="movement_state_machine/attack" to="." method="_on_attack_do_attack"]
|
||||||
|
|
|
||||||
57
src/playerD/states/attack.gd
Normal file
57
src/playerD/states/attack.gd
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
extends StateAnimatedActor
|
||||||
|
|
||||||
|
export (NodePath) var jump_node
|
||||||
|
export (NodePath) var idle_node
|
||||||
|
export (NodePath) var fall_node
|
||||||
|
export (NodePath) var move_node
|
||||||
|
|
||||||
|
onready var jump_state: State = get_node(jump_node)
|
||||||
|
onready var idle_state: State = get_node(idle_node)
|
||||||
|
onready var fall_state: State = get_node(fall_node)
|
||||||
|
onready var move_state: State = get_node(move_node)
|
||||||
|
|
||||||
|
var can_fire = true
|
||||||
|
signal do_attack()
|
||||||
|
|
||||||
|
func enter() -> void:
|
||||||
|
.enter()
|
||||||
|
state_timeout.start()
|
||||||
|
can_fire = true
|
||||||
|
if modifier_stack_ref.has($"../draw_weapon") == false:
|
||||||
|
$"../draw_weapon".enter()
|
||||||
|
modifier_stack_ref.push_front($"../draw_weapon")
|
||||||
|
|
||||||
|
func process_frame(delta: float) -> State:
|
||||||
|
if animations.frame == 2:
|
||||||
|
animations.stop()
|
||||||
|
if state_timeout.time_left == 0:
|
||||||
|
return idle_state
|
||||||
|
return null
|
||||||
|
|
||||||
|
|
||||||
|
func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
|
if can_fire: # trying to do this in the physics because irrecular behavior
|
||||||
|
emit_signal("do_attack")
|
||||||
|
can_fire = false
|
||||||
|
|
||||||
|
if move_component.wants_jump() and parent.is_on_floor():
|
||||||
|
return jump_state
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
func exit() -> void:
|
||||||
|
# force timer reset
|
||||||
|
$"../draw_weapon".state_timeout.start()
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
|
@ -4,16 +4,28 @@ export (NodePath) var idle_node
|
||||||
|
|
||||||
onready var idle_state: State = get_node(idle_node)
|
onready var idle_state: State = get_node(idle_node)
|
||||||
|
|
||||||
|
func enter() -> void:
|
||||||
|
.enter()
|
||||||
|
# Jump to fall frame
|
||||||
|
animations.frame = 5
|
||||||
|
animations.stop()
|
||||||
|
|
||||||
func process_physics(delta: float) -> State:
|
func process_physics(delta: float) -> State:
|
||||||
#parent.velocity.y += gravity * delta
|
|
||||||
move_component.velocity.y += gravity * delta
|
|
||||||
|
|
||||||
move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
|
# First allow horizontal movement.
|
||||||
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
move_actor_as_desired(delta)
|
||||||
|
|
||||||
|
#Flip the character before tha actual move maybe.
|
||||||
if move_component.get_movement_direction() != 0.0:
|
if move_component.get_movement_direction() != 0.0:
|
||||||
parent.transform.x.x = move_component.get_movement_direction()
|
parent.transform.x.x = move_component.get_movement_direction()
|
||||||
|
|
||||||
if parent.is_on_floor():
|
if parent.is_on_floor():
|
||||||
return idle_state
|
return idle_state
|
||||||
|
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
func exit() -> void:
|
||||||
|
.exit()
|
||||||
|
$"../landing".enter()
|
||||||
|
modifier_stack_ref.push_front($"../landing")
|
||||||
|
return
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,13 @@ extends StateAnimatedActor
|
||||||
|
|
||||||
export (NodePath) var fall_node
|
export (NodePath) var fall_node
|
||||||
export (NodePath) var move_node
|
export (NodePath) var move_node
|
||||||
|
export (NodePath) var jump_node
|
||||||
|
export (NodePath) var attack_node
|
||||||
|
|
||||||
onready var fall_state: State = get_node(fall_node)
|
onready var fall_state: State = get_node(fall_node)
|
||||||
onready var move_state: State = get_node(move_node)
|
onready var move_state: State = get_node(move_node)
|
||||||
|
onready var jump_state: State = get_node(jump_node)
|
||||||
|
onready var attack_state: State = get_node(attack_node)
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
.enter()
|
.enter()
|
||||||
|
|
@ -15,10 +19,11 @@ func enter() -> void:
|
||||||
|
|
||||||
func process_physics(delta: float) -> State:
|
func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
# parent.velocity.y += gravity * delta
|
if move_component.wants_jump() and parent.is_on_floor():
|
||||||
# #parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
return jump_state
|
||||||
# parent.velocity.x = move_component.desired_movement_vector.x * move_speed
|
|
||||||
# parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
if move_component.wants_shoot():
|
||||||
|
return attack_state
|
||||||
|
|
||||||
move_actor_as_desired(delta)
|
move_actor_as_desired(delta)
|
||||||
|
|
||||||
|
|
|
||||||
32
src/playerD/states/jump.gd
Normal file
32
src/playerD/states/jump.gd
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
extends StateAnimatedActor
|
||||||
|
|
||||||
|
|
||||||
|
export (NodePath) var idle_node
|
||||||
|
export (NodePath) var fall_node
|
||||||
|
|
||||||
|
onready var idle_state: State = get_node(idle_node)
|
||||||
|
onready var fall_state: State = get_node(fall_node)
|
||||||
|
|
||||||
|
export var jump_force: float = 200.0
|
||||||
|
|
||||||
|
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():
|
||||||
|
return idle_state
|
||||||
|
|
||||||
|
return null
|
||||||
|
|
@ -2,11 +2,15 @@ extends StateAnimatedActor
|
||||||
|
|
||||||
export (NodePath) var fall_node
|
export (NodePath) var fall_node
|
||||||
export (NodePath) var idle_node
|
export (NodePath) var idle_node
|
||||||
|
export (NodePath) var jump_node
|
||||||
|
|
||||||
onready var fall_state: State = get_node(fall_node)
|
onready var fall_state: State = get_node(fall_node)
|
||||||
onready var idle_state: State = get_node(idle_node)
|
onready var idle_state: State = get_node(idle_node)
|
||||||
|
onready var jump_state: State = get_node(jump_node)
|
||||||
|
|
||||||
func process_physics(delta: float) -> State:
|
func process_physics(delta: float) -> State:
|
||||||
|
if move_component.wants_jump() and parent.is_on_floor():
|
||||||
|
return jump_state
|
||||||
|
|
||||||
move_actor_as_desired(delta)
|
move_actor_as_desired(delta)
|
||||||
|
|
||||||
|
|
@ -14,6 +18,7 @@ func process_physics(delta: float) -> State:
|
||||||
return idle_state
|
return idle_state
|
||||||
|
|
||||||
#Flip the character before tha actual move maybe.
|
#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()
|
parent.transform.x.x = move_component.get_movement_direction()
|
||||||
|
|
||||||
if !parent.is_on_floor():
|
if !parent.is_on_floor():
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ func enter() -> void:
|
||||||
animation_suffix = modifier_stack_ref[-1].animation_name
|
animation_suffix = modifier_stack_ref[-1].animation_name
|
||||||
else:
|
else:
|
||||||
animations.play(modifier_stack_ref[-1].animation_name)
|
animations.play(modifier_stack_ref[-1].animation_name)
|
||||||
|
animations.frame = modifier_stack_ref[-1].starting_frame
|
||||||
return
|
return
|
||||||
if animation_sequence.size() > 0:
|
if animation_sequence.size() > 0:
|
||||||
animation_index = 0
|
animation_index = 0
|
||||||
|
|
@ -92,13 +93,20 @@ func process_input(_event: InputEvent) -> State:
|
||||||
return null
|
return null
|
||||||
|
|
||||||
func process_frame(_delta: float) -> State:
|
func process_frame(_delta: float) -> State:
|
||||||
if animation_sequence.size() > 0 and current_animation_sequence != animation_index:
|
#if animation_sequence.size() > 0 and current_animation_sequence != animation_index:
|
||||||
|
if animation_sequence.size() > animation_index and current_animation_sequence != animation_index:
|
||||||
if animation_index >= animation_sequence.size():
|
if animation_index >= animation_sequence.size():
|
||||||
animation_index = 0
|
animation_index = 0
|
||||||
##TODO: Add a safety check here.
|
##TODO: Add a safety check here.
|
||||||
animations.play(animation_sequence[animation_index] + animation_suffix)
|
animations.play(animation_sequence[animation_index] + animation_suffix)
|
||||||
|
if debug_state:
|
||||||
print("An animation sequence: ", animations.animation , animation_index)
|
print("An animation sequence: ", animations.animation , animation_index)
|
||||||
current_animation_sequence = animation_index
|
current_animation_sequence = animation_index
|
||||||
|
# We have no more sequence animations and the current one doesn't loop
|
||||||
|
# we do this to prevent the default idle animation from playing.
|
||||||
|
if animation_index >= animation_sequence.size() and animations.frames.get_animation_loop(
|
||||||
|
animations.animation) == false:
|
||||||
|
animations.stop()
|
||||||
|
|
||||||
# Singal based frame call.
|
# Singal based frame call.
|
||||||
if emitter_frame_subscriptions.has(animations.frame):
|
if emitter_frame_subscriptions.has(animations.frame):
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,11 @@ func process_frame(delta: float) -> void:
|
||||||
# Reset animation suffix
|
# Reset animation suffix
|
||||||
current_state.animation_suffix = ''
|
current_state.animation_suffix = ''
|
||||||
var current_frame = current_state.animations.frame
|
var current_frame = current_state.animations.frame
|
||||||
current_state.animations.play(current_state.animation_sequence[current_state.animation_index])
|
#current_state.animations.play(current_state.animation_sequence[current_state.animation_index])
|
||||||
|
#TODO: Bodge to fix crash
|
||||||
|
current_state.animation_index = 0
|
||||||
|
current_state.current_animation_sequence = 0
|
||||||
|
current_state.animations.play(current_state.animation_sequence[0])
|
||||||
current_state.animations.frame = current_frame;
|
current_state.animations.frame = current_frame;
|
||||||
var new_state = current_state.process_frame(delta)
|
var new_state = current_state.process_frame(delta)
|
||||||
if new_state:
|
if new_state:
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,10 @@ extends Node
|
||||||
##
|
##
|
||||||
## @WIP
|
## @WIP
|
||||||
|
|
||||||
|
export var debug_state: bool = false
|
||||||
|
|
||||||
export var animation_name: String
|
export var animation_name: String
|
||||||
|
export var starting_frame: int = 0
|
||||||
export var move_speed: float = 60
|
export var move_speed: float = 60
|
||||||
export var timeout_seconds: float = 0.0
|
export var timeout_seconds: float = 0.0
|
||||||
|
|
||||||
|
|
@ -39,6 +41,7 @@ func _ready():
|
||||||
add_child(state_timeout)
|
add_child(state_timeout)
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
|
if debug_state:
|
||||||
print("Apply State Modifier: ", self.name)
|
print("Apply State Modifier: ", self.name)
|
||||||
state_timeout.start()
|
state_timeout.start()
|
||||||
#modifier_stack_ref = state_modifiers
|
#modifier_stack_ref = state_modifiers
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user