#==============================================================================# ** 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,

OWN => :B, :LEFT => :C, :RIGHT => , :C => :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 = 10 #-------------------------------------------------------------------------- # * WaitNote : The frames to wait before play another note #-------------------------------------------------------------------------- WaitNote = 5 #-------------------------------------------------------------------------- # * 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 = 0end#==============================================================================# ** 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) endend#==============================================================================# ** 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 + 0, 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(1)) end # 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
[0], (i * 26) + 10, (@notes[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 endend#==============================================================================# ** 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?
&& @played_notes.size > 0 # Play Clear SE Audio.se_play('Audio/SE/cancel', 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 endend