07-26-2006, 01:00 PM
Letter Minigame
by Zeriab
Version: 1.1
July 26, 2006
Version History
Version 1.1:
Adds $letter_minigame.score - works also after $letter_minigame.dispose.
Gives a solution to the F12 issue present in the earlier demo.
Introduction
The Letter Minigame has been made by Zeriab.
Thanks goes to RMXP for making this possible and Near Fantastica for the Anti Event Lag Script.
Credits should be given.
The purpose in the Letter Minigame is to get a good score by collecting as many letters in the maze as possible within the time limit.
Different letters give different amount of points.
You can see how much each letter gives by looking at the letters on this island.
The more points the rarer the letter.
A yellow letter = 10 points
A green letter = 15 points
A azure letter = 20 points
A red letter = 25 points
A purple letter = 30 points
A black letter = 100 points
Script
-=Extensions=-
-=Maze_Generator=-
-=Letter Minigame=-
Instructions
Here I will try to explain how the scripts is used.
I have split this section in two.
One for the Maze Generator. This generates the maze and places the events.
This is not linked with the Letter Minigame.
One for the Letter Minigame. This controls the letters collected and the visual effects.
This is not linked with the Maze Generator. A normally made level could be used.
You can look at the scripts in the end of the scripts editor.
I have also edited some of the normal scripts in the demo. These has been marked by having a * in front of its name in the script chooser.
Maze Generator
Letter Minigame
The command $letter_minigame.score returns the score.
This works even after the $letter_minigame.dispose command is used.
That is because .dispose leaves the little information needed for calculation the score.
You can for example use this for giving prizes afterwards.
FAQ
How could I make a maze that has no timer on it with this script? Cause I wanna make a maze, and put a boss in it, but I want the maze to be randomized, and I don't want the timer either. The other thing is, how can I set this up so that I can have just the 1 boss event in it in a specific spot, and not have to worry about that spot being in a wall, or unreachable because the maze wasn't made right.
Long answer
How do I set up item prizes?
For example, if I had 250 points, I win a potion or something like that.
Using this command will return the score: $letter_minigame.score
For non-scripters you can use the Call Script command with $game_variables[10] = $letter_minigame.score, where the 10 is the variable number. Just set it to the number of the variable you want to use.
Now that you have the score in a variable I assume that you can do the rest.
.
Compatibility
Is not compatible with saving and loading. The map will reset if loaded.
Might be SDK compliant.
Credits and Thanks
I would like to thank RMXP – Underground personal for creating a scripting contest which inspired me to create this work.
I would like to thank everyone using their time to try this and finally I would like to thank everyone reading this topic.
Thanks.
Author's Notes
I suggest using Near Fantastica's anti event lag script due to the often high amount events.
This script can create more than 1000 events. I suggest however that you refrain from designing level where this is an eminent possibility.
Using the event command Erase Event will not entirely delete the event.
The event still exists in the $game_map.events and lags about as much as a blank events.
And finally: ENJOY!
- Zeriab
by Zeriab
Version: 1.1
July 26, 2006
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given.
No support is given.
Version History
Version 1.1:
Adds $letter_minigame.score - works also after $letter_minigame.dispose.
Gives a solution to the F12 issue present in the earlier demo.
Introduction
The Letter Minigame has been made by Zeriab.
Thanks goes to RMXP for making this possible and Near Fantastica for the Anti Event Lag Script.
Credits should be given.
The purpose in the Letter Minigame is to get a good score by collecting as many letters in the maze as possible within the time limit.
Different letters give different amount of points.
You can see how much each letter gives by looking at the letters on this island.
The more points the rarer the letter.
A yellow letter = 10 points
A green letter = 15 points
A azure letter = 20 points
A red letter = 25 points
A purple letter = 30 points
A black letter = 100 points
Script
-=Extensions=-
Game_Event extended
Code:
#===============================================================================
# Author: Zeriab Date:03-06-2006
# Last Modified: 04-06-2006
#
# Game_Event: (Extension)
# ----------------------
# Adds the ability to change the id
# Adds the ability to copy the event
#===============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# * Sets @id and @event.id to the given value
#--------------------------------------------------------------------------
def id=(value)
@id = value
@event.id = value
end
#--------------------------------------------------------------------------
# * Copies the event
#--------------------------------------------------------------------------
def copy
temp = Game_Event.new(@map_id, @event.dup)
temp.id = @id
return temp
end
end
Game_Map extended
Code:
#===============================================================================
# Author: Zeriab Date:09-06-2006
# Last Modified: 09-06-2006
#
# Game_Map: (Extension)
# ----------------------
# Adds the ability to change the height and width
#===============================================================================
class Game_Map
#--------------------------------------------------------------------------
# * Sets height of the map to a given value
#--------------------------------------------------------------------------
def height=(value)
@map.height = value
end
#--------------------------------------------------------------------------
# * Sets width of the map to a given value
#--------------------------------------------------------------------------
def width=(value)
@map.width = value
end
end
-=Maze_Generator=-
Pointer
Code:
#===============================================================================
# Author: Zeriab Date:03-06-2006
# Last Modified: 07-06-2006
#
# Pointer:
# ----------------------
# Points to a specific position on the map
#===============================================================================
module Maze_Generator
class Pointer
attr_reader :x # Stored x
attr_reader :y # Stored y
attr_accessor :tail #A possible tail behind the pointer
#--------------------------------------------------------------------------
# * Object Initialization
# x : x-coordinate for starting point
# y : y-coordinate for starting point
#--------------------------------------------------------------------------
def initialize(x, y)
@x = x
@y = y
end
#--------------------------------------------------------------------------
# * Checks the pointers location
# true is returned if the pointer is inside $game_map
# false is returned if the pointer is outside $game_map
#--------------------------------------------------------------------------
def check
if (x / $game_map.width) == 0 and (y / $game_map.height) == 0
return true
else
return false
end
end
#--------------------------------------------------------------------------
# * Get the tile value
#--------------------------------------------------------------------------
def get(layer)
return $game_map.data[x,y,layer]
end
#--------------------------------------------------------------------------
# * Set the tile value
#--------------------------------------------------------------------------
def set(value, layer)
$game_map.data[x,y,layer] = value
if @tail != nil
@tail.set(value,layer)
end
end
#--------------------------------------------------------------------------
# * The to_s-method.
# Information about the pointer returned as a string
#--------------------------------------------------------------------------
def to_s
return 'Pointer - x=' + @x.to_s + ', y=' + @y.to_s +
' - hasTail=' + (!(@tail==nil)).to_s
end
end
end
Event_Spawner
Code:
#===============================================================================
# Author: Zeriab Date:04-06-2006
# Last Modified: 04-06-2006
#
# Event_Spawner:
# ----------------------
# Creates a list during initialization which later is used for choosing events
# The events given when initialized is removed from the map.
# If the max_chance is bigger than the total sum of the events chance value
# the possibility to not retrieving an event is present.
# In that case 'nil' is returned.
#===============================================================================
module Maze_Generator
class Event_Spawner
#--------------------------------------------------------------------------
# * Object Initialization
# max_chance : The total chance used for choosing among the events
# array_of_events : Numbers on events paired with their chance value
#--------------------------------------------------------------------------
def initialize(max_chance, array_of_events)
@max_chance = max_chance
@array_of_events = array_of_events
counter = 0
for tuple in @array_of_events
tuple[0] = $game_map.events.delete(tuple[0])
counter += tuple[1]
end
if counter > @max_chance
@max_chance = counter
end
end
#--------------------------------------------------------------------------
# * Gets an event randomly from the list
# returns 'nil' if no event is chosen
#--------------------------------------------------------------------------
def get_event
result = nil
chance = rand(@max_chance) + 1
for tuple in @array_of_events
chance = chance - tuple[1]
if chance <= 0 and tuple[0] != nil
result = tuple[0].copy
break
end
end
return result
end
end
end
Maze_Generator
Code:
#===============================================================================
# Author: Zeriab Date:03-06-2006
# Last Modified: 07-06-2006
#
# Maze_Generator:
# ----------------------
# Creates a maze on the current map.
#===============================================================================
module Maze_Generator
class Maze
#--------------------------------------------------------------------------
# * Object Initialization
# x : x-coordinate for starting point
# y : y-coordinate for starting point
# max_chance : The total chance used for choosing among the events
# array_of_events : Numbers on events paired with their chance value
# value : value of the tileset assigned to the maze
# layer : the layer that will be crawled
#--------------------------------------------------------------------------
def initialize(x, y, max_chance, array_of_events, value=0, layer=1)
x = x % $game_map.width
y = y % $game_map.height
@value = value
@layer = layer % 3
@events = Event_Spawner.new(max_chance, array_of_events)
@counter = 1000
pon = Pointer.new(23,54)
pointer = Pointer.new(x,y)
pointer.tail=pon
pointer.set(@value,@layer)
crawl(pointer)
$scene = Scene_Map.new
end
#--------------------------------------------------------------------------
# * Crawls the map
# pointer : The start pointer.
#--------------------------------------------------------------------------
def crawl(pointer)
k = 0
list = [pointer]
while list.length > 0
k += 1
k += 1
r = rand(list.length)
pointer = list.delete_at(r)
array = getDirection
array2 = relax(pointer, array)
for i in 0...array2.length
list.push(array2[i])
end
end
end
#--------------------------------------------------------------------------
# * Get the directions. (Randomized)
# Returnes an array of length 2..4 containing the numbers 1..4
#--------------------------------------------------------------------------
def getDirection
array = [1,2,3,4]
r = rand(3)+2
while (array.length-r) > 0
r2 = rand(array.length)
array.delete_at(r2)
end
return array
end
#--------------------------------------------------------------------------
# * Relaxes the given pointer with the given array
# Creates paths for the valid directions
# Returns the valid pointers
#--------------------------------------------------------------------------
def relax(pointer, array)
result = []
while array.length > 0
key = array.pop
case key
#---------------------------------------------------
# * up
#---------------------------------------------------
when 1
p2 = Pointer.new(pointer.x, pointer.y - 2)
if p2.check && p2.get(@layer) != @value
p3 = Pointer.new(pointer.x,pointer.y - 1)
p2.tail = p3
p2.set(@value,@layer)
result.push(p2)
end
#---------------------------------------------------
# * rigth
#---------------------------------------------------
when 2
p2 = Pointer.new(pointer.x + 2, pointer.y)
if p2.check && p2.get(@layer) != @value
p3 = Pointer.new(pointer.x + 1,pointer.y)
p2.tail = p3
p2.set(@value,@layer)
result.push(p2)
end
#---------------------------------------------------
# * down
#---------------------------------------------------
when 3
p2 = Pointer.new(pointer.x, pointer.y + 2)
if p2.check && p2.get(@layer) != @value
p3 = Pointer.new(pointer.x,pointer.y + 1)
p2.tail = p3
p2.set(@value,@layer)
result.push(p2)
end
#---------------------------------------------------
# * left
#---------------------------------------------------
when 4
p2 = Pointer.new(pointer.x - 2, pointer.y)
if p2.check && p2.get(@layer) != @value
p3 = Pointer.new(pointer.x - 1,pointer.y)
p2.tail = p3
p2.set(@value,@layer)
result.push(p2)
end
end
end
#----------------------------------------------------------------------
# * If result = [] (Dead end) an event might be placed in the current
# position.
#----------------------------------------------------------------------
if result == []
new_event = @events.get_event
if new_event != nil
new_event.id = @counter
new_event.moveto(pointer.x,pointer.y)
$game_map.events[@counter] = new_event
@counter += 1
end
end
#----------------------------------------------------------------------
return result
end
end
end
-=Letter Minigame=-
Letter_Minigame
Code:
#===============================================================================
# Author: Zeriab Date:08-06-2006
# Last Modified: 27-07-2006
#
# Letter_Minigame
# ----------------------
# Counts the amount of letters collected and controls the score displaying in
# the top-right corner
#===============================================================================
class Letter_Minigame
attr_reader :array_of_points
attr_reader :array_of_bitmaps
attr_reader :array_of_sprites
attr_reader :array_count
#--------------------------------------------------------------------------
# * Object Initialization.
# array_of_events : Numbers on the events used.
# array_of_points : The amount of points for the corresponding event in
# array_of_events. Linked by placement.
#--------------------------------------------------------------------------
def initialize(array_of_events, array_of_points)
@array_of_points = array_of_points
getSprites(array_of_events)
@array_count = Array.new(array_of_points.size,0)
end
#--------------------------------------------------------------------------
# * Adds a letter to the to corresponding group.
# letter : indicating the position the letter have in
# the array_of_points with 0 as first letter.
#--------------------------------------------------------------------------
def add(letter)
@array_count[letter] += 1
update_letter(letter)
end
#--------------------------------------------------------------------------
# * Gets an array sprites and and array of their base bitmaps from an array
# of events.
# array : An array of eventnumbers which sprites is wanted.
#--------------------------------------------------------------------------
def getSprites(array)
@array_of_bitmaps = []
@array_of_sprites = []
counter = 0
for i in array
event = $game_map.events[i]
bitmap = RPG::Cache.character(event.character_name, event.character_hue)
#---------------------------------------------------
cw = bitmap.width / 4
ch = bitmap.height / 4
sx = event.pattern * cw
sy = (event.direction - 2) / 2 * ch
#---------------------------------------------------
sprite = Sprite.new(Viewport.new(640-64,10+(32*counter),cw,ch))
sprite.visible = false
sprite.bitmap = bitmap
sprite.src_rect.set(sx, sy, cw, ch)
#---------------------------------------------------
new_bitmap = Bitmap.new(cw*3,ch)
new_bitmap.blt(0,0,sprite.bitmap,sprite.src_rect)
sprite.bitmap = new_bitmap.dup
#---------------------------------------------------
@array_of_bitmaps.push(new_bitmap.dup)
@array_of_sprites.push(sprite)
new_bitmap.dispose
counter += 1
end
end
#--------------------------------------------------------------------------
# * Single Letter Update
# letter : Number on the letter which will be updated
#--------------------------------------------------------------------------
def update_letter(letter)
sprite = @array_of_sprites[letter]
value = @array_count[letter]
var = (value.to_s.length - 1) * 11
sprite.bitmap.dispose
sprite.bitmap = @array_of_bitmaps[letter].dup
sprite.bitmap.draw_text(28,12,64,64,'x ' + value.to_s)
sprite.src_rect.width = 64 + var
sprite.viewport.rect.width = 64 + var
sprite.viewport.rect.x = 640 - sprite.viewport.rect.width
sprite.update
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update(x = 640, y = 10, step = 32)
counter = 0
for element in @array_of_sprites
sprite = Sprite.new(Viewport.new(x-64,y+(step*counter),
64, element.viewport.rect.height))
sprite.bitmap = element.bitmap
element.dispose
value = @array_count[counter]
var = (value.to_s.length - 1) * 11
sprite.bitmap.dispose
sprite.bitmap = @array_of_bitmaps[counter].dup
sprite.bitmap.draw_text(28,12,64,64,'x ' + value.to_s)
sprite.src_rect.width = 64 + var
sprite.viewport.rect.width = 64 + var
sprite.viewport.rect.x = 640 - sprite.viewport.rect.width
@array_of_sprites[counter] = sprite
sprite.update
counter += 1
end
end
#--------------------------------------------------------------------------
# * Hide
#--------------------------------------------------------------------------
def hide
for sprite in @array_of_sprites
sprite.visible = false
end
end
#--------------------------------------------------------------------------
# * Show
#--------------------------------------------------------------------------
def show
for sprite in @array_of_sprites
sprite.visible = true
end
end
#--------------------------------------------------------------------------
# * Score
#--------------------------------------------------------------------------
def score
temp = 0
for i in 0...@array_of_points.size
temp += @array_of_points[i] * @array_count[i]
end
return temp
end
#--------------------------------------------------------------------------
# * Disposal
#--------------------------------------------------------------------------
def dispose
for element in @array_of_sprites
element.dispose
end
for element in @array_of_bitmaps
element.dispose
end
@array_of_bitmaps.clear
@array_of_sprites.clear
#@array_of_points.clear
#@array_count.clear
end
end
Letter_Result_Menu
Code:
#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
# This class performs menu screen processing.
#==============================================================================
class Letter_Result_Menu
#--------------------------------------------------------------------------
# * Object Initialization
# menu_index : command cursor's initial position
#--------------------------------------------------------------------------
def initialize
@menu_index = 0
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make command window
s1 = "Okay"
@command_window = Window_Command.new(160, [s1])
@command_window.index = @menu_index
# Make letter window
@letters_window = Window_Letters.new
@letters_window.x = 0
@letters_window.y = 64
# Make letter amount window
@amount_window = Window_Letter_Amount.new
@amount_window.x = 0
@amount_window.y = 416
# Make results window
@results_window = Window_Letter_Results.new
@results_window.x = 160
@results_window.y = 64
# Make level window
@level_window = Window_Letter_Level.new
@level_window.x = 160
@level_window.y = 0
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
if $letter_minigame != nil
$letter_minigame.update
end
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@command_window.dispose
@letters_window.dispose
@amount_window.dispose
@results_window.dispose
@level_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update windows
@command_window.update
@letters_window.update
@results_window.update
@results_window.update
@level_window.update
# If command window is active: call update_command
if @command_window.active
update_command
return
end
# If status window is active: call update_status
if @status_window.active
update_status
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when command window is active)
#--------------------------------------------------------------------------
def update_command
# If B or C button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Dispose of $letter_minigame
$letter_minigame.dispose
# Switch to map screen
$scene = Scene_Map.new
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Dispose of $letter_minigame
$letter_minigame.dispose
# Switch to map screen
$scene = Scene_Map.new
return
end
end
end
Window_Letters
Code:
#==============================================================================
# ** Window_Letters
#------------------------------------------------------------------------------
# This window displays amount of each Letter.
#==============================================================================
class Window_Letters < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 160, 352)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
if $letter_minigame != nil
counter = 0
for sprite in $letter_minigame.array_of_sprites
self.contents.blt(0,-22+32*counter,sprite.bitmap,sprite.src_rect)
counter += 1
end
end
end
end
Window_Letter_Amount
Code:
#==============================================================================
# ** Window_Letter_Amount
#------------------------------------------------------------------------------
# This window displays the total amount of letters.
#==============================================================================
class Window_Letter_Amount < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 160, 64)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
word = $data_system.words.gold
if $game_party.gold == 1 then
word = word.chop
end
amount = 0
for element in $letter_minigame.array_count
amount += element
end
cx = contents.text_size(word).width
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, 120-cx-2, 32, amount.to_s, 2)
self.contents.font.color = system_color
self.contents.draw_text(124-cx, 0, cx, 32, word, 2)
end
end
Window_Letter_Results
Code:
#==============================================================================
# ** Window_Letter_Results
#------------------------------------------------------------------------------
# This window displays the score of the level and how it is computed.
#==============================================================================
class Window_Letter_Results < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 480, 416)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
if $letter_minigame != nil
array_count = $letter_minigame.array_count
array_of_points = $letter_minigame.array_of_points
array_of_sprites = $letter_minigame.array_of_sprites
counter = 0
sum = 0
for sprite in array_of_sprites
firstpart = (array_count[counter].to_s.length + 1) * 11 + 36
secondpart = (array_of_points[counter].to_s.length + 1) * 11
value = array_of_points[counter]
result = value * array_count[counter]
sum += result
y = 32*counter
if y > 351 then
y = 550
end
self.contents.blt(0,-22+y,sprite.bitmap,sprite.src_rect)
self.contents.draw_text(firstpart,-10+y,
480,64,'x ' + value.to_s)
self.contents.draw_text(firstpart + secondpart + 7,-10+y,
480,64,'= ' + result.to_s)
counter += 1
end
self.contents.draw_text(0,336,480,64, 'Total Score: ' + sum.to_s)
end
end
end
Window_Letter_Level
Code:
#==============================================================================
# ** Window_Letter_Level
#------------------------------------------------------------------------------
# This window displays some level information
#==============================================================================
class Window_Letter_Level < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 480, 64)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
text = $game_map.width.to_s + 'x' + $game_map.height.to_s + ' at speed ' +
$game_variables[2].to_s
self.contents.font.color = system_color
self.contents.draw_text(0,-16,480,64,text)
end
end
Instructions
Here I will try to explain how the scripts is used.
I have split this section in two.
One for the Maze Generator. This generates the maze and places the events.
This is not linked with the Letter Minigame.
One for the Letter Minigame. This controls the letters collected and the visual effects.
This is not linked with the Maze Generator. A normally made level could be used.
You can look at the scripts in the end of the scripts editor.
I have also edited some of the normal scripts in the demo. These has been marked by having a * in front of its name in the script chooser.
Maze Generator
Letter Minigame
The command $letter_minigame.score returns the score.
This works even after the $letter_minigame.dispose command is used.
That is because .dispose leaves the little information needed for calculation the score.
You can for example use this for giving prizes afterwards.
FAQ
How could I make a maze that has no timer on it with this script? Cause I wanna make a maze, and put a boss in it, but I want the maze to be randomized, and I don't want the timer either. The other thing is, how can I set this up so that I can have just the 1 boss event in it in a specific spot, and not have to worry about that spot being in a wall, or unreachable because the maze wasn't made right.
Long answer
How do I set up item prizes?
For example, if I had 250 points, I win a potion or something like that.
Using this command will return the score: $letter_minigame.score
For non-scripters you can use the Call Script command with $game_variables[10] = $letter_minigame.score, where the 10 is the variable number. Just set it to the number of the variable you want to use.
Now that you have the score in a variable I assume that you can do the rest.
.
Compatibility
Is not compatible with saving and loading. The map will reset if loaded.
Might be SDK compliant.
Credits and Thanks
I would like to thank RMXP – Underground personal for creating a scripting contest which inspired me to create this work.
I would like to thank everyone using their time to try this and finally I would like to thank everyone reading this topic.
Thanks.
Author's Notes
I suggest using Near Fantastica's anti event lag script due to the often high amount events.
This script can create more than 1000 events. I suggest however that you refrain from designing level where this is an eminent possibility.
Using the event command Erase Event will not entirely delete the event.
The event still exists in the $game_map.events and lags about as much as a blank events.
And finally: ENJOY!
- Zeriab