Class: Lotu::Actor
- Inherits:
-
Object
- Object
- Lotu::Actor
- Includes:
- Controllable, SystemUser
- Defined in:
- lib/lotu/actor.rb
Instance Attribute Summary collapse
-
#angle ⇒ Object
Returns the value of attribute angle.
-
#center_x ⇒ Object
Returns the value of attribute center_x.
-
#center_y ⇒ Object
Returns the value of attribute center_y.
-
#color ⇒ Object
Returns the value of attribute color.
-
#factor_x ⇒ Object
Returns the value of attribute factor_x.
-
#factor_y ⇒ Object
Returns the value of attribute factor_y.
-
#height ⇒ Object
Returns the value of attribute height.
-
#image ⇒ Object
Returns the value of attribute image.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#systems ⇒ Object
Returns the value of attribute systems.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#z ⇒ Object
Returns the value of attribute z.
Instance Method Summary collapse
- #adjust_width_and_height(opts) ⇒ Object
- #calc_zoom ⇒ Object
-
#die ⇒ Object
Remove ourselves from the update queue.
- #draw ⇒ Object
- #draw_box(x, y, w, h, c = 0xffff0000) ⇒ Object
- #draw_debug ⇒ Object
-
#dt ⇒ Object
Easy access to delta-time.
-
#initialize(opts = {}) ⇒ Actor
constructor
A new instance of Actor.
- #parse_options(opts) ⇒ Object
- #rand_color ⇒ Object
- #set_gosu_image(image, opts = {}) ⇒ Object
- #set_image(image, opts = {}) ⇒ Object
- #update ⇒ Object
Methods included from Controllable
Methods included from SystemUser
Constructor Details
#initialize(opts = {}) ⇒ Actor
Returns a new instance of Actor.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lotu/actor.rb', line 11 def initialize(opts={}) default_opts = { :x => 0, :y => 0, :z => 0, :angle => 0.0, :center_x => 0.5, :center_y => 0.5, :factor_x => 1.0, :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] (opts) @color = rand_color if opts[:rand_color] @systems = {} set_keys(opts[:keys]) unless opts[:keys].nil? # Add extra functionality self.extend Eventful self.extend Collidable use(AnimationSystem) use(TransformationSystem) end |
Instance Attribute Details
#angle ⇒ Object
Returns the value of attribute angle.
3 4 5 |
# File 'lib/lotu/actor.rb', line 3 def angle @angle end |
#center_x ⇒ Object
Returns the value of attribute center_x.
3 4 5 |
# File 'lib/lotu/actor.rb', line 3 def center_x @center_x end |
#center_y ⇒ Object
Returns the value of attribute center_y.
3 4 5 |
# File 'lib/lotu/actor.rb', line 3 def center_y @center_y end |
#color ⇒ Object
Returns the value of attribute color.
3 4 5 |
# File 'lib/lotu/actor.rb', line 3 def color @color end |
#factor_x ⇒ Object
Returns the value of attribute factor_x.
3 4 5 |
# File 'lib/lotu/actor.rb', line 3 def factor_x @factor_x end |
#factor_y ⇒ Object
Returns the value of attribute factor_y.
3 4 5 |
# File 'lib/lotu/actor.rb', line 3 def factor_y @factor_y end |
#height ⇒ Object
Returns the value of attribute height.
3 4 5 |
# File 'lib/lotu/actor.rb', line 3 def height @height end |
#image ⇒ Object
Returns the value of attribute image.
3 4 5 |
# File 'lib/lotu/actor.rb', line 3 def image @image end |
#mode ⇒ Object
Returns the value of attribute mode.
3 4 5 |
# File 'lib/lotu/actor.rb', line 3 def mode @mode end |
#parent ⇒ Object
Returns the value of attribute parent.
3 4 5 |
# File 'lib/lotu/actor.rb', line 3 def parent @parent end |
#systems ⇒ Object
Returns the value of attribute systems.
3 4 5 |
# File 'lib/lotu/actor.rb', line 3 def systems @systems end |
#width ⇒ Object
Returns the value of attribute width.
3 4 5 |
# File 'lib/lotu/actor.rb', line 3 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
3 4 5 |
# File 'lib/lotu/actor.rb', line 3 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
3 4 5 |
# File 'lib/lotu/actor.rb', line 3 def y @y end |
#z ⇒ Object
Returns the value of attribute z.
3 4 5 |
# File 'lib/lotu/actor.rb', line 3 def z @z end |
Instance Method Details
#adjust_width_and_height(opts) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/lotu/actor.rb', line 95 def adjust_width_and_height(opts) if(opts[:width] && opts[:height]) @width = Float(opts[:width]) @height = Float(opts[:height]) elsif(opts[:width]) @width = Float(opts[:width]) @height = @width * @image.height / @image.width elsif(opts[:height]) @height = Float(opts[:height]) @width = @height * @image.width / @image.height else @width = Float(@image.width) @height = Float(@image.height) end end |
#calc_zoom ⇒ Object
111 112 113 114 |
# File 'lib/lotu/actor.rb', line 111 def calc_zoom @zoom_x = Float(@width)/@image.width @zoom_y = Float(@height)/@image.height end |
#die ⇒ Object
Remove ourselves from the update queue
117 118 119 |
# File 'lib/lotu/actor.rb', line 117 def die @parent.kill_me(self) end |
#draw ⇒ Object
127 128 129 130 131 132 |
# File 'lib/lotu/actor.rb', line 127 def draw 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 |
#draw_box(x, y, w, h, c = 0xffff0000) ⇒ Object
139 140 141 142 143 144 |
# File 'lib/lotu/actor.rb', line 139 def draw_box(x, y, w, h, c = 0xffff0000) $lotu.draw_line(x, y, c, x+w, y, c) $lotu.draw_line(x, y, c, x, y+h, c) $lotu.draw_line(x+w, y+h, c, x+w, y, c) $lotu.draw_line(x+w, y+h, c, x, y+h, c) end |
#draw_debug ⇒ Object
134 135 136 137 |
# File 'lib/lotu/actor.rb', line 134 def draw_debug draw_box(@x-@image.width/2, @y-@image.height/2, @image.width, @image.height) draw_box(@x-@width/2, @y-@height/2, @width, @height, 0xff00ff00) end |
#dt ⇒ Object
Easy access to delta-time
43 44 45 |
# File 'lib/lotu/actor.rb', line 43 def dt $lotu.dt end |
#parse_options(opts) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/lotu/actor.rb', line 47 def (opts) @x = opts[:x] || @x @y = opts[:y] || @y @z = opts[:z] || @z @angle = opts[:angle] || @angle @center_x = opts[:center_x] || @center_x @center_y = opts[:center_y] || @center_y @factor_x = opts[:factor_x] || @factor_x @factor_y = opts[:factor_y] || @factor_y @color = opts[:color] || @color if @color.kind_of?(Integer) @color = Gosu::Color.new(opts[:color]) end @mode = opts[:mode] || @mode end |
#rand_color ⇒ Object
63 64 65 |
# File 'lib/lotu/actor.rb', line 63 def rand_color Gosu::Color.from_hsv(rand(360), 1, 1) end |
#set_gosu_image(image, opts = {}) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/lotu/actor.rb', line 78 def set_gosu_image(image, opts={}) @image = image (opts) adjust_width_and_height(opts) calc_zoom end |
#set_image(image, opts = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/lotu/actor.rb', line 67 def set_image(image, opts={}) @image = @parent.image(image) if @image.nil? puts "Image \"#{image}\" not found".red return end (opts) adjust_width_and_height(opts) calc_zoom end |
#update ⇒ Object
121 122 123 124 125 |
# File 'lib/lotu/actor.rb', line 121 def update @systems.each_pair do |klass, system| system.update end end |