-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathulse_plus.rb
452 lines (452 loc) · 18.5 KB
/
ulse_plus.rb
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
=begin
[General]
Author: Dax Soft
Version: 6.0
Site: www.dax-soft.weebly.com
Requirement: Ligni Core
@tiagoms : Feedback that helped improve more on the project
[Description]
System of the sensor event. Useful to stealth games and whatever.
[How to Use]
Check out in:
Web: http://tutorial-dax.weebly.com/ulse.html
[Version]
@1.0
- Sensor by area
- Check if is below/top/left/right/above of the event
- Verification in the form of cross
- Just on vision of event
@2.5
- Check if is behind of event. Just from behind
- Check if is on left of event. Just on left
- Check if is on right of event. Just on right
@3.0
- Check if is on top-left/lower-left/top-right/lower-right on diagonal
- Check if is in all sides on diagonal
- Verification in the form of the circle
- Check diagonally according to the vision of the event
@3.5
- Verification in the form of rectangle on vision of event
@4.0
- Update to new version of the Core
@5.1
- Option to set which switch will be activated
@5.2
- Removed the UlseSound
@6.0
- Code improved
- Sensor works between events
=end
Ligni.register(:ulse, "dax", 6.0) {
# -- class:Game_Interpreter
class Game_Interpreter
# performace:
# perfect: 1-5
# best: 5-15
# medium: 15-35
# bad: 35-60
ULSE_UPDATE = 5
# get the coord of player and event
def getCoordPE(id=nil) # id event
event = get_character(id)
yield(event.x, event.y, $game_player.x, $game_player.y)
end
# get the coord of two event
def getCoordEE(id, id2=nil)
event = get_character(id)
event2 = get_character(id2)
yield(event2.x, event2.y, event.x, event.y)
end
# by area?
def uArea?(tile=1, eid=0, sid=nil)
eid = 0 if eid.nil?
if eid.is_a?(Array)
distance = Ligni::Mathf.euclidean_distance_2d( get_character(eid[0]), get_character(eid[1]) )
else
distance = Ligni::Mathf.euclidean_distance_2d($game_player, get_character(eid))
end
$game_switches[sid] = (distance <= tile) unless sid.nil?
return (distance <= tile) if (Graphics.frame_count %= ULSE_UPDATE)
end
# front?
def uFront?(tile=1, eid=0, sid=nil)
eid = 0 if eid.nil?
if eid.is_a?(Array)
getCoordEE(*eid) { |e2x, e2y, ex, ey|
return unless e2x == ex
(e2y..(e2y + tile)).each { |y|
break unless $game_map.passable?(e2x, y, 2)
$game_switches[sid] = true if ey == y and !sid.nil?
return true if ey == y
}
} if (Graphics.frame_count %= ULSE_UPDATE)
else
getCoordPE(eid) { |ex, ey, px, py|
return unless px == ex
(ey..(ey + tile)).each { |y|
break unless $game_map.passable?(ex, y, 2)
$game_switches[sid] = true if py == y and !sid.nil?
return true if py == y
}
} if (Graphics.frame_count %= ULSE_UPDATE)
end
$game_switches[sid] = false unless sid.nil?
return false
end
# uAgo?
def uAgo?(tile=1, eid=0, sid=nil)
eid = 0 if eid.nil?
if eid.is_a?(Array)
getCoordEE(*eid) { |e2x, e2y, ex, ey|
return unless e2x == ex
ey.downto(ey - tile).each { |y|
break unless $game_map.passable?(ex, y, 8)
$game_switches[sid] = true if e2y == y and !sid.nil?
return true if e2y == y
}
} if (Graphics.frame_count %= ULSE_UPDATE)
else
getCoordPE(eid) { |ex, ey, px, py|
return unless px == ex
ey.downto(ey - tile).each { |y|
break unless $game_map.passable?(ex, y, 8)
$game_switches[sid] = true if py == y and !sid.nil?
return true if py == y
}
} if (Graphics.frame_count %= ULSE_UPDATE)
end
$game_switches[sid] = false unless sid.nil?
return false
end
# uAbout?
def uAbout?(eid=0, sid=nil)
eid = 0 if eid.nil?
if eid.is_a?(Array)
getCoordEE(*eid) { |e2x, e2y, ex, ey|
if e2x == ex && e2y == ey
$game_switches[sid] = true unless sid.nil?
return true
end
} if (Graphics.frame_count %= ULSE_UPDATE)
else
getCoordPE(eid) { |ex, ey, px, py|
if px == ex && py == ey
$game_switches[sid] = true unless sid.nil?
return true
end
} if (Graphics.frame_count %= ULSE_UPDATE)
end
$game_switches[sid] = false unless sid.nil?
return false
end
# uRight?
def uRight?(tile=1, eid=0, sid=nil)
eid = 0 if eid.nil?
if eid.is_a?(Array)
getCoordEE(*eid) { |e2x, e2y, ex, ey|
return unless e2y == ey
(ex..(ex + tile)).each { |x|
break unless $game_map.passable?(x, ey, 6)
$game_switches[sid] = true if !sid.nil? and e2x == x
return true if e2x == x
}
} if (Graphics.frame_count %= ULSE_UPDATE)
else
getCoordPE(eid) { |ex, ey, px, py|
return unless py == ey
(ex..(ex + tile)).each { |x|
break unless $game_map.passable?(x, ey, 6)
$game_switches[sid] = true if !sid.nil? and px == x
return true if px == x
}
} if (Graphics.frame_count %= ULSE_UPDATE)
end
$game_switches[sid] = false unless sid.nil?
return false
end
# uLeft?
def uLeft?(tile=1, eid=0, sid=nil)
eid = 0 if eid.nil?
if eid.is_a?(Array)
getCoordEE(*eid) { |e2x, e2y, ex, ey|
return unless e2y == ey
ex.downto(ex - tile).each { |x|
break unless $game_map.passable?(x, ey, 4)
$game_switches[sid] = true if !sid.nil? and e2x == x
return true if e2x == x
}
} if (Graphics.frame_count %= ULSE_UPDATE)
else
getCoordPE(eid) { |ex, ey, px, py|
return unless py == ey
ex.downto(ex - tile).each { |x|
break unless $game_map.passable?(x, ey, 4)
$game_switches[sid] = true if !sid.nil? and px == x
return true if px == x
}
} if (Graphics.frame_count %= ULSE_UPDATE)
end
$game_switches[sid] = false unless sid.nil?
return false
end
# uCross?
def uCross?(tile, eid, sid=nil)
uFront?(tile, eid, sid) || uAgo?(tile, eid, sid) || uLeft?(tile, eid, sid) || uRight?(tile, eid, sid)
end
# uVision?
def uVision?(tile=1, eid=0, sid=nil)
case get_character(eid.is_a?(Array) ? eid.last : eid).direction
when 2 then uFront?(tile, eid, sid)
when 4 then uLeft?(tile, eid, sid)
when 6 then uRight?(tile, eid, sid)
when 8 then uAgo?(tile, eid, sid)
end
end
# uBehind?
def uBehind?(tile=1, eid=0, sid=nil)
case get_character(eid.is_a?(Array) ? eid.last : eid).direction
when 8 then uFront?(tile, eid, sid)
when 6 then uLeft?(tile, eid, sid)
when 4 then uRight?(tile, eid, sid)
when 2 then uAgo?(tile, eid, sid)
end
end
# vLeft?
def vLeft?(tile=1, eid=0, sid=nil)
case get_character(eid.is_a?(Array) ? eid.last : eid).direction
when 4 then uFront?(tile, eid, sid)
when 8 then uLeft?(tile, eid, sid)
when 2 then uRight?(tile, eid, sid)
when 6 then uAgo?(tile, eid, sid)
end
end
# vRight?
def vRight?(tile=1, eid=0, sid=nil)
case get_character(eid.is_a?(Array) ? eid.last : eid).direction
when 4 then uFront?(tile, eid, sid)
when 2 then uLeft?(tile, eid, sid)
when 8 then uRight?(tile, eid, sid)
when 6 then uAgo?(tile, eid, sid)
end
end
# dLeft?
def dLeft?(tile=1, eid=0, sid=nil)
eid = 0 if eid.nil?
if eid.is_a?(Array)
getCoordEE(*eid) { |e2x, e2y, ex, ey|
0.upto(tile) { |i|
if e2x == (ex - i) and e2y == (ey - i)
$game_switches[sid] = true unless sid.nil?
return true
end
}
} if (Graphics.frame_count %= ULSE_UPDATE)
else
getCoordPE(eid) { |ex, ey, px, py|
0.upto(tile) { |i|
if px == (ex - i) and py == (ey - i)
$game_switches[sid] = true unless sid.nil?
return true
end
}
} if (Graphics.frame_count %= ULSE_UPDATE)
end
$game_switches[sid] = false unless sid.nil?
return false
end
# dRight?
def dRight?(tile=1, eid=0, sid=nil)
eid = 0 if eid.nil?
if eid.is_a?(Array)
getCoordEE(*eid) { |e2x, e2y, ex, ey|
0.upto(tile) { |i|
if e2x == (ex + i) and e2y == (ey - i)
$game_switches[sid] = true unless sid.nil?
return true
end
}
} if (Graphics.frame_count %= ULSE_UPDATE)
else
getCoordPE(eid) { |ex, ey, px, py|
0.upto(tile) { |i|
if px == (ex + i) and py == (ey - i)
$game_switches[sid] = true unless sid.nil?
return true
end
}
} if (Graphics.frame_count %= ULSE_UPDATE)
end
$game_switches[sid] = false unless sid.nil?
return false
end
# diLeft?
def diLeft?(tile=1, eid=0, sid=nil)
eid = 0 if eid.nil?
if eid.is_a?(Array)
getCoordEE(*eid) { |e2x, e2y, ex, ey|
0.upto(tile) { |i|
if e2x == (ex - i) and e2y == (ey + i)
$game_switches[sid] = true unless sid.nil?
return true
end
}
} if (Graphics.frame_count %= ULSE_UPDATE)
else
getCoordPE(eid) { |ex, ey, px, py|
0.upto(tile) { |i|
if px == (ex - i) and py == (ey + i)
$game_switches[sid] = true unless sid.nil?
return true
end
}
} if (Graphics.frame_count %= ULSE_UPDATE)
end
$game_switches[sid] = false unless sid.nil?
return false
end
# diRight?
def diRight?(tile=1, eid=0, sid=nil)
eid = 0 if eid.nil?
if eid.is_a?(Array)
getCoordEE(*eid) { |e2x, e2y, ex, ey|
0.upto(tile) { |i|
if e2x == (ex + i) and e2y == (ey + i)
$game_switches[sid] = true unless sid.nil?
return true
end
}
} if (Graphics.frame_count %= ULSE_UPDATE)
else
getCoordPE(eid) { |ex, ey, px, py|
0.upto(tile) { |i|
if px == (ex + i) and py == (ey + i)
$game_switches[sid] = true unless sid.nil?
return true
end
}
} if (Graphics.frame_count %= ULSE_UPDATE)
end
$game_switches[sid] = false unless sid.nil?
return false
end
# uDiagonal?
def uDiagonal?(tile=1, eid=0, sid=nil)
dLeft?(tile, eid, sid) || dRight?(tile, eid, sid) || diLeft?(tile, eid, sid) || diRight?(tile, eid, sid)
end
# vDiagonal?
def vDiagonal?(tile=1, eid=0, sid=nil)
case get_character(eid.is_a?(Array) ? eid.last : eid).direction
when 2 then diLeft?(tile, eid, sid) || diRight?(tile, eid, sid)
when 4 then dLeft?(tile, eid, sid) || diLeft?(tile, eid, sid)
when 6 then dRight?(tile, eid, sid) || diRight?(tile, eid, sid)
when 8 then dLeft?(tile, eid, sid) || dRight?(tile, eid, sid)
end
end
# uCircle?
def uCircle?(tile=2, eid=0, sid=nil)
tile = tile < 2 ? 2 : tile
uDiagonal?(tile-1, eid, sid) || uCross?(tile, eid, sid)
end
# uCubic?
def uCubic?(tile=3, eid=0, sid=nil)
eid = 0 if eid.nil?
if eid.is_a?(Array)
case get_character(eid.last).direction
when 2
getCoordEE(*eid) { |ex, ey, px, py|
(ex - (tile - 2)).upto(ex + (tile - 2)).each { |x|
(ey).upto(ey + tile).each { |y|
if e2x == x and e2y == y
$game_switches[sid] = true unless sid.nil?
return true
end
}
}
} if (Graphics.frame_count %= ULSE_UPDATE)
when 4
getCoordEE(*eid) { |ex, ey, px, py|
tile.next.times { |i|
( ey - (tile - 2) ).upto(ey + (tile - 2)).each { |y|
if e2x == ex - i and e2y == y
$game_switches[sid] = true unless sid.nil?
return true
end
}
}
} if (Graphics.frame_count %= ULSE_UPDATE)
when 6
getCoordEE(*eid) { |ex, ey, px, py|
tile.next.times { |i|
( ey - (tile - 2) ).upto(ey + (tile - 2)).each { |y|
if e2x == ex + i and e2y == y
$game_switches[sid] = true unless sid.nil?
return true
end
}
}
} if (Graphics.frame_count %= ULSE_UPDATE)
when 8
getCoordEE(*eid) { |ex, ey, px, py|
(ex - (tile - 2)).upto(ex + (tile - 2)).each { |x|
(ey).downto(ey-tile).each { |y|
if e2x == x and e2y == y
$game_switches[sid] = true unless sid.nil?
return true
end
}
}
} if (Graphics.frame_count %= ULSE_UPDATE)
end
else
case get_character(eid).direction
when 2
getCoordPE(eid) { |ex, ey, px, py|
(ex - (tile - 2)).upto(ex + (tile - 2)).each { |x|
(ey).upto(ey + tile).each { |y|
if px == x and py == y
$game_switches[sid] = true unless sid.nil?
return true
end
}
}
} if (Graphics.frame_count %= ULSE_UPDATE)
when 4
getCoordPE(eid) { |ex, ey, px, py|
tile.next.times { |i|
( ey - (tile - 2) ).upto(ey + (tile - 2)).each { |y|
if px == ex - i and py == y
$game_switches[sid] = true unless sid.nil?
return true
end
}
}
} if (Graphics.frame_count %= ULSE_UPDATE)
when 6
getCoordPE(eid) { |ex, ey, px, py|
tile.next.times { |i|
( ey - (tile - 2) ).upto(ey + (tile - 2)).each { |y|
if px == ex + i and py == y
$game_switches[sid] = true unless sid.nil?
return true
end
}
}
} if (Graphics.frame_count %= ULSE_UPDATE)
when 8
getCoordPE(eid) { |ex, ey, px, py|
(ex - (tile - 2)).upto(ex + (tile - 2)).each { |x|
(ey).downto(ey-tile).each { |y|
if px == x and py == y
$game_switches[sid] = true unless sid.nil?
return true
end
}
}
} if (Graphics.frame_count %= ULSE_UPDATE)
end
end
$game_switches[sid] = false unless sid.nil?
return false
end
end # end
} #px = e2x