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
| #==============================================================================
# ** Meph's Playable Instrument (A.K.A Ocarina Script)
#------------------------------------------------------------------------------
# MephistoX (Meph's Labs)
# Version 1.5
# 27/02/2012
# RPGMaker VXAce
#------------------------------------------------------------------------------
# * Version History :
#
# Version 1 ---------------------------------------------------- (26/02/2012)
# - First Released Version
# Version 1.1 -------------------------------------------------(26/02/2012)
# - Added Common Event Trigger (Thanks Patrick, you're clever)
# Version 1.2 -------------------------------------------------(26/02/2012)
# - Simplified System, removed switch and teleport.
# Version 1.5 -------------------------------------------------(27/02/2012)
# - Added Tetragram Style and Song List, little fix on Tetratram Y.pos
#------------------------------------------------------------------------------
# * Description :
#
# As no need for a big introduction this instrument system allows you to
# create an instrument and play it, like the ocarina system in the Zelda's
# Ocarina of Time or whatever that includes an ocarina.
#
# When you play a correct song, a common event will be activated.
#------------------------------------------------------------------------------
# * Instructions :
#
# Place The Script in the Materiales Section of your Script List
#------------------------------------------------------------------------------
# * Syntax :
#
# Refer to the module to see how to configure every aspect of the system.
# also use:
#
# - $game_party.get_song(song_id) => Learn a song and you can activate it.
#
# This code allow you to learn a song, otherwise even if you play the correct
# notes nothing will happen.
#------------------------------------------------------------------------------
# * Notes :
#
# - Any other Thing, see the demo to see how to configure.
#==============================================================================
#==============================================================================
# ** Game_Instrument
#==============================================================================
module Game_Instrument
#--------------------------------------------------------------------------
# * KeyNotes : The Input button and the assigned note
# - Keynotes = {Button => Note, ...} both as symbols
#--------------------------------------------------------------------------
KeyNotes = {:UP => :A, :DOWN => :B, :LEFT => :C, :RIGHT => , :X => :E}
#--------------------------------------------------------------------------
# * Notes : Parameters for the different playable Notes
# Notes = {NoteSymbol => [SE, Icon, index]}
# - Note Symbol => The Note Symbol defined at KeyNotes
# - SE => Special Effect when playing a note
# - Icon => Icon of the note to be shown at Tetragram
# - Index => Index of the Note in the Tetragram (wich line to put it)
#--------------------------------------------------------------------------
Notes = {:A => ['Ocarina-Key-Up', 529, 0],
:B => ['Ocarina-Key-Down', 531, 3],
:C => ['Ocarina-Key-Left', 532, 1],
=> ['Ocarina-Key-Right', 530, 2],
:E => ['Ocarina-Key-A', 528, 3] }
#--------------------------------------------------------------------------
# * Songs : The Playable Songs and their configuration
# Songs = {id => {:name => '', :notes => [], :common_event => id}
# - id => ID of the Song (don't repeat)
# - name => Name of The song
# - icon => Icon of the song (for Songlist)
# - notes => List of Notes that create the Song
# - common_event => Activate a common event
#--------------------------------------------------------------------------
Songs = {}
Songs[:saraissong] = {:name => 'Sairias Song',
:icon => 344,
:notes => [:B, , :C, :B, , :C],
:common_event => 5}
Songs[:zeldaslullaby] = {:name => 'Zeldas Lullaby',
:icon => 344,
:notes => [:C, :A, , :C, :A, ],
:common_event => 6}
Songs[:sunssong] = {:name => 'Suns Song',
:icon => 248,
:notes => [, :B, :A, , :B, :A],
:common_event => 7}
Songs[:songofstorms] = {:name => 'Song of Storms',
:icon => 328,
:notes => [:E, :B, :A, :E, :B, :A],
:common_event => 8}
Songs[:songoftime] = {:name => 'Song of Time',
:icon => 328,
:notes => [, :E, :B, , :E, :B],
:common_event => 9}
Songs[:eponassong] = {:name => 'Eponas Song',
:icon => 328,
:notes => [:A, :C, , :A, :C, ],
:common_event => 10}
Songs[:minuetofforest] = {:name => 'Minuet of Forest',
:icon => 344,
:notes => [:E, :A, :C, , :C, ],
:common_event => 11}
Songs[:bolerooffire] = {:name => 'Bolero of Fire',
:icon => 344,
:notes => [:B, :E, :B, :E, , :B, , :B],
:common_event => 12}
Songs[:serenadeofwater] = {:name => 'Serenade of Water',
:icon => 248,
:notes => [:E, :B, , , :C],
:common_event => 13}
Songs[:nocturneofshadow] = {:name => 'Nocturne of Shadow',
:icon => 328,
:notes => [:C, , , :E, :C, , :B],
:common_event => 14}
Songs[:requiemofspirit] = {:name => 'Requiem of Spirit',
:icon => 328,
:notes => [:E, :B, :E, , :B, :E],
:common_event => 15}
Songs[:songofhealing] = {:name => 'Song of Healing',
:icon => 328,
:notes => [:C, , :B, :C, , :B],
:common_event => 16}
#--------------------------------------------------------------------------
# * MaxNotes : The Number of Max Notes in the Tetragram
# - Consider 10 as the Maximum, according to the width of the tetragram
#--------------------------------------------------------------------------
MaxNotes = 8
#--------------------------------------------------------------------------
# * WaitNote : The frames to wait before play another note
#--------------------------------------------------------------------------
WaitNote = 15
#--------------------------------------------------------------------------
# * Success SE : SE that will play when play a correct song
#--------------------------------------------------------------------------
SuccessSE = 'Ocarina-SongisCorrect'
#--------------------------------------------------------------------------
# * WindowStyle : Style of the Tetragram
# 0 => Classic Style | 1 => Window Style
#--------------------------------------------------------------------------
WindowStyle = 0
end
#==============================================================================
# ** Game_Party
#==============================================================================
class Game_Party
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :songs
#--------------------------------------------------------------------------
# * Alias Listing
#--------------------------------------------------------------------------
alias_method :meph_gplayinstrum_gparty_inaltems, :init_all_items
#--------------------------------------------------------------------------
# * Initialize all Items
#--------------------------------------------------------------------------
def init_all_items
# The Usual
meph_gplayinstrum_gparty_inaltems
# Song List
@songs = []
end
#--------------------------------------------------------------------------
# * Get Song : Get a Song
#--------------------------------------------------------------------------
def get_song(song_id)
# Return if Song Doesn't Exist
return unless Game_Instrument::Songs.keys.include?(song_id)
# Return if song already known
return if @songs.include?(song_id)
# Push Song into the list
@songs << song_id
end
#--------------------------------------------------------------------------
# * has_song? : Check if Party has song
#--------------------------------------------------------------------------
def has_song?(song_id)
@songs.include?(song_id)
end
end
#==============================================================================
# ** Window_Tetragram
#==============================================================================
class Window_Tetragram < Window_Base
#--------------------------------------------------------------------------
# * Window Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 400, 100)
# Create Note List
@notes = []
# Refresh
refresh
end
#--------------------------------------------------------------------------
# * Set Standard Padding
#--------------------------------------------------------------------------
def standard_padding
0 # 0 to match in case of dim background
end
#--------------------------------------------------------------------------
# * Create Window BackGround
#--------------------------------------------------------------------------
def create_back_bitmap
color = Color.new(0, 0, 0)
color.alpha = 160
contents.fill_rect(0, 0, width + 10, height + 10, color)
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
contents.clear
# If WindowStyle is 0
if Game_Instrument::WindowStyle == 0
# Draw BackGround
create_back_bitmap
# Set Opacity
self.opacity = 0
end
# Draw Tetragram
4.times do |i|
contents.fill_rect(12, 20 + (i * 20), 376, 2, text_color(10))
end
# Draw Musical Key (Occidental Key of Sol)
keybitmap = Cache.system('MusicKey')
contents.blt(25, 8, keybitmap, keybitmap.rect)
# Draw Played Notes
draw_played_notes
end
#--------------------------------------------------------------------------
# * Draw Played Notes : Draw the Played Notes in the Tetragram
#--------------------------------------------------------------------------
def draw_played_notes
# Pass Through each note by index
@notes.each_index do |i|
# Draw Icon at position in the Tetragram
draw_icon(@notes[i][0], (i * 26) + 80, (@notes[i][1] * 20) + 9)
end
end
#--------------------------------------------------------------------------
# * Add Note : Add Note to Note List
#--------------------------------------------------------------------------
def add_note(note)
# Add Note to Note List
@notes << note
# Refresh
refresh
end
#--------------------------------------------------------------------------
# * Add Note : Add Note to Note List
#--------------------------------------------------------------------------
def clear_notes
# Clear Note List
@notes.clear
# Refresh
refresh
end
end
#==============================================================================
# ** Scene_Instruments
#==============================================================================
class Scene_Instrument < Scene_MenuBase
#--------------------------------------------------------------------------
# * Mixin Game_Instrument
#--------------------------------------------------------------------------
include Game_Instrument
#--------------------------------------------------------------------------
# * Start
#--------------------------------------------------------------------------
def start
# Create Played Notes Handler
@played_notes = []
# Created Played song handler
@played_song = nil
# Set BGM to last
BattleManager.save_bgm_and_bgs
# FadeOut Music
fadeout_all(0)
# SuperClass Method
super
# Create Tetragram
create_tetragram
end
#--------------------------------------------------------------------------
# * Create BackGround
#--------------------------------------------------------------------------
def create_background
@background_sprite = Sprite.new
@background_sprite.bitmap = SceneManager.background_bitmap
end
#--------------------------------------------------------------------------
# * Create Tetragram : Create the Tetragram
#--------------------------------------------------------------------------
def create_tetragram
@tetragram = Window_Tetragram.new
# Center at X
@tetragram.x = (Graphics.width - @tetragram.width) / 2
# Position at Bottom
@tetragram.y = (Graphics.height - @tetragram.height) - 20
end
#--------------------------------------------------------------------------
# * Main Update
#--------------------------------------------------------------------------
def update
super
# Check Played Note
check_played_note
# Update Classic Input
update_classic_input
end
#--------------------------------------------------------------------------
# * Update Classic Input
#--------------------------------------------------------------------------
def update_classic_input
if Input.trigger?(:
# Play Cancel Se
Sound.play_cancel
# Replay BGMs
BattleManager.replay_bgm_and_bgs
# Return to Scene
SceneManager.return
end
# Clear notes if input C
if Input.trigger?(:C) && @played_notes.size > 0
# Play Clear SE
Audio.se_play('Audio/SE/Cancel1', 80)
# Clear Notes
return clear_notes
end
end
#--------------------------------------------------------------------------
# * Check Played Note : Check if a Note was Played (by input)
#--------------------------------------------------------------------------
def check_played_note
# Pass Through each Keynote Input Key
KeyNotes.keys.each do |knote|
# If Inputted trigger is a Note
if Input.trigger?(knote)
# Go to Play Note
return play_note(knote)
end
end
end
#--------------------------------------------------------------------------
# * Play Note : Play a note
#--------------------------------------------------------------------------
def play_note(note)
# Clear Notes if Currently played notes is more than MaxNotes
if @played_notes.size > MaxNotes
# Play Buzzer
Sound.play_buzzer
# Clear Notes
return clear_notes
end
# Get Parameters
pars = Notes[KeyNotes[note]]
# Play Note SE
Audio.se_play('Audio/SE/' + pars[0], 80)
# Add Note to the Tetragram
@tetragram.add_note([pars[1], pars[2]])
# Add Played note to Played Notes List
@played_notes << KeyNotes[note]
# Wait for Next Note
Graphics.wait(WaitNote)
# Check if notes form a song
check_song unless @played_notes.size < 4
end
#--------------------------------------------------------------------------
# * Check Song : Check if Notes Form a Defined Song
#--------------------------------------------------------------------------
def check_song
# Pass Through Each Song
Songs.each do |song|
# If Song Notes match with played notes
if song[1][:notes] == @played_notes && $game_party.has_song?(song[0])
# Set played Song as song id
@played_song = song[0]
# Go to Play Song
return success_song
end
end
end
#--------------------------------------------------------------------------
# * Terminate Playing
#--------------------------------------------------------------------------
def success_song
# Play Success SE
Audio.se_play('Audio/SE/' + SuccessSE, 80)
# Wait
Graphics.wait(50)
# Return to Scene
SceneManager.return
# Replay BGMs
BattleManager.replay_bgm_and_bgs
# Do Common Event
$game_temp.reserve_common_event(Songs[@played_song][:common_event])
end
#--------------------------------------------------------------------------
# * Clear Notes : Clear Played Notes
#--------------------------------------------------------------------------
def clear_notes
# Clear Tetragram (Window) Notes
@tetragram.clear_notes
# Clear Main Variable (Played Notes for Scene)
@played_notes.clear
end
end |