Class: Doom::Wad::Flat

Inherits:
Object
  • Object
show all
Defined in:
lib/doom/wad/flat.rb

Constant Summary collapse

WIDTH =
64
HEIGHT =
64
SIZE =
WIDTH * HEIGHT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, pixels) ⇒ Flat

Returns a new instance of Flat.



20
21
22
23
# File 'lib/doom/wad/flat.rb', line 20

def initialize(name, pixels)
  @name = name
  @pixels = pixels
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/doom/wad/flat.rb', line 10

def name
  @name
end

#pixelsObject (readonly)

Returns the value of attribute pixels.



10
11
12
# File 'lib/doom/wad/flat.rb', line 10

def pixels
  @pixels
end

Class Method Details

.load_all(wad) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/doom/wad/flat.rb', line 29

def self.load_all(wad)
  entries = wad.lumps_between('F_START', 'F_END')
  entries.map do |entry|
    next if entry.size != SIZE

    data = wad.read_lump_at(entry)
    new(entry.name, data.bytes)
  end.compact
end

Instance Method Details

#[](x, y) ⇒ Object



25
26
27
# File 'lib/doom/wad/flat.rb', line 25

def [](x, y)
  @pixels[(y & 63) * WIDTH + (x & 63)]
end

#heightObject



16
17
18
# File 'lib/doom/wad/flat.rb', line 16

def height
  HEIGHT
end

#widthObject



12
13
14
# File 'lib/doom/wad/flat.rb', line 12

def width
  WIDTH
end