1010require 'pbox2d'
1111require 'forwardable'
1212require_relative 'lib/boundary'
13+ require_relative 'lib/bubble_factory'
1314require_relative 'lib/bubble'
1415
15- Vect = Struct . new ( :x , :y )
16- attr_reader :boundaries , :box2d , :bubble , :bubble1 , :bubble2
16+
17+ attr_reader :boundaries , :box2d , :bubble , :bubble1 , :bubble2 , :bubble_factory
1718
1819def settings
1920 size ( 400 , 400 )
@@ -25,26 +26,27 @@ def setup
2526 @box2d = WorldBuilder . build ( app : self , gravity : [ 0 , 30 ] )
2627 box2d . create_world
2728 @boundaries = [ ]
28- boundaries << Boundary . new ( box2d , Vect . new ( 160 , 135 ) , Vect . new ( 20 , height * 0.2 ) )
29- boundaries << Boundary . new ( box2d , Vect . new ( 240 , 135 ) , Vect . new ( 20 , height * 0.2 ) )
29+ boundaries << Boundary . new ( box2d , Vect . new ( 160 , 135 ) , Vect . new ( 20 , height * 0.21 ) )
30+ boundaries << Boundary . new ( box2d , Vect . new ( 240 , 135 ) , Vect . new ( 20 , height * 0.21 ) )
3031 boundaries << Boundary . new ( box2d , Vect . new ( 130 , 190 ) , Vect . new ( 80 , 20 ) , 0.5 )
3132 boundaries << Boundary . new ( box2d , Vect . new ( 270 , 190 ) , Vect . new ( 80 , 20 ) , -0.5 )
3233 boundaries << Boundary . new ( box2d , Vect . new ( 100 , height * 0.9 ) , Vect . new ( 20 , height * 0.8 ) )
3334 boundaries << Boundary . new ( box2d , Vect . new ( 300 , height * 0.9 ) , Vect . new ( 20 , height * 0.8 ) )
34- @bubble = Bubble . new ( pos : Vect . new ( rand ( 130 ..270 ) , height - 20 ) , hue : 255 )
35- @bubble1 = Bubble . new ( pos : Vect . new ( rand ( 130 ..270 ) , height + 20 ) , hue : 255 )
36- @bubble2 = Bubble . new ( pos : Vect . new ( rand ( 130 ..270 ) , height + 60 ) , hue : 255 )
35+ @bubble_factory = BubbleFactory . new ( xrange : ( 145 ..255 ) )
36+ @bubble = bubble_factory . create_bubble ( height : height - 20 , hue : 255 )
37+ @bubble1 = bubble_factory . create_bubble ( height : height + 20 , hue : 255 )
38+ @bubble2 = bubble_factory . create_bubble ( height : height + 60 , hue : 255 )
3739end
3840
3941def draw
4042 background ( 0 , 0 , 255 )
41- # We must always step through time!
43+
4244 boundaries . each ( &:display )
4345 # Show the blobs!
44- @bubble = Bubble . new ( pos : Vect . new ( rand ( 120 .. 280 ) , height - 20 ) , hue : 255 ) if ( ( frame_count % 340 ) == 0 )
46+ @bubble = bubble_factory . create_bubble ( height : height - 20 , hue : 255 ) if ( ( frame_count % 240 ) == 0 )
4547 bubble . display
46- @bubble1 = Bubble . new ( pos : Vect . new ( rand ( 120 .. 280 ) , height - 20 ) , hue : 255 ) if ( ( frame_count % 440 ) == 0 )
48+ @bubble1 = bubble_factory . create_bubble ( height : height + 20 , hue : 255 ) if ( ( frame_count % 280 ) == 0 )
4749 bubble1 . display
48- @bubble2 = Bubble . new ( pos : Vect . new ( rand ( 120 .. 280 ) , height - 20 ) , hue : 255 ) if ( ( frame_count % 540 ) == 0 )
50+ @bubble2 = bubble_factory . create_bubble ( height : height + 60 , hue : 255 ) if ( ( frame_count % 320 ) == 0 )
4951 bubble2 . display
5052end
0 commit comments