Class: Teien::ActorManagerProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/teien/actor/actor_manager_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeActorManagerProxy



11
12
13
14
15
# File 'lib/teien/actor/actor_manager_proxy.rb', line 11

def initialize()
  @actors = Hash.new
  @event_router = Teien::get_component("event_router")
  @event_router.register_receiver(self)
end

Instance Attribute Details

#actorsObject

Returns the value of attribute actors.



9
10
11
# File 'lib/teien/actor/actor_manager_proxy.rb', line 9

def actors
  @actors
end

Instance Method Details

#create_actor(actor_info) ⇒ Object



17
18
19
20
21
# File 'lib/teien/actor/actor_manager_proxy.rb', line 17

def create_actor(actor_info)
  actor = ActorFactory::create_actor(actor_info)
  @actors[actor_info.actor_name] = actor
  actor
end

#receive_event(event, from) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/teien/actor/actor_manager_proxy.rb', line 29

def receive_event(event, from)
  case event
  when Teien::Event::Actor::SyncActor
    if @actors[event.actor_info.actor_name]
      # sync some stuff. (ex. state)
      @actors[event.actor_info.actor_name].receive_event(event, from)
    else
      @actors[event.actor_info.actor_name] = create_actor(event.actor_info)
    end
  when Teien::Event::Actor::SetForwardDirection
    if @actors[event.actor_name]
      @actors[event.actor_name].set_forward_direction(event.dir)
    else
      puts "no actor_name"
    end
  when Teien::Event::Actor::EnableAction
    if event.forward
      @actors[event.actor_name].move_forward(true)
    elsif event.backward
      @actors[event.actor_name].move_backward(true)
    elsif event.left
      @actors[event.actor_name].move_left(true)
    elsif event.right
      @actors[event.actor_name].move_right(true)
    elsif event.jump
      @actors[event.actor_name].jump(true)
    end
  when Teien::Event::Actor::DisableAction
    if event.forward
      @actors[event.actor_name].move_forward(false)
    elsif event.backward
      @actors[event.actor_name].move_backward(false)
    elsif event.left
      @actors[event.actor_name].move_left(false)
    elsif event.right
      @actors[event.actor_name].move_right(false)
    elsif event.jump
      @actors[event.actor_name].jump(false)
    end
  end
end

#update(delta) ⇒ Object



23
24
25
26
27
# File 'lib/teien/actor/actor_manager_proxy.rb', line 23

def update(delta)
  @actors.each_value {|actor|
    actor.update(delta)
  }
end