Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Ocarina Script

Nachos

Sponsor

You have to play the notes acording to the songs. This can be like a "challenge" in an adventure game, or for summoning monsters. I'M PROVIDING THE IMAGES WITH THE DEMO
It's an ocarina Script, like the one in Zelda games.
here it goes:
Call the script using: $scene = Ocarina.new

i ended up editing all the script so, yay credits!. :P

Code:
#============================================================================
# ** Ocarina System (Revised)
#----------------------------------------------------------------------------
# Rudy_Guillan : RENEGADEOFBMX : vpcdmd
# 2.0
# 2/16/2008
#---
# ~ Originally Created by                 : Rudy_Guillan
# ~ Edited by                             : RENEGADEOFBMX
# ~ Revised and Rewrite by                : vpcdmd
#============================================================================

#----------------------------------------------------------------------------
# ** Game_System
#----------------------------------------------------------------------------

class Game_System
  attr_reader :ocarina, :ocarina_down, :ocarina_right, :ocarina_up, :ocarina_left
  alias tsu_ocarina_initialize initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    @ocarina = []
    #------------------------------------------------------------------------
    @ocarina_down = "001-System01"
    @ocarina_left = "002-System02"
    @ocarina_right = "003-System03"
    @ocarina_up = "004-System04"
    #------------------------------------------------------------------------
    @ocarina[0] = []
    @ocarina[0][0] = 4
    @ocarina[0][1] = 4
    @ocarina[0][2] = 6
    @ocarina[0][3] = 6
    @ocarina[0][4] = 2
    @ocarina[0][5] = 2
    @ocarina[0][6] = "Bolero of fire"
    @ocarina[0][7] = Color.new(0, 255, 0)
    @ocarina[0][8] = "023-Dive03"
    @ocarina[0][9] = 1
    #------------------------------------------------------------------------
    @ocarina[1] = []
    @ocarina[1][0] = 8
    @ocarina[1][1] = 2
    @ocarina[1][2] = 2
    @ocarina[1][3] = 8
    @ocarina[1][4] = 2
    @ocarina[1][5] = 2
    @ocarina[1][6] = "Canción del fuego"
    @ocarina[1][7] = Color.new(255, 0, 0)
    @ocarina[1][8] = "023-Dive03"
    @ocarina[1][9] = 47
    #------------------------------------------------------------------------
    @ocarina[2] = []
    @ocarina[2][0] = 2
    @ocarina[2][1] = 2
    @ocarina[2][2] = 8
    @ocarina[2][3] = 8
    @ocarina[2][4] = 8
    @ocarina[2][5] = 2
    @ocarina[2][6] = 2
    @ocarina[2][7] = "Bolero with seven"
    @ocarina[2][8] = Color.new(0, 0, 255)
    @ocarina[2][9] = "060-Cheer01"
    @ocarina[2][10] = 2
    #------------------------------------------------------------------------
    @ocarina[3] = []
    @ocarina[3][0] = 2
    @ocarina[3][1] = 8
    @ocarina[3][2] = 2
    @ocarina[3][3] = 8
    @ocarina[3][7] = "Small with four"
    @ocarina[3][8] = Color.new(0, 255, 255)
    @ocarina[3][9] = "022-Dive02"
    @ocarina[3][10] = 3
    #------------------------------------------------------------------------
    tsu_ocarina_initialize
  end
end
#----------------------------------------------------------------------------
# ** Scene_Ocarina
#----------------------------------------------------------------------------

