Class: Badline::VIC::Sprite
- Inherits:
-
Object
- Object
- Badline::VIC::Sprite
- Defined in:
- lib/badline/vic/sprite.rb
Constant Summary collapse
- X_OFFSET =
104- ROWS =
21
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#line_pixels ⇒ Object
readonly
Returns the value of attribute line_pixels.
Instance Method Summary collapse
- #color ⇒ Object
- #displaying? ⇒ Boolean
- #enabled? ⇒ Boolean
-
#initialize(index, registers, bank, width) ⇒ Sprite
constructor
A new instance of Sprite.
- #leftmost ⇒ Object
- #multicolor? ⇒ Boolean
- #pixel(raster_x) ⇒ Object
- #pixel_width ⇒ Object
- #priority? ⇒ Boolean
- #start_line(line) ⇒ Object
- #x ⇒ Object
- #x_expanded? ⇒ Boolean
- #y ⇒ Object
- #y_expanded? ⇒ Boolean
Constructor Details
#initialize(index, registers, bank, width) ⇒ Sprite
Returns a new instance of Sprite.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/badline/vic/sprite.rb', line 11 def initialize(index, registers, bank, width) @index = index @registers = registers @bank = bank @width = width @bit = 1 << index @displaying = false @counter = 0 @bits = nil @line_pixels = nil @pixel_buffer = Array.new(48) end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
9 10 11 |
# File 'lib/badline/vic/sprite.rb', line 9 def index @index end |
#line_pixels ⇒ Object (readonly)
Returns the value of attribute line_pixels.
9 10 11 |
# File 'lib/badline/vic/sprite.rb', line 9 def line_pixels @line_pixels end |
Instance Method Details
#color ⇒ Object
38 |
# File 'lib/badline/vic/sprite.rb', line 38 def color = @registers[0x27 + index] & 0x0f |
#displaying? ⇒ Boolean
24 |
# File 'lib/badline/vic/sprite.rb', line 24 def = @displaying |
#enabled? ⇒ Boolean
26 |
# File 'lib/badline/vic/sprite.rb', line 26 def enabled? = @registers[0x15].anybits?(@bit) |
#leftmost ⇒ Object
40 |
# File 'lib/badline/vic/sprite.rb', line 40 def leftmost = (x + X_OFFSET) % @width |
#multicolor? ⇒ Boolean
27 |
# File 'lib/badline/vic/sprite.rb', line 27 def multicolor? = @registers[0x1c].anybits?(@bit) |
#pixel(raster_x) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/badline/vic/sprite.rb', line 62 def pixel(raster_x) return nil unless @line_pixels dist = raster_x - leftmost dist += @width if dist.negative? dist < pixel_width ? @line_pixels[dist] : nil end |
#pixel_width ⇒ Object
41 |
# File 'lib/badline/vic/sprite.rb', line 41 def pixel_width = ? 48 : 24 |
#priority? ⇒ Boolean
30 |
# File 'lib/badline/vic/sprite.rb', line 30 def priority? = @registers[0x1b].anybits?(@bit) |
#start_line(line) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/badline/vic/sprite.rb', line 43 def start_line(line) if !@displaying && enabled? && line == y @displaying = true @counter = 0 end return @line_pixels = nil unless @displaying row = ? @counter / 2 : @counter if row >= ROWS @displaying = false return @line_pixels = nil end @counter += 1 fetch(row) decode_line end |
#x ⇒ Object
32 33 34 35 |
# File 'lib/badline/vic/sprite.rb', line 32 def x msb = @registers[0x10].anybits?(@bit) ? 0x100 : 0 msb | @registers[index * 2] end |
#x_expanded? ⇒ Boolean
28 |
# File 'lib/badline/vic/sprite.rb', line 28 def = @registers[0x1d].anybits?(@bit) |
#y ⇒ Object
37 |
# File 'lib/badline/vic/sprite.rb', line 37 def y = @registers[(index * 2) + 1] |
#y_expanded? ⇒ Boolean
29 |
# File 'lib/badline/vic/sprite.rb', line 29 def = @registers[0x17].anybits?(@bit) |