1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
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
func _ready():
size = sprite.scale.x
target_pos = position
update_visuals()
func _process(_delta):
sprite.scale = Vector2(size, size)
shadow_sprite.scale = sprite.scale
func _physics_process(_delta):
position = position.lerp(target_pos, 0.2)
func join_from(node : NumberNode):
node.value += self.value
var modifier_label = node.get_node_or_null("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.target_pos = self.position
node.update_visuals()
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
## @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()
|