Class: Retrograph::Easy::SpriteManager
- Inherits:
-
Object
- Object
- Retrograph::Easy::SpriteManager
- Defined in:
- lib/retrograph/easy/sprites.rb
Constant Summary collapse
- BLANK_SPRITES =
("\000" * 256).freeze
Instance Method Summary collapse
- #add_multi_sprite(x, y, pattern, width_tiles, height_tiles, flags) ⇒ Object
- #add_sprite(x, y, pattern, flags) ⇒ Object
- #add_sprite_group(x, y, width, height, flags) ⇒ Object
- #clear_sprites ⇒ Object
-
#initialize(display) ⇒ SpriteManager
constructor
A new instance of SpriteManager.
Constructor Details
#initialize(display) ⇒ SpriteManager
Returns a new instance of SpriteManager.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/retrograph/easy/sprites.rb', line 43 def initialize(display) @display = display @sprite_data = "\000" * 4 @data_offset = 0 @flip_flags = 0 @other_flags = 0 @x_exp = 0 @y_exp = 0 @x = 0 @y = 0 @mirror_x = 0 @mirror_y = 0 end |
Instance Method Details
#add_multi_sprite(x, y, pattern, width_tiles, height_tiles, flags) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/retrograph/easy/sprites.rb', line 91 def add_multi_sprite(x, y, pattern, width_tiles, height_tiles, flags) add_sprite_group(x, y, width_tiles << 3, height_tiles << 3, flags) do row = 0 while row < height_tiles col = 0 while col < width_tiles add_sprite(x + (col << 3), y + (row << 3), (pattern + col) & 0xff, 0) col += 1 end pattern += 32 row += 1 end end nil end |
#add_sprite(x, y, pattern, flags) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/retrograph/easy/sprites.rb', line 107 def add_sprite(x, y, pattern, flags) return nil unless @data_offset < 256 x = @mirror_x - x if (@flip_flags & 0b00100000).nonzero? y = @mirror_y - y if (@flip_flags & 0b00010000).nonzero? x = (x << @x_exp) + @x y = (y << @y_exp) + @y if x >= 0 and x < 256 and y >= 0 and y < 224 flags = (flags ^ @flip_flags) | @other_flags @sprite_data._retrograph_set_byte(0, x) @sprite_data._retrograph_set_byte(1, y + 1) @sprite_data._retrograph_set_byte(2, pattern) @sprite_data._retrograph_set_byte(3, flags) @display.write_vdu(0x7e00 + @data_offset, @sprite_data) end @data_offset += 4 nil end |
#add_sprite_group(x, y, width, height, flags) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/retrograph/easy/sprites.rb', line 57 def add_sprite_group(x, y, width, height, flags) saved_flip_flags = @flip_flags saved_other_flags = @other_flags saved_x_exp = @x_exp saved_y_exp = @y_exp saved_x = @x saved_y = @y saved_mirror_x = @mirror_x saved_mirror_y = @mirror_y begin x = @mirror_x - x if (@flip_flags & 0b00100000).nonzero? y = @mirror_y - y if (@flip_flags & 0b00010000).nonzero? @x = (x << @x_exp) + @x @y = (y << @y_exp) + @y @flip_flags ^= flags & 0b00110000 @other_flags |= flags & 0b00001111 @x_exp = (@flip_flags & 0b00001000) >> 3 @y_exp = (@flip_flags & 0b00000100) >> 2 @mirror_x = (width << @x_exp) - (8 << @x_exp) @mirror_y = (height << @y_exp) - (8 << @y_exp) yield rescue @flip_flags = saved_flip_flags @other_flags = saved_other_flags @x_exp = saved_x_exp @y_exp = saved_y_exp @x = saved_x @y = saved_y @mirror_x = saved_mirror_x @mirror_y = saved_mirror_y end nil end |
#clear_sprites ⇒ Object
125 126 127 128 129 |
# File 'lib/retrograph/easy/sprites.rb', line 125 def clear_sprites @display.write_vdu(0x7e00, BLANK_SPRITES) @data_offset = 0 self end |