diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 90825e2392b2d70e43c7a25b8a3752299a933894 (patch) | |
tree | e33aa27f02b74604afbfd0ea4f1cfca8833d882a /qtruby/rubylib/examples/ruboids/ruboids/World.rb | |
download | tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'qtruby/rubylib/examples/ruboids/ruboids/World.rb')
-rw-r--r-- | qtruby/rubylib/examples/ruboids/ruboids/World.rb | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/qtruby/rubylib/examples/ruboids/ruboids/World.rb b/qtruby/rubylib/examples/ruboids/ruboids/World.rb new file mode 100644 index 00000000..17608bca --- /dev/null +++ b/qtruby/rubylib/examples/ruboids/ruboids/World.rb @@ -0,0 +1,82 @@ +# +# Copyright (c) 2001 by Jim Menard <jimm@io.com> +# +# Released under the same license as Ruby. See +# http://www.ruby-lang.org/en/LICENSE.txt. +# + +require 'singleton' +require 'Qt' +require 'Params' +require 'Cloud' +require 'Flock' +require 'Boid' +require 'Camera' +require 'Canvas' + +class World < Qt::Object + slots 'slotMove()' + + include Singleton + + attr_accessor :canvas + attr_reader :width, :height, :depth, :camera, :clouds, :flock + + 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 + + # Should be called whenever camera or screen changes. + def setupTranslation + @canvas.update() if @canvas + end + + def start + @clock.start($PARAMS['world_sleep_millis']) + end + + 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 +end + |