Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Sprite
- end
- class Table
- attr_reader :xsize, :ysize, :zsize
- # Creates a Table object. Specifies the size of each dimension in the multidimensional array. 1-, 2-, and 3-dimensional arrays are possible. Arrays with no parameters are also permitted.
- def initialize(xsize, ysize=1, zsize=1)
- @xsize = xsize
- @ysize = ysize
- @zsize = zsize
- @data = Array.new(@xsize*@ysize*@zsize, 0)
- end
- # Changes the size of the array. All data from before the size change is retained.
- def resize(xsize, ysize=1, zsize=1)
- xsize = [1, xsize].max
- ysize = [1, ysize].max
- zsize = [1, zsize].max
- copyX = [@xsize, xsize].min
- copyY = [@ysize, ysize].min
- copyZ = [@zsize, zsize].min
- data = Array.new(xsize * ysize * zsize, 0)
- (0...copyX).each {|x| (0...copyY).each {|y| (0...copyZ).each {|z|
- data[x + xsize * (y + ysize * z)] = @data[x + @xsize * (y + @ysize * z)];
- }}}
- @xsize = xsize
- @ysize = ysize
- @zsize = zsize
- @data = data
- end
- # :call-seq:
- # self[x]
- # self[x, y]
- # self[x, y, z]
- #
- # Accesses the array's elements. Pulls the same number of arguments as there are dimensions in the created array. Returns nil if the specified element does not exist.
- def [](x, y=0, z=0)
- return 0 if x >= @xsize or y >= @ysize
- v = @data[x + y * @xsize + z * @xsize * @ysize]
- return v == nil ? 0 : v
- end
- def []=(x, y=0, z=0, v) #:nodoc:
- @data[x + y * @xsize + z * @xsize * @ysize]=v
- end
- def self._load(s) #:nodoc:
- Table.new(1).instance_eval {
- @size, @xsize, @ysize, @zsize, xx, *@data = s.unpack('LLLLLS*')
- self
- }
- end
- def _dump(d = 0) #:nodoc:
- [@size, @xsize, @ysize, @zsize, @xsize*@ysize*@zsize, *@data].pack('LLLLLS*')
- end
- end
- class Tone
- def initialize(r, g, b, a = 0)
- @red = r
- @green = g
- @blue = b
- @gray = a
- end
- def set(r, g, b, a = 0)
- @red = r
- @green = g
- @blue = b
- @gray = a
- end
- def color
- Color.new(@red, @green, @blue, @gray)
- end
- def _dump(d = 0)
- [@red, @green, @blue, @gray].pack('d4')
- end
- def self._load(s)
- Tone.new(*s.unpack('d4'))
- end
- attr_accessor(:red, :green, :blue, :gray)
- end
- class Color
- def initialize(r, g, b, a = 255)
- @red = r
- @green = g
- @blue = b
- @alpha = a
- end
- def set(r, g, b, a = 255)
- @red = r
- @green = g
- @blue = b
- @alpha = a
- end
- def color
- Color.new(@red, @green, @blue, @alpha)
- end
- def _dump(d = 0)
- [@red, @green, @blue, @alpha].pack('d4')
- end
- def self._load(s)
- Color.new(*s.unpack('d4'))
- end
- attr_accessor(:red, :green, :blue, :alpha)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement