var stat_sprite = {"verun": preload("res://stat sprite.tscn")}
@onready var stat_sprite_container = $StatSpriteContainer var stat_sprite_instances = [] @onready var body_parts_container = $BodyPartsContainer var body_parts_instances = []
func _ready(): # Создаем и добавляем части тела в контейнер for part in body_parts: var instance = body_parts[part].instantiate() body_parts_container.add_child(instance) instance.hide() body_parts_instances.append(instance) for part in stat_sprite: var instance = stat_sprite[part].instantiate() stat_sprite_container.add_child(instance) instance.show() stat_sprite_instances.append(instance)
func _input(event): if event is InputEventMouseButton: if event.pressed: hide_stat_sprite() show_body_parts() elif event is InputEventMouseMotion: hide_body_parts() show_stat_sprite()
func show_body_parts(): for part in body_parts_instances: part.show()
func hide_body_parts(): for part in body_parts_instances: part.hide()
func hide_stat_sprite(): for part in stat_sprite_instances: part.hide()
func show_stat_sprite(): for part in stat_sprite_instances: part.show()
const SPEED = 300.0 const JUMP_VELOCITY = -800.0
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _physics_process(delta): if not is_on_floor(): velocity.y += gravity * delta
if Input.is_action_just_pressed("ui_up") and is_on_floor(): velocity.y = JUMP_VELOCITY
var direction = Input.get_axis("ui_left", "ui_right") if direction: velocity.x = direction * SPEED else: velocity.x = move_toward(velocity.x, 0, SPEED)