Module: Robot

Defined in:
lib/rrobots/robot.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionsObject

the action hash of your robot



29
30
31
# File 'lib/rrobots/robot.rb', line 29

def actions
  @actions
end

#eventsObject

the event hash of your robot



32
33
34
# File 'lib/rrobots/robot.rb', line 32

def events
  @events
end

#skin_prefixObject

path to where your robot’s optional skin images are



35
36
37
# File 'lib/rrobots/robot.rb', line 35

def skin_prefix
  @skin_prefix
end

#stateObject

the state hash of your robot. also accessible through the attr_state methods



26
27
28
# File 'lib/rrobots/robot.rb', line 26

def state
  @state
end

Class Method Details

.attr_action(*names) ⇒ Object



11
12
13
14
15
16
# File 'lib/rrobots/robot.rb', line 11

def self.attr_action(*names)
  names.each{|n|
    n = n.to_sym
    define_method(n){|param| @actions[n] = param }
  }
end

.attr_event(*names) ⇒ Object



18
19
20
21
22
23
# File 'lib/rrobots/robot.rb', line 18

def self.attr_event(*names)
  names.each{|n|
    n = n.to_sym
    define_method(n){ @events[n] }
  }
end

.attr_state(*names) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/rrobots/robot.rb', line 3

def self.attr_state(*names)
  names.each{|n|
    n = n.to_sym
    attr_writer n
    attr_reader n
  }
end

Instance Method Details

#stopObject

accelerates negativ if moving forward (and vice versa), may take 8 ticks to stop (and you have to call it every tick)



84
85
86
# File 'lib/rrobots/robot.rb', line 84

def stop
  accelerate((speed > 0) ? -1 : ((speed < 0) ? 1 :0))
end