Class: Things

Inherits:
DecodedLump show all
Defined in:
lib/ruby-doom.rb

Constant Summary collapse

BYTES_EACH =
10
NAME =
"THINGS"

Instance Attribute Summary

Attributes inherited from DecodedLump

#items

Attributes inherited from Lump

#name

Instance Method Summary collapse

Methods inherited from DecodedLump

#add, #write

Constructor Details

#initializeThings

Returns a new instance of Things.



514
515
516
# File 'lib/ruby-doom.rb', line 514

def initialize
  super(NAME)
end

Instance Method Details

#add_barrel(p) ⇒ Object



533
534
535
# File 'lib/ruby-doom.rb', line 533

def add_barrel(p)
  items << Thing.new(p, Dictionary.get.thing_for_name("Barrel").id)
end

#add_commando(p) ⇒ Object



530
531
532
# File 'lib/ruby-doom.rb', line 530

def add_commando(p)
  items << Thing.new(p, Dictionary.get.thing_for_name("Commando").id)
end

#add_imp(p) ⇒ Object



539
540
541
# File 'lib/ruby-doom.rb', line 539

def add_imp(p)
  items << Thing.new(p, Dictionary.get.thing_for_name("Imp").id)
end

#add_player(p) ⇒ Object



542
543
544
# File 'lib/ruby-doom.rb', line 542

def add_player(p)  
  items << Thing.new(p, Dictionary.get.thing_for_name("Player 1").id)
end

#add_sergeant(p) ⇒ Object



527
528
529
# File 'lib/ruby-doom.rb', line 527

def add_sergeant(p)
  items << Thing.new(p, Dictionary.get.thing_for_name("Sergeant").id)
end

#add_shotgun(p) ⇒ Object



536
537
538
# File 'lib/ruby-doom.rb', line 536

def add_shotgun(p)
  items << Thing.new(p, Dictionary.get.thing_for_name("Shotgun").id)
end

#playerObject



545
546
547
# File 'lib/ruby-doom.rb', line 545

def player
  @items.find {|t| t.type_id == Dictionary.get.thing_for_name("Player 1").id} 
end

#read(bytes) ⇒ Object



517
518
519
520
521
522
523
# File 'lib/ruby-doom.rb', line 517

def read(bytes)
  (bytes.size / BYTES_EACH).times {|index|
    thing = Thing.new
    thing.read(bytes.slice(index*BYTES_EACH, BYTES_EACH))
    @items << thing
  }
end

#sizeObject



524
525
526
# File 'lib/ruby-doom.rb', line 524

def size
  @items.size * BYTES_EACH
end