Sha256: d072022fece7f8c9cec931ab66b6bb88f24d06184309ff68928f604d7f54daa1

Contents?: true

Size: 940 Bytes

Versions: 4

Compression:

Stored size: 940 Bytes

Contents

require 'actor_view'

class GraphicalActorView < ActorView
  def draw(target, x_off, y_off)
    x = @actor.x
    y = @actor.y

    offset_x = x+x_off
    offset_y = y+y_off

    img = @actor.image
    return if img.nil?

    #if @actor.is? :animated or 
    if @actor.is? :physical
      w,h = *img.size
      offset_x = x-w/2 + x_off
      offset_y = y-h/2 + y_off
      img.blit target.screen, [offset_x,offset_y]
    else
      graphical_behavior = @actor.graphical if @actor.is? :graphical
      if graphical_behavior && graphical_behavior.tiled?
        x_tiles = graphical_behavior.num_x_tiles
        y_tiles = graphical_behavior.num_y_tiles
        img_w, img_h = *img.size
        x_tiles.times do |col|
          y_tiles.times do |row|
            img.blit target.screen, [offset_x+col*img_w,offset_y+row*img_h]
          end
        end
      else
        img.blit target.screen, [offset_x,offset_y]
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gamebox-0.1.1 lib/gamebox/views/graphical_actor_view.rb
gamebox-0.1.0 lib/gamebox/views/graphical_actor_view.rb
gamebox-0.0.9 lib/gamebox/views/graphical_actor_view.rb
gamebox-0.0.8 lib/gamebox/views/graphical_actor_view.rb