diff options
| author | realtradam <[email protected]> | 2021-01-19 18:55:59 -0500 |
|---|---|---|
| committer | realtradam <[email protected]> | 2021-01-19 18:55:59 -0500 |
| commit | 344daa131d2343283e9e33e454b328f3e233f6b4 (patch) | |
| tree | 1a10595dc9dc00e828a2990e73f40f2ddb7324e1 /animator.rb | |
| download | ruby2d-camera-old-344daa131d2343283e9e33e454b328f3e233f6b4.tar.gz ruby2d-camera-old-344daa131d2343283e9e33e454b328f3e233f6b4.zip | |
initial
Diffstat (limited to 'animator.rb')
| -rw-r--r-- | animator.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/animator.rb b/animator.rb new file mode 100644 index 0000000..4a94a87 --- /dev/null +++ b/animator.rb @@ -0,0 +1,42 @@ + +class AnimatedSquare + def initialize(x: '0', y: '0', size: 10, color: 'random') + @speed = (1..5).to_a.sample + @square = Square.new(x: x, y: y, size: size, color: color) + @axis = (0..1).to_a.sample + if @axis == 0 + @range = [(((x-(250..500).to_a.sample)..x).to_a.sample),((x..(x+(250..500).to_a.sample)).to_a.sample)] + else + @range = [(((y-(250..500).to_a.sample)..y).to_a.sample),((y..(y+(250..500).to_a.sample)).to_a.sample)] + end + end + def x + @square.x + end + def x= x + @square.x = x + end + def y + @square.y + end + def y= y + @square.y = y + end + + + + def update offset + if @axis == 0 + @square.x += @speed + if @square.x > (@range[1] - offset[0]) or @square.x < (@range[0] - offset[0]) + @speed = -@speed + end + else + @square.y += @speed + if @square.y > (@range[1] - offset[1]) or @square.y < (@range[0] - offset[1]) + @speed = -@speed + end + end + puts offset + end +end |
