Moved actor direction into movement component. Velocity is going to be tough.
This commit is contained in:
parent
2a54a8f8fd
commit
50c1c9db51
|
|
@ -2,11 +2,12 @@ class_name Actor
|
||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
var velocity = Vector2(0,0)
|
var velocity = Vector2(0,0)
|
||||||
var direction = Vector2(-1,0)
|
#var direction = Vector2(-1,0)
|
||||||
|
|
||||||
export(String, "Player", "Enemy", "NPC") var actor_type
|
export(String, "Player", "Enemy", "NPC") var actor_type
|
||||||
export var sprite_facing_right: bool = true
|
#export var sprite_facing_right: bool = true
|
||||||
export(Array, Resource) var SoundEffects
|
export(Array, Resource) var SoundEffects
|
||||||
|
export var debug_actor: bool = false
|
||||||
|
|
||||||
onready var movement_animations: AnimatedSprite = $AnimatedSprite
|
onready var movement_animations: AnimatedSprite = $AnimatedSprite
|
||||||
|
|
||||||
|
|
@ -44,6 +45,7 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||||
movement_state_machine.process_input(event)
|
movement_state_machine.process_input(event)
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
|
movement_component.process_physics(delta)
|
||||||
movement_state_machine.process_physics(delta)
|
movement_state_machine.process_physics(delta)
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
|
|
@ -67,4 +69,4 @@ func play_sound_frame(animation: String, frame: int ):
|
||||||
if sound_effects_dict.has(sound_index):
|
if sound_effects_dict.has(sound_index):
|
||||||
sound_effect_player.stream = sound_effects_dict[sound_index]
|
sound_effect_player.stream = sound_effects_dict[sound_index]
|
||||||
sound_effect_player.play()
|
sound_effect_player.play()
|
||||||
print("Playing SE: ", sound_index)
|
print(self.name, " Playing SE: ", sound_index)
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ actor_type = "Enemy"
|
||||||
position = Vector2( 11, -7 )
|
position = Vector2( 11, -7 )
|
||||||
frames = SubResource( 20 )
|
frames = SubResource( 20 )
|
||||||
animation = "idle"
|
animation = "idle"
|
||||||
frame = 0
|
frame = 1
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_aseprite_wizard_config_": {
|
"_aseprite_wizard_config_": {
|
||||||
"layer": "",
|
"layer": "",
|
||||||
|
|
@ -156,10 +156,18 @@ animation_sequence = [ "attack" ]
|
||||||
[node name="move" parent="movement_state_machine" index="3"]
|
[node name="move" parent="movement_state_machine" index="3"]
|
||||||
animation_sequence = [ "walk" ]
|
animation_sequence = [ "walk" ]
|
||||||
|
|
||||||
[node name="PlayerDetection" type="RayCast2D" parent="." index="6"]
|
[node name="EdgeDetection" type="RayCast2D" parent="." index="6"]
|
||||||
|
modulate = Color( 0.054902, 1, 0, 1 )
|
||||||
|
show_behind_parent = true
|
||||||
|
position = Vector2( 15, 3 )
|
||||||
|
enabled = true
|
||||||
|
cast_to = Vector2( 0, 17 )
|
||||||
|
collide_with_areas = true
|
||||||
|
|
||||||
|
[node name="PlayerDetection" type="RayCast2D" parent="." index="7"]
|
||||||
cast_to = Vector2( 21, 0 )
|
cast_to = Vector2( 21, 0 )
|
||||||
|
|
||||||
[node name="Hitbox_Component" type="Area2D" parent="." index="7"]
|
[node name="Hitbox_Component" type="Area2D" parent="." index="8"]
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox_Component" index="0"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox_Component" index="0"]
|
||||||
modulate = Color( 1, 0.596078, 0.121569, 1 )
|
modulate = Color( 1, 0.596078, 0.121569, 1 )
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,20 @@
|
||||||
extends MovementComponent
|
extends MovementComponent
|
||||||
|
|
||||||
onready var idle_timeout = $IdleTimeout
|
onready var idle_timeout = $IdleTimeout
|
||||||
|
onready var edge_detector:RayCast2D = $"../EdgeDetection"
|
||||||
|
|
||||||
var flip_flop = false
|
var flip_flop = false
|
||||||
|
|
||||||
|
func process_physics(delta):
|
||||||
|
if current_movement_state == "move" and edge_detector.is_colliding() == false:
|
||||||
|
#print(owner.name, "uh oh gonna fall!")
|
||||||
|
stop()
|
||||||
|
return
|
||||||
|
|
||||||
func process(delta):
|
func process(delta):
|
||||||
if current_movement_state == "idle" and idle_timeout.time_left == 0:
|
if current_movement_state == "idle" and idle_timeout.time_left == 0:
|
||||||
print ("Time to move!")
|
if debug_component:
|
||||||
|
print ("Time to move!")
|
||||||
if flip_flop:
|
if flip_flop:
|
||||||
flip_flop = false
|
flip_flop = false
|
||||||
go_right()
|
go_right()
|
||||||
|
|
@ -16,7 +24,8 @@ func process(delta):
|
||||||
go_left()
|
go_left()
|
||||||
idle_timeout.start()
|
idle_timeout.start()
|
||||||
if current_movement_state == "move" and idle_timeout.time_left == 0:
|
if current_movement_state == "move" and idle_timeout.time_left == 0:
|
||||||
print("Time to stop.")
|
if debug_component:
|
||||||
|
print("Time to stop.")
|
||||||
idle_timeout.start()
|
idle_timeout.start()
|
||||||
stop()
|
stop()
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
class_name MovementComponent
|
class_name MovementComponent
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
export var debug_component: bool = false
|
||||||
|
|
||||||
onready var desired_movement_vector: Vector2 = Vector2(0,0)
|
onready var desired_movement_vector: Vector2 = Vector2(0,0)
|
||||||
var current_movement_state:String
|
var current_movement_state:String
|
||||||
|
|
||||||
|
|
@ -12,6 +14,9 @@ const DOWN = 1.0
|
||||||
const LEFT = -1.0
|
const LEFT = -1.0
|
||||||
const RIGHT = 1.0
|
const RIGHT = 1.0
|
||||||
|
|
||||||
|
func process_physics(delta):
|
||||||
|
pass
|
||||||
|
|
||||||
func process(delta):
|
func process(delta):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ func set_hurtbox(enabled: bool):
|
||||||
|
|
||||||
func shoot_projectile():
|
func shoot_projectile():
|
||||||
var is_shooting = false
|
var is_shooting = false
|
||||||
is_shooting = gun.shoot(direction.x)
|
is_shooting = gun.shoot(movement_component.get_movement_direction())
|
||||||
|
|
||||||
#func play_sound():
|
#func play_sound():
|
||||||
# sound_effects.stream = "res://assets/Sounds/crappy pew.wav"
|
# sound_effects.stream = "res://assets/Sounds/crappy pew.wav"
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,8 @@ func process_physics(delta: float) -> State:
|
||||||
# if parent.velocity.x != 0.0:
|
# if parent.velocity.x != 0.0:
|
||||||
# parent.direction.x = parent.velocity.x
|
# parent.direction.x = parent.velocity.x
|
||||||
|
|
||||||
if parent.velocity.x > 0:
|
if move_component.get_movement_direction() != 0.0:
|
||||||
parent.direction.x = 1
|
parent.transform.x.x = move_component.get_movement_direction()
|
||||||
elif parent.velocity.x < 0:
|
|
||||||
parent.direction.x = -1
|
|
||||||
|
|
||||||
parent.transform.x.x = parent.direction.x
|
|
||||||
# if move_component.flipped_sprite == false:
|
# if move_component.flipped_sprite == false:
|
||||||
# #parent.scale.x = parent.direction.x * -1
|
# #parent.scale.x = parent.direction.x * -1
|
||||||
# parent.transform.x.x = parent.direction.x * -1 # -1
|
# parent.transform.x.x = parent.direction.x * -1 # -1
|
||||||
|
|
|
||||||
|
|
@ -37,10 +37,11 @@ func process_input(_event: InputEvent) -> State:
|
||||||
return null
|
return null
|
||||||
|
|
||||||
func process_physics(delta: float) -> State:
|
func process_physics(delta: float) -> State:
|
||||||
debugTimeTracker += delta
|
if debug_state:
|
||||||
if debugTimeTracker > 2:
|
debugTimeTracker += delta
|
||||||
debugTimeTracker = 0.0
|
if debugTimeTracker > 2:
|
||||||
print("DEBUG TRANSFORM:", parent.transform)
|
debugTimeTracker = 0.0
|
||||||
|
print(owner.name, " DEBUG TRANSFORM:", parent.transform)
|
||||||
|
|
||||||
parent.velocity.y += gravity * delta
|
parent.velocity.y += gravity * delta
|
||||||
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||||
|
|
|
||||||
|
|
@ -29,11 +29,9 @@ 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:
|
if move_component.get_movement_direction() != 0.0:
|
||||||
parent.direction.x = 1
|
parent.transform.x.x = move_component.get_movement_direction()
|
||||||
elif parent.velocity.x < 0:
|
|
||||||
parent.direction.x = -1
|
|
||||||
parent.transform.x.x = parent.direction.x
|
|
||||||
# if move_component.flipped_sprite == false:
|
# if move_component.flipped_sprite == false:
|
||||||
# #parent.scale.x = parent.direction.x * -1
|
# #parent.scale.x = parent.direction.x * -1
|
||||||
# parent.transform.x.x = parent.direction.x * -1 # -1
|
# parent.transform.x.x = parent.direction.x * -1 # -1
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,11 @@ func process_input(_event: InputEvent) -> State:
|
||||||
func process_physics(delta: float) -> State:
|
func process_physics(delta: float) -> State:
|
||||||
# if move_component.wants_jump() and parent.is_on_floor():
|
# if move_component.wants_jump() and parent.is_on_floor():
|
||||||
# return jump_state
|
# return jump_state
|
||||||
debugTimeTracker += delta
|
if debug_state:
|
||||||
if debugTimeTracker > 2:
|
debugTimeTracker += delta
|
||||||
debugTimeTracker = 0.0
|
if debugTimeTracker > 2:
|
||||||
print("DEBUG TRANSFORM:", parent.transform)
|
debugTimeTracker = 0.0
|
||||||
|
print("DEBUG TRANSFORM:", parent.transform)
|
||||||
|
|
||||||
parent.velocity.y += gravity * delta
|
parent.velocity.y += gravity * delta
|
||||||
|
|
||||||
|
|
@ -45,13 +46,10 @@ func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
if parent.velocity.x == 0.0:
|
if parent.velocity.x == 0.0:
|
||||||
return idle_state
|
return idle_state
|
||||||
else:
|
|
||||||
if parent.velocity.x > 0:
|
if move_component.get_movement_direction() != 0.0:
|
||||||
parent.direction.x = 1
|
parent.transform.x.x = move_component.get_movement_direction()
|
||||||
elif parent.velocity.x < 0:
|
|
||||||
parent.direction.x = -1
|
|
||||||
|
|
||||||
parent.transform.x.x = parent.direction.x
|
|
||||||
# if move_component.flipped_sprite == true:
|
# if move_component.flipped_sprite == true:
|
||||||
# animations.flip_h = parent.direction.x > 0
|
# animations.flip_h = parent.direction.x > 0
|
||||||
# else:
|
# else:
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,8 @@ 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:
|
if move_component.get_movement_direction() != 0.0:
|
||||||
parent.direction.x = 1
|
parent.transform.x.x = move_component.get_movement_direction()
|
||||||
elif parent.velocity.x < 0:
|
|
||||||
parent.direction.x = -1
|
|
||||||
|
|
||||||
parent.transform.x.x = parent.direction.x
|
|
||||||
|
|
||||||
if parent.is_on_floor():
|
if parent.is_on_floor():
|
||||||
return idle_state
|
return idle_state
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ func enter() -> void:
|
||||||
.enter()
|
.enter()
|
||||||
# parent.set_hurtbox(true)
|
# parent.set_hurtbox(true)
|
||||||
parent.velocity.x = 0
|
parent.velocity.x = 0
|
||||||
print("Move Component: ", move_component.desired_movement_vector.x)
|
if debug_state:
|
||||||
|
print(owner.name, " Move Component: ", move_component.desired_movement_vector.x)
|
||||||
|
|
||||||
func process_physics(delta: float) -> State:
|
func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
|
|
@ -23,7 +24,6 @@ func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
if parent.velocity.x != 0.0:
|
if parent.velocity.x != 0.0:
|
||||||
return move_state
|
return move_state
|
||||||
|
|
||||||
|
|
||||||
if !parent.is_on_floor():
|
if !parent.is_on_floor():
|
||||||
return fall_state
|
return fall_state
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,12 @@ onready var idle_state: State = get_node(idle_node)
|
||||||
func process_physics(delta: float) -> State:
|
func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
move_actor_as_desired(delta)
|
move_actor_as_desired(delta)
|
||||||
|
|
||||||
if parent.velocity.x == 0.0:
|
if parent.velocity.x == 0.0:
|
||||||
return idle_state
|
return idle_state
|
||||||
else:
|
|
||||||
if parent.velocity.x > 0:
|
#Flip the character before tha actual move maybe.
|
||||||
parent.direction.x = 1
|
parent.transform.x.x = move_component.get_movement_direction()
|
||||||
elif parent.velocity.x < 0:
|
|
||||||
parent.direction.x = -1
|
|
||||||
|
|
||||||
parent.transform.x.x = parent.direction.x
|
|
||||||
|
|
||||||
if !parent.is_on_floor():
|
if !parent.is_on_floor():
|
||||||
return fall_state
|
return fall_state
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user