#==============================================================================# ** Instrument#------------------------------------------------------------------------------# This module defines all data associated with playable compositions. Data is# defined within constants as hash expressions / hash arrays.#==============================================================================module Instrument #-------------------------------------------------------------------------- # * Constants (General Settings) #-------------------------------------------------------------------------- MAX = 6 # max key input before clearing score VOLUME = 80 # Volume of note playback PITCH = {:LOW => 50, # Sets low pitch playback :MID => 100, # Sets standard pitch playback :HIG => 150} # Sets high pitch playback NOTESET = 'Noteset' # filename for graphics (system folder) #-------------------------------------------------------------------------- # * Constants (Note Input Processing) #-------------------------------------------------------------------------- # where KEYS is array of available input keys. # where DATA is [filename, index, line number, pitch] #-------------------------------------------------------------------------- KEYS = [

OWN, :LEFT, :RIGHT, :UP, :A, :C] DATA = {

OWN => ['Audio\SE\Cursor2', 0, 3, PITCH[:LOW]], :LEFT => ['Audio\SE\Cursor2', 1, 2, PITCH[:MID]], :RIGHT => ['Audio\SE\Cursor2', 2, 1, PITCH[:MID]], :UP => ['Audio\SE\Cursor2', 3, 0, PITCH[:HIG]], :A => ['Audio\SE\Cursor2', 4, 3, PITCH[:LOW]], # :B => ['Audio\SE\Cursor2', 5, 2, PITCH[:MID]], :C => ['Audio\SE\Cursor2', 6, 1, PITCH[:HIG]], :X => ['Audio\SE\Cursor2', 4, 3, PITCH[:LOW]], :Y => ['Audio\SE\Cursor2', 4, 2, PITCH[:MID]], :Z => ['Audio\SE\Cursor2', 4, 1, PITCH[:HIG]], :L => ['Audio\SE\Cursor2', 4, 0, PITCH[:HIG]], :R => ['Audio\SE\Cursor2', 4, 0, PITCH[:HIG]],} #-------------------------------------------------------------------------- # * Constants (Songs) #-------------------------------------------------------------------------- # where SONGS[symbol] is song symbol # where :name is string value of song # where :score is array of keys comprising song # where :event is common event to be called #-------------------------------------------------------------------------- SONGS = {} SONGS[:songofstorms] = {:name => 'Song of Storms', :score => [:LEFT,

OWN, :UP, :LEFT,

OWN, :UP], :event => 1 } SONGS[:songoftravel] = {:name => 'Song of Travel', :score => [:UP, :LEFT, :RIGHT, :UP, :LEFT, :RIGHT], :event => 2 } SONGS[:songofdeath] = {:name => 'Song of Death', :score => [:LEFT, :RIGHT, :A, :LEFT, :RIGHT, :A], :event => 3 }end#==============================================================================# ** Game_System#------------------------------------------------------------------------------# This class handles system data. It has been modified to save the disable# state of instruments. Instances of this class are referenced by $game_system.#==============================================================================class Game_System #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :instrument_disabled # instrument forbidden #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- alias init_instrument_disabled initialize def initialize init_instrument_disabled @instrument_disabled = false endend#==============================================================================# ** Game_Party#------------------------------------------------------------------------------# This class handles parties. It has been modified to include the party's# acquired songs. Instances of this class are referenced by $game_party.#==============================================================================class Game_Party < Game_Unit #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor = :songs # party's acquired songs #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- alias init_party_songs initialize def initialize init_party_songs @songs = [] end def list_songs p @songs end #-------------------------------------------------------------------------- # * Add Song #-------------------------------------------------------------------------- def add_song(song_id) return unless song_exists?(song_id) return if song_acquired?(song_id) @songs.push song_id end #-------------------------------------------------------------------------- # * Determine if Song Exists #-------------------------------------------------------------------------- def song_exists?(song_id) return true if Instrument::SONGS.include?(song_id) end #-------------------------------------------------------------------------- # * Determine if Song Already Acquired #-------------------------------------------------------------------------- def song_acquired?(song_id) return true if @songs.include?(song_id) endend#==============================================================================# ** Scene_Map#------------------------------------------------------------------------------# This class performs the map screen processing. It has been modified to# include processing for calling an instrument to play. In turn, a constant has# been provided for specifying an Input key for instrument calling.#==============================================================================class Scene_Map < Scene_Base #-------------------------------------------------------------------------- # * Constants #-------------------------------------------------------------------------- INSTRUMENT = :SHIFT # calls instrument #-------------------------------------------------------------------------- # * Start Processing #-------------------------------------------------------------------------- alias init_instrument_calling start def start init_instrument_calling @instrument_calling = false end #-------------------------------------------------------------------------- # * Update Scene Transition #-------------------------------------------------------------------------- alias call_instrument_scene update_scene def update_scene call_instrument_scene update_call_instrument unless scene_changing? end #-------------------------------------------------------------------------- # * Determine if Instrument is Called due to Instrument Calling Key #-------------------------------------------------------------------------- def update_call_instrument if $game_system.instrument_disabled || $game_map.interpreter.running? @instrument_calling = false else @instrument_calling ||= Input.trigger?(INSTRUMENT) call_instrument if @instrument_calling && !$game_player.moving? end end #-------------------------------------------------------------------------- # * Call Instrument #-------------------------------------------------------------------------- def call_instrument Sound.play_ok SceneManager.call(Scene_Instrument) endend#==============================================================================# ** Window_NoteInput#------------------------------------------------------------------------------# This window is displayed on the instrument scene and handles note# processing.#==============================================================================class Window_NoteInput < Window_Selectable #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :score attr_accessor :note_index #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize super(window_x, window_y, window_width, window_height) @note_index = 0 @score = [] refresh activate end #-------------------------------------------------------------------------- # * Get Window X-Coordinate #-------------------------------------------------------------------------- def window_x return Graphics.width / 8 end #-------------------------------------------------------------------------- # * Get Window Y-Coordinate #-------------------------------------------------------------------------- def window_y return Graphics.height / 2 - window_height / 2 end #-------------------------------------------------------------------------- # * Get Window Width #-------------------------------------------------------------------------- def window_width return Graphics.width - Graphics.width / 4 end #-------------------------------------------------------------------------- # * Get Window Height #-------------------------------------------------------------------------- def window_height return line_height * 6 end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh draw_all_horz_lines draw_all_notes unless @score.empty? end #-------------------------------------------------------------------------- # * Draw All Notes #-------------------------------------------------------------------------- def draw_all_notes @score.each_with_index do |note, index| draw_note(note_index(note), note_x(index), note_y(note)) end end #-------------------------------------------------------------------------- # * Draw Note #-------------------------------------------------------------------------- def draw_note(index, x, y) bitmap = Cache.system(Instrument::NOTESET) rect = Rect.new(index % 6 * 24, index / 6 * 24, 24, 24) contents.blt(x, y, bitmap, rect) end #-------------------------------------------------------------------------- # * Get Graphics Index for Drawing Note #-------------------------------------------------------------------------- def note_index(note) return Instrument:

