08-27-2006, 01:00 PM
(This post was last modified: 07-29-2017, 03:47 AM by DerVVulfman.)
Wordlock Chests
By Zeriab & Avernus
Aug 27 2006
By Zeriab & Avernus
Aug 27 2006
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.
No support is given. If you are the owner of the thread, please contact administration.
This is a mini game that adds an element of fun to your chests. It places a lock similar to a bike lock on chests you specify, and can only be opened by entering the correct combination. In this case, it uses a riddle. A riddle is displayed on screen, and in order to open the chest and get the goods, you must solve it.
The story behind this script is a short one. I created a mini game using events mid-last year, and have been painstakingly adding more and more chests throughout my game. Then it hit me, why not just script it out? Well, right away, I ran into my first problem... I didn't know the first thing about scripting.
So I came here, and searched for a pro to do the work for me. I PMed Zeriab, and he said that he was very interested and would script out the mini in no time! What a sport!
All credits go to Zeriab for his genius, simple, and neatly orginized script, and just the idea part goes to me.
Wordlock Script
Code:
#==============================================================================
# ** Wordlock Chests
#------------------------------------------------------------------------------
# Zeriab
# V 1
# 25-08-2006
#==============================================================================
module Wordlock_Chest
#--------------------------------------------------------------------------
# * The filename of the default Panorame picture
# It must be placed in 'Panoramas'
#--------------------------------------------------------------------------
PanoramaDefault = 'Riddle_Chest.png'
#--------------------------------------------------------------------------
# * This is if you want more panorama pictures
# If you want another panorame picture for chest no. 10
# just put this inside the {}:
# 10 => 'Riddle_Chest2.png'
# The text in the '' is just the filename on the panorama.
# Must be placed in 'Panorams'
#
# If you want more special chest just seperate with a comma (,)
#--------------------------------------------------------------------------
Panorama = {}
#--------------------------------------------------------------------------
# * Pictures used for the riddle.
# Usage: Write the name on the filename to be used.
# Must be in 'Pictures'
#
# The position determines the chest number.
# First position is for chest 1, second for chest 2 and so on.
#--------------------------------------------------------------------------
Pic = ['R_3.png', 'R_1.png', 'R_2.png']
#--------------------------------------------------------------------------
# * Here are the information on the chests.
# For each chest it is arrange so:
# [letter1, letter2, ... , letterX]
# Where letter1 determines the possible letters for the first place
# letter2 likewise and so on
#
# Each letter is represent by a string. The characters in the string
# will be those the player cycles through
#
# Make an array per chest.(Remember the comma - ,)
#
# The position determines the chest number.
# First position is for chest 1, second for chest 2 and so on.
#--------------------------------------------------------------------------
Chest = [
['TJYR', 'IQNS', 'PNOU', 'RGCE'],
['WGHN', 'EORH', 'MPLI', 'HTEO', 'IDFS'],
['SCWA', 'ATHR', 'ERLS', 'TLON', 'EURS', 'STDY']
]
#--------------------------------------------------------------------------
# * Here are the solutions for the chests
# The number is the correct character for the corresponding letter
#
# For example. We have above the first letter of the first chest
# containing the string 'TJYR'. If you look down you can see that at
# the same location is the number 4. This means that 'R' correct.
# Had it been 3, then 'Y' would be correct.
#
# The position determines the chest number.
# First position is for chest 1, second for chest 2 and so on.
#--------------------------------------------------------------------------
Solution = [
[4,1,2,2],
[3,2,3,3,4],
[3,1,3,4,2,2]
]
end
#==============================================================================
# ** Window_Wordlock
# Contains the static pictures
#==============================================================================
class Window_Wordlock
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(chest)
@contents = Sprite.new(Viewport.new(0, 0, 640, 480))
@contents.bitmap = Bitmap.new(32, 32)
refresh(chest)
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh(chest)
@contents.bitmap.dispose
# Gets the filename on the Panorama
filename = Wordlock_Chest::Panorama[chest]
# Checks if default should be used
if filename == nil
filename = Wordlock_Chest::PanoramaDefault
end
# Loads the panorama
@contents.bitmap = Bitmap.new('Graphics\\Panoramas\\' + filename)
# Draws the riddle
@contents.bitmap.blt(0, 0, Bitmap.new('Graphics\\Pictures\\' +
Wordlock_Chest::Pic[chest]), Rect.new(0, 0, 640, 480))
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
@contents.bitmap.dispose
@contents.dispose
end
end
#==============================================================================
# ** Window_Gamos_Selection
#==============================================================================
class Window_Wordlock_Selection
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(chest)
# Letters
@letter_bitmap = [Bitmap.new("Graphics\\Characters\\Letters_01.png"),
Bitmap.new("Graphics\\Characters\\Letters_02.png")]
# Chest Data
@data = Wordlock_Chest::Chest[chest]
@solution = Wordlock_Chest::Solution[chest]
@position = Array.new(@data.size,0)
@index = 0
@counter = 0
# Total width of the numbers
width = 32 * @data.size
@left_border = 320-(width/2)
# The letters
@contents = Sprite.new(Viewport.new(@left_border, 224, width, 32))
@contents.bitmap = Bitmap.new(width,96)
# The cursor (Crystal)
@cursor = Sprite.new(Viewport.new(@left_border, 160, @data.size*32, 64))
@cursor.bitmap = Bitmap.new(128,64)
@cursor.bitmap.blt(0, 0, Bitmap.new('Graphics\\Characters\\' +
'198-support06.png'), Rect.new(0, 128, 128, 64))
# The arrows shown.
@arrows = Sprite.new(Viewport.new(540, 192, 96, 96))
@arrows.bitmap = Bitmap.new(96,96)
# Up Arrow
@arrows.bitmap.blt(32, 0, Bitmap.new('Graphics\\Characters\\' +
'arrows.png'), Rect.new(64, 0, 32, 32))
# Right Arrow
@arrows.bitmap.blt(64, 32, Bitmap.new('Graphics\\Characters\\' +
'arrows.png'), Rect.new(64, 32, 32, 32))
# Left Arrow
@arrows.bitmap.blt(0, 32, Bitmap.new('Graphics\\Characters\\' +
'arrows.png'), Rect.new(64, 64, 32, 32))
# Down Arrow
@arrows.bitmap.blt(32, 64, Bitmap.new('Graphics\\Characters\\' +
'arrows.png'), Rect.new(64, 96, 32, 32))
# Light
bitmap = Bitmap.new('Graphics\\Characters\\185-Light02.png')
bitmap.hue_change(180)
@arrows.bitmap.blt(32, 0, bitmap, Rect.new(0, 0, 32, 64))
# Refreshes and updates
refresh
update
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
@contents.bitmap.clear
#@contents.bitmap = Bitmap.new(32 * @data.size,96)
for i in 0...@data.size
@contents.bitmap.blt(i*32, 0, get_letter(@data[i].upcase[@position[i]]),
Rect.new(0,0,32,32))
end
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update
# Updates the cursor position
@cursor.src_rect.set((@counter/15)*32, 0, 32, 64)
@cursor.x = @index * 32
# Counter for animation
@counter = (@counter + 1) % 60
# Updates the sprites
@cursor.update
@contents.update
@arrows.update
end
#--------------------------------------------------------------------------
# * Get letter as bitmap
# char : letter
#--------------------------------------------------------------------------
def get_letter(char)
#--------------------------------------------------------------------------
# In ASCII the upcase alphabet has values ranging from A = 65 to Z = 90
# 65 is subtracted so you have the alphabet in the range [0..24]
#--------------------------------------------------------------------------
val = char - 65
# Gets which of the two bitmaps to use
no = val / 16 + 1
# Gets the position of the letter
val = val % 16
# Transfers the letter to the bitmap
bitmap = Bitmap.new(32,32)
bitmap.blt(0, 0, @letter_bitmap[no-1],
Rect.new((val % 4)*32, (val/4)*32, 32, 32))
return bitmap
end
#--------------------------------------------------------------------------
# * Move in the direction given
# dir : The direction.
#--------------------------------------------------------------------------
def move(dir)
case dir
when 2: # Down
@position[@index] = (@position[@index] - 1) % @data[@index].size
refresh
when 4: # Left
@index = (@index - 1) % @data.size
when 6: # Right
@index = (@index + 1) % @data.size
when 8: # Up
@position[@index] = (@position[@index] + 1) % @data[@index].size
refresh
end
end
#--------------------------------------------------------------------------
# * Checks if the solution is solved
#--------------------------------------------------------------------------
def solved?
#--------------------------------------------------------------------------
# In @position the first letter is considered as 0 where as in @solution
# the first letter is considered as 1. Checks if all the elements in
# @position is just 1 less than the designated element in @solution
#--------------------------------------------------------------------------
for i in 0...@solution.size
if @solution[i] != @position[i] + 1
return false
end
end
return true
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
@cursor.bitmap.dispose
@cursor.dispose
@contents.bitmap.dispose
@contents.dispose
end
end
#==============================================================================
# ** Scene_Wordlock
#==============================================================================
class Scene_Wordlock
#--------------------------------------------------------------------------
# * Object Initialization
# chest : The chest number
# switch_number : Number on the switch which will be turned on
# if the player solves the chest
#--------------------------------------------------------------------------
def initialize(chest, switch_number)
# First element in an Array have index = 0
@chest = chest-1
@switch_number = switch_number
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Creates Wordlock Window
@wordlock_window = Window_Wordlock.new(@chest)
# Creates Selection Window
@selection_window = Window_Wordlock_Selection.new(@chest)
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Updates Selection Window
@selection_window.update
## Frame update
update
# Abort loop if screen is changed
break if $scene != self
end
# Prepare for transition
Graphics.freeze
# Dispose Scene Objects
@selection_window.dispose
@wordlock_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# If Up Is Pressed
if Input.repeat?(Input::UP)
# Refresh Selection
@selection_window.move(8)
end
# If Down Is Pressed
if Input.repeat?(Input::DOWN)
# Refresh Selection
@selection_window.move(2)
end
# If Left Is Pressed
if Input.repeat?(Input::LEFT)
# Refresh Selection
@selection_window.move(4)
end
# If Right Is Pressed
if Input.repeat?(Input::RIGHT)
# Refresh Selection
@selection_window.move(6)
end
# If B Button Is Pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to map screen
$scene = Scene_Map.new
return
end
# If C Button Is Pressed
if Input.trigger?(Input::C)
# Level active Check
unless @selection_window.solved?
# Play Buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play Decision SE
$game_system.se_play($data_system.decision_se)
# Turn switch ON
$game_switches[@switch_number] = true
# Refresh player
$game_player.refresh
# Refreshes Map
$game_map.refresh
# Switch to map screen
$scene = Scene_Map.new
end
end
end