extends Node2D class_name NumberNode @export_group("Values") @export var value : int @export var modifier : float enum Operations { NONE, ADDITION, SUBTRACTION, MULTIPLICATION, DIVISION, } @export var modifier_operation : Operations ## Scan for mouse as a target. Uncheck if player / AI. @export var do_scanning : bool = true @export_group("Visuals") @export_subgroup("Visual Nodes") @export var label : Label @export var sprite : Sprite2D @export var shadow_sprite : Sprite2D @export var sprite_modifier : Sprite2D @export_subgroup("Visual Values") @export var color : Color = Color.BLACK @export var min_scale : float @export var max_scale : float @export var target_pos : Vector2 var size : float = 1 var stored_node var stored_prev_value func _ready(): size = sprite.scale.x target_pos = position update_visuals() #func _process(_delta): func _physics_process(_delta): position = position.lerp(target_pos, 0.2) if sqrt(((target_pos.x - position.x) * (target_pos.x - position.x) + (target_pos.y - position.y) * (target_pos.y - position.y))) < 15: # distance tolerance sprite.scale = sprite.scale.lerp(Vector2(size, size), 0.2) shadow_sprite.scale = sprite.scale func join_from(node : NumberNode): var prev_value = node.value node.value += self.value if self.modifier_operation != Operations.NONE: $"ModifierTimer".start() GlobalVariables.gameloop.get_node("BetweenPlayerAndAI").wait_time = 2 stored_node = node stored_prev_value = prev_value else: GlobalVariables.gameloop.get_node("BetweenPlayerAndAI").wait_time = 1 node.target_pos = self.position node.update_visuals() if node.value >= prev_value: node.get_node("Score").playing = true else: node.get_node("Ouch").playing = true visible = false if self.modifier_operation == Operations.NONE: queue_free() func update_visuals(): label.text = str(self.value) sprite.modulate = color if self.modifier_operation == Operations.ADDITION: sprite_modifier.visible = true if self.modifier_operation == Operations.SUBTRACTION: sprite_modifier.visible = true if self.modifier_operation == Operations.MULTIPLICATION: sprite_modifier.visible = true if self.modifier_operation == Operations.DIVISION: sprite_modifier.visible = true if self.modifier_operation == Operations.NONE: sprite_modifier.visible = false if self.value < 0: sprite.modulate.a = 0.5 ## @deprecated func softlock_check(): var shape_cast : ShapeCast2D = $"ShapeCast2D3" # sorry, too lazy to change names! shape_cast.force_shapecast_update() if shape_cast.get_collision_count() < 2: print("softlock may happen, " + str(shape_cast.collision_result)) var pos = Vector2(randf_range(global_position.x - 80, global_position.x + 80), randf_range(global_position.y - 80, global_position.y + 80)) var scene : PackedScene = load("res://Reusable Scenes/number_node.tscn") var new = scene.instantiate() new.global_position = pos new.value = value get_node(GlobalVariables.NODE).add_child(new) new.softlock_check() func _on_modifier_timer_timeout(): var node = stored_node var prev_value = stored_prev_value var modifier_label = node.get_node_or_null("Control/ModifierLabel") if self.modifier_operation == Operations.ADDITION: node.value += roundi(self.modifier) if modifier_label: modifier_label.pop("+ " + str(self.modifier)) if self.modifier_operation == Operations.SUBTRACTION: node.value -= roundi(self.modifier) if modifier_label: modifier_label.pop("- " + str(self.modifier)) if self.modifier_operation == Operations.MULTIPLICATION: node.value = roundi(float(node.value) * self.modifier) if modifier_label: modifier_label.pop("* " + str(self.modifier)) if self.modifier_operation == Operations.DIVISION: node.value = roundi(float(node.value) / float(self.modifier)) if modifier_label: modifier_label.pop("/ " + str(self.modifier)) node.get_node("Control/AnimationPlayer").play("mod") node.update_visuals() if node.value >= prev_value: node.get_node("Score").playing = true else: node.get_node("Ouch").playing = true queue_free()