class Ocarina
  #--------------------------------------------------------------------------
  # * Main
  #--------------------------------------------------------------------------
  def main
    @spriteset = Spriteset_Map.new
    @ocarina_window = Window_Ocarina.new
    @back = Sprite.new
    @back.bitmap = RPG::Cache.picture("pentagrama")
    @back.x = 40
    @back.y = 360
    @back.opacity = 160
    @arrow = []
    @max_notes = 0
    for i in 0...$game_system.ocarina.size
      size = $game_system.ocarina[i].size - 4
      @max_notes = size > @max_notes ? size : @max_notes
    end
    for i in 1..@max_notes
      @arrow[i] = Sprite.new
      @arrow[i].bitmap = RPG::Cache.picture("arrow")
      @arrow[i].ox = @arrow[i].bitmap.width / 2
      @arrow[i].oy = @arrow[i].bitmap.height / 2
      @arrow[i].opacity = 0
    end
    @song = []
    @correct = false
    @counter = 0
    @objects = [@spriteset, @back, @ocarina_window]
    Graphics.transition
    while $scene == self
      Graphics.update
      Input.update
      @objects.each {|x| x.update}
      update
    end
    Graphics.freeze
    @objects.each {|object| object.dispose}
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    if @correct
      if @counter == 0
        @ocarina_window.set_text(@i)
        se = $game_system.ocarina[@i].size - 2
        Audio.se_play("Audio/SE/" + $game_system.ocarina[@i][se], 80, 100)
        for i in 1..@max_notes
          @arrow[i].opacity = 255
        end
        switch = $game_system.ocarina[@i].size - 1
        $game_switches[$game_system.ocarina[@i][switch]] = true
      end
      @counter += 1
      if @counter >= 200
        $scene = Scene_Map.new
        $game_map.autoplay
        $game_map.refresh
      end
    else
      if Input.trigger?(Input::B)
        $game_system.se_play($data_system.cancel_se)
        $scene = Scene_Map.new
        return
      end
      for @i in 0...$game_system.ocarina.size
        correct = true
        for j in 0...$game_system.ocarina[@i].size - 4
          if @song[j] != $game_system.ocarina[@i][j]
            correct = false
          end
        end
        if correct == true
          @correct = true
          break
        end
      end
      if @song.size >= @max_notes  && @correct == false
        @counter += 1
        if @counter >= 80
          $scene = Scene_Map.new
        end
      end
      if Input.trigger?(Input::DOWN) && @song.size < @max_notes
        Audio.se_play("Audio/SE/" + $game_system.ocarina_down, 80, 100)
        @song.push(2)
        for i in 1..@song.size
          if i == @song.size
            @arrow[i].angle = 180
            @arrow[i].opacity = 160
            @arrow[i].x = 80 + ((400/(@max_notes-1)) * i)
            @arrow[i].y = 440
          end
        end
      end
      if Input.trigger?(Input::LEFT) && @song.size < @max_notes
        Audio.se_play("Audio/SE/" + $game_system.ocarina_left, 80, 100)
        @song.push(4)
        for i in 1..@song.size
          if i == @song.size
            @arrow[i].angle = 90
            @arrow[i].opacity = 160
            @arrow[i].x = 80 + ((400/(@max_notes-1)) * i)
            @arrow[i].y = 420
          end
        end
      end
      if Input.trigger?(Input::RIGHT) && @song.size < @max_notes
        Audio.se_play("Audio/SE/" + $game_system.ocarina_right, 80, 100)
        @song.push(6)
        for i in 1..@song.size
          if i == @song.size
            @arrow[i].angle = 270
            @arrow[i].opacity = 160
            @arrow[i].x = 80 + ((400/(@max_notes-1)) * i)
            @arrow[i].y = 400
          end
        end
      end
      if Input.trigger?(Input::UP) && @song.size < @max_notes
        Audio.se_play("Audio/SE/" + $game_system.ocarina_up, 80, 100)
        @song.push(8)
        for i in 1..@song.size
          if i == @song.size
            @arrow[i].opacity = 160
            @arrow[i].x = 80 + ((400/(@max_notes-1)) * i)
            @arrow[i].y = 380
          end
        end
      end
    end
  end
end
#--------------------------------------------------------------------------
# ** Window_Ocarina
#--------------------------------------------------------------------------

class Window_Ocarina < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 280, 640, 80)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    @song = []
    @correct = false
    @counter = 0
  end
  #--------------------------------------------------------------------------
  # * Set Text
  #--------------------------------------------------------------------------
  def set_text(index)
    col = $game_system.ocarina[index].size - 3
    text = $game_system.ocarina[index].size - 4
    self.contents.font.color = $game_system.ocarina[index][col]
    self.contents.draw_text(0, 0, 618, 48, $game_system.ocarina[index][text], 1)
  end
end

http://www.savefile.com/files/1384925

@jbrist:

Cutomization

paste the script above main, and edit this part:


Code:
SOUND FOR EACH NOTE
    @ocarina_down = "001-System01"
    @ocarina_left = "002-System02"
    @ocarina_right = "003-System03"
    @ocarina_up = "004-System04"

   
Code:
    @ocarina[i] = []Array number
    @ocarina[i][0] = direction (2 = down, 4 = left, 6 = right, 8 = up)
    @ocarina[i][1] = direction (2 = down, 4 = left, 6 = right, 8 = up)
    @ocarina[i][2] = direction (2 = down, 4 = left, 6 = right, 8 = up)
    @ocarina[i][3] = direction (2 = down, 4 = left, 6 = right, 8 = up)
    @ocarina[i][4] = direction (2 = down, 4 = left, 6 = right, 8 = up)
    @ocarina[i][5] = direction (2 = down, 4 = left, 6 = right, 8 = up)
    @ocarina[i][6] = Name_of_song
    @ocarina[i][7] = Color_of_song_name
    @ocarina[i][8] = Song's sound file (SE)
    @ocarina[i][9] = Switch that activates when the song is player correctly.
ç

copy this to add songs
 
Pretty sweet system.  :thumb:
Pretty messy coding. xD

Also, you might want to explain how to set up new songs.

