73 lines
2.2 KiB
GDScript
73 lines
2.2 KiB
GDScript
extends KinematicBody2D
|
|
|
|
var velocity = Vector2(0,0)
|
|
var direction = Vector2(-1,0)
|
|
|
|
export var player_number: int = 1
|
|
|
|
export var sprite_facing_right: bool = true
|
|
|
|
onready var movement_animations: AnimatedSprite = $AnimatedSprite
|
|
|
|
onready var movement_state_machine: Node = $Controllers/state_machine
|
|
|
|
onready var player_move_component = $Controllers/move_component
|
|
|
|
onready var player_hurtbox = $Hurtbox_Component/CollisionShape2D
|
|
|
|
onready var gun = $Gun
|
|
|
|
func _ready() -> void:
|
|
movement_state_machine.init(self, movement_animations, player_move_component)
|
|
player_move_component.player_number = player_number
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
movement_state_machine.process_input(event)
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
movement_state_machine.process_physics(delta)
|
|
# #TODO: So much hack
|
|
# if direction.x != 0:
|
|
# gun.set_scale( Vector2(direction.x,1))
|
|
|
|
# Commented out to try parent transforms instead
|
|
# if direction.x < 0:
|
|
# var t = Transform2D()
|
|
# # Translation
|
|
# t.origin = Vector2(gun.offset_position.x * -1, gun.offset_position.y)
|
|
# gun.transform = t
|
|
# elif direction.x > 0:
|
|
# var t = Transform2D()
|
|
# # Translation
|
|
# t.origin = Vector2(gun.offset_position.x, gun.offset_position.y)
|
|
# gun.transform = t
|
|
|
|
# Attempting a Kinematic2D level scale for flip operations instead.
|
|
#self.transform
|
|
#self.scale.x = -1
|
|
|
|
func _process(delta: float) -> void:
|
|
movement_state_machine.process_frame(delta)
|
|
PlayerInfo.player_position = global_position
|
|
|
|
func _on_AnimatedSprite_animation_finished():
|
|
if movement_animations.frames.get_animation_loop(movement_animations.animation) == false:
|
|
movement_state_machine.current_state.animation_index += 1
|
|
|
|
func _on_Hurtbox_area_entered(area):
|
|
print("Ouch.",area)
|
|
movement_state_machine.change_state($Controllers/state_machine/hurt)
|
|
|
|
func set_hurtbox(enabled: bool):
|
|
#player_hurtbox.disabled = enabled #nope
|
|
player_hurtbox.set_deferred("disabled", !enabled) #WTF Apparently this is how to do it
|
|
#$Hurtbox.monitoring = enabled #nope
|
|
#$Hurtbox.set_deferred("monitoring", enabled) #works
|
|
#$Hurtbox.monitoring = false #nope
|
|
#$Hurtbox.set_monitoring(enabled) # Nope
|
|
|
|
func shoot_projectile():
|
|
var is_shooting = false
|
|
is_shooting = gun.shoot(direction.x)
|
|
|