Moved actor direction into movement component. Velocity is going to be tough.
This commit is contained in:
parent
e076952b12
commit
9149e89865
|
|
@ -2,11 +2,12 @@ class_name Actor
|
|||
extends KinematicBody2D
|
||||
|
||||
var velocity = Vector2(0,0)
|
||||
var direction = Vector2(-1,0)
|
||||
#var direction = Vector2(-1,0)
|
||||
|
||||
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 var debug_actor: bool = false
|
||||
|
||||
onready var movement_animations: AnimatedSprite = $AnimatedSprite
|
||||
|
||||
|
|
@ -44,6 +45,7 @@ func _unhandled_input(event: InputEvent) -> void:
|
|||
movement_state_machine.process_input(event)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
movement_component.process_physics(delta)
|
||||
movement_state_machine.process_physics(delta)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
|
|
@ -67,4 +69,4 @@ func play_sound_frame(animation: String, frame: int ):
|
|||
if sound_effects_dict.has(sound_index):
|
||||
sound_effect_player.stream = sound_effects_dict[sound_index]
|
||||
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 )
|
||||
frames = SubResource( 20 )
|
||||
animation = "idle"
|
||||
frame = 0
|
||||
frame = 1
|
||||
__meta__ = {
|
||||
"_aseprite_wizard_config_": {
|
||||
"layer": "",
|
||||
|
|
@ -156,10 +156,18 @@ animation_sequence = [ "attack" ]
|
|||
[node name="move" parent="movement_state_machine" index="3"]
|
||||
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 )
|
||||
|
||||
[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"]
|
||||
modulate = Color( 1, 0.596078, 0.121569, 1 )
|
||||
|
|
|
|||
|
|
@ -1,11 +1,19 @@
|
|||
extends MovementComponent
|
||||
|
||||
onready var idle_timeout = $IdleTimeout
|
||||
onready var edge_detector:RayCast2D = $"../EdgeDetection"
|
||||
|
||||
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):
|
||||
if current_movement_state == "idle" and idle_timeout.time_left == 0:
|
||||
if debug_component:
|
||||
print ("Time to move!")
|
||||
if flip_flop:
|
||||
flip_flop = false
|
||||
|
|
@ -16,6 +24,7 @@ func process(delta):
|
|||
go_left()
|
||||
idle_timeout.start()
|
||||
if current_movement_state == "move" and idle_timeout.time_left == 0:
|
||||
if debug_component:
|
||||
print("Time to stop.")
|
||||
idle_timeout.start()
|
||||
stop()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
class_name MovementComponent
|
||||
extends Node
|
||||
|
||||
export var debug_component: bool = false
|
||||
|
||||
onready var desired_movement_vector: Vector2 = Vector2(0,0)
|
||||
var current_movement_state:String
|
||||
|
||||
|
|
@ -12,6 +14,9 @@ const DOWN = 1.0
|
|||
const LEFT = -1.0
|
||||
const RIGHT = 1.0
|
||||
|
||||
func process_physics(delta):
|
||||
pass
|
||||
|
||||
func process(delta):
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ func set_hurtbox(enabled: bool):
|
|||
|
||||
func shoot_projectile():
|
||||
var is_shooting = false
|
||||
is_shooting = gun.shoot(direction.x)
|
||||
is_shooting = gun.shoot(movement_component.get_movement_direction())
|
||||
|
||||
#func play_sound():
|
||||
# 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:
|
||||
# parent.direction.x = parent.velocity.x
|
||||
|
||||
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 move_component.get_movement_direction() != 0.0:
|
||||
parent.transform.x.x = move_component.get_movement_direction()
|
||||
# if move_component.flipped_sprite == false:
|
||||
# #parent.scale.x = parent.direction.x * -1
|
||||
# parent.transform.x.x = parent.direction.x * -1 # -1
|
||||
|
|
|
|||
|
|
@ -37,10 +37,11 @@ func process_input(_event: InputEvent) -> State:
|
|||
return null
|
||||
|
||||
func process_physics(delta: float) -> State:
|
||||
if debug_state:
|
||||
debugTimeTracker += delta
|
||||
if debugTimeTracker > 2:
|
||||
debugTimeTracker = 0.0
|
||||
print("DEBUG TRANSFORM:", parent.transform)
|
||||
print(owner.name, " DEBUG TRANSFORM:", parent.transform)
|
||||
|
||||
parent.velocity.y += gravity * delta
|
||||
#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 = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||
|
||||
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 move_component.get_movement_direction() != 0.0:
|
||||
parent.transform.x.x = move_component.get_movement_direction()
|
||||
|
||||
# if move_component.flipped_sprite == false:
|
||||
# #parent.scale.x = parent.direction.x * -1
|
||||
# parent.transform.x.x = parent.direction.x * -1 # -1
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ func process_input(_event: InputEvent) -> State:
|
|||
func process_physics(delta: float) -> State:
|
||||
# if move_component.wants_jump() and parent.is_on_floor():
|
||||
# return jump_state
|
||||
if debug_state:
|
||||
debugTimeTracker += delta
|
||||
if debugTimeTracker > 2:
|
||||
debugTimeTracker = 0.0
|
||||
|
|
@ -45,13 +46,10 @@ func process_physics(delta: float) -> State:
|
|||
|
||||
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 move_component.get_movement_direction() != 0.0:
|
||||
parent.transform.x.x = move_component.get_movement_direction()
|
||||
|
||||
# if move_component.flipped_sprite == true:
|
||||
# animations.flip_h = parent.direction.x > 0
|
||||
# else:
|
||||
|
|
|
|||
|
|
@ -10,12 +10,8 @@ func process_physics(delta: float) -> State:
|
|||
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:
|
||||
parent.direction.x = 1
|
||||
elif parent.velocity.x < 0:
|
||||
parent.direction.x = -1
|
||||
|
||||
parent.transform.x.x = parent.direction.x
|
||||
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
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ func enter() -> void:
|
|||
.enter()
|
||||
# parent.set_hurtbox(true)
|
||||
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:
|
||||
|
||||
|
|
@ -24,7 +25,6 @@ func process_physics(delta: float) -> State:
|
|||
if parent.velocity.x != 0.0:
|
||||
return move_state
|
||||
|
||||
|
||||
if !parent.is_on_floor():
|
||||
return fall_state
|
||||
return null
|
||||
|
|
|
|||
|
|
@ -12,13 +12,9 @@ func process_physics(delta: float) -> State:
|
|||
|
||||
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
|
||||
#Flip the character before tha actual move maybe.
|
||||
parent.transform.x.x = move_component.get_movement_direction()
|
||||
|
||||
if !parent.is_on_floor():
|
||||
return fall_state
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user