GodotWIP/state.gd

63 lines
1.6 KiB
GDScript

class_name State
extends Node
export var animation_name: String
export var move_speed: float = 60
export var timeout_seconds: float = 0.0
export(Array, String) var animation_sequence
var animation_index: int = 0
var current_animation_sequence: int = 0
var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
var animations: AnimatedSprite
var move_component: Node
var parent: KinematicBody2D
#var animation_sequence_timer: Timer
var state_timeout: Timer
func _ready():
if(timeout_seconds > 0.0):
state_timeout = Timer.new()
state_timeout.wait_time = timeout_seconds
state_timeout.one_shot = true
state_timeout.autostart = false
add_child(state_timeout)
func enter() -> void:
print(parent.name, " entering State: ", self.name)
if animation_name != '':
animations.play(animation_name)
elif animation_sequence.size() > 0:
animation_index = 0
current_animation_sequence = 0
animations.play(animation_sequence[animation_index])
func exit() -> void:
pass
func process_input(_event: InputEvent) -> State:
return null
func process_frame(_delta: float) -> State:
if animation_sequence.size() > 0 and current_animation_sequence != animation_index:
if animation_index >= animation_sequence.size():
animation_index = 0
animations.play(animation_sequence[animation_index])
print("An animation sequence: ", animations.animation , animation_index)
current_animation_sequence = animation_index
return null
func process_physics(_delta: float) -> State:
return null
#func get_movement_input() -> float:
# return move_component.get_movement_direction()
#
#func get_jump() -> bool:
# return move_component.wants_jump()