Painted into corner.
This commit is contained in:
parent
31c49ef828
commit
3162ec56ad
|
|
@ -131,6 +131,7 @@ script = ExtResource( 1 )
|
||||||
position = Vector2( 8, -8 )
|
position = Vector2( 8, -8 )
|
||||||
frames = SubResource( 168 )
|
frames = SubResource( 168 )
|
||||||
animation = "idle"
|
animation = "idle"
|
||||||
|
frame = 2
|
||||||
playing = true
|
playing = true
|
||||||
flip_h = true
|
flip_h = true
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
[gd_scene load_steps=22 format=2]
|
[gd_scene load_steps=26 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/state_animated_actor.gd" type="Script" id=3]
|
||||||
|
[ext_resource path="res://src/enemyC/states/idle.gd" type="Script" id=4]
|
||||||
|
[ext_resource path="res://src/enemyC/states/wander.gd" type="Script" id=5]
|
||||||
|
|
||||||
[sub_resource type="StreamTexture" id=1]
|
[sub_resource type="StreamTexture" id=1]
|
||||||
load_path = "res://.import/botEnemy.png-46efd539a38730ff15fb4ddb087329c6.stex"
|
load_path = "res://.import/botEnemy.png-46efd539a38730ff15fb4ddb087329c6.stex"
|
||||||
|
|
@ -105,13 +108,16 @@ animations = [ {
|
||||||
"speed": 10.0
|
"speed": 10.0
|
||||||
} ]
|
} ]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id=21]
|
||||||
|
extents = Vector2( 9, 3.5 )
|
||||||
|
|
||||||
[node name="EnemyC" instance=ExtResource( 1 )]
|
[node name="EnemyC" instance=ExtResource( 1 )]
|
||||||
|
|
||||||
[node name="AnimatedSprite" parent="." index="0"]
|
[node name="AnimatedSprite" parent="." index="0"]
|
||||||
position = Vector2( 11, -7 )
|
position = Vector2( 11, -7 )
|
||||||
frames = SubResource( 20 )
|
frames = SubResource( 20 )
|
||||||
animation = "idle"
|
animation = "idle"
|
||||||
frame = 1
|
frame = 2
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_aseprite_wizard_config_": {
|
"_aseprite_wizard_config_": {
|
||||||
"layer": "",
|
"layer": "",
|
||||||
|
|
@ -129,7 +135,34 @@ __meta__ = {
|
||||||
position = Vector2( -0.5, -2 )
|
position = Vector2( -0.5, -2 )
|
||||||
|
|
||||||
[node name="idle" parent="movement_state_machine" index="0"]
|
[node name="idle" parent="movement_state_machine" index="0"]
|
||||||
|
script = ExtResource( 4 )
|
||||||
|
timeout_seconds = 2.0
|
||||||
animation_sequence = [ "idle" ]
|
animation_sequence = [ "idle" ]
|
||||||
|
wander_node = NodePath("../wander")
|
||||||
|
attack_node = NodePath("../attack")
|
||||||
|
|
||||||
[node name="fall" parent="movement_state_machine" index="1"]
|
[node name="fall" parent="movement_state_machine" index="1"]
|
||||||
animation_sequence = [ "idle" ]
|
animation_sequence = [ "idle" ]
|
||||||
|
|
||||||
|
[node name="wander" type="Node" parent="movement_state_machine" index="2"]
|
||||||
|
script = ExtResource( 5 )
|
||||||
|
timeout_seconds = 2.0
|
||||||
|
animation_sequence = [ "walk" ]
|
||||||
|
idle_node = NodePath("../idle")
|
||||||
|
attack_node = NodePath("../attack")
|
||||||
|
fall_node = NodePath("../fall")
|
||||||
|
|
||||||
|
[node name="attack" type="Node" parent="movement_state_machine" index="3"]
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
timeout_seconds = 3.0
|
||||||
|
animation_sequence = [ "attack" ]
|
||||||
|
|
||||||
|
[node name="PlayerDetection" type="RayCast2D" parent="." index="6"]
|
||||||
|
cast_to = Vector2( 21, 0 )
|
||||||
|
|
||||||
|
[node name="Hitbox_Component" type="Area2D" parent="." index="7"]
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox_Component" index="0"]
|
||||||
|
modulate = Color( 1, 0.596078, 0.121569, 1 )
|
||||||
|
position = Vector2( 18, -8.5 )
|
||||||
|
shape = SubResource( 21 )
|
||||||
|
|
|
||||||
|
|
@ -3,31 +3,24 @@ extends "res://src/templates/Actor/states/idle.gd"
|
||||||
|
|
||||||
var debugTimeTracker := 0.0
|
var debugTimeTracker := 0.0
|
||||||
|
|
||||||
export (NodePath) var jump_node
|
export (NodePath) var wander_node
|
||||||
export (NodePath) var move_node
|
export (NodePath) var attack_node
|
||||||
export (NodePath) var fire_node
|
|
||||||
|
|
||||||
onready var jump_state: State = get_node(jump_node)
|
onready var wander_state: State = get_node(wander_node)
|
||||||
onready var move_state: State = get_node(move_node)
|
onready var attack_state: State = get_node(attack_node)
|
||||||
onready var fire_state: State = get_node(fire_node)
|
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
.enter()
|
.enter()
|
||||||
parent.set_hurtbox(true)
|
parent.set_hurtbox(true)
|
||||||
parent.velocity.x = 0
|
parent.velocity.x = 0
|
||||||
|
state_timeout.start()
|
||||||
|
|
||||||
func process_input(_event: InputEvent) -> State:
|
func process_frame(_delta: float) -> State:# if get_jump() and parent.is_on_floor():
|
||||||
# if get_jump() and parent.is_on_floor():
|
|
||||||
# return jump_state
|
# return jump_state
|
||||||
|
|
||||||
if move_component.wants_jump() and parent.is_on_floor():
|
if state_timeout.time_left == 0:
|
||||||
return jump_state
|
return wander_state
|
||||||
|
|
||||||
# if move_component.get_movement_direction() != 0.0:
|
|
||||||
# return move_state
|
|
||||||
if move_component.wants_shoot():
|
|
||||||
return fire_state
|
|
||||||
|
|
||||||
# move_component.wants_jump()
|
# move_component.wants_jump()
|
||||||
move_component.get_movement_direction()
|
move_component.get_movement_direction()
|
||||||
|
|
||||||
|
|
@ -46,8 +39,6 @@ func process_physics(delta: float) -> State:
|
||||||
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
|
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
|
||||||
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||||
|
|
||||||
if parent.velocity.x != 0.0:
|
|
||||||
return move_state
|
|
||||||
|
|
||||||
if !parent.is_on_floor():
|
if !parent.is_on_floor():
|
||||||
return fall_state
|
return fall_state
|
||||||
58
src/enemyC/states/wander.gd
Normal file
58
src/enemyC/states/wander.gd
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
extends StateAnimatedActor
|
||||||
|
|
||||||
|
export (NodePath) var idle_node
|
||||||
|
export (NodePath) var attack_node
|
||||||
|
export (NodePath) var fall_node
|
||||||
|
|
||||||
|
onready var idle_state: State = get_node(idle_node)
|
||||||
|
onready var attack_state: State = get_node(attack_node)
|
||||||
|
onready var fall_state: State = get_node(fall_node)
|
||||||
|
|
||||||
|
var flip_flop = false
|
||||||
|
|
||||||
|
func enter(state_modifiers: Array = []) -> void:
|
||||||
|
.enter()
|
||||||
|
parent.set_hurtbox(true)
|
||||||
|
state_timeout.start()
|
||||||
|
if flip_flop:
|
||||||
|
flip_flop = false
|
||||||
|
move_component.desired_movement_vector.x = 1.0
|
||||||
|
else:
|
||||||
|
flip_flop = true
|
||||||
|
move_component.desired_movement_vector.x = -1.0
|
||||||
|
|
||||||
|
func process_frame(_delta: float) -> State:
|
||||||
|
|
||||||
|
# if parent.player_detection.is_colliding():
|
||||||
|
# return attack_state
|
||||||
|
|
||||||
|
if state_timeout.time_left == 0:
|
||||||
|
return idle_state
|
||||||
|
|
||||||
|
# if move_component.wants_jump() and parent.is_on_floor():
|
||||||
|
# return jump_state
|
||||||
|
#
|
||||||
|
# move_component.get_movement_direction()
|
||||||
|
return null
|
||||||
|
|
||||||
|
|
||||||
|
func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
|
parent.velocity.y += gravity * delta
|
||||||
|
|
||||||
|
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
|
||||||
|
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||||
|
|
||||||
|
if parent.velocity.x == 0.0:
|
||||||
|
return idle_state
|
||||||
|
else:
|
||||||
|
if parent.velocity.x > 0:
|
||||||
|
parent.direction.x = 1
|
||||||
|
elif parent.velocity.x < 0:
|
||||||
|
parent.direction.x = -1
|
||||||
|
|
||||||
|
parent.transform.x.x = parent.direction.x
|
||||||
|
|
||||||
|
if !parent.is_on_floor():
|
||||||
|
return fall_state
|
||||||
|
return null
|
||||||
|
|
@ -2,17 +2,23 @@ class_name MovementComponent
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
onready var desired_movement_vector: Vector2 = Vector2(0,0)
|
onready var desired_movement_vector: Vector2 = Vector2(0,0)
|
||||||
|
var current_movement_state:String
|
||||||
|
|
||||||
|
enum directions {UP, DOWN, LEFT, RIGHT}
|
||||||
|
|
||||||
|
func process(delta):
|
||||||
|
pass
|
||||||
|
|
||||||
# Return the desired direction of movement for the character
|
# Return the desired direction of movement for the character
|
||||||
# in the range [-1, 1], where positive values indicate a desire
|
# in the range [-1, 1], where positive values indicate a desire
|
||||||
# to move to the right and negative values to the left.
|
# to move to the right and negative values to the left.
|
||||||
func get_movement_direction() -> float:
|
func get_movement_direction() -> float:
|
||||||
return 0.0
|
return desired_movement_vector.x
|
||||||
|
|
||||||
# Return a boolean indicating if the character wants to jump
|
# Return a boolean indicating if the character wants to jump
|
||||||
func wants_jump() -> bool:
|
func wants_jump() -> bool:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
# Return a boolean indicating if the character wants to jump
|
# Return a boolean indicating if the character wants to attack
|
||||||
func wants_shoot() -> bool:
|
func wants_shoot() -> bool:
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
class_name State
|
class_name State
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
export var debug_state: bool = false
|
||||||
export var timeout_seconds: float = 0.0
|
export var timeout_seconds: float = 0.0
|
||||||
|
|
||||||
# Declare member variables here. Examples:
|
# Declare member variables here. Examples:
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ var parent: KinematicBody2D
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
##TODO: this bit me in the butt. Should add a safety or something.
|
||||||
# Only add timout node if timer value was specified.
|
# Only add timout node if timer value was specified.
|
||||||
if(timeout_seconds > 0.0):
|
if(timeout_seconds > 0.0):
|
||||||
state_timeout = Timer.new()
|
state_timeout = Timer.new()
|
||||||
|
|
@ -53,7 +54,9 @@ func enter() -> void:
|
||||||
# animations.connect("animation_finished", self, "_on_AnimatedSprite_animation_finished")
|
# animations.connect("animation_finished", self, "_on_AnimatedSprite_animation_finished")
|
||||||
# Reset animation suffix in case there isn't one
|
# Reset animation suffix in case there isn't one
|
||||||
animation_suffix = ''
|
animation_suffix = ''
|
||||||
print(parent.name, " entering State: ", self.name)
|
if debug_state:
|
||||||
|
print(parent.name, " entering State: ", self.name)
|
||||||
|
move_component.current_movement_state = self.name
|
||||||
#modifier_stack_ref = state_modifiers
|
#modifier_stack_ref = state_modifiers
|
||||||
if modifier_stack_ref.empty() == false:
|
if modifier_stack_ref.empty() == false:
|
||||||
if modifier_stack_ref[-1].animation_name != '':
|
if modifier_stack_ref[-1].animation_name != '':
|
||||||
|
|
@ -92,8 +95,16 @@ func process_frame(_delta: float) -> State:
|
||||||
return null
|
return null
|
||||||
|
|
||||||
func process_physics(_delta: float) -> State:
|
func process_physics(_delta: float) -> State:
|
||||||
|
move_actor_as_desired(_delta)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
#func _on_AnimatedSprite_animation_finished():
|
#func _on_AnimatedSprite_animation_finished():
|
||||||
# if animations.frames.get_animation_loop(animations.animation) == false:
|
# if animations.frames.get_animation_loop(animations.animation) == false:
|
||||||
# animation_index += 1
|
# animation_index += 1
|
||||||
|
|
||||||
|
func move_actor_as_desired(delta: float):
|
||||||
|
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))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ func _physics_process(delta: float) -> void:
|
||||||
#self.scale.x = -1
|
#self.scale.x = -1
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
|
movement_component.process(delta)
|
||||||
movement_state_machine.process_frame(delta)
|
movement_state_machine.process_frame(delta)
|
||||||
play_sound_frame(movement_animations.animation , movement_animations.frame)
|
play_sound_frame(movement_animations.animation , movement_animations.frame)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=16 format=2]
|
[gd_scene load_steps=17 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://src/components/Hurtbox_Component.tscn" type="PackedScene" id=1]
|
[ext_resource path="res://src/components/Hurtbox_Component.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://src/state_machine_animated_actor.gd" type="Script" id=2]
|
[ext_resource path="res://src/state_machine_animated_actor.gd" type="Script" id=2]
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
[ext_resource path="res://src/templates/Actor/states/idle.gd" type="Script" id=4]
|
[ext_resource path="res://src/templates/Actor/states/idle.gd" type="Script" id=4]
|
||||||
[ext_resource path="res://src/movement_component.gd" type="Script" id=5]
|
[ext_resource path="res://src/movement_component.gd" type="Script" id=5]
|
||||||
[ext_resource path="res://src/templates/Actor/resources/Smiley.png" type="Texture" id=6]
|
[ext_resource path="res://src/templates/Actor/resources/Smiley.png" type="Texture" id=6]
|
||||||
|
[ext_resource path="res://src/templates/Actor/states/move.gd" type="Script" id=7]
|
||||||
[ext_resource path="res://src/templates/Actor/ActorTemplate.gd" type="Script" id=12]
|
[ext_resource path="res://src/templates/Actor/ActorTemplate.gd" type="Script" id=12]
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id=76]
|
[sub_resource type="AtlasTexture" id=76]
|
||||||
|
|
@ -49,7 +50,7 @@ script = ExtResource( 12 )
|
||||||
|
|
||||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
||||||
frames = SubResource( 75 )
|
frames = SubResource( 75 )
|
||||||
frame = 2
|
frame = 4
|
||||||
playing = true
|
playing = true
|
||||||
flip_h = true
|
flip_h = true
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
|
|
@ -86,6 +87,12 @@ script = ExtResource( 3 )
|
||||||
animation_sequence = [ "default" ]
|
animation_sequence = [ "default" ]
|
||||||
idle_node = NodePath("../idle")
|
idle_node = NodePath("../idle")
|
||||||
|
|
||||||
|
[node name="move" type="Node" parent="movement_state_machine"]
|
||||||
|
script = ExtResource( 7 )
|
||||||
|
animation_sequence = [ "default" ]
|
||||||
|
fall_node = NodePath("../fall")
|
||||||
|
idle_node = NodePath("../idle")
|
||||||
|
|
||||||
[node name="Hurtbox_Component" parent="." instance=ExtResource( 1 )]
|
[node name="Hurtbox_Component" parent="." instance=ExtResource( 1 )]
|
||||||
|
|
||||||
[node name="SE_Player" type="AudioStreamPlayer" parent="."]
|
[node name="SE_Player" type="AudioStreamPlayer" parent="."]
|
||||||
|
|
|
||||||
25
src/templates/Actor/states/move.gd
Normal file
25
src/templates/Actor/states/move.gd
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
extends StateAnimatedActor
|
||||||
|
|
||||||
|
export (NodePath) var fall_node
|
||||||
|
export (NodePath) var idle_node
|
||||||
|
|
||||||
|
onready var fall_state: State = get_node(fall_node)
|
||||||
|
onready var idle_state: State = get_node(idle_node)
|
||||||
|
|
||||||
|
func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
|
move_actor_as_desired(delta)
|
||||||
|
|
||||||
|
if parent.velocity.x == 0.0:
|
||||||
|
return idle_state
|
||||||
|
else:
|
||||||
|
if parent.velocity.x > 0:
|
||||||
|
parent.direction.x = 1
|
||||||
|
elif parent.velocity.x < 0:
|
||||||
|
parent.direction.x = -1
|
||||||
|
|
||||||
|
parent.transform.x.x = parent.direction.x
|
||||||
|
|
||||||
|
if !parent.is_on_floor():
|
||||||
|
return fall_state
|
||||||
|
return null
|
||||||
Loading…
Reference in New Issue
Block a user