/
mrFeld
/
Platformer
Обзор
Документация
Войти
/
mrFeld
/
Platformer
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Script/Player/player.gd
123 строки
3 KB
Neterov Vladimir
nonstable
25 окт 2025, 13:32
25 окт 2025, 13:32
8f17866
Код
Авторство
О чём код?
extends CharacterBody2D @export var normal_speed := 100.0 @export var acceleration := 5.0 @export var friction := 8.0 @export var max_health := 100 @export var damage := 30 @export var attack_sector_scene: PackedScene @onready var health: int = max_health @onready var dash = $Dash @onready var ui: CanvasLayer = $UserInterface/UI @onready var attack_sector: Node = $AttackSector var ui_visible: bool = true func _ready(): dash.cooldown_updated.connect(_on_dash_cooldown_updated) ui.update_health(health) attack_sector.cooldown_updated.connect(ui.update_attack_cooldown) func _on_inventory_opened(): ui.hide() set_process_unhandled_input(false) get_tree().paused = true func _on_inventory_closed(): ui.visible = ui_visible set_process_unhandled_input(true) get_tree().paused = false func _unhandled_input(_event: InputEvent) -> void: if Input.is_action_just_pressed("Acept"): DialogueManager.show_example_dialogue_balloon(load("res://Dialogue/Test.dialogue"), "start") func _process(delta): var input_vector = Vector2.ZERO if Input.is_action_just_pressed("Dash") and dash.is_ready(): dash.start_dash() input_vector.x = Input.get_axis("ui_left", "ui_right") input_vector.y = Input.get_axis("ui_up", "ui_down") var target_velocity = input_vector.normalized() * (dash.current_dash_speed() if dash.is_dashing() else normal_speed) if input_vector != Vector2.ZERO: velocity = velocity.lerp(target_velocity, acceleration * delta) else: velocity = velocity.lerp(Vector2.ZERO, friction * delta) move_and_slide() if Input.is_action_just_pressed("Attack"): # Это должно выводиться attack() func attack(): if attack_sector.has_method("activate"): var mouse_direction = (get_global_mouse_position() - global_position).normalized() attack_sector.activate(global_position, (get_global_mouse_position() - global_position).normalized()) func take_damage(amount: int): health = clamp(health - amount, 0, max_health) ui.update_health(health) _check_health() func heal(amount: int): health = clamp(health + amount, 0, max_health) ui.update_health(health) func _check_health(): if health <= 0: die() func die(): get_tree().paused = true $Sprite2D.hide() ui.hide() $UserInterface.hide() $"../UserInterface/EscMenu".hide() $"../UserInterface/DeathMenu".show() func _on_dash_cooldown_updated(time_left: float, cooldown: float): ui.update_dash_cooldown(time_left, cooldown) func _on_attack_cooldown_updated(time_left: float, cooldown: float): ui.update_attack_cooldown(time_left, cooldown) func _input(event): if event.is_action_pressed("Pickup"): if $PickupZone.items_in_range.size() > 0: var pickup_item = $PickupZone.items_in_range.values()[0] pickup_item.pick_up_item(self) $PickupZone.items_in_range.erase(pickup_item) func save(): var save_dict = { "filename" : get_scene_file_path(), "parent" : get_parent().get_path(), "pos_x" : position.x, # Vector2 is not supported by JSON "pos_y" : position.y, #"attack" : attack, #"defense" : defense, "current_health" : health, "max_health" : max_health, "damage" : damage, #"regen" : regen, #"experience" : experience, #"tnl" : tnl, #"level" : level, #"attack_growth" : attack_growth, #"defense_growth" : defense_growth, #"health_growth" : health_growth, #"is_alive" : is_alive, #"last_attack" : last_attack } return save_dict func load_save_data(data): pass