-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.tscn
220 lines (189 loc) · 15.2 KB
/
main.tscn
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
[gd_scene load_steps=5 format=1]
[ext_resource path="res://terrain-tileset.tres" type="TileSet" id=1]
[ext_resource path="res://entity.tscn" type="PackedScene" id=2]
[ext_resource path="res://blur.tscn" type="PackedScene" id=3]
[sub_resource type="GDScript" id=1]
script/source = "
var player
var player_bag
var terrain
var entities
var anim
const SHIFT_X = 10
const SHIFT_Y = 13
const GROUP_LETTER = \"letter\"
const GROUP_SNAKES = \"snakes\"
var letter = preload(\"res://letter.tscn\")
var snake = preload(\"res://snake.tscn\")
const LETTERS = [
'a','b','c','d','e','f','g','h','i',
'j','k','l','m','n','o','p','q','r',
's','t','u','w','v','x','y','z']
const CANT_MOVE = [-1,0,1,2]
func _ready():
self.terrain = get_node(\"terrain\")
self.entities = get_node(\"entities\")
self.player = self.entities.get_node(\"player\")
self.player_bag = self.player.get_node(\"g\")
self.anim = self.player.get_node(\"anim\")
self.anim.connect(\"finished\", self, \"move_post_anim\")
spawn_letters(self.player_bag)
spawn_enemies()
self.player.raise()
set_process_input(true)
func spawn_enemies():
var cords = [[1,-1], [-1,-7], [6, -2]]
for cord in cords:
var new_snake = self.snake.instance()
new_snake.set_position(cord[0], cord[1])
new_snake.add_to_group(self.GROUP_SNAKES)
self.entities.add_child(new_snake)
func spawn_letters(player):
player.add_child(get_letter(Vector2(-2*SHIFT_X,0), 'a'))
player.add_child(get_letter(Vector2(2*SHIFT_X,0), 'd'))
player.add_child(get_letter(Vector2(-SHIFT_X,-SHIFT_Y), 'q'))
player.add_child(get_letter(Vector2(SHIFT_X,-SHIFT_Y),'e'))
player.add_child(get_letter(Vector2(-SHIFT_X,SHIFT_Y),'z'))
player.add_child(get_letter(Vector2(SHIFT_X,SHIFT_Y),'c'))
randomize_letters(player)
check_letters(self.player, self.terrain)
func get_letter(pos, direction):
var new_letter = self.letter.instance()
new_letter.direction = direction
new_letter.set_pos(pos)
new_letter.add_to_group(self.GROUP_LETTER)
return new_letter
func randomize_letters(player):
var nodes = get_tree().get_nodes_in_group(self.GROUP_LETTER)
var dictionary = self.LETTERS
for node in nodes:
dictionary = node.new_letter(dictionary)
func get_move(x, y, terrain, skip_shift_check = false):
if not skip_shift_check and (y % 2 == 0): x+=1
var block = terrain.get_cell(x, y) in self.CANT_MOVE
if not block:
var nodes = get_tree().get_nodes_in_group(self.GROUP_SNAKES)
for node in nodes:
if Vector2(node.x, node.y) == Vector2(x, y): return true
return block
func check_letters(player, t):
var x = player.x
var y = player.y
var nodes = get_tree().get_nodes_in_group(self.GROUP_LETTER)
for node in nodes:
node.show()
if node.direction == 'a' and get_move(x-1, y, t, true): node.hide()
if node.direction == 'd' and get_move(x+1, y, t, true): node.hide()
if node.direction == 'q' and get_move(x-1, y-1, t): node.hide()
if node.direction == 'e' and get_move(x, y-1, t): node.hide()
if node.direction == 'z' and get_move(x-1, y+1, t): node.hide()
if node.direction == 'c' and get_move(x, y+1, t): node.hide()
func get_visible_letters():
var letters = []
for node in get_tree().get_nodes_in_group(self.GROUP_LETTER):
if node.is_visible():
letters.append(node.letter)
return letters
func get_letter_direction(letter):
for node in get_tree().get_nodes_in_group(self.GROUP_LETTER):
if node.is_visible() and node.letter == letter:
return node.direction
func move_player(x, y, xx, yy):
if not(self.player.y % 2 == 0) and not(y == 0): x+=1
self.player.x += x
self.player.y += y
self.player.set_position()
randomize_letters(self.player)
check_letters(self.player, self.terrain)
func _input(event):
var now = self.anim.get_current_animation()
if(Input.is_key_pressed(KEY_ESCAPE)):
get_tree().quit()
if event.type == InputEvent.KEY and event.is_pressed():
var hit = OS.get_scancode_string(event.unicode)
if now == \"idle\" and hit in get_visible_letters():
self.anim.play(\"move_\" + get_letter_direction(hit))
func move_post_anim():
var move = self.anim.get_current_animation()
if move == \"move_a\":
move_player(-1, 0, -2*SHIFT_X, 0)
elif move == \"move_d\":
move_player(1, 0, 2*SHIFT_X, 0)
elif move == \"move_q\":
move_player(-1, -1, -SHIFT_X, -SHIFT_Y)
elif move == \"move_e\":
move_player(0, -1, SHIFT_X, -SHIFT_Y)
elif move == \"move_z\":
move_player(-1, 1, -SHIFT_X, SHIFT_Y)
elif move == \"move_c\":
move_player(0, 1, SHIFT_X, SHIFT_Y)
self.anim.play(\"idle\")"
[node name="main" type="Control"]
anchor/right = 1
anchor/bottom = 1
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
margin/left = 0.0
margin/top = 0.0
margin/right = 800.0
margin/bottom = 600.0
script/script = SubResource( 1 )
__meta__ = {
"_edit_lock_": true
}
[node name="terrain" type="TileMap" parent="."]
mode = 2
tile_set = ExtResource( 1 )
cell/size = Vector2( 20, 22 )
cell/quadrant_size = 16
cell/custom_transform = Matrix32( 20, 0, 0, 13, 0, 0 )
cell/half_offset = 0
cell/tile_origin = 1
cell/y_sort = true
collision/use_kinematic = false
collision/friction = 1.0
collision/bounce = 0.0
collision/layers = 1
collision/mask = 1
occluder/light_mask = 1
tile_data = IntArray( -1179649, 0, -1245184, 0, -1245183, 0, -1245182, 0, -1114116, 0, -1114115, 0, -1114114, 0, -1114113, 0, -1179648, 0, -1179647, 0, -1179646, 0, -1179645, 0, -1179644, 0, -1048581, 0, -1048580, 0, -1048579, 0, -1048578, 0, -1048577, 0, -1114112, 0, -1114111, 0, -1114110, 0, -1114109, 0, -1114108, 0, -1114107, 0, -1114106, 0, -983045, 0, -983044, 1, -983043, 1, -983042, 1, -983041, 1, -1048576, 1, -1048575, 1, -1048574, 1, -1048573, 1, -1048572, 0, -1048571, 0, -1048570, 0, -1048569, 0, -917510, 0, -917509, 0, -917508, 1, -917507, 1, -917506, 4, -917505, 4, -983040, 4, -983039, 4, -983038, 1, -983037, 1, -983036, 1, -983035, 0, -983034, 0, -983033, 0, -851973, 0, -851972, 1, -851971, 4, -851970, 4, -851969, 3, -917504, 3, -917503, 3, -917502, 4, -917501, 4, -917500, 1, -917499, 1, -917498, 0, -917497, 0, -786438, 0, -786437, 0, -786436, 1, -786435, 4, -786434, 3, -786433, 5, -851968, 5, -851967, 3, -851966, 4, -851965, 4, -851964, 1, -851963, 1, -851962, 0, -851961, 0, -720903, 0, -720902, 0, -720901, 0, -720900, 0, -720899, 4, -720898, 3, -720897, 6, -786432, 5, -786431, 5, -786430, 3, -786429, 3, -786428, 4, -786427, 1, -786426, 1, -786425, 0, -786424, 0, -786423, 0, -786422, 0, -655368, 0, -655367, 0, -655366, 0, -655365, 1, -655364, 4, -655363, 4, -655362, 7, -655361, 5, -720896, 7, -720895, 7, -720894, 3, -720893, 3, -720892, 4, -720891, 1, -720890, 1, -720889, 0, -720888, 0, -720887, 0, -720886, 0, -720885, 0, -720884, 0, -589831, 0, -589830, 0, -589829, 1, -589828, 4, -589827, 4, -589826, 5, -589825, 5, -655360, 22, -655359, 6, -655358, 5, -655357, 7, -655356, 4, -655355, 4, -655354, 1, -655353, 0, -655352, 0, -655351, 0, -655350, 0, -655349, 0, -655348, 0, -655347, 0, -524296, 0, -524295, 0, -524294, 1, -524293, 1, -524292, 4, -524291, 4, -524290, 3, -524289, 6, -589824, 10, -589823, 5, -589822, 5, -589821, 3, -589820, 4, -589819, 1, -589818, 1, -589817, 0, -589816, 0, -589815, 0, -589814, 0, -589813, 0, -589812, 0, -589811, 0, -458759, 0, -458758, 0, -458757, 1, -458756, 1, -458755, 4, -458754, 4, -458753, 7, -524288, 6, -524287, 10, -524286, 7, -524285, 3, -524284, 4, -524283, 1, -524282, 1, -524281, 1, -524280, 0, -524279, 0, -524278, 0, -524277, 0, -524276, 0, -524275, 0, -524274, 0, -393223, 0, -393222, 1, -393221, 1, -393220, 4, -393219, 1, -393218, 5, -393217, 6, -458752, 7, -458751, 17, -458750, 5, -458749, 4, -458748, 1, -458747, 1, -458746, 1, -458745, 1, -458744, 1, -458743, 1, -458742, 1, -458741, 1, -458740, 1, -458739, 0, -458738, 0, -327689, 0, -327688, 0, -327687, 0, -327686, 1, -327685, 1, -327684, 1, -327683, 1, -327682, 4, -327681, 2, -393216, 6, -393215, 15, -393214, 6, -393213, 7, -393212, 1, -393211, 1, -393210, 1, -393209, 1, -393208, 1, -393207, 4, -393206, 4, -393205, 1, -393204, 1, -393203, 1, -393202, 0, -393201, 0, -262155, 0, -262154, 0, -262153, 0, -262152, 0, -262151, 1, -262150, 4, -262149, 1, -262148, 1, -262147, 4, -262146, 2, -262145, 2, -327680, 15, -327679, 2, -327678, 6, -327677, 1, -327676, 1, -327675, 1, -327674, 1, -327673, 1, -327672, 4, -327671, 5, -327670, 4, -327669, 4, -327668, 1, -327667, 1, -327666, 0, -327665, 0, -327664, 0, -196619, 0, -196618, 0, -196617, 0, -196616, 1, -196615, 1, -196614, 4, -196613, 4, -196612, 4, -196611, 4, -196610, 2, -196609, 2, -262144, 15, -262143, 2, -262142, 6, -262141, 4, -262140, 1, -262139, 1, -262138, 1, -262137, 4, -262136, 4, -262135, 5, -262134, 5, -262133, 5, -262132, 4, -262131, 4, -262130, 1, -262129, 0, -262128, 0, -262127, 0, -131084, 0, -131083, 0, -131082, 1, -131081, 1, -131080, 1, -131079, 4, -131078, 4, -131077, 13, -131076, 18, -131075, 5, -131074, 2, -131073, 12, -196608, 2, -196607, 2, -196606, 5, -196605, 4, -196604, 4, -196603, 4, -196602, 4, -196601, 5, -196600, 5, -196599, 2, -196598, 7, -196597, 5, -196596, 4, -196595, 4, -196594, 1, -196593, 0, -196592, 0, -196591, 0, -65547, 0, -65546, 0, -65545, 1, -65544, 4, -65543, 4, -65542, 4, -65541, 15, -65540, 5, -65539, 10, -65538, 2, -65537, 2, -131072, 16, -131071, 8, -131070, 8, -131069, 8, -131068, 18, -131067, 3, -131066, 5, -131065, 5, -131064, 7, -131063, 2, -131062, 2, -131061, 2, -131060, 5, -131059, 4, -131058, 4, -131057, 1, -131056, 0, -131055, 0, -13, 0, -12, 0, -11, 0, -10, 1, -9, 1, -8, 4, -7, 4, -6, 15, -5, 5, -4, 5, -3, 14, -2, 8, -1, 24, -65536, 3, -65535, 5, -65534, 4, -65533, 3, -65532, 14, -65531, 18, -65530, 5, -65529, 7, -65528, 6, -65527, 6, -65526, 2, -65525, 2, -65524, 5, -65523, 5, -65522, 1, -65521, 1, -65520, 0, -65519, 0, 65523, 0, 65524, 0, 65525, 0, 65526, 0, 65527, 1, 65528, 4, 65529, 4, 65530, 12, 65531, 7, 65532, 5, 65533, 4, 65534, 4, 65535, 3, 0, 20, 1, 4, 2, 4, 3, 4, 4, 4, 5, 4, 6, 10, 7, 5, 8, 6, 9, 7, 10, 7, 11, 2, 12, 6, 13, 5, 14, 4, 15, 1, 16, 0, 17, 0, 131059, 0, 131060, 0, 131061, 0, 131062, 0, 131063, 1, 131064, 4, 131065, 3, 131066, 17, 131067, 5, 131068, 5, 131069, 1, 131070, 4, 131071, 4, 65536, 1, 65537, 1, 65538, 1, 65539, 4, 65540, 4, 65541, 4, 65542, 14, 65543, 8, 65544, 21, 65545, 7, 65546, 7, 65547, 7, 65548, 5, 65549, 4, 65550, 1, 65551, 1, 65552, 0, 65553, 0, 196596, 0, 196597, 0, 196598, 1, 196599, 1, 196600, 4, 196601, 4, 196602, 15, 196603, 5, 196604, 4, 196605, 1, 196606, 1, 196607, 4, 131072, 4, 131073, 1, 131074, 1, 131075, 1, 131076, 1, 131077, 1, 131078, 4, 131079, 4, 131080, 5, 131081, 7, 131082, 7, 131083, 6, 131084, 5, 131085, 4, 131086, 1, 131087, 0, 131088, 0, 131089, 0, 262132, 0, 262133, 0, 262134, 1, 262135, 1, 262136, 4, 262137, 12, 262138, 5, 262139, 5, 262140, 4, 262141, 1, 262142, 1, 262143, 1, 196608, 1, 196609, 0, 196610, 0, 196611, 0, 196612, 1, 196613, 1, 196614, 4, 196615, 5, 196616, 6, 196617, 6, 196618, 6, 196619, 5, 196620, 4, 196621, 1, 196622, 0, 196623, 0, 196624, 0, 327669, 0, 327670, 0, 327671, 1, 327672, 1, 327673, 4, 327674, 10, 327675, 5, 327676, 4, 327677, 1, 327678, 1, 327679, 0, 262144, 1, 262145, 0, 262146, 0, 262147, 0, 262148, 0, 262149, 1, 262150, 1, 262151, 4, 262152, 5, 262153, 5, 262154, 5, 262155, 5, 262156, 4, 262157, 1, 262158, 0, 262159, 0, 262160, 0, 262161, 0, 393204, 0, 393205, 0, 393206, 0, 393207, 1, 393208, 4, 393209, 3, 393210, 10, 393211, 4, 393212, 1, 393213, 1, 393214, 0, 393215, 0, 327680, 0, 327681, 0, 327682, 0, 327683, 0, 327684, 0, 327685, 1, 327686, 4, 327687, 5, 327688, 4, 327689, 4, 327690, 4, 327691, 4, 327692, 1, 327693, 0, 327694, 0, 327695, 0, 327696, 0, 458740, 0, 458741, 0, 458742, 0, 458743, 1, 458744, 1, 458745, 4, 458746, 3, 458747, 10, 458748, 4, 458749, 4, 458750, 1, 458751, 0, 393216, 0, 393217, 0, 393218, 0, 393219, 0, 393220, 0, 393221, 0, 393222, 1, 393223, 4, 393224, 4, 393225, 1, 393226, 1, 393227, 1, 393228, 1, 393229, 0, 393230, 0, 393231, 0, 393232, 0, 524276, 0, 524277, 0, 524278, 1, 524279, 1, 524280, 1, 524281, 4, 524282, 3, 524283, 10, 524284, 4, 524285, 4, 524286, 1, 524287, 1, 458752, 0, 458753, 0, 458754, 0, 458755, 0, 458756, 0, 458757, 0, 458758, 1, 458759, 4, 458760, 1, 458761, 0, 458762, 0, 458763, 0, 458764, 0, 458765, 0, 458766, 0, 589813, 0, 589814, 0, 589815, 1, 589816, 1, 589817, 1, 589818, 4, 589819, 3, 589820, 17, 589821, 3, 589822, 4, 589823, 4, 524288, 1, 524289, 1, 524290, 0, 524291, 0, 524292, 0, 524293, 0, 524294, 0, 524295, 0, 524296, 1, 524297, 0, 524298, 0, 524299, 0, 524300, 0, 524301, 0, 655348, 0, 655349, 0, 655350, 1, 655351, 1, 655352, 4, 655353, 4, 655354, 4, 655355, 15, 655356, 3, 655357, 3, 655358, 4, 655359, 4, 589824, 4, 589825, 1, 589826, 0, 589827, 0, 589828, 0, 589829, 0, 589830, 0, 589831, 0, 589832, 0, 589833, 0, 589834, 0, 589835, 0, 589836, 0, 720885, 0, 720886, 1, 720887, 1, 720888, 4, 720889, 3, 720890, 3, 720891, 21, 720892, 5, 720893, 5, 720894, 5, 720895, 3, 655360, 4, 655361, 4, 655362, 1, 655363, 0, 655364, 0, 655365, 0, 655366, 0, 655367, 0, 655368, 0, 786420, 0, 786421, 0, 786422, 1, 786423, 4, 786424, 4, 786425, 3, 786426, 5, 786427, 5, 786428, 7, 786429, 5, 786430, 5, 786431, 3, 720896, 4, 720897, 1, 720898, 0, 720899, 0, 720900, 0, 720902, 0, 720903, 0, 851957, 0, 851958, 1, 851959, 1, 851960, 4, 851961, 5, 851962, 6, 851963, 6, 851964, 6, 851965, 5, 851966, 3, 851967, 3, 786432, 4, 786433, 1, 786434, 1, 786435, 0, 917492, 0, 917493, 0, 917494, 1, 917495, 4, 917496, 3, 917497, 5, 917498, 7, 917499, 5, 917500, 5, 917501, 3, 917502, 4, 917503, 4, 851968, 1, 851969, 0, 851970, 0, 851971, 0, 983028, 0, 983029, 0, 983030, 1, 983031, 4, 983032, 4, 983033, 4, 983034, 5, 983035, 5, 983036, 3, 983037, 4, 983038, 4, 983039, 4, 917504, 1, 917505, 1, 917506, 0, 917507, 0, 1048564, 0, 1048565, 0, 1048566, 1, 1048567, 4, 1048568, 4, 1048569, 4, 1048570, 4, 1048571, 4, 1048572, 4, 1048573, 1, 1048574, 1, 1048575, 1, 983040, 0, 983041, 0, 983042, 0, 983043, 0, 1114100, 0, 1114101, 0, 1114102, 1, 1114103, 1, 1114104, 4, 1114105, 4, 1114106, 4, 1114107, 4, 1114108, 1, 1114109, 1, 1114110, 0, 1114111, 0, 1048576, 0, 1048577, 0, 1048578, 0, 1048579, 0, 1179635, 0, 1179636, 0, 1179637, 0, 1179638, 1, 1179639, 1, 1179640, 1, 1179641, 1, 1179642, 1, 1179643, 0, 1179644, 0, 1179645, 0, 1179646, 0, 1179647, 0, 1114112, 0, 1245172, 0, 1245173, 0, 1245174, 0, 1245175, 0, 1245176, 0, 1245177, 0, 1245178, 0, 1245179, 0, 1245180, 0, 1245181, 0, 1245182, 0, 1245183, 0, 1310708, 0, 1310709, 0, 1310710, 0, 1310711, 0, 1310712, 0, 1310713, 0, 1310714, 0, 1310715, 0, 1376247, 0, 1376248, 0, 1376249, 0 )
__meta__ = {
"_edit_lock_": true
}
[node name="entities" type="YSort" parent="."]
z/z = 10
z/relative = false
sort/enabled = true
[node name="player" parent="entities" instance=ExtResource( 2 )]
transform/pos = Vector2( 0, -1 )
[node name="g" parent="entities/player"]
editor/display_folded = true
[node name="camera" type="Camera2D" parent="entities/player"]
transform/pos = Vector2( -200, -150 )
transform/scale = Vector2( 0.5, 0.5 )
z/z = 999
z/relative = false
anchor_mode = 0
rotating = false
current = true
zoom = Vector2( 0.5, 0.5 )
limit/left = -10000000
limit/top = -10000000
limit/right = 10000000
limit/bottom = 10000000
drag_margin/h_enabled = true
drag_margin/v_enabled = true
smoothing/enable = true
smoothing/speed = 2.0
drag_margin/left = 0.2
drag_margin/top = 0.2
drag_margin/right = 0.2
drag_margin/bottom = 0.2
[node name="blur" parent="entities/player/camera" instance=ExtResource( 3 )]
margin/left = -114.0
margin/top = -70.0
margin/right = -622.0
margin/bottom = -466.0
[editable path="entities/player"]