ATA[note][1] end #-------------------------------------------------------------------------- # * Get X-Coordinate for Drawing Note #-------------------------------------------------------------------------- def note_x(index) width = 24 return (index + 1) * (width + standard_padding) end #-------------------------------------------------------------------------- # * Get Y-Coordinate for Drawing Note #-------------------------------------------------------------------------- def note_y(note) return (Instrument:

ATA[note][2] * line_height) + standard_padding end #-------------------------------------------------------------------------- # * Draw All Horizontal Lines #-------------------------------------------------------------------------- def draw_all_horz_lines hl = Instrument::KEYS.size + 1 hl.times {|hl| draw_horz_line(hl * line_height)} end #-------------------------------------------------------------------------- # * Draw Horizontal Line #-------------------------------------------------------------------------- def draw_horz_line(y) line_y = y + line_height / 2 - 1 contents.fill_rect(0, line_y, contents_width, 2, line_color) end #-------------------------------------------------------------------------- # * Get Color of Horizontal Line #-------------------------------------------------------------------------- def line_color color = normal_color color.alpha = 48 color endend#==============================================================================# ** Scene_Instrument#------------------------------------------------------------------------------# This class performs song playing processing.#==============================================================================class Scene_Instrument < Scene_MenuBase #-------------------------------------------------------------------------- # * Start Processing #-------------------------------------------------------------------------- def start super create_note_input_window end #-------------------------------------------------------------------------- # * Create Note Input Window #-------------------------------------------------------------------------- def create_note_input_window @note_input_window = Window_NoteInput.new @note_input_window.set_handler

cancel, method

return_scene)) end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update super process_input unless score_complete? process_score if score_complete? end #-------------------------------------------------------------------------- # * Input Processing #-------------------------------------------------------------------------- def process_input return unless @note_input_window.open? && @note_input_window.active process_note

DOWN) if Input.trigger?

DOWN) process_note

LEFT) if Input.trigger?

LEFT) process_note

RIGHT) if Input.trigger?

RIGHT) process_note

UP) if Input.trigger?

UP) process_note

A) if Input.trigger?

A) process_note

C) if Input.trigger?

C) @note_input_window.contents.clear @note_input_window.refresh end #-------------------------------------------------------------------------- # * Process Note #-------------------------------------------------------------------------- def process_note(note) Audio.se_play(note_audio(note), note_volume, note_pitch(note)) @note_input_window.score.push note @note_input_window.note_index += 1 end #-------------------------------------------------------------------------- # * Get Note Audio File #-------------------------------------------------------------------------- def note_audio(note) return Instrument:

ATA[note][0] end #-------------------------------------------------------------------------- # * Get Note Playback Volume #-------------------------------------------------------------------------- def note_volume return Instrument::VOLUME end #-------------------------------------------------------------------------- # * Get Note Pitch #-------------------------------------------------------------------------- def note_pitch(note) return Instrument:

ATA[note][3] end #-------------------------------------------------------------------------- # * Process Score #-------------------------------------------------------------------------- def process_score process_song if song_played? clear_score if score_complete? && !song_played? end #-------------------------------------------------------------------------- # * Determine if Song Played #-------------------------------------------------------------------------- def song_played? Instrument::SONGS.each do |song_symbol| return true if song_symbol[1][:score] == @note_input_window.score end end #-------------------------------------------------------------------------- # * Process Song #-------------------------------------------------------------------------- def process_song song = Instrument::SONGS case @note_input_window.score when song[:songofstorms] ; $game_temp.reserve_common_event(song[:songofstorms][2]) when song[:songoftravel] ; $game_temp.reserve_common_event(song[:songoftravel][2]) when song[:songofdeath] ; $game_temp.reserve_common_event(song[:songofdeath][2]) end Graphics.wait(6) Sound.play_ok Graphics.wait(60) SceneManager.return end #-------------------------------------------------------------------------- # * Clear Score #-------------------------------------------------------------------------- def clear_score @note_input_window.note_index = 0 @note_input_window.score.clear Graphics.wait(6) Sound.play_buzzer Graphics.wait(60) contents.clear refresh end #-------------------------------------------------------------------------- # * Determine if Score is Complete #-------------------------------------------------------------------------- def score_complete? return true if @note_input_window.note_index == Instrument::MAX endend