khanhdu

CSCA_Title System

Jun 4th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.72 KB | None | 0 0
  1. =begin
  2. CSCA Title System
  3. version: 1.0.0 (Released: January 11, 2013)
  4. Created by: Casper Gaming (http://www.caspergaming.com/)
  5.  
  6. Compatibility:
  7. Made for RPGVXAce
  8. IMPORTANT: ALL CSCA Scripts should be compatible with each other unless
  9. otherwise noted.
  10.  
  11. WHAT IT DOES:
  12. Modifies the title screen to cycle through maps as well as the title image. The
  13. maps are actual map files and can use events to tint screen and show weatehr
  14. effects/aniamtions. You can also use CSCA Light Effects in the title maps (other
  15. light effect scripts may work, but are not tested).
  16.  
  17. SETUP
  18. Set up required. Instructions below.
  19.  
  20. CREDIT:
  21. Free to use in noncommercial games if credit is given to:
  22. Casper Gaming (http://www.caspergaming.com/)
  23.  
  24. To use in a commercial game, please purchase a license here:
  25. http://www.caspergaming.com/licenses.html
  26.  
  27. TERMS:
  28. http://www.caspergaming.com/terms_of_use.html
  29. =end
  30. module CSCA
  31.   module TS
  32.     MAPS = [2,3,4,5,6] # Array of map ID's to cycle through.
  33.    
  34.     CONTINUOUS = false # Skip title image showing after complete map cycle?
  35.     IDLE_TIME = 600 # Time in frames to wait before fading to maps from title image.
  36.     MAP_TIME = 600 # Time in frames to wait before cycling to next map.
  37.    
  38.     TRANSITION_SPEED = 5 # Speed of the title image fade in/out
  39.     FADE_SPEED = 20 # Speed of the map fade in/out
  40.   end
  41. end
  42. $imported = {} if $imported.nil?
  43. $imported["CSCA-TitleSystem"] = true
  44. #==============================================================================
  45. # ** Scene_Title
  46. #------------------------------------------------------------------------------
  47. # This class performs the title screen processing.
  48. #Aliases: start, terminate, command_new_game
  49. #==============================================================================
  50. class Scene_Title < Scene_Base
  51.   #--------------------------------------------------------------------------
  52.   # Alias Method; start
  53.   #--------------------------------------------------------------------------
  54.   alias :csca_ts_start :start
  55.   def start
  56.     csca_ts_start
  57.     @map_number.nil? ? @map_number = 0 : hide_image
  58.     @image_timer = 0 if @image_timer.nil?
  59.     @map_timer = 0 if @map_timer.nil?
  60.     csca_create_map(CSCA::TS::MAPS[@map_number]) if @map_timer == 0
  61.     create_spriteset
  62.     set_z_values
  63.   end
  64.   #--------------------------------------------------------------------------
  65.   # Alias Method; terminate
  66.   #--------------------------------------------------------------------------
  67.   alias :csca_ts_terminate :terminate
  68.   def terminate
  69.     csca_ts_terminate
  70.     dispose_spriteset
  71.   end
  72.   #--------------------------------------------------------------------------
  73.   # Alias Method; command_new_game
  74.   #--------------------------------------------------------------------------
  75.   alias :csca_ts_new_game :command_new_game
  76.   def command_new_game
  77.     close_command_window
  78.     fadeout_all
  79.     csca_ts_new_game
  80.   end
  81.   #--------------------------------------------------------------------------
  82.   # Update
  83.   #--------------------------------------------------------------------------
  84.   def update
  85.     super
  86.     update_timers
  87.     update_image
  88.     update_map_cycle
  89.     $game_map.update(true)
  90.     @spriteset.update
  91.   end
  92.   #--------------------------------------------------------------------------
  93.   # Update timers
  94.   #--------------------------------------------------------------------------
  95.   def update_timers
  96.     @image_timer += 1
  97.     @map_timer += 1 if @image_timer > CSCA::TS::IDLE_TIME
  98.   end
  99.   #--------------------------------------------------------------------------
  100.   # Update image opacity
  101.   #--------------------------------------------------------------------------
  102.   def update_image
  103.     if @image_timer >= CSCA::TS::IDLE_TIME && !image_opacity(0)
  104.       update_hide_image
  105.     elsif @image_timer <= CSCA::TS::IDLE_TIME && !image_opacity(255)
  106.       update_show_image
  107.     end
  108.   end
  109.   #--------------------------------------------------------------------------
  110.   # Update map cycle
  111.   #--------------------------------------------------------------------------
  112.   def update_map_cycle
  113.     do_fade
  114.     if @map_timer == CSCA::TS::MAP_TIME
  115.       @map_timer = 0
  116.       if @map_number == CSCA::TS::MAPS.size - 1
  117.         @image_timer = 0 unless CSCA::TS::CONTINUOUS
  118.         @map_number = 0
  119.         @map_made = false
  120.         @cycle_done = true if CSCA::TS::CONTINUOUS
  121.       else
  122.         @map_number += 1
  123.       end
  124.       csca_create_map(CSCA::TS::MAPS[@map_number]) unless @image_timer == 0
  125.     end
  126.     if image_opacity(255) && @map_number == 0 && @map_made == false
  127.       csca_create_map(CSCA::TS::MAPS[@map_number])
  128.     end
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # Hide title image
  132.   #--------------------------------------------------------------------------
  133.   def update_hide_image
  134.     @sprite1.opacity -= CSCA::TS::TRANSITION_SPEED
  135.     @sprite2.opacity -= CSCA::TS::TRANSITION_SPEED
  136.     @foreground_sprite.opacity -= CSCA::TS::TRANSITION_SPEED
  137.   end
  138.   #--------------------------------------------------------------------------
  139.   # Hide title image
  140.   #--------------------------------------------------------------------------
  141.   def update_show_image
  142.     @sprite1.opacity += CSCA::TS::TRANSITION_SPEED
  143.     @sprite2.opacity += CSCA::TS::TRANSITION_SPEED
  144.     @foreground_sprite.opacity += CSCA::TS::TRANSITION_SPEED
  145.   end
  146.   #--------------------------------------------------------------------------
  147.   # Compare image opacity
  148.   #--------------------------------------------------------------------------
  149.   def image_opacity(opacity)
  150.     @sprite1.opacity == opacity && @sprite2.opacity == opacity && @foreground_sprite.opacity == opacity
  151.   end
  152.   #--------------------------------------------------------------------------
  153.   # Load map
  154.   #--------------------------------------------------------------------------
  155.   def csca_create_map(map)
  156.     $game_map.setup(map)
  157.     @map_made = true
  158.   end
  159.   #--------------------------------------------------------------------------
  160.   # Create Sprite Set
  161.   #--------------------------------------------------------------------------
  162.   def create_spriteset
  163.     @spriteset = Spriteset_Map.new
  164.   end
  165.   #--------------------------------------------------------------------------
  166.   # Free Sprite Set
  167.   #--------------------------------------------------------------------------
  168.   def dispose_spriteset
  169.     @spriteset.dispose
  170.   end
  171.   #--------------------------------------------------------------------------
  172.   # Set sprite z values
  173.   #--------------------------------------------------------------------------
  174.   def set_z_values
  175.     @sprite1.z = 6
  176.     @sprite2.z = 6
  177.     @foreground_sprite.z = 7
  178.   end
  179.   #--------------------------------------------------------------------------
  180.   # Immediately hide image
  181.   #--------------------------------------------------------------------------
  182.   def hide_image
  183.     return if @image_timer < CSCA::TS::IDLE_TIME
  184.     @sprite1.opacity = 0
  185.     @sprite2.opacity = 0
  186.     @foreground_sprite.opacity = 0
  187.   end
  188.   #--------------------------------------------------------------------------
  189.   # Handle when to fade in/out
  190.   #--------------------------------------------------------------------------
  191.   def do_fade
  192.     return if CSCA::TS::MAPS.size == 1
  193.     if @map_timer == 1 && @map_number > 0 || @cycle_done
  194.       Graphics.wait(CSCA::TS::FADE_SPEED / 2)
  195.       fadein(CSCA::TS::FADE_SPEED)
  196.       @cycle_done = false
  197.     elsif @map_timer == CSCA::TS::MAP_TIME - CSCA::TS::FADE_SPEED && (@map_number != CSCA::TS::MAPS.size - 1 || CSCA::TS::CONTINUOUS)
  198.       fadeout(CSCA::TS::FADE_SPEED)
  199.     end
  200.   end
  201.   #--------------------------------------------------------------------------
  202.   # General-Purpose Fade Processing
  203.   #--------------------------------------------------------------------------
  204.   def fade_loop(duration)
  205.     duration.times do |i|
  206.       yield 255 * (i + 1) / duration
  207.       update_for_fade
  208.     end
  209.   end
  210.   #--------------------------------------------------------------------------
  211.   # Fadein Screen
  212.   #--------------------------------------------------------------------------
  213.   def fadein(duration)
  214.     fade_loop(duration) {|v| Graphics.brightness = v }
  215.   end
  216.   #--------------------------------------------------------------------------
  217.   # Fadeout Screen
  218.   #--------------------------------------------------------------------------
  219.   def fadeout(duration)
  220.     fade_loop(duration) {|v| Graphics.brightness = 255 - v }
  221.   end
  222.   #--------------------------------------------------------------------------
  223.   # Update Frame (for Fade In)
  224.   #--------------------------------------------------------------------------
  225.   def update_for_fade
  226.     update_basic
  227.     $game_map.update(false)
  228.     @spriteset.update
  229.   end
  230. end
Advertisement
Add Comment
Please, Sign In to add comment