Code:
    @ocarina[i] = []
    @ocarina[i][0] = direction (2 = down, 4 = left, 6 = right, 8 = up)
    @ocarina[i][1] = direction (2 = down, 4 = left, 6 = right, 8 = up)
    @ocarina[i][2] = direction (2 = down, 4 = left, 6 = right, 8 = up)
    @ocarina[i][3] = direction (2 = down, 4 = left, 6 = right, 8 = up)
    @ocarina[i][4] = direction (2 = down, 4 = left, 6 = right, 8 = up)
    @ocarina[i][5] = direction (2 = down, 4 = left, 6 = right, 8 = up)
    @ocarina[i][6] = Name_of_song
    @ocarina[i][7] = Color_of_song_name
    @ocarina[i][8] = Song's sound file (SE)
    @ocarina[i][9] = Switch that activates when the song is player correctly.

Where i is the number of the song.
 

mawk

Sponsor

So, wait, did you edit all the script, or just the settings? I recall you saying that you didn't make this a while back, so unless you completely overhauled the base code, it'd be a good idea to at least say who made it originally. What did you change, anyway?

Sorry if I come off a little beligerrent. I'm asking out of curiosity, not to bust yo ass all over the curb.
 
I'm with Miek on this.  I'm checking the new version and the old one, and they don't look that much different, besides even if you did edit it and gave it a complete overhaul (which I'm actually doing since there it a lot of unnecesary lines)  The original author should be given credit.
 
I tried this out, and it works really well. The only thing I have a problem with is the left and right notes. They are facing the opposite directions. :smile:
 
Well, if you want you can use my revision of it.

I just cleaned the code a bit, made the case statements into loops instead, and added a way to have songs with more or less than six notes. (thanks to Regimos for the idea :P)


Code:
#============================================================================
# ** Ocarina System (Revised)
#----------------------------------------------------------------------------
# Rudy_Guillan : RENEGADEOFBMX : vpcdmd
# 2.0
# 2/16/2008
#---
# ~ Originally Created by                 : Rudy_Guillan
# ~ Edited by                             : RENEGADEOFBMX
# ~ Revised and Rewrite by                : vpcdmd
#============================================================================

#----------------------------------------------------------------------------
# ** Game_System
#----------------------------------------------------------------------------

class Game_System
  attr_reader :ocarina, :ocarina_down, :ocarina_right, :ocarina_up, :ocarina_left
  alias tsu_ocarina_initialize initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    @ocarina = []
    #------------------------------------------------------------------------
    @ocarina_down = "001-System01"
    @ocarina_left = "002-System02"
    @ocarina_right = "003-System03"
    @ocarina_up = "004-System04"
    #------------------------------------------------------------------------
    @ocarina[0] = []
    @ocarina[0][0] = 4
    @ocarina[0][1] = 4
    @ocarina[0][2] = 6
    @ocarina[0][3] = 6
    @ocarina[0][4] = 2
    @ocarina[0][5] = 2
    @ocarina[0][6] = "Bolero of fire"
    @ocarina[0][7] = Color.new(0, 255, 0)
    @ocarina[0][8] = "023-Dive03"
    @ocarina[0][9] = 1
    #------------------------------------------------------------------------
    @ocarina[1] = []
    @ocarina[1][0] = 8
    @ocarina[1][1] = 2
    @ocarina[1][2] = 2
    @ocarina[1][3] = 8
    @ocarina[1][4] = 2
    @ocarina[1][5] = 2
    @ocarina[1][6] = "Canción del fuego"
    @ocarina[1][7] = Color.new(255, 0, 0)
    @ocarina[1][8] = "023-Dive03"
    @ocarina[1][9] = 47
    #------------------------------------------------------------------------
    @ocarina[2] = []
    @ocarina[2][0] = 2
    @ocarina[2][1] = 2
    @ocarina[2][2] = 8
    @ocarina[2][3] = 8
    @ocarina[2][4] = 8
    @ocarina[2][5] = 2
    @ocarina[2][6] = 2
    @ocarina[2][7] = "Bolero with seven"
    @ocarina[2][8] = Color.new(0, 0, 255)
    @ocarina[2][9] = "060-Cheer01"
    @ocarina[2][10] = 2
    #------------------------------------------------------------------------
    @ocarina[3] = []
    @ocarina[3][0] = 2
    @ocarina[3][1] = 8
    @ocarina[3][2] = 2
    @ocarina[3][3] = 8
    @ocarina[3][7] = "Small with four"
    @ocarina[3][8] = Color.new(0, 255, 255)
    @ocarina[3][9] = "022-Dive02"
    @ocarina[3][10] = 3
    #------------------------------------------------------------------------
    tsu_ocarina_initialize
  end
end
#----------------------------------------------------------------------------
# ** Scene_Ocarina
#----------------------------------------------------------------------------

