extends CharacterBody2D
@export var speed: int=150
@export var enemy_id: int
var chase= false
var onset=false
func _ready()->void:
if enemy_id==1:
signals.connect("defeated",on_defeated)
if enemy_id==2:
signals.connect("defeated2",on_defeated)
func on_defeated():
queue_free()
func test():
print("worked")
func _physics_process(_delta):
var player=$"../player"
var direction=(player.position-self.position).normalized()
if chase==true:
velocity=direction*speed
else:
velocity.x=0
velocity.y=0
move_and_slide()
func _on_detector_body_entered(body):
if body.name =="player":
chase=true
func _on_detector_body_exited(body):
if body.name =="player":
chase=false
func _on_battle_detector_body_entered(body):
if body.name =="player":
onset=true
func _process(_delta):
if onset==true:
globals.circleCount+=1
if enemy_id==1:
signals.battle_1.emit()
get_tree().change_scene_to_file("res://elements/battle/battle_scene.tscn")
level code
/
extends Node2D
@onready var player=$player
func _ready():
if globals.last_position !=Vector2(0, 0):
$player.position=globals.last_position+Vector2(0, 5)
load_room()
func load_room():
signals.connect("battle_1",load_battle)
func load_battle():
print("worked")
var inst = preload("res://elements/battle/battle_scene.tscn")
var win = inst.instantiate()
add_child(win)
func _on_detector_body_entered(body):
if body.name =="player":
globals.last_position=$player.position
battle code
/
@export var enemy: Resource=null
var HP_T=0
var HP_E=0
var ANG_E=0
var def = false
func _ready():
display_text("Бой начался")
set_health($health_T, state.currentHP_T, state.maxHP_T)
set_health($health_enemy, enemy.currentHP_E, enemy.maxHP_E)
HP_T=state.currentHP_T
HP_E=enemy.currentHP_E
ANG_E=enemy.currentAnger
func display_text(text):
$battle_cont/HBoxContainer/text/Display.show()
$battle_cont/HBoxContainer/text/Display/Label.text=text
func set_health(progress_bar, HP, maxHP):
progress_bar.value= HP
progress_bar.max_value=maxHP
progress_bar.get_node("Label").text="HP: %d/%d"%[HP,maxHP]
func _on_def_t_pressed():
def=true
enemy_turn()
func _on_hug_t_pressed():
HP_E=max(0,HP_E-state.damage_T)
set_health($health_enemy, HP_E, enemy.maxHP_E)
enemy_turn()
if HP_E==0:
display_text("Вы победили")
var inst = preload("res://maps/mount/level1.tscn")
var instance = inst.instantiate()
add_child(instance)
if enemy.ID_E==1:
signals.defeated.emit()
elif enemy.ID_E==2:
signals.defeated2.emit()
func _on_heal_t_pressed():
if HP_T<state.maxHP_T:
HP_T=min(state.maxHP_T, HP_T + state.heal_T)
set_health($health_T, HP_T, state.maxHP_T)
enemy_turn()
else:
display_text("nuh uh")
func enemy_turn():
if def:
def=false
display_text("вы удачно защитились")
else:
var random_dam=randi_range(enemy.mindam_E, enemy.damage_E)
HP_T=max(0,HP_T-random_dam)
set_health($health_T, HP_T, state.maxHP_T)
if HP_T==0:
display_text("вы погибли")
$battle_cont.visible=false
func _on_talk_pressed():
ANG_E=max(0,ANG_E-state.talk)
display_text("враг не хочет поговорить поэтому от вас удрал")
if ANG_E==0:
display_text("Вы победили")
var inst = preload("res://maps/mount/level1.tscn")
var win = inst.instantiate()
add_child(win)
if enemy.ID_E==1:
signals.defeated.emit()
elif enemy.ID_E==2:
signals.defeated2.emit()
remove_child(win)
In your menu scene you change to your level scene, which preloads your battle scene, which preloads your level scene again, which (as the errors correctly pointed out) is a cyclic resource inclusion. As @gertkeno already pointed out, your inclusion of the level in the battle scene seems superfluous, because you instantiate it, add it to the scene and then remove it in the same frame again without doing anything with it.