about summary refs log tree commit diff stats
path: root/Archipelago/mypainting.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Archipelago/mypainting.gd')
-rw-r--r--Archipelago/mypainting.gd99
1 files changed, 99 insertions, 0 deletions
diff --git a/Archipelago/mypainting.gd b/Archipelago/mypainting.gd new file mode 100644 index 0000000..5e9c703 --- /dev/null +++ b/Archipelago/mypainting.gd
@@ -0,0 +1,99 @@
1extends Spatial
2
3var orientation = "" # north, south, east, west
4var move = false
5var move_to_x
6var move_to_z
7var target = null
8var key
9
10
11func _ready():
12 var _connected = get_tree().get_root().get_node("Spatial/player").connect(
13 "looked_at", self, "_looked_at"
14 )
15 if move:
16 key.get_node("Viewport/GUI/Panel/TextEdit").connect(
17 "answer_correct", self, "_answer_correct"
18 )
19
20
21func _answer_correct():
22 var apclient = global.get_node("Archipelago")
23 if not apclient._door_shuffle or apclient.paintingIsVanilla(self.get_parent().name):
24 movePainting()
25
26
27func movePainting():
28 self.get_parent().translation.x = move_to_x
29 self.get_parent().translation.z = move_to_z
30
31
32func _looked_at(body, painting):
33 if (
34 target != null
35 and body.is_in_group("player")
36 and (painting.get_name() == self.get_parent().get_name())
37 ):
38 var target_dir = _dir_to_int(target.orientation)
39 var source_dir = _dir_to_int(orientation)
40 var rotate = target_dir - source_dir
41 if rotate < 0:
42 rotate += 4
43 rotate *= 90
44
45 var target_painting = target.get_parent()
46
47 # this is ACW
48 if rotate == 0:
49 body.translation.x = (
50 target_painting.translation.x + (body.translation.x - painting.translation.x)
51 )
52 body.translation.y = (
53 target_painting.translation.y + (body.translation.y - painting.translation.y)
54 )
55 body.translation.z = (
56 target_painting.translation.z + (body.translation.z - painting.translation.z)
57 )
58 elif rotate == 180:
59 body.translation.x = (
60 target_painting.translation.x - (body.translation.x - painting.translation.x)
61 )
62 body.translation.y = (
63 target_painting.translation.y + (body.translation.y - painting.translation.y)
64 )
65 body.translation.z = (
66 target_painting.translation.z - (body.translation.z - painting.translation.z)
67 )
68 body.rotate_y(PI)
69 body.velocity = body.velocity.rotated(Vector3(0, 1, 0), PI)
70 elif rotate == 90:
71 var diff_x = body.translation.x - painting.translation.x
72 var diff_y = body.translation.y - painting.translation.y
73 var diff_z = body.translation.z - painting.translation.z
74 body.translation.x = target_painting.translation.x + diff_z
75 body.translation.y = target_painting.translation.y + diff_y
76 body.translation.z = target_painting.translation.z - diff_x
77 body.rotate_y(PI / 2)
78 body.velocity = body.velocity.rotated(Vector3(0, 1, 0), PI / 2)
79 elif rotate == 270:
80 var diff_x = body.translation.x - painting.translation.x
81 var diff_y = body.translation.y - painting.translation.y
82 var diff_z = body.translation.z - painting.translation.z
83 body.translation.x = target_painting.translation.x - diff_z
84 body.translation.y = target_painting.translation.y + diff_y
85 body.translation.z = target_painting.translation.z + diff_x
86 body.rotate_y(3 * PI / 2)
87 body.velocity = body.velocity.rotated(Vector3(0, 1, 0), 3 * PI / 2)
88
89
90func _dir_to_int(dir):
91 if dir == "north":
92 return 0
93 elif dir == "west":
94 return 1
95 elif dir == "south":
96 return 2
97 elif dir == "east":
98 return 3
99 return 4