Guest User

Untitled

a guest
Jun 3rd, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.39 KB | None | 0 0
  1. module Csk_Parallax
  2.   def self.parallax_sprite
  3.     spr = Parallax_sprite.new
  4.     $game_map.parallax_sprites << spr
  5.     return spr
  6.   end
  7. end
  8.  
  9. class Parallax_Sprite
  10.   attr_accessor :active, :visible, :filename, :opacity,
  11.                 :x, :y, :ox, :oy, :parallax_x, :parallax_y
  12.   def initialize
  13.     clear
  14.   end
  15.  
  16.   def clear
  17.     @active = false
  18.     @visible = true
  19.     @filename = ""
  20.     @opacity = 255
  21.     @x = 0
  22.     @y = 0
  23.     @z = -100000
  24.     @ox = 0
  25.     @oy = 0
  26.     @parallax_x = 1.0
  27.     @parallax_y = 1.0
  28.     @sprite = nil
  29.     @remove_x = 0
  30.     @remove_y = 0
  31.   end
  32.  
  33.   def setup(filename)
  34.     @active = true
  35.     @filename = filename
  36.    
  37.     @sprite ||= Sprite.new(@viewport)
  38.     @sprite.bitmap     = Cache.picture(@filename)
  39.     @sprite.visible    = @visible
  40.     w = @sprite.bitmap.width
  41.     h = @sprite.bitmap.height
  42.     @sprite.x          = @x - $game_map.display_x * @parallax_x * 32
  43.     @sprite.y          = @y - $game_map.display_y * @parallax_y * 32
  44.     @sprite.z          = @z
  45.     @sprite.ox         = @ox * w
  46.     @sprite.oy         = @oy * h
  47.     @sprite.opacity    = @opacity
  48.   end
  49.  
  50.   def set_pos(x, y)
  51.     @x = x
  52.     @y = y
  53.   end
  54.  
  55.   def set_origin(ox, oy)
  56.     @ox = ox
  57.     @oy = oy
  58.   end
  59.  
  60.   def set_parallax(x, y)
  61.     @parallax_x = x
  62.     @parallax_y = y
  63.   end
  64.  
  65.   def set_opacity(opacity)
  66.     @opacity = opacity
  67.   end
  68.  
  69.   def set_z(z)
  70.     @z = z
  71.     @sprite.z = @z unless @sprite == nil
  72.   end
  73.  
  74.   def set_remove_pos(x, y)
  75.     @remove_x = x
  76.     @remove_y = y
  77.   end
  78.  
  79.   def update
  80.     if @sprite != nil
  81.       @sprite.x = @x - $game_map.display_x * @parallax_x * 32
  82.       @sprite.y = @y - $game_map.display_y * @parallax_y * 32
  83.       @sprite.update unless @sprite
  84.      
  85.       @active = false if (@remove_x != 0 and @sprite.x < @remove_x)
  86.       @active = false if (@remove_y != 0 and @sprite.y < @remove_y)
  87.     end
  88.   end
  89. end
  90.  
  91. class Game_Map
  92.   attr_reader :parallax_sprites
  93.  
  94.   alias csk_parallax_setup setup
  95.   def setup(map_id)
  96.     csk_parallax_setup(map_id)
  97.     @parallax_sprites  ||= []
  98.   end
  99.  
  100.   alias csk_parallax_update update
  101.   def update(*args)
  102.     csk_parallax_update(*args)
  103.     @parallax_sprites.each {|data|
  104.       data.update
  105.       @parallax_sprites.delete(data) unless data.active
  106.     }
  107.   end
  108.  
  109.   def parallax_sprite
  110.     spr = Parallax_Sprite.new
  111.     @parallax_sprites << spr
  112.     return spr
  113.   end
  114. end
Advertisement
Add Comment
Please, Sign In to add comment