111 lines
2.8 KiB
GDScript
111 lines
2.8 KiB
GDScript
class_name Player extends CharacterBody2D
|
|
|
|
@export var move_speed:float
|
|
@export var interaction_pivot:Node2D
|
|
@export var berry_scene:PackedScene
|
|
|
|
@export var pickup_point:Marker2D
|
|
@export var potion_scene:PackedScene
|
|
|
|
@export var idel_down_sprite:Texture2D
|
|
@export var left_sprite:Texture2D
|
|
@export var right_sprite:Texture2D
|
|
@export var up_sprite:Texture2D
|
|
|
|
@export var sprite: Sprite2D
|
|
|
|
|
|
var has_berry:bool
|
|
var has_essence:bool
|
|
|
|
var has_item:bool = false
|
|
|
|
signal info_pressed
|
|
signal help_pressed(is_active:bool)
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
# Get the input direction and handle the movement/deceleration.
|
|
var direction: Vector2 = Input.get_vector("move_left","move_right","move_up","move_down").normalized()
|
|
if direction:
|
|
velocity = direction * move_speed
|
|
interaction_pivot.rotation = direction.angle()
|
|
|
|
else:
|
|
velocity.x = move_toward(velocity.x, 0, move_speed)
|
|
velocity.y = move_toward(velocity.y, 0, move_speed)
|
|
|
|
|
|
update_sprite(direction)
|
|
|
|
move_and_slide()
|
|
|
|
|
|
func update_sprite(dir:Vector2)->void:
|
|
if dir.x > 0:
|
|
sprite.texture = left_sprite
|
|
elif dir.x < 0:
|
|
sprite.texture = right_sprite
|
|
elif dir.y > 0:
|
|
sprite.texture = idel_down_sprite
|
|
elif dir.y < 0:
|
|
sprite.texture = up_sprite
|
|
else:
|
|
sprite.texture = idel_down_sprite
|
|
|
|
|
|
func _on_interaction_triggert(interaction_target: Node2D) -> void:
|
|
|
|
if interaction_target.is_in_group("item_collection"):
|
|
if interaction_target is PickUpArea:
|
|
interaction_target.genreate_item(self)
|
|
|
|
if interaction_target is Kessel:
|
|
if has_item:
|
|
if pickup_point.get_child(0) is Item:
|
|
var active_item:Item = pickup_point.get_child(0)
|
|
interaction_target.add_item(active_item)
|
|
# hinzufügen das man eine fertige potion nicht mehr in den topf werfen kann
|
|
remove_items()
|
|
#interaction_target.play_throw_sound()
|
|
has_item = false
|
|
|
|
else:
|
|
if interaction_target.has_potion():
|
|
var potion = potion_scene.instantiate()
|
|
pickup_point.add_child(potion)
|
|
interaction_target.hide_kessel_ui()
|
|
else:
|
|
print("Ption not finiesd")
|
|
|
|
if interaction_target.is_in_group("trash"):
|
|
remove_items()
|
|
interaction_target.get_child(3).play()
|
|
has_item = false
|
|
|
|
elif interaction_target is Theke:
|
|
## muss hier aber noch schaune ob des was in der hand ist eine Potion ist
|
|
interaction_target.interaction_with_player(self)
|
|
|
|
|
|
|
|
func player_round_start_pos()->void:
|
|
self.position = Vector2(241.0,160.0)
|
|
|
|
func remove_items()-> void:
|
|
for n in pickup_point.get_children():
|
|
pickup_point.remove_child(n)
|
|
n.queue_free()
|
|
|
|
func set_itm_to_spot(item:Node2D)->void:
|
|
if !has_item:
|
|
pickup_point.add_child(item)
|
|
has_item = true
|
|
else:
|
|
print("Already have an Item")
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
|
|
if event.is_action_pressed("pause") and Global.is_in_game:
|
|
Global.game_scene.process_mode = Node.PROCESS_MODE_DISABLED
|
|
UiManager.mainUI.show_pause_screen()
|