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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
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
self.stored_prev_value = prev_value
node.value += self.value
if self.modifier_operation != Operations.NONE:
stored_node = node
self.stored_prev_value = node.value
$"ModifierTimer".start()
GlobalVariables.gameloop.get_node("BetweenPlayerAndAI").wait_time = 2
if GlobalVariables.gameloop.current_turns + 1 >= GlobalVariables.gameloop.turns:
GlobalVariables.gameloop.get_node("AudioDelay").wait_time = 2
else:
GlobalVariables.gameloop.get_node("BetweenPlayerAndAI").wait_time = 1
GlobalVariables.gameloop.get_node("AudioDelay").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 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 >= self.stored_prev_value:
print(str(node.value) + " >= " + str(self.stored_prev_value))
node.get_node("Score").playing = true
else:
node.get_node("Ouch").playing = true
self.stored_prev_value = node.value
queue_free()
|