Class: EhbGameLib::Nes::AllColorsPalette

Inherits:
Object
  • Object
show all
Defined in:
lib/ehb_game_lib/nes/all_colors_palette.rb

Instance Method Summary collapse

Constructor Details

#initialize(pal_file) ⇒ AllColorsPalette

Returns a new instance of AllColorsPalette.



6
7
8
9
10
11
12
13
14
15
# File 'lib/ehb_game_lib/nes/all_colors_palette.rb', line 6

def initialize(pal_file)
  @colors = []
  File.open(pal_file) do |file|
    while (b = file.read(3))
      b = b.bytes.to_a
      @colors << Gosu::Color.rgba(b[0], b[1], b[2], 0xFF)
    end
  end
  @colors.freeze
end

Instance Method Details

#draw(x, y) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/ehb_game_lib/nes/all_colors_palette.rb', line 21

def draw(x, y)
  s = 32
  @colors.each_with_index do |c, i|
    cx = x + (i % 16) * s
    cy = y + (i / 16) * s
    Gosu.draw_rect(cx, cy, s, s, c)
  end
end

#gosu_color(i) ⇒ Object



17
18
19
# File 'lib/ehb_game_lib/nes/all_colors_palette.rb', line 17

def gosu_color(i)
  @colors[i]
end