+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+---- Forum: RPGMaker XP (RGSS) Engine (https://www.save-point.org/forum-116.html)
+---- Thread: SLOLS: Snake Look-alike on Load Script (/thread-2486.html)
SLOLS: Snake Look-alike on Load Script - Zeriab - 03-06-2008
Snake Look-alike on Load Script
Version: 1.0
Introduction
The SLOLS has been made by Zeriab.
Thanks goes to RMXP for making this possible
Credits should be given.
The purpose of SLOLS is to provide the player an opportunity to interact with something during loading sequences. I think the loading time will not seem as long as normally if the player as something to do while the program is loading.
They don't experience the time it takes to load as bad even though the script reduced the loading speed.
In the game itself the principle is to collect dots by moving a bigger dot into them. There is no time limit. There is no way to die or get stuck or etc. Steering is done by the arrow keys.
When the loading is finished a sound will be played and visual aids will be used to let the player know that the loading is finished.
The player can then continue by pressing a trigger key (fx. ENTER)
There is no need to press enter. The player can play the game as long as he or she wants unless the script loaded does something that changes this.
Screenshots
Demo
The demo has been combined with my Letter Ninigame to show a example of use.
If the Letter Minigame is used credits mentionen in the Letter Minigame should be given.
#==============================================================================
# ** Snake Look-alike on Loading Script
#------------------------------------------------------------------------------
# Zeriab
# v 1.0
# 28-09-2006
#==============================================================================
class Scene_SLOLS
# The variable the number of dots collected will be stored
Cheese_Variable = 25
# The size of the margin in pixels
Margin = 10
# The thickness of the border in pixels
Border_Thickness = 3
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(scene=Scene_Map.new)
@next_scene = scene
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Creates Bar Window (Loading bar)
@bar_window = Window_SLOLS_Bar.new
# Creates Info Window
@info_window = Window_SLOLS_Info.new(Margin, Border_Thickness, Cheese_Variable)
# Creates Game Window
@game_window = Window_SLOLS_Game.new(Margin, Border_Thickness, Cheese_Variable)
# Execute transition
Graphics.transition
# Scene Objects
@scene_objects = [@bar_window, @info_window, @game_window]
# Main loop
loop do
# Sleeps a short while to let the other thread work.
sleep(0.01)
# Update game screen
Graphics.update
# Update input information
Input.update
## Frame update
update
# Abort loop if screen is changed
break if $scene != self
end
# Prepare for transition
Graphics.freeze
# Dispose Scene Objects
@scene_objects.each { |x| x.dispose }
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Updates Scene Objects
@scene_objects.each { |x| x.update }
# If B or C Button Is Pressed
if Input.trigger?(Input::B) || Input.trigger?(Input::C)
# If the loading thread is finished (not alive)
if !$loader.is_a?(Thread) || !$loader.alive?
# Play Decision SE
$game_system.se_play($data_system.decision_se)
# Switch to map screen
$scene = @next_scene
return
else
# Play Buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
end
end
end
# Width of the playing field
@width = 480-(@margin*2) - (@border_thickness*2)
# Height of the playing field
@height = 416-(@margin*2) - (@border_thickness*2)
# Player info
@player_x = 200
@player_y = 208
@player_trail = []
@player_dir = 6 #2 - up, 4 - left, 6 - right, 8 - down
@speed = Default_Speed
# The cheese array
@cheese = []
@cheese.push(make_cheese)
# The amount of cheese caught during this season.
@cheese_amount = 0
# Create the Sprite for viewing the border
@border = Sprite.new(Viewport.new(@margin, @margin, 480-@margin, 416-@margin))
@border.bitmap = Bitmap.new(480-(@margin*2),416-(@margin*2))
# Creates the main Sprite
@contents = Sprite.new(Viewport.new(@margin + @border_thickness,
@margin + @border_thickness, @width, @height))
@contents.bitmap = Bitmap.new(@width,@height)
# Refreshes
refresh
# Updates
update
end
#--------------------------------------------------------------------------
# * Make Cheese
# ---------------------
# Generates a pointer to a place where a cheese will be at least 3 pixels
# away from the player
#--------------------------------------------------------------------------
def make_cheese
result = []
# Total size. (Sum of player size and cheese size)
size = Size + Cheese_Size
loop do
# Generating the x and y coordinates
x = rand(@width - (size + 5)*2)
y = rand(@height - (size + 5)*2)
# Adjusts the x and y coordinates so the cheese will not be
# placed in the player
if x > @width / 2 - (size + 5)
x += 2*(Size + 5)
end
if y > @height / 2 - (size + 5)
y += 2*(Size + 5)
end
# Makes sure that no cheese exists in that exact same place
# Does not consider the size of the cheese.
if !@cheese.include?([x,y])
result = [x,y]
break
end
end
return result
end
#--------------------------------------------------------------------------
# * Check Player
# --------------------
# Checks if the player have caught a cheese. (Is touching one)
# Returns the indices of the cheese in an array
#--------------------------------------------------------------------------
def check_player
result = []
# Checks every cheese
for i in 0...@cheese.size
# Distance in the x-plane
d = (@cheese[i][0] - @player_x).abs
# Distance in the y-plane
d_y = (@cheese[i][1] - @player_y).abs
# Makes 'd' contain the largest distance
if d < d_y
d = d_y
end
# If the largest distance is less than the size of the player and the
# cheese the player must be touching the cheese.
if d < (Size + Cheese_Size - 1)
result.push(i)
end
end
return result
end
#--------------------------------------------------------------------------
# * Draw Cheese
# i : The index on the cheese
# color : The color wanted for the cheese
# --------------------
# Draws the designated cheese with the given color
#--------------------------------------------------------------------------
def draw_cheese(i, color)
cheese = @cheese[i]
size = Cheese_Size
# Draws the cheese
@contents.bitmap.fill_rect(cheese[0]-(size-1),cheese[1]-(size-1),
(size*2)-1, (size*2)-1, color)
end
#--------------------------------------------------------------------------
# * Delete Cheese
# i : The index on the cheese
# --------------------
# Deletes the cheese by first drawing it black and then removing the cheese
# from @cheese.
#--------------------------------------------------------------------------
def delete_cheese(i)
draw_cheese(i, Color.new(0,0,0,0))
@cheese.delete_at(i)
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
@border.bitmap.clear
# Draws a white block
@border.bitmap.fill_rect(0,0,480-@margin, 416-@margin,Color.new(225, 225, 225, 255))
# Draws a smaller black block to give the border
@border.bitmap.fill_rect(@border_thickness, @border_thickness,
@width, @height, Color.new(0, 0, 0, 0))
end
# Checks if the player gets any cheese
array = check_player
if array.size > 0
# Removes all the cheese
for i in array
# Cheese counters
$game_variables[@cheese_variable] += 1
@cheese_amount += 1
# Deletes the old cheese
delete_cheese(i)
# Creates a new one
@cheese.push(make_cheese)
# Might create another one
if @cheese.size < Max_Cheese_Amount
# Creates an extra cheese if enough cheese have been caught
if @cheese_amount > @cheese.size * @cheese.size + 1
# Creates a new one
@cheese.push(make_cheese)
end
end
end
end
# Draws the cheese
for i in 0...@cheese.size
draw_cheese(i, Color.new(10,200,20,255))
end
# Makes sure the trail isn't too short
while @player_trail.size < Trail_Length
# Adds the player positions into the trail
@player_trail.push([@player_x,@player_y])
end
coords = @player_trail.shift
# Draws the trail
@contents.bitmap.fill_rect(coords[0]-(Size-1),coords[1]-(Size-1),
(Size*2)-1, (Size*2)-1, Color.new(0,0,0,255))
#Calculates the steps per shade
step = 200 / (Trail_Length)
for i in 0...Trail_Length-1
# Calculations
coords = @player_trail[i]
s = step*(Trail_Length-i)
# Draws the trail
@contents.bitmap.fill_rect(coords[0]-(Size-1),coords[1]-(Size-1),
(Size*2)-1, (Size*2)-1, Color.new(200-s,200-s,100-(s/2),255))
end
# Draws the player
@contents.bitmap.fill_rect(@player_x-(Size-1),@player_y-(Size-1),
(Size*2)-1, (Size*2)-1, Color.new(200,200,100,255))
# If UP Is Pressed
if Input.trigger?(Input::UP)
@player_dir = 8 unless @player_dir == 2
end
# If DOWN Is Pressed
if Input.trigger?(Input::DOWN)
@player_dir = 2 unless @player_dir == 8
end
# If LEFT Is Pressed
if Input.trigger?(Input::LEFT)
@player_dir = 4 unless @player_dir == 6
end
# If RIGHT Is Pressed
if Input.trigger?(Input::RIGHT)
@player_dir = 6 unless @player_dir == 4
end
# Moves the player accordingly to the directions
case @player_dir
when 8 # Down
@player_y -= @speed
when 2 # Up
@player_y += @speed
when 4 # Left
@player_x -= @speed
when 6 # Right
@player_x += @speed
end
# Warping the player
@player_x = (@player_x) % @width
@player_y = (@player_y) % @height
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
@contents.bitmap.dispose
@contents.dispose
end
end
class Window_SLOLS_Info
# Instructions
Instructs = [
'Navigate using the','arrow keys.',
'Collect green dots.',
'This is done by','going into them.',
'A sound will play','when the loading','is finished',
'','Enter to continue'
]
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(margin, border_thickness, cheese_variable)
# The name of the arrow images
@arrow_file_names = ["Down_Arrow.png", "Left_Arrow.png",
"Right_Arrows.png", "Up_Arrow.png"]
# The arrow images
@arrow_images = []
for i in 0..3
# Makes sure that the program keeps running if one or more of the files
# given don't exists. (read: wrong filename or missing file)
begin
# Reads the bitmap
bitmap = Bitmap.new('Graphics\\Pictures\\'+@arrow_file_names[i])
rescue Exception => ex
# Creates a blank 32x32 bitmap if the reading fails
bitmap = Bitmap.new(32,32)
# Prints the exception if in Debug mode.
if $DEBUG
p ex
end
end
# Pushes the resulting bitmap into the array
@arrow_images.push(bitmap)
end
# The margin and border thickness
@margin = margin
@border_thickness = border_thickness
@cheese_variable = cheese_variable
# Height with border excluding margin
@height = 416-@margin
# The main Sprite
@contents = Sprite.new(Viewport.new(480, 0, 160, @height))
@contents.bitmap = Bitmap.new(160, @height)
@contents.bitmap.font.color = Color.new(225, 225, 225, 255)
@contents.bitmap.font.size = 22
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
# Simplifying the variables used
border = @border_thickness
spacing = @margin + border
# Removes any old contents, garbage and so on.
@contents.bitmap.clear
# Draws the white block used for the border of the score
@contents.bitmap.fill_rect(0,@margin,159-@margin,22+border*2,
Color.new(225, 225, 225, 255))
# Draws the white block used for the border of the instructions
@contents.bitmap.fill_rect(0,48,159-@margin,282+border*2-@margin*4+4,
Color.new(225, 225, 225, 255))
# Draws a black block on the white block creating the border.
@contents.bitmap.fill_rect(border, 48+border,159-spacing-border,
282-@margin*4+4, Color.new(0, 0, 0, 0))
# Draws the left arrow
@contents.bitmap.blt(0,373-@margin,@arrow_images[1],Rect.new(0,0,43,43))
# Draws the down arrow
@contents.bitmap.blt(43+@margin,373-@margin,@arrow_images[0],
Rect.new(0,0,43,43))
# Draws the right arrow
@contents.bitmap.blt(43*2+@margin*2,373-@margin,@arrow_images[2],
Rect.new(0,0,43,43))
# Draws the up arrow
@contents.bitmap.blt(43+@margin,330-@margin*2,@arrow_images[3],
Rect.new(0,0,43,43))
# Draws the text 'Instructions:'
@contents.bitmap.draw_text(border, 48, 150-border*2, 22, 'Instructions',1)
# Draws the intructions
for i in 0...Instructs.size
# Gets the string
str = Instructs[i]
# Draws the string
@instru.bitmap.draw_text(2, 22*(i+1), 150-border*2, 20, str,1)
end
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update
# Simplifying the variables used
border = @border_thickness
spacing = @margin + border
# Updates the sprite
@contents.update
# Removes old contents
@contents.bitmap.fill_rect(border, spacing, 159-spacing-border, 22,
Color.new(0, 0, 0, 0))
# Draws the amount of dots collected
@contents.bitmap.draw_text(border, spacing, 153-spacing, 22,
$game_variables[@cheese_variable].to_s, 2)
# Draws the text 'Dots:'
@contents.bitmap.draw_text(border+2, spacing, 157-spacing, 22, 'Dots:')
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
@contents.bitmap.dispose
@contents.dispose
end
end
Instructions
You must have these pictures in your graphics\pictures folder or the arrow keys shown on the picture will be missing:
The Script:
This script used the global variable $loader.
It can run without $loader being initialized in which case the script considers the loading as done.
To use $loader you must set it to a Thread. The syntax is:
Thread.new( [arg]* ) {| args | block } -> aThread (Reference)
An example: $loader = Thread.new { MyClass.new }
To get the SLOLS scene use this syntax: $scene = Scene_SLOLS.new(scene=Scene_Map.new) scene will be used to set the scene that comes after Scene_SLOLS. The scene to be used after finished loading and player pressing trigger.
An example; syntax for standard scene: (Scene_Map)
Code:
$scene = Scene_SLOLS.new
# or
$scene = Scene_SLOLS.new(Scene_Map.new)
The script will store the amount of dots in the variable number specified by Cheese_Variable in Scene_SLOLS. (Near top)
There also are the Margin (in pixels) and the Border_Thickness (in pixels).
Changing these may break the design. The info bar with the instructions is a bit fragile.
FAQ
None yet
Compatibility
Should be independent which increases compatibility.
Credits and Thanks
I would like to thank everyone using their time to try and use SLOLS.
I would like to thank everyone reading this topic.
Thanks.
Author's Notes
I don't recommend letting the script being 'loaded' change the $scene as makes the SLOLS stop rather suddenly from my point of view (Players position).
And finally: ENJOY!
- Zeriab
SLOLS: Snake Look-alike on Load Script - neonjosa123 - 10-29-2009
Is this Plug and Play?
SLOLS: Snake Look-alike on Load Script - Zeriab - 10-29-2009
You have to use a script like
Code:
$scene = Scene_SLOLS.new
But otherwise it's plug and play ^^
Note that variable 25 is used if you simply plug it in.
#==============================================================================
# ** Snake Look-alike on Loading Script
#------------------------------------------------------------------------------
# Zeriab
# v 1.0
# 28-09-2006
#==============================================================================
class Scene_SLOLS
# The variable the number of dots collected will be stored
Cheese_Variable = 25
# The size of the margin in pixels
Margin = 10
# The thickness of the border in pixels
Border_Thickness = 3
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(scene=Scene_Map.new)
@next_scene = scene
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Creates Bar Window (Loading bar)
@bar_window = Window_SLOLS_Bar.new
# Creates Info Window
info = [Margin, Border_Thickness, Cheese_Variable]
@info_window = Window_SLOLS_Info.new(*info)
# Creates Game Window
@game_window = Window_SLOLS_Game.new(*info)
# Execute transition
Graphics.transition
# Scene Objects
@scene_objects = [@bar_window, @info_window, @game_window]
# Main loop
while $scene == self
# Sleeps a short while to let the other thread work.
sleep(0.01)
# Update game screen
Graphics.update
# Update input information
Input.update
## Frame update
update
end
# Prepare for transition
Graphics.freeze
# Dispose Scene Objects
@scene_objects.each { |x| x.dispose }
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Updates Scene Objects
@scene_objects.each { |x| x.update }
# If B or C Button Is Pressed
if Input.trigger?(Input::B) || Input.trigger?(Input::C)
# If the loading thread is finished (not alive)
if !$loader.is_a?(Thread) || !$loader.alive?
# Play Decision SE
$game_system.se_play($data_system.decision_se)
# Switch to map screen
$scene = @next_scene
return
else
# Play Buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
end
end
end
class Window_SLOLS_Info
# Instructions
Instructs = [
'Navigate using the','arrow keys.',
'Collect green dots.',
'This is done by','going into them.',
'A sound will play','when the loading','is finished',
'','Enter to continue'
]
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(margin, border_thickness, cheese_variable)
# The name of the arrow images
@arrow_file_names = ["Down_Arrow.png", "Left_Arrow.png",
"Right_Arrow.png", "Up_Arrow.png"]
# The windowskin images
@windowskin = RPG::Cache.windowskin($game_system.windowskin_name)
# The arrow images
@arrow_images = []
for i in 0..3
# Makes sure that the program keeps running if one or more of the files
# given don't exists. (read: wrong filename or missing file)
begin
# Reads the bitmap
bitmap = Bitmap.new('Graphics\\Pictures\\'+@arrow_file_names[i])
rescue Exception => ex
# Creates a blank 32x32 bitmap and Blt windowskin arrows if the
# reading fails
bitmap = Bitmap.new(32,32)
# Arrow down
bitmap.blt(0,0,@windowskin,Rect.new(128,128,32,-32))if [0,1].include?(i)
# Arrow up
bitmap.blt(0,0,@windowskin,Rect.new(128,96,32,32)) if [3,2].include?(i)
# Arrow left or Arrow right
if [1,2].include?(i)
# Clone the Arrow
copy = bitmap.clone
# Rotate 90 degrees clockwise
32.times do |j|
32.times {|k| bitmap.set_pixel(32-j-1,k, copy.get_pixel(k, j))}
end
# Dispose clone
copy.dispose
end
# Prints the exception if in Debug mode.
if $DEBUG
p ex
end
rescue Exception => ex
# Creates a blank 32x32 bitmap if the reading fails
bitmap = Bitmap.new(32,32)
# Prints the exception if in Debug mode.
if $DEBUG
p ex
end
end
# Pushes the resulting bitmap into the array
@arrow_images.push(bitmap)
end
# Dispose windowskin
@windowskin.dispose
# The margin and border thickness
@margin = margin
@border_thickness = border_thickness
@cheese_variable = cheese_variable
# Height with border excluding margin
@height = 416-@margin
# The main Sprite
@contents = Sprite.new(Viewport.new(480, 0, 160, @height))
@contents.bitmap = Bitmap.new(160, @height)
@contents.bitmap.font.color = Color.new(225, 225, 225, 255)
@contents.bitmap.font.size = 22
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
# Simplifying the variables used
border = @border_thickness
spacing = @margin + border
# Removes any old contents, garbage and so on.
@contents.bitmap.clear
# Draws the white block used for the border of the score
@contents.bitmap.fill_rect(0,@margin,159-@margin,22+border*2,
Color.new(225, 225, 225, 255))
# Draws the white block used for the border of the instructions
@contents.bitmap.fill_rect(0,48,159-@margin,282+border*2-@margin*4+4,
Color.new(225, 225, 225, 255))
# Draws a black block on the white block creating the border.
@contents.bitmap.fill_rect(border, 48+border,159-spacing-border,
282-@margin*4+4, Color.new(0, 0, 0, 0))
# Draws the left arrow
@contents.bitmap.blt(0,373-@margin,@arrow_images[1],Rect.new(0,0,43,43))
# Draws the down arrow
@contents.bitmap.blt(43+@margin,373-@margin,@arrow_images[0],
Rect.new(0,0,43,43))
# Draws the right arrow
@contents.bitmap.blt(43*2+@margin*2,373-@margin,@arrow_images[2],
Rect.new(0,0,43,43))
# Draws the up arrow
@contents.bitmap.blt(43+@margin,330-@margin*2,@arrow_images[3],
Rect.new(0,0,43,43))
# Draws the text 'Instructions:'
@contents.bitmap.draw_text(border, 48, 150-border*2, 22, 'Instructions',1)
# Draws the intructions
for i in 0...Instructs.size
# Gets the string
str = Instructs[i]
# Draws the string
@instru.bitmap.draw_text(2, 22*(i+1), 150-border*2, 20, str,1)
end
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update
# Simplifying the variables used
border = @border_thickness
spacing = @margin + border
# Updates the sprite
@contents.update
# Removes old contents
@contents.bitmap.fill_rect(border, spacing, 159-spacing-border, 22,
Color.new(0, 0, 0, 0))
# Draws the amount of dots collected
@contents.bitmap.draw_text(border, spacing, 153-spacing, 22,
$game_variables[@cheese_variable].to_s, 2)
# Draws the text 'Dots:'
@contents.bitmap.draw_text(border+2, spacing, 157-spacing, 22, 'Dots:')
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
@contents.bitmap.dispose
@contents.dispose
end
end
# Width of the playing field
@width = 480-(@margin*2) - (@border_thickness*2)
# Height of the playing field
@height = 416-(@margin*2) - (@border_thickness*2)
# Player info
@player_x = 200
@player_y = 208
@player_trail = []
@player_dir = 6 #2 - up, 4 - left, 6 - right, 8 - down
@speed = Default_Speed
# The cheese array
@cheese = []
@cheese.push(make_cheese)
# The amount of cheese caught during this season.
@cheese_amount = 0
# Create the Sprite for viewing the border
view = @margin, @margin, 480-@margin, 416-@margin
@border = Sprite.new(Viewport.new(*view))
@border.bitmap = Bitmap.new(480-(@margin*2),416-(@margin*2))
# Creates the main Sprite
@contents = Sprite.new(Viewport.new(@margin + @border_thickness,
@margin + @border_thickness, @width, @height))
@contents.bitmap = Bitmap.new(@width,@height)
# Refreshes
refresh
# Updates
update
end
#--------------------------------------------------------------------------
# * Make Cheese
# ---------------------
# Generates a pointer to a place where a cheese will be at least 3 pixels
# away from the player
#--------------------------------------------------------------------------
def make_cheese
result = []
# Total size. (Sum of player size and cheese size)
size = Size + Cheese_Size
loop do
# Generating the x and y coordinates
x = rand(@width - (size + 5)*2)
y = rand(@height - (size + 5)*2)
# Adjusts the x and y coordinates so the cheese will not be
# placed in the player
x += 2*(Size + 5) if x > @width / 2 - (size + 5)
y += 2*(Size + 5) if y > @height / 2 - (size + 5)
# Makes sure that no cheese exists in that exact same place
# Does not consider the size of the cheese.
if !@cheese.include?([x,y])
result = [x,y]
break
end
end
return result
end
#--------------------------------------------------------------------------
# * Check Player
# --------------------
# Checks if the player have caught a cheese. (Is touching one)
# Returns the indices of the cheese in an array
#--------------------------------------------------------------------------
def check_player
result = []
# Checks every cheese
for i in 0...@cheese.size
# Distance in the x-plane
d = (@cheese[i][0] - @player_x).abs
# Distance in the y-plane
d_y = (@cheese[i][1] - @player_y).abs
# Makes 'd' contain the largest distance
d = d_y if d < d_y
# If the largest distance is less than the size of the player and the
# cheese the player must be touching the cheese.
result.push(i) if d < (Size + Cheese_Size - 1)
end
return result
end
#--------------------------------------------------------------------------
# * Draw Cheese
# i : The index on the cheese
# color : The color wanted for the cheese
# --------------------
# Draws the designated cheese with the given color
#--------------------------------------------------------------------------
def draw_cheese(i, color)
cheese = @cheese[i]
size = Cheese_Size
# Draws the cheese
@contents.bitmap.fill_rect(cheese[0]-(size-1),cheese[1]-(size-1),
(size*2)-1, (size*2)-1, color)
end
#--------------------------------------------------------------------------
# * Delete Cheese
# i : The index on the cheese
# --------------------
# Deletes the cheese by first drawing it black and then removing the cheese
# from @cheese.
#--------------------------------------------------------------------------
def delete_cheese(i)
draw_cheese(i, Color.new(0,0,0,0))
@cheese.delete_at(i)
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
@border.bitmap.clear
# Draws a white block
@border.bitmap.fill_rect(0,0,480-@margin, 416-@margin,
Color.new(225, 225, 225, 255))
# Draws a smaller black block to give the border
@border.bitmap.fill_rect(@border_thickness, @border_thickness,
@width, @height, Color.new(0, 0, 0, 0))
end
# Checks if the player gets any cheese
array = check_player
if array.size > 0
# Removes all the cheese
for i in array
# Cheese counters
$game_variables[@cheese_variable] += 1
@cheese_amount += 1
# Deletes the old cheese
delete_cheese(i)
# Creates a new one
@cheese.push(make_cheese)
# Might create another one
if @cheese.size < Max_Cheese_Amount
# Creates an extra cheese if enough cheese have been caught
if @cheese_amount > @cheese.size * @cheese.size + 1
# Creates a new one
@cheese.push(make_cheese)
end
end
end
end
# Draws the cheese
for i in 0...@cheese.size
draw_cheese(i, Color.new(10,200,20,255))
end
# Makes sure the trail isn't too short
while @player_trail.size < Trail_Length
# Adds the player positions into the trail
@player_trail.push([@player_x,@player_y])
end
coords = @player_trail.shift
# Draws the trail
@contents.bitmap.fill_rect(coords[0]-(Size-1),coords[1]-(Size-1),
(Size*2)-1, (Size*2)-1, Color.new(0,0,0,255))
#Calculates the steps per shade
step = 200 / (Trail_Length)
for i in 0...Trail_Length-1
# Calculations
coords = @player_trail[i]
s = step*(Trail_Length-i)
# Draws the trail
@contents.bitmap.fill_rect(coords[0]-(Size-1),coords[1]-(Size-1),
(Size*2)-1, (Size*2)-1,
Color.new(200-s,200-s,100-(s/2),255))
end
# Draws the player
@contents.bitmap.fill_rect(@player_x-(Size-1),@player_y-(Size-1),
(Size*2)-1, (Size*2)-1, Color.new(200,200,100,255))
# If UP Is Pressed
if Input.trigger?(Input::UP)
@player_dir = 8 unless @player_dir == 2
end
# If DOWN Is Pressed
if Input.trigger?(Input::DOWN)
@player_dir = 2 unless @player_dir == 8
end
# If LEFT Is Pressed
if Input.trigger?(Input::LEFT)
@player_dir = 4 unless @player_dir == 6
end
# If RIGHT Is Pressed
if Input.trigger?(Input::RIGHT)
@player_dir = 6 unless @player_dir == 4
end
# Moves the player accordingly to the directions
case @player_dir
when 8 then @player_y -= @speed # Down
when 2 then @player_y += @speed # Up
when 4 then @player_x -= @speed # Left
when 6 then @player_x += @speed # Right
end
# Warping the player
@player_x = (@player_x) % @width
@player_y = (@player_y) % @height
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
@contents.bitmap.dispose
@contents.dispose
end
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update
@bar.ox -= 1
@bar.ox = @bar.ox % 100
@bar.update
if @bar_fx == 0 && (!$loader.is_a?(Thread) || !$loader.alive?)
@bar_fx = 1
@count = 3
$game_system.se_play($data_system.load_se)
end
if @bar_fx > 0 && @bar_fx < 255
@bar_fx += @count
@bar_f.bitmap.fill_rect(0,0,100,4,Color.new(255,255,0,@bar_fx))
@blocks.each do |x|
x.bitmap.fill_rect(0,0,48,48,Color.new(255,255,0,@bar_fx))
end
case @bar_fx
when 10..20 then @count = 50
when 180..230 then @count = 5
end
end
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
@sprites.each { |x| x.bitmap.dispose}
@sprites.each { |x| x.dispose}
end
end
Also..... VX ACE version :
SLOLS VXAce
Code:
#==============================================================================
# ** Snake Look-alike on Loading Script (VXAce Ver)
# - Original by Zeriab (v 1.0) - 28-09-2006
# - VXAce ver by LiTTleDRAgo (v 1.0ace) - 15-05-2017
#------------------------------------------------------------------------------
#
# EXAMPLE :
# SceneManager.SLOLS
# - or -
# SceneManager.SLOLS(Scene_Map.new)
#
#==============================================================================
class Scene_SLOLS
# The variable the number of dots collected will be stored
Cheese_Variable = 25
# The size of the margin in pixels
Margin = 10
# The thickness of the border in pixels
Border_Thickness = 3
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(scene=Scene_Map.new)
# Sorry, this minigame only for resolution 640 x 480
@resolution = [Graphics.width,Graphics.height]
Graphics.resize_screen(640,480) if @resolution != [640,480]
@next_scene = scene
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Creates Bar Window (Loading bar)
@bar_window = Window_SLOLS_Bar.new
# Creates Info Window
info = [Margin, Border_Thickness, Cheese_Variable]
@info_window = Window_SLOLS_Info.new(*info)
# Creates Game Window
@game_window = Window_SLOLS_Game.new(*info)
# Execute transition
Graphics.transition
# Scene Objects
@scene_objects = [@bar_window, @info_window, @game_window]
# Main loop
while SceneManager.scene == self
# Sleeps a short while to let the other thread work.
sleep(0.01)
# Update game screen
Graphics.update
# Update input information
Input.update
## Frame update
update
end
# Prepare for transition
Graphics.freeze
# Dispose Scene Objects
@scene_objects.each { |x| x.dispose }
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Updates Scene Objects
@scene_objects.each { |x| x.update }
# If B or C Button Is Pressed
if Input.trigger?(Input::B) || Input.trigger?(Input::C)
# If the loading thread is finished (not alive)
if !$loader.is_a?(Thread) || !$loader.alive?
# Play Decision SE
Sound.play_ok
# Switch to map screen
SceneManager.send(:instance_variable_set,:@scene,@next_scene)
# Camouflage the screen
@sprite_black = Sprite.new
@sprite_black.bitmap = (s = Graphics.snap_to_bitmap)
@sprite_black.bitmap.fill_rect(s.rect,Color.new(0,0,0))
@scene_objects << @sprite_black.bitmap << @sprite_black
# Revert resolution
Graphics.resize_screen(*@resolution) if @resolution != [640,480]
return
else
# Play Buzzer SE
Sound.play_buzzer
return
end
end
end
end
#==============================================================================
# ** SceneManager
#------------------------------------------------------------------------------
# This module manages scene transitions. For example, it can handle
# hierarchical structures such as calling the item screen from the main menu
# or returning from the item screen to the main menu.
#==============================================================================
module SceneManager
#--------------------------------------------------------------------------
# * Direct Transition
#--------------------------------------------------------------------------
def self.SLOLS(scene_class = nil)
@stack.push(@scene) if scene_class
temp = @scene
@scene = Scene_SLOLS.new(scene_class ? scene_class : temp)
end
end
class Window_SLOLS_Info
# Instructions
Instructs = [
'Navigate using the','arrow keys.',
'Collect green dots.',
'This is done by','going into them.',
'A sound will play','when the loading','is finished',
'','Enter to continue'
]
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(margin, border_thickness, cheese_variable)
# The name of the arrow images
@arrow_file_names = ["Down_Arrow.png", "Left_Arrow.png",
"Right_Arrow.png", "Up_Arrow.png"]
# The windowskin images
@windowskin = Cache.tileset("Inside_B")
# The arrow images
@arrow_images = []
for i in 0..3
# Makes sure that the program keeps running if one or more of the files
# given don't exists. (read: wrong filename or missing file)
begin
# Reads the bitmap
bitmap = Bitmap.new('Graphics\\Pictures\\'+@arrow_file_names[i])
rescue
# Creates a blank 32x32 bitmap and Blt windowskin arrows if the
# reading fails
bitmap = Bitmap.new(32,32)
# Arrow down
bitmap.blt(0,0,@windowskin,Rect.new(128,96,32,-32))if [0,1].include?(i)
# Arrow up
bitmap.blt(0,0,@windowskin,Rect.new(128,64,32,32)) if [3,2].include?(i)
# Arrow left or Arrow right
if [1,2].include?(i)
# Clone the Arrow
copy = bitmap.clone
# Rotate 90 degrees clockwise
32.times do |j|
32.times {|k| bitmap.set_pixel(32-j-1,k, copy.get_pixel(k, j))}
end
# Dispose clone
copy.dispose
end
rescue Exception => ex
# Creates a blank 32x32 bitmap if the reading fails
bitmap = Bitmap.new(32,32)
# Prints the exception if in Debug mode.
if $DEBUG
p ex
end
end
# Pushes the resulting bitmap into the array
@arrow_images.push(bitmap)
end
# Dispose windowskin
@windowskin.dispose
# The margin and border thickness
@margin = margin
@border_thickness = border_thickness
@cheese_variable = cheese_variable
# Height with border excluding margin
@height = 416-@margin
# The main Sprite
@contents = Sprite.new(Viewport.new(480, 0, 160, @height))
@contents.bitmap = Bitmap.new(160, @height)
@contents.bitmap.font.color = Color.new(225, 225, 225, 255)
@contents.bitmap.font.size = 22
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
# Simplifying the variables used
border = @border_thickness
spacing = @margin + border
# Removes any old contents, garbage and so on.
@contents.bitmap.clear
# Draws the white block used for the border of the score
@contents.bitmap.fill_rect(0,@margin,159-@margin,22+border*2,
Color.new(225, 225, 225, 255))
# Draws the white block used for the border of the instructions
@contents.bitmap.fill_rect(0,48,159-@margin,282+border*2-@margin*4+4,
Color.new(225, 225, 225, 255))
# Draws a black block on the white block creating the border.
@contents.bitmap.fill_rect(border, 48+border,159-spacing-border,
282-@margin*4+4, Color.new(0, 0, 0, 0))
# Draws the left arrow
@contents.bitmap.blt(0,373-@margin,@arrow_images[1],Rect.new(0,0,43,43))
# Draws the down arrow
@contents.bitmap.blt(43+@margin,373-@margin,@arrow_images[0],
Rect.new(0,0,43,43))
# Draws the right arrow
@contents.bitmap.blt(43*2+@margin*2,373-@margin,@arrow_images[2],
Rect.new(0,0,43,43))
# Draws the up arrow
@contents.bitmap.blt(43+@margin,330-@margin*2,@arrow_images[3],
Rect.new(0,0,43,43))
# Draws the text 'Instructions:'
@contents.bitmap.draw_text(border, 48, 150-border*2, 22, 'Instructions',1)
# Draws the intructions
for i in 0...Instructs.size
# Gets the string
str = Instructs[i]
# Draws the string
@instru.bitmap.draw_text(2, 22*(i+1), 150-border*2, 20, str,1)
end
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update
# Simplifying the variables used
border = @border_thickness
spacing = @margin + border
# Updates the sprite
@contents.update
# Removes old contents
@contents.bitmap.fill_rect(border, spacing, 159-spacing-border, 22,
Color.new(0, 0, 0, 0))
# Draws the amount of dots collected
@contents.bitmap.draw_text(border, spacing, 153-spacing, 22,
$game_variables[@cheese_variable].to_s, 2)
# Draws the text 'Dots:'
@contents.bitmap.draw_text(border+2, spacing, 157-spacing, 22, 'Dots:')
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
@contents.bitmap.dispose
@contents.dispose
end
end
# Width of the playing field
@width = 480-(@margin*2) - (@border_thickness*2)
# Height of the playing field
@height = 416-(@margin*2) - (@border_thickness*2)
# Player info
@player_x = 200
@player_y = 208
@player_trail = []
@player_dir = 6 #2 - up, 4 - left, 6 - right, 8 - down
@speed = Default_Speed
# The cheese array
@cheese = []
@cheese.push(make_cheese)
# The amount of cheese caught during this season.
@cheese_amount = 0
# Create the Sprite for viewing the border
view = @margin, @margin, 480-@margin, 416-@margin
@border = Sprite.new(Viewport.new(*view))
@border.bitmap = Bitmap.new(480-(@margin*2),416-(@margin*2))
# Creates the main Sprite
@contents = Sprite.new(Viewport.new(@margin + @border_thickness,
@margin + @border_thickness, @width, @height))
@contents.bitmap = Bitmap.new(@width,@height)
# Refreshes
refresh
# Updates
update
end
#--------------------------------------------------------------------------
# * Make Cheese
# ---------------------
# Generates a pointer to a place where a cheese will be at least 3 pixels
# away from the player
#--------------------------------------------------------------------------
def make_cheese
result = []
# Total size. (Sum of player size and cheese size)
size = Size + Cheese_Size
loop do
# Generating the x and y coordinates
x = rand(@width - (size + 5)*2)
y = rand(@height - (size + 5)*2)
# Adjusts the x and y coordinates so the cheese will not be
# placed in the player
x += 2*(Size + 5) if x > @width / 2 - (size + 5)
y += 2*(Size + 5) if y > @height / 2 - (size + 5)
# Makes sure that no cheese exists in that exact same place
# Does not consider the size of the cheese.
if !@cheese.include?([x,y])
result = [x,y]
break
end
end
return result
end
#--------------------------------------------------------------------------
# * Check Player
# --------------------
# Checks if the player have caught a cheese. (Is touching one)
# Returns the indices of the cheese in an array
#--------------------------------------------------------------------------
def check_player
result = []
# Checks every cheese
for i in 0...@cheese.size
# Distance in the x-plane
d = (@cheese[i][0] - @player_x).abs
# Distance in the y-plane
d_y = (@cheese[i][1] - @player_y).abs
# Makes 'd' contain the largest distance
d = d_y if d < d_y
# If the largest distance is less than the size of the player and the
# cheese the player must be touching the cheese.
result.push(i) if d < (Size + Cheese_Size - 1)
end
return result
end
#--------------------------------------------------------------------------
# * Draw Cheese
# i : The index on the cheese
# color : The color wanted for the cheese
# --------------------
# Draws the designated cheese with the given color
#--------------------------------------------------------------------------
def draw_cheese(i, color)
cheese = @cheese[i]
size = Cheese_Size
# Draws the cheese
@contents.bitmap.fill_rect(cheese[0]-(size-1),cheese[1]-(size-1),
(size*2)-1, (size*2)-1, color)
end
#--------------------------------------------------------------------------
# * Delete Cheese
# i : The index on the cheese
# --------------------
# Deletes the cheese by first drawing it black and then removing the cheese
# from @cheese.
#--------------------------------------------------------------------------
def delete_cheese(i)
draw_cheese(i, Color.new(0,0,0,0))
@cheese.delete_at(i)
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
@border.bitmap.clear
# Draws a white block
@border.bitmap.fill_rect(0,0,480-@margin, 416-@margin,
Color.new(225, 225, 225, 255))
# Draws a smaller black block to give the border
@border.bitmap.fill_rect(@border_thickness, @border_thickness,
@width, @height, Color.new(0, 0, 0, 0))
end
# Checks if the player gets any cheese
array = check_player
if array.size > 0
# Removes all the cheese
for i in array
# Cheese counters
$game_variables[@cheese_variable] += 1
@cheese_amount += 1
# Deletes the old cheese
delete_cheese(i)
# Creates a new one
@cheese.push(make_cheese)
# Might create another one
if @cheese.size < Max_Cheese_Amount
# Creates an extra cheese if enough cheese have been caught
if @cheese_amount > @cheese.size * @cheese.size + 1
# Creates a new one
@cheese.push(make_cheese)
end
end
end
end
# Draws the cheese
for i in 0...@cheese.size
draw_cheese(i, Color.new(10,200,20,255))
end
# Makes sure the trail isn't too short
while @player_trail.size < Trail_Length
# Adds the player positions into the trail
@player_trail.push([@player_x,@player_y])
end
coords = @player_trail.shift
# Draws the trail
@contents.bitmap.fill_rect(coords[0]-(Size-1),coords[1]-(Size-1),
(Size*2)-1, (Size*2)-1, Color.new(0,0,0,255))
#Calculates the steps per shade
step = 200 / (Trail_Length)
for i in 0...Trail_Length-1
# Calculations
coords = @player_trail[i]
s = step*(Trail_Length-i)
# Draws the trail
@contents.bitmap.fill_rect(coords[0]-(Size-1),coords[1]-(Size-1),
(Size*2)-1, (Size*2)-1,
Color.new(200-s,200-s,100-(s/2),255))
end
# Draws the player
@contents.bitmap.fill_rect(@player_x-(Size-1),@player_y-(Size-1),
(Size*2)-1, (Size*2)-1, Color.new(200,200,100,255))
# If UP Is Pressed
if Input.trigger?(Input::UP)
@player_dir = 8 unless @player_dir == 2
end
# If DOWN Is Pressed
if Input.trigger?(Input::DOWN)
@player_dir = 2 unless @player_dir == 8
end
# If LEFT Is Pressed
if Input.trigger?(Input::LEFT)
@player_dir = 4 unless @player_dir == 6
end
# If RIGHT Is Pressed
if Input.trigger?(Input::RIGHT)
@player_dir = 6 unless @player_dir == 4
end
# Moves the player accordingly to the directions
case @player_dir
when 8 then @player_y -= @speed # Down
when 2 then @player_y += @speed # Up
when 4 then @player_x -= @speed # Left
when 6 then @player_x += @speed # Right
end
# Warping the player
@player_x = (@player_x) % @width
@player_y = (@player_y) % @height
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
@contents.bitmap.dispose
@contents.dispose
end
end