Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ** 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
- #==============================================================================
- # ** Window_SLOLS_Info
- #==============================================================================
- 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 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 instructions Sprite
- @instru = Sprite.new(Viewport.new(480 + @border_thickness,
- 48 + @border_thickness,
- 159 - @margin - @border_thickness*2,
- 282 - @margin*4 + 4))
- @instru.bitmap = Bitmap.new(159 - @margin - @border_thickness*2,
- 282 - @margin*4 + 4)
- @instru.bitmap.font.color = Color.new(225, 225, 225, 255)
- @instru.bitmap.font.size = 20
- # 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
- #==============================================================================
- # ** Window_SLOLS_Game
- #==============================================================================
- class Window_SLOLS_Game
- #Player Settings
- Size = 5
- Default_Speed = 3
- Trail_Length = 19
- #Cheese Settings
- Cheese_Size = 3
- Cheese_Colors = [Color.new(10,200,20,255)]
- Max_Cheese_Amount = 200
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(margin, border_thickness, cheese_variable)
- # The margin and border thickness
- @margin = margin
- @border_thickness = border_thickness
- @cheese_variable = cheese_variable
- # 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
- #--------------------------------------------------------------------------
- # * Update
- #--------------------------------------------------------------------------
- def update
- @contents.update
- # 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
- #==============================================================================
- # ** Window_SLOLS_Bar
- #==============================================================================
- class Window_SLOLS_Bar
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize
- @contents = Sprite.new(Viewport.new(0, 416, 640, 64))
- @contents.bitmap = Bitmap.new(640, 64)
- @left_block = Sprite.new(Viewport.new(540-48, 424, 48, 48))
- @left_block.bitmap = Bitmap.new(64, 64)
- @right_block = Sprite.new(Viewport.new(100, 424, 48, 48))
- @right_block.bitmap = Bitmap.new(640, 64)
- @blocks = [@left_block, @right_block]
- @bar = Sprite.new(Viewport.new(270, 446, 100, 4))
- @bar.bitmap = Bitmap.new(200, 4)
- @bar_f = Sprite.new(Viewport.new(270, 446, 100, 4))
- @bar_f.bitmap = Bitmap.new(100, 4)
- @bar_fx = 0
- # The sprites used
- @sprites = [@contents,@bar,@bar_f]
- refresh
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- @contents.bitmap.clear
- bar_color = Color.new(225,225,225,255)
- fin_color = Color.new(255,255,0,0)
- @bar.bitmap.fill_rect(0,0,25,4,bar_color)
- @bar.bitmap.fill_rect(50,0,25,4,bar_color)
- @bar.bitmap.fill_rect(100,0,25,4,bar_color)
- @bar.bitmap.fill_rect(150,0,25,4,bar_color)
- @bar_f.bitmap.fill_rect(0,0,100,4,fin_color)
- @blocks.each {|x| x.bitmap.fill_rect(0,0,64,64,fin_color)}
- 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 {|x| x.bitmap.fill_rect(0,0,48,48,Color.new(255,255,0,@bar_fx))}
- case @bar_fx
- when 10..20
- @count = 50
- when 180..230
- @count = 5
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Dispose
- #--------------------------------------------------------------------------
- def dispose
- @sprites.each { |x| x.bitmap.dispose}
- @sprites.each { |x| x.dispose}
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement