class World

Attributes

camera[R]
canvas[RW]
clouds[R]
depth[R]
flock[R]
height[R]
width[R]

Public Class Methods

new() click to toggle source
Calls superclass method
# File examples/ruboids/ruboids/World.rb, line 25
def initialize
    super
    @width = $PARAMS['world_width']
    @height = $PARAMS['world_height']
    @depth = $PARAMS['world_depth']

    @clouds = []
    minAltitude = $PARAMS['cloud_min_altitude']
    $PARAMS['cloud_count'].times {
        c = Cloud.new
        c.position =
            Point.new(rand(@width) - @width / 2,
                      rand(@height) - @height / 2,
                      rand(@depth - minAltitude) - @depth / 2 + minAltitude)
        @clouds << c
    }
    # Sort clouds by height so lower/darker shadows are drawn last
    @clouds.sort { |a, b| a.position.y <=> b.position.y }

    @flock = Flock.new
    $PARAMS['flock_boids'].times {
        b = Boid.new
        b.position = Point.new(rand(@width) - @width / 2,
                               rand(@height) - @height / 2,
                               rand(@depth) - @depth / 2)
        @flock.add(b)      # flock will delete boid
    }

    @clock = Qt::Timer.new()
    connect(@clock, SIGNAL('timeout()'), self, SLOT('slotMove()'))

    @camera = Camera.new   # Reads values from params
    setupTranslation()
end

Public Instance Methods

setupTranslation() click to toggle source

Should be called whenever camera or screen changes.

# File examples/ruboids/ruboids/World.rb, line 61
def setupTranslation
    @canvas.update() if @canvas
end
slotMove() click to toggle source
# File examples/ruboids/ruboids/World.rb, line 69
    def slotMove
        @clouds.each { | c | c.move() }
        @flock.move()
        @canvas.update() if @canvas

        # Camera follow boid.
#       b = @flock.members.first
#       @camera.position = b.position
#       @camera.rotation = Graphics.rotations(b.vector)
#       @camera.zoom = 1.0
            
    end
start() click to toggle source
# File examples/ruboids/ruboids/World.rb, line 65
def start
    @clock.start($PARAMS['world_sleep_millis'])
end