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.



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

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



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

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



15
16
17
# File 'lib/ehb_game_lib/nes/all_colors_palette.rb', line 15

def gosu_color(i)
  @colors[i]
end