class Ocarina
  #--------------------------------------------------------------------------
  # * Main
  #--------------------------------------------------------------------------
  def main
    @spriteset = Spriteset_Map.new
    @ocarina_window = Window_Ocarina.new
    @back = Sprite.new
    @back.bitmap = RPG::Cache.picture("pentagrama")
    @back.x = 40
    @back.y = 360
    @back.opacity = 160
    @arrow = []
    @max_notes = 0
    for i in 0...$game_system.ocarina.size
      size = $game_system.ocarina[i].size - 4
      @max_notes = size > @max_notes ? size : @max_notes
    end
    for i in 1..@max_notes
      @arrow[i] = Sprite.new
      @arrow[i].bitmap = RPG::Cache.picture("arrow")
      @arrow[i].ox = @arrow[i].bitmap.width / 2
      @arrow[i].oy = @arrow[i].bitmap.height / 2
      @arrow[i].opacity = 0
    end
    @song = []
    @correct = false
    @counter = 0
    @objects = [@spriteset, @back, @ocarina_window]
    Graphics.transition
    while $scene == self
      Graphics.update
      Input.update
      @objects.each {|x| x.update}
      update
    end
    Graphics.freeze
    @objects.each {|object| object.dispose}
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    if @correct
      if @counter == 0
        @ocarina_window.set_text(@i)
        se = $game_system.ocarina[@i].size - 2
        Audio.se_play("Audio/SE/" + $game_system.ocarina[@i][se], 80, 100)
        for i in 1..@max_notes
          @arrow[i].opacity = 255
        end
        switch = $game_system.ocarina[@i].size - 1
        $game_switches[$game_system.ocarina[@i][switch]] = true
      end
      @counter += 1
      if @counter >= 200
        $scene = Scene_Map.new
        $game_map.autoplay
        $game_map.refresh
      end
    else
      if Input.trigger?(Input::B)
        $game_system.se_play($data_system.cancel_se)
        $scene = Scene_Map.new
        return
      end
      for @i in 0...$game_system.ocarina.size
        correct = true
        for j in 0...$game_system.ocarina[@i].size - 4
          if @song[j] != $game_system.ocarina[@i][j]
            correct = false
          end
        end
        if correct == true
          @correct = true
          break
        end
      end
      if @song.size >= @max_notes  && @correct == false
        @counter += 1
        if @counter >= 80
          $scene = Scene_Map.new
        end
      end
      if Input.trigger?(Input::DOWN) && @song.size < @max_notes
        Audio.se_play("Audio/SE/" + $game_system.ocarina_down, 80, 100)
        @song.push(2)
        for i in 1..@song.size
          if i == @song.size
            @arrow[i].angle = 180
            @arrow[i].opacity = 160
            @arrow[i].x = 80 + ((400/(@max_notes-1)) * i)
            @arrow[i].y = 440
          end
        end
      end
      if Input.trigger?(Input::LEFT) && @song.size < @max_notes
        Audio.se_play("Audio/SE/" + $game_system.ocarina_left, 80, 100)
        @song.push(4)
        for i in 1..@song.size
          if i == @song.size
            @arrow[i].angle = 90
            @arrow[i].opacity = 160
            @arrow[i].x = 80 + ((400/(@max_notes-1)) * i)
            @arrow[i].y = 420
          end
        end
      end
      if Input.trigger?(Input::RIGHT) && @song.size < @max_notes
        Audio.se_play("Audio/SE/" + $game_system.ocarina_right, 80, 100)
        @song.push(6)
        for i in 1..@song.size
          if i == @song.size
            @arrow[i].angle = 270
            @arrow[i].opacity = 160
            @arrow[i].x = 80 + ((400/(@max_notes-1)) * i)
            @arrow[i].y = 400
          end
        end
      end
      if Input.trigger?(Input::UP) && @song.size < @max_notes
        Audio.se_play("Audio/SE/" + $game_system.ocarina_up, 80, 100)
        @song.push(8)
        for i in 1..@song.size
          if i == @song.size
            @arrow[i].opacity = 160
            @arrow[i].x = 80 + ((400/(@max_notes-1)) * i)
            @arrow[i].y = 380
          end
        end
      end
    end
  end
end
#--------------------------------------------------------------------------
# ** Window_Ocarina
#--------------------------------------------------------------------------

class Window_Ocarina < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 280, 640, 80)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    @song = []
    @correct = false
    @counter = 0
  end
  #--------------------------------------------------------------------------
  # * Set Text
  #--------------------------------------------------------------------------
  def set_text(index)
    col = $game_system.ocarina[index].size - 3
    text = $game_system.ocarina[index].size - 4
    self.contents.font.color = $game_system.ocarina[index][col]
    self.contents.draw_text(0, 0, 618, 48, $game_system.ocarina[index][text], 1)
  end
end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top