72 lines
2.2 KiB
GDScript
72 lines
2.2 KiB
GDScript
extends Actor
|
|
|
|
export var player_number: int = 1
|
|
|
|
onready var player_hurtbox = $Hurtbox_Component/CollisionShape2D
|
|
|
|
onready var gun = $Gun
|
|
|
|
|
|
func _ready() -> void:
|
|
PlayerInfo.player_health = $Health_Component.health
|
|
global_position = LevelInfo.player_start_position.transform.origin
|
|
movement_component.player_number = player_number
|
|
|
|
|
|
var portrait = preload("res://assets/MManPortrait.png")
|
|
|
|
|
|
func hit_Receiver(damage):
|
|
$Hurtbox_Component.set_hurtbox(false)
|
|
$Health_Component.take_damage(damage)
|
|
if $Health_Component.health > 0:
|
|
movement_state_machine.change_state($movement_state_machine/hurt)
|
|
PlayerInfo.player_health = $Health_Component.health
|
|
if PlayerInfo.player_health <= 0:
|
|
return
|
|
yield( get_tree().create_timer(2 + $movement_state_machine/hurt.timeout_seconds), "timeout")
|
|
$Hurtbox_Component.set_hurtbox(true)
|
|
|
|
func receive_modifier(incomming_modifier :StateModifier, is_adding_modifier_operation: bool):
|
|
#var mod :StateModifier
|
|
if is_adding_modifier_operation:
|
|
print("Player Received modifier:", incomming_modifier.name)
|
|
if movement_state_machine.current_state is StateAnimatedActor:
|
|
movement_state_machine.current_state.physics_modifier = incomming_modifier
|
|
else:
|
|
print("Player Removed modifier:", incomming_modifier.name)
|
|
if movement_state_machine.current_state is StateAnimatedActor:
|
|
movement_state_machine.current_state.physics_modifier = null
|
|
|
|
func touch_the_thing(the_thing: Interactable) -> bool:
|
|
print("You see! a THING...", the_thing.name)
|
|
if the_thing is HealthPickup:
|
|
# Do some healthy stuff.
|
|
the_thing.trigger_interaction()
|
|
return false
|
|
return true
|
|
|
|
func _on_attack_do_attack():
|
|
var is_shooting = false
|
|
print("Direction: ", transform.x.x)
|
|
is_shooting = gun.shoot(int(transform.x.x))
|
|
|
|
|
|
|
|
func _on_Health_Component_health_depleted():
|
|
$Hurtbox_Component.set_hurtbox(false)
|
|
movement_state_machine.change_state($movement_state_machine/die)
|
|
yield( get_tree().create_timer(10), "timeout")
|
|
#queue_free()
|
|
|
|
func _on_roll_frame_reached(state_name, animation_name, frame_number):
|
|
print("I'm invincible!!!")
|
|
$Hurtbox_Component.set_hurtbox(false)
|
|
|
|
func _on_roll_state_exited():
|
|
print("Nevermind. I'm vulnerable.")
|
|
$Hurtbox_Component.set_hurtbox(true)
|
|
|
|
func _on_die_state_entered():
|
|
pass # Replace with function body.
|