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.

Konami Code Input

Is there any way I can set a conditional branch so that if the player does the Konami Code in the overworld map a special scene plays?
 
Code:
module Code_Input
  Codes = {}
  Codes[[Input::UP, Input::UP, Input::DOWN, Input::DOWN, Input::LEFT, Input::RIGHT, Input::LEFT, Input::RIGHT, Input::L, Input::R]] = 1
  @on = false
  Delay_Frames = 400
  # Do not modify
  Max_Keys = 0
  Codes.keys.each {|a| Max_Keys = a.size if a.size > Max_Keys}
  Keys = []
  Codes.keys.each do |code_list|
    code_list.each do |constant|
      Keys << constant unless Keys.include?(constant)
    end
  end
  @delay_frames = Delay_Frames
  def self.on=(bool)
    @inputed = [] if bool != @on
    @on = bool
  end
  def self.on
    return @on
  end
  def self.update
    return if @on == false
    Keys.each do |constant|
      if Input.trigger?(constant)
        @inputed << constant
        self.check_inputed
        @inputed.shift until @inputed.size <= Max_Keys
      end
    end
    if @delay_frames > 0
      @delay_frames -= 1
      return
    end
    @delay_frames = Delay_Frames
    @inputed.shift
  end
  def self.check_inputed
    for i in 0...@inputed.size
      for code_list in Codes.keys
        entered = true
        for j in 0..code_list.size
          if @inputed[i + j] != code_list[j]
            entered = false
            break
          end
        end
        if entered
          $game_temp.common_event_id = Codes[code_list]
          return
        end
      end
    end
  end
end

module Input
  class << self
    alias_method :seph_codeinput_input_update, :update
    def update
      seph_codeinput_input_update
      Code_Input.update
    end
  end
end

Adding a new code (check helpfile for input constants)
  Codes[[input_button, ...]] = common_event_id

Number of time to enter a code
  Delay_Frames = 400

Turning it on or off
  Code_Input.on = true (on) or false (off)


Enjoy!
 

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