lib/lotu/actor.rb in lotu-0.1.15 vs lib/lotu/actor.rb in lotu-0.1.16
- old
+ new
@@ -1,15 +1,22 @@
module Lotu
class Actor
- attr_accessor :parent, :x, :y, :systems,
+ extend Behavior
+
+ behave_like SystemUser
+ use AnimationSystem
+ use InterpolationSystem
+
+ behave_like Eventful
+ behave_like Collidable
+ behave_like Controllable
+
+ attr_accessor :parent, :x, :y,
:z, :angle, :center_x, :center_y,
:factor_x, :factor_y, :color, :mode, :image,
:width, :height
- include SystemUser
- include Controllable
-
def initialize(opts={})
default_opts = {
:x => 0,
:y => 0,
:z => 0,
@@ -20,24 +27,21 @@
:factor_y => 1.0,
:color => 0xffffffff,
:mode => :default,
:parent => $lotu
}
+
opts = default_opts.merge!(opts)
@parent = opts[:parent]
@parent.manage_me(self)
set_image(opts[:image], opts) if opts[:image]
parse_options(opts)
@color = rand_color if opts[:rand_color]
-
set_keys(opts[:keys]) unless opts[:keys].nil?
- # Add extra functionality
- self.extend Eventful
- self.extend Collidable
- use(AnimationSystem)
- use(InterpolationSystem)
+ # so it can start behaving
+ init_behavior opts
end
# Easy access to delta-time
def dt
$lotu.dt
@@ -116,15 +120,19 @@
def die
@parent.kill_me(self)
end
def update
- @systems.each_pair do |klass, system|
- system.update
- end
+ # to call update on behaviors (that in turn wil call
+ # update on systems, for example)
+ super
end
def draw
+ # to call draw on behaviors (that in turn will call
+ # draw on systems, for example)
+ super
+
unless @image.nil?
@image.draw_rot(@x, @y, @z, @angle, @center_x, @center_y, @factor_x*@zoom_x, @factor_y*@zoom_y, @color, @mode)
draw_debug if $lotu.debug?
end
end