extends CharacterBody2D var enemy_inattack_range = false var enemy_attack_cooldown = true var health = 100 var player_alive = true var attack_ip = false const speed = 100 var current_dir = "none" @onready var area_spell = $AreaSpell func _ready(): $AnimatedSprite2D.play("front_idle") func _physics_process(delta): player_movement(delta) enemy_attack() attack() update_health() current_camera() if health <= 0: player_alive = false health = 0 get_tree().change_scene_to_file("res://Scenes/death_screen.tscn") func player_movement(delta): if Input.is_action_pressed("ui_right"): current_dir = "right" play_anim(1) velocity.x = speed velocity.y = 0 elif Input.is_action_pressed("ui_left"): current_dir = "left" play_anim(1) velocity.x = -speed velocity.y = 0 elif Input.is_action_pressed("ui_down"): current_dir = "down" play_anim(1) velocity.y = speed velocity.x = 0 elif Input.is_action_pressed("ui_up"): current_dir = "up" play_anim(1) velocity.y = -speed velocity.x = 0 else: play_anim(0) velocity.x = 0 velocity.y = 0 move_and_slide() func play_anim(movement): var dir = current_dir var anim = $AnimatedSprite2D if dir == "right": if movement == 1: anim.play("right_walk") elif movement == 0: if attack_ip == false: anim.play("right_idle") if dir == "left": if movement == 1: anim.play("left_walk") elif movement == 0: if attack_ip == false: anim.play("left_idle") if dir == "down": if movement == 1: anim.play("front_walk") elif movement == 0: if attack_ip == false: anim.play("front_idle") if dir == "up": if movement == 1: anim.play("back_walk") elif movement == 0: if attack_ip == false: anim.play("back_idle") func player(): pass func _on_player_hitbox_body_entered(body: Node2D) -> void: if body.has_method("enemy"): enemy_inattack_range = true func _on_player_hitbox_body_exited(body: Node2D) -> void: if body.has_method("enemy"): enemy_inattack_range = false func enemy_attack(): if enemy_inattack_range and enemy_attack_cooldown == true: health = health - 10 enemy_attack_cooldown = false $attack_cooldown.start() func _on_attack_cooldown_timeout() -> void: enemy_attack_cooldown = true func attack(): var dir = current_dir if Input.is_action_just_pressed("attack"): Global.player_current_attack = true attack_ip = true if dir == "right": $AnimatedSprite2D.play("right_attack") $deal_attack_timer.start() if dir == "left": $AnimatedSprite2D.play("left_attack") $deal_attack_timer.start() if dir == "down": $AnimatedSprite2D.play("front_attack") $deal_attack_timer.start() if dir == "up": $AnimatedSprite2D.play("back_attack") $deal_attack_timer.start() func _on_deal_attack_timer_timeout(): $deal_attack_timer.stop() Global.player_current_attack = false attack_ip = false func current_camera(): if Global.current_scene == "world": $world_camera.enabled = true $church_camera.enabled = false elif Global.current_scene == "church": $world_camera.enabled = false $church_camera.enabled = true func update_health(): var healthbar = $healthbar healthbar.value = health if health >= 100: healthbar.visible = false else: healthbar.visible = true func _on_regen_timer_timeout() -> void: if health < 100: health = health + 20 if health > 100: health = 100 if health <= 0: health = 0 func _unhandled_input(event): if event.is_action_pressed("cast_spell"): $AreaSpell.cast_spell() func cast_area_spell(): area_spell.cast_spell()