Advertisement
Zeriab

[RMXP] SLOLS

Mar 22nd, 2013
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 19.07 KB | None | 0 0
  1. #==============================================================================
  2. # ** Snake Look-alike on Loading Script
  3. #------------------------------------------------------------------------------
  4. # Zeriab
  5. # v 1.0
  6. # 28-09-2006
  7. #==============================================================================
  8.  
  9. class Scene_SLOLS
  10.   # The variable the number of dots collected will be stored
  11.   Cheese_Variable = 25
  12.   # The size of the margin in pixels
  13.   Margin = 10
  14.   # The thickness of the border in pixels
  15.   Border_Thickness = 3
  16.  
  17.   #--------------------------------------------------------------------------
  18.   # * Object Initialization
  19.   #--------------------------------------------------------------------------
  20.   def initialize(scene=Scene_Map.new)
  21.     @next_scene = scene
  22.   end
  23.  
  24.   #--------------------------------------------------------------------------
  25.   # * Main Processing
  26.   #--------------------------------------------------------------------------
  27.   def main
  28.     # Creates Bar Window (Loading bar)
  29.     @bar_window = Window_SLOLS_Bar.new
  30.     # Creates Info Window
  31.     @info_window = Window_SLOLS_Info.new(Margin, Border_Thickness, Cheese_Variable)
  32.     # Creates Game Window
  33.     @game_window = Window_SLOLS_Game.new(Margin, Border_Thickness, Cheese_Variable)
  34.     # Execute transition
  35.     Graphics.transition
  36.     # Scene Objects
  37.     @scene_objects = [@bar_window, @info_window, @game_window]
  38.     # Main loop
  39.     loop do
  40.       # Sleeps a short while to let the other thread work.
  41.       sleep(0.01)
  42.       # Update game screen
  43.       Graphics.update
  44.       # Update input information
  45.       Input.update
  46.       ## Frame update
  47.       update
  48.       # Abort loop if screen is changed
  49.       break if $scene != self
  50.     end
  51.     # Prepare for transition
  52.     Graphics.freeze
  53.     # Dispose Scene Objects
  54.     @scene_objects.each { |x| x.dispose }
  55.   end
  56.  
  57.   #--------------------------------------------------------------------------
  58.   # * Frame Update
  59.   #--------------------------------------------------------------------------
  60.   def update
  61.       # Updates Scene Objects
  62.       @scene_objects.each { |x| x.update }
  63.       # If B or C Button Is Pressed
  64.       if Input.trigger?(Input::B) || Input.trigger?(Input::C)
  65.         # If the loading thread is finished (not alive)
  66.         if !$loader.is_a?(Thread) || !$loader.alive?
  67.           # Play Decision SE
  68.           $game_system.se_play($data_system.decision_se)
  69.           # Switch to map screen
  70.           $scene = @next_scene
  71.           return
  72.         else
  73.           # Play Buzzer SE
  74.           $game_system.se_play($data_system.buzzer_se)
  75.           return
  76.         end
  77.       end
  78.   end
  79. end
  80.  
  81. #==============================================================================
  82. # ** Window_SLOLS_Info
  83. #==============================================================================
  84.  
  85.  
  86. class Window_SLOLS_Info
  87.   # Instructions
  88.   Instructs = [
  89.                 'Navigate using the','arrow keys.',
  90.                 'Collect green dots.',
  91.                 'This is done by','going into them.',
  92.                 'A sound will play','when the loading','is finished',
  93.                 '','Enter to continue'
  94.              ]
  95.  
  96.   #--------------------------------------------------------------------------
  97.   # * Object Initialization
  98.   #--------------------------------------------------------------------------
  99.   def initialize(margin, border_thickness, cheese_variable)
  100.     # The name of the arrow images
  101.     @arrow_file_names = ["Down_Arrow.png", "Left_Arrow.png",
  102.                          "Right_Arrow.png", "Up_Arrow.png"]
  103.     # The arrow images
  104.     @arrow_images = []
  105.     for i in 0..3
  106.       # Makes sure that the program keeps running if one or more of the files
  107.       # given don't exists. (read: wrong filename or missing file)
  108.       begin
  109.         # Reads the bitmap
  110.         bitmap = Bitmap.new('Graphics\\Pictures\\'+@arrow_file_names[i])
  111.       rescue Exception => ex
  112.         # Creates a blank 32x32 bitmap if the reading fails
  113.         bitmap = Bitmap.new(32,32)
  114.         # Prints the exception if in Debug mode.
  115.         if $DEBUG
  116.           p ex
  117.         end
  118.       end
  119.       # Pushes the resulting bitmap into the array
  120.       @arrow_images.push(bitmap)
  121.     end
  122.    
  123.     # The margin and border thickness
  124.     @margin = margin
  125.     @border_thickness = border_thickness
  126.     @cheese_variable = cheese_variable
  127.    
  128.     # Height with border excluding margin
  129.     @height = 416-@margin
  130.    
  131.     # The instructions Sprite
  132.     @instru = Sprite.new(Viewport.new(480 + @border_thickness,
  133.                         48 + @border_thickness,
  134.                         159 - @margin - @border_thickness*2,
  135.                         282 - @margin*4 + 4))
  136.     @instru.bitmap = Bitmap.new(159 - @margin - @border_thickness*2,
  137.                                282 - @margin*4 + 4)
  138.     @instru.bitmap.font.color = Color.new(225, 225, 225, 255)
  139.     @instru.bitmap.font.size = 20
  140.    
  141.    
  142.     # The main Sprite
  143.     @contents = Sprite.new(Viewport.new(480, 0, 160, @height))
  144.     @contents.bitmap = Bitmap.new(160, @height)
  145.     @contents.bitmap.font.color = Color.new(225, 225, 225, 255)
  146.     @contents.bitmap.font.size = 22
  147.     refresh
  148.   end
  149.  
  150.   #--------------------------------------------------------------------------
  151.   # * Refresh
  152.   #--------------------------------------------------------------------------
  153.   def refresh
  154.     # Simplifying the variables used
  155.     border = @border_thickness
  156.     spacing = @margin + border
  157.    
  158.     # Removes any old contents, garbage and so on.
  159.     @contents.bitmap.clear
  160.     # Draws the white block used for the border of the score
  161.     @contents.bitmap.fill_rect(0,@margin,159-@margin,22+border*2,
  162.                                 Color.new(225, 225, 225, 255))
  163.     # Draws the white block used for the border of the instructions
  164.     @contents.bitmap.fill_rect(0,48,159-@margin,282+border*2-@margin*4+4,
  165.                                 Color.new(225, 225, 225, 255))
  166.     # Draws a black block on the white block creating the border.
  167.     @contents.bitmap.fill_rect(border, 48+border,159-spacing-border,
  168.                                282-@margin*4+4, Color.new(0, 0, 0, 0))
  169.    
  170.     # Draws the left arrow
  171.     @contents.bitmap.blt(0,373-@margin,@arrow_images[1],Rect.new(0,0,43,43))
  172.     # Draws the down arrow
  173.     @contents.bitmap.blt(43+@margin,373-@margin,@arrow_images[0],
  174.                          Rect.new(0,0,43,43))
  175.     # Draws the right arrow
  176.     @contents.bitmap.blt(43*2+@margin*2,373-@margin,@arrow_images[2],
  177.                          Rect.new(0,0,43,43))
  178.     # Draws the up arrow
  179.     @contents.bitmap.blt(43+@margin,330-@margin*2,@arrow_images[3],
  180.                          Rect.new(0,0,43,43))
  181.    
  182.     # Draws the text 'Instructions:'
  183.     @contents.bitmap.draw_text(border, 48, 150-border*2, 22, 'Instructions',1)
  184.    
  185.     # Draws the intructions
  186.     for i in 0...Instructs.size
  187.       # Gets the string
  188.       str = Instructs[i]
  189.       # Draws the string
  190.       @instru.bitmap.draw_text(2, 22*(i+1), 150-border*2, 20, str,1)
  191.     end
  192.   end
  193.  
  194.   #--------------------------------------------------------------------------
  195.   # * Update
  196.   #--------------------------------------------------------------------------
  197.   def update
  198.     # Simplifying the variables used
  199.     border = @border_thickness
  200.     spacing = @margin + border
  201.     # Updates the sprite
  202.     @contents.update
  203.     # Removes old contents
  204.     @contents.bitmap.fill_rect(border, spacing, 159-spacing-border, 22,
  205.                                Color.new(0, 0, 0, 0))
  206.     # Draws the amount of dots collected
  207.     @contents.bitmap.draw_text(border, spacing, 153-spacing, 22,
  208.                                $game_variables[@cheese_variable].to_s, 2)
  209.     # Draws the text 'Dots:'
  210.     @contents.bitmap.draw_text(border+2, spacing, 157-spacing, 22, 'Dots:')
  211.   end
  212.  
  213.   #--------------------------------------------------------------------------
  214.   # * Dispose
  215.   #--------------------------------------------------------------------------
  216.   def dispose
  217.     @contents.bitmap.dispose
  218.     @contents.dispose
  219.   end
  220. end
  221.  
  222. #==============================================================================
  223. # ** Window_SLOLS_Game
  224. #==============================================================================
  225.  
  226. class Window_SLOLS_Game
  227.   #Player Settings
  228.   Size = 5
  229.   Default_Speed = 3
  230.   Trail_Length = 19
  231.  
  232.   #Cheese Settings
  233.   Cheese_Size = 3
  234.   Cheese_Colors = [Color.new(10,200,20,255)]
  235.   Max_Cheese_Amount = 200
  236.  
  237.   #--------------------------------------------------------------------------
  238.   # * Object Initialization
  239.   #--------------------------------------------------------------------------
  240.   def initialize(margin, border_thickness, cheese_variable)
  241.     # The margin and border thickness
  242.     @margin = margin
  243.     @border_thickness = border_thickness
  244.     @cheese_variable = cheese_variable
  245.    
  246.     # Width of the playing field
  247.     @width = 480-(@margin*2) - (@border_thickness*2)
  248.     # Height of the playing field
  249.     @height = 416-(@margin*2) - (@border_thickness*2)
  250.    
  251.     # Player info
  252.     @player_x = 200
  253.     @player_y = 208
  254.     @player_trail = []
  255.     @player_dir = 6   #2 - up, 4 - left, 6 - right, 8 - down
  256.     @speed = Default_Speed
  257.    
  258.     # The cheese array
  259.     @cheese = []
  260.     @cheese.push(make_cheese)
  261.     # The amount of cheese caught during this season.
  262.     @cheese_amount = 0
  263.    
  264.     # Create the Sprite for viewing the border
  265.     @border = Sprite.new(Viewport.new(@margin, @margin, 480-@margin, 416-@margin))
  266.     @border.bitmap = Bitmap.new(480-(@margin*2),416-(@margin*2))
  267.    
  268.     # Creates the main Sprite
  269.     @contents = Sprite.new(Viewport.new(@margin + @border_thickness,
  270.                                 @margin + @border_thickness, @width, @height))
  271.     @contents.bitmap = Bitmap.new(@width,@height)
  272.     # Refreshes
  273.     refresh
  274.     # Updates
  275.     update
  276.   end
  277.  
  278.   #--------------------------------------------------------------------------
  279.   # * Make Cheese
  280.   # ---------------------
  281.   # Generates a pointer to a place where a cheese will be at least 3 pixels
  282.   # away from the player
  283.   #--------------------------------------------------------------------------
  284.   def make_cheese
  285.     result = []
  286.     # Total size. (Sum of player size and cheese size)
  287.     size = Size + Cheese_Size
  288.    
  289.     loop do
  290.       # Generating the x and y coordinates
  291.       x = rand(@width - (size + 5)*2)
  292.       y = rand(@height - (size + 5)*2)
  293.      
  294.       # Adjusts the x and y coordinates so the cheese will not be
  295.       # placed in the player
  296.       if x > @width / 2 - (size + 5)
  297.         x += 2*(Size + 5)
  298.       end
  299.       if y > @height / 2 - (size + 5)
  300.         y += 2*(Size + 5)
  301.       end
  302.      
  303.       # Makes sure that no cheese exists in that exact same place
  304.       # Does not consider the size of the cheese.
  305.       if !@cheese.include?([x,y])
  306.         result = [x,y]
  307.         break
  308.       end
  309.     end
  310.    
  311.     return result
  312.   end
  313.  
  314.   #--------------------------------------------------------------------------
  315.   # * Check Player
  316.   # --------------------
  317.   # Checks if the player have caught a cheese. (Is touching one)
  318.   # Returns the indices of the cheese in an array
  319.   #--------------------------------------------------------------------------
  320.   def check_player
  321.     result = []
  322.     # Checks every cheese
  323.     for i in 0...@cheese.size
  324.       # Distance in the x-plane
  325.       d = (@cheese[i][0] - @player_x).abs
  326.       # Distance in the y-plane
  327.       d_y = (@cheese[i][1] - @player_y).abs
  328.       # Makes 'd' contain the largest distance
  329.       if d < d_y
  330.         d = d_y
  331.       end
  332.      
  333.       # If the largest distance is less than the size of the player and the
  334.       # cheese the player must be touching the cheese.
  335.       if d < (Size + Cheese_Size - 1)
  336.         result.push(i)
  337.       end
  338.     end
  339.     return result
  340.   end
  341.  
  342.   #--------------------------------------------------------------------------
  343.   # * Draw Cheese
  344.   #     i     : The index on the cheese
  345.   #     color : The color wanted for the cheese
  346.   # --------------------
  347.   # Draws the designated cheese with the given color
  348.   #--------------------------------------------------------------------------
  349.   def draw_cheese(i, color)
  350.     cheese = @cheese[i]
  351.     size = Cheese_Size
  352.     # Draws the cheese
  353.     @contents.bitmap.fill_rect(cheese[0]-(size-1),cheese[1]-(size-1),
  354.                             (size*2)-1, (size*2)-1, color)
  355.   end
  356.  
  357.   #--------------------------------------------------------------------------
  358.   # * Delete Cheese
  359.   #     i : The index on the cheese
  360.   # --------------------
  361.   # Deletes the cheese by first drawing it black and then removing the cheese
  362.   # from @cheese.
  363.   #--------------------------------------------------------------------------
  364.   def delete_cheese(i)
  365.     draw_cheese(i, Color.new(0,0,0,0))
  366.     @cheese.delete_at(i)
  367.   end
  368.  
  369.   #--------------------------------------------------------------------------
  370.   # * Refresh
  371.   #--------------------------------------------------------------------------
  372.   def refresh
  373.     @border.bitmap.clear
  374.     # Draws a white block
  375.     @border.bitmap.fill_rect(0,0,480-@margin, 416-@margin,Color.new(225, 225, 225, 255))
  376.     # Draws a smaller black block to give the border
  377.     @border.bitmap.fill_rect(@border_thickness, @border_thickness,
  378.                   @width, @height, Color.new(0, 0, 0, 0))
  379.   end
  380.  
  381.   #--------------------------------------------------------------------------
  382.   # * Update
  383.   #--------------------------------------------------------------------------
  384.   def update
  385.     @contents.update
  386.  
  387.     # Checks if the player gets any cheese
  388.     array = check_player
  389.     if array.size > 0
  390.       # Removes all the cheese
  391.       for i in array
  392.         # Cheese counters
  393.         $game_variables[@cheese_variable] += 1
  394.         @cheese_amount += 1
  395.         # Deletes the old cheese
  396.         delete_cheese(i)
  397.         # Creates a new one
  398.         @cheese.push(make_cheese)
  399.        
  400.         # Might create another one
  401.         if @cheese.size < Max_Cheese_Amount
  402.           # Creates an extra cheese if enough cheese have been caught
  403.           if @cheese_amount > @cheese.size * @cheese.size + 1
  404.             # Creates a new one
  405.             @cheese.push(make_cheese)
  406.           end
  407.         end
  408.       end
  409.     end
  410.    
  411.     # Draws the cheese
  412.     for i in 0...@cheese.size
  413.       draw_cheese(i, Color.new(10,200,20,255))
  414.     end
  415.    
  416.     # Makes sure the trail isn't too short
  417.     while @player_trail.size < Trail_Length
  418.       # Adds the player positions into the trail
  419.       @player_trail.push([@player_x,@player_y])
  420.     end
  421.    
  422.     coords = @player_trail.shift
  423.     # Draws the trail
  424.     @contents.bitmap.fill_rect(coords[0]-(Size-1),coords[1]-(Size-1),
  425.                           (Size*2)-1, (Size*2)-1, Color.new(0,0,0,255))
  426.     #Calculates the steps per shade
  427.     step = 200 / (Trail_Length)
  428.     for i in 0...Trail_Length-1
  429.       # Calculations
  430.       coords = @player_trail[i]
  431.       s = step*(Trail_Length-i)
  432.       # Draws the trail
  433.       @contents.bitmap.fill_rect(coords[0]-(Size-1),coords[1]-(Size-1),
  434.                           (Size*2)-1, (Size*2)-1, Color.new(200-s,200-s,100-(s/2),255))
  435.     end
  436.                          
  437.     # Draws the player
  438.     @contents.bitmap.fill_rect(@player_x-(Size-1),@player_y-(Size-1),
  439.                             (Size*2)-1, (Size*2)-1, Color.new(200,200,100,255))
  440.    
  441.     # If UP Is Pressed
  442.     if Input.trigger?(Input::UP)
  443.       @player_dir = 8 unless @player_dir == 2
  444.     end
  445.     # If DOWN Is Pressed
  446.     if Input.trigger?(Input::DOWN)
  447.       @player_dir = 2 unless @player_dir == 8
  448.     end
  449.     # If LEFT Is Pressed
  450.     if Input.trigger?(Input::LEFT)
  451.       @player_dir = 4 unless @player_dir == 6
  452.     end
  453.     # If RIGHT Is Pressed
  454.     if Input.trigger?(Input::RIGHT)
  455.       @player_dir = 6 unless @player_dir == 4
  456.     end
  457.    
  458.     # Moves the player accordingly to the directions
  459.     case @player_dir
  460.     when 8  # Down
  461.       @player_y -= @speed
  462.     when 2  # Up
  463.       @player_y += @speed
  464.     when 4  # Left
  465.       @player_x -= @speed
  466.     when 6  # Right
  467.       @player_x += @speed
  468.     end
  469.     # Warping the player
  470.     @player_x = (@player_x) % @width
  471.     @player_y = (@player_y) % @height
  472.   end
  473.  
  474.   #--------------------------------------------------------------------------
  475.   # * Dispose
  476.   #--------------------------------------------------------------------------
  477.   def dispose
  478.     @contents.bitmap.dispose
  479.     @contents.dispose
  480.   end
  481. end
  482.  
  483. #==============================================================================
  484. # ** Window_SLOLS_Bar
  485. #==============================================================================
  486.  
  487. class Window_SLOLS_Bar
  488.   #--------------------------------------------------------------------------
  489.   # * Object Initialization
  490.   #--------------------------------------------------------------------------
  491.   def initialize
  492.     @contents = Sprite.new(Viewport.new(0, 416, 640, 64))
  493.     @contents.bitmap = Bitmap.new(640, 64)
  494.     @left_block = Sprite.new(Viewport.new(540-48, 424, 48, 48))
  495.     @left_block.bitmap = Bitmap.new(64, 64)
  496.     @right_block = Sprite.new(Viewport.new(100, 424, 48, 48))
  497.     @right_block.bitmap = Bitmap.new(640, 64)
  498.     @blocks = [@left_block, @right_block]
  499.     @bar = Sprite.new(Viewport.new(270, 446, 100, 4))
  500.     @bar.bitmap = Bitmap.new(200, 4)
  501.     @bar_f = Sprite.new(Viewport.new(270, 446, 100, 4))
  502.     @bar_f.bitmap = Bitmap.new(100, 4)
  503.     @bar_fx = 0
  504.    
  505.     # The sprites used
  506.     @sprites = [@contents,@bar,@bar_f]
  507.    
  508.     refresh
  509.   end
  510.  
  511.   #--------------------------------------------------------------------------
  512.   # * Refresh
  513.   #--------------------------------------------------------------------------
  514.   def refresh
  515.     @contents.bitmap.clear
  516.     bar_color = Color.new(225,225,225,255)
  517.     fin_color = Color.new(255,255,0,0)
  518.     @bar.bitmap.fill_rect(0,0,25,4,bar_color)
  519.     @bar.bitmap.fill_rect(50,0,25,4,bar_color)
  520.     @bar.bitmap.fill_rect(100,0,25,4,bar_color)
  521.     @bar.bitmap.fill_rect(150,0,25,4,bar_color)
  522.     @bar_f.bitmap.fill_rect(0,0,100,4,fin_color)
  523.     @blocks.each {|x| x.bitmap.fill_rect(0,0,64,64,fin_color)}
  524.   end
  525.  
  526.   #--------------------------------------------------------------------------
  527.   # * Update
  528.   #--------------------------------------------------------------------------
  529.   def update
  530.     @bar.ox -= 1
  531.     @bar.ox = @bar.ox % 100
  532.     @bar.update
  533.     if @bar_fx == 0 && (!$loader.is_a?(Thread) || !$loader.alive?)
  534.       @bar_fx = 1
  535.       @count = 3
  536.       $game_system.se_play($data_system.load_se)
  537.     end
  538.     if @bar_fx > 0 && @bar_fx < 255
  539.       @bar_fx += @count
  540.       @bar_f.bitmap.fill_rect(0,0,100,4,Color.new(255,255,0,@bar_fx))
  541.       @blocks.each {|x| x.bitmap.fill_rect(0,0,48,48,Color.new(255,255,0,@bar_fx))}
  542.       case @bar_fx
  543.       when 10..20
  544.         @count = 50
  545.       when 180..230
  546.         @count = 5
  547.       end
  548.     end
  549.   end
  550.  
  551.   #--------------------------------------------------------------------------
  552.   # * Dispose
  553.   #--------------------------------------------------------------------------
  554.   def dispose
  555.     @sprites.each { |x| x.bitmap.dispose}
  556.     @sprites.each { |x| x.dispose}
  557.   end
  558. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement