extends CharacterBody2D
var speed = 200
var health = 100
var score = 0
func _physics_process(_delta):
if Input.is_action_pressed("ui_right"):
velocity.x = speed
elif Input.is_action_pressed("ui_left"):
velocity.x = -speed
else:
velocity.x = 0
if Input.is_action_pressed("ui_up"):
velocity.y = -speed
elif Input.is_action_pressed("ui_down"):
velocity.y = speed
else :
velocity.y = 0
if Input.is_action_pressed("shift"):
speed = 100
else:
speed = 50
move_and_slide()
func _take_damage(amount):
health -= amount
print("Здоровье:",health)
if health <= 0:
die()
func die():
print("Игрок погиб!")
get_tree().reload_current_scene()
var attack_damage = 20
var is_attacking = false
func _on_attack_zone_body_entered(body):
if body.is_in_group("enemy") and not is_attacking:
is_attacking = true
body.take_damage(attack_damage)
await get_tree().create_timer(0.5).timeout
is_attacking = false
func attack():
var tween = create_tween()
tween.tween_property(self,"scale",Vector2(1.2, 1.2), 0.1)
tween.tween_property(self,"scale",Vector2(1,1), 0.1)
func add_score(amount):
score += amount
print("Ваш счет: ", score)
func heal(amount):
health += amount
print("Здоровье:", health)
@onready var spawn_marker = null
func _ready():
gamemanager.load_player_state(self)
spawn_marker = $"../Marker2D"
if spawn_marker:
position = spawn_marker.position
else:
print("Ошибка: точка входа EntryPoint не найдена!")