diff options
| author | realtradam <[email protected]> | 2021-04-25 04:25:57 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2021-04-25 04:25:57 -0400 |
| commit | 505a4735d519253c5f173f47fbe9691bc5d9ce93 (patch) | |
| tree | a3b2600a87a4285e60165728f48a346a7b05dec3 /lib | |
| parent | 93290fb327f4dac63ac201c4c21e13c60cae0eff (diff) | |
| download | ruby2d-camera-old-505a4735d519253c5f173f47fbe9691bc5d9ce93.tar.gz ruby2d-camera-old-505a4735d519253c5f173f47fbe9691bc5d9ce93.zip | |
.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/camera/camera.rb | 4 | ||||
| -rw-r--r-- | lib/camera/wrappers/circle_wrapper.rb | 4 | ||||
| -rw-r--r-- | lib/camera/wrappers/line_wrapper.rb | 4 | ||||
| -rw-r--r-- | lib/camera/wrappers/quad_wrapper.rb | 7 | ||||
| -rw-r--r-- | lib/camera/wrappers/rectangle_wrapper.rb | 13 | ||||
| -rw-r--r-- | lib/camera/wrappers/square_wrapper.rb | 17 | ||||
| -rw-r--r-- | lib/camera/wrappers/triangle_wrapper.rb | 4 |
7 files changed, 38 insertions, 15 deletions
diff --git a/lib/camera/camera.rb b/lib/camera/camera.rb index 2b94150..6a6dd3d 100644 --- a/lib/camera/camera.rb +++ b/lib/camera/camera.rb @@ -59,6 +59,10 @@ module Camera objects.push(item) unless objects.include?(item) end + def self.remove(item) + objects.delete(item) if objects.include?(item) + end + # Redraw all objects that # are tracked by the Camera def self.redraw diff --git a/lib/camera/wrappers/circle_wrapper.rb b/lib/camera/wrappers/circle_wrapper.rb index 52a97c0..a7db05a 100644 --- a/lib/camera/wrappers/circle_wrapper.rb +++ b/lib/camera/wrappers/circle_wrapper.rb @@ -10,9 +10,9 @@ module Camera angle = Camera.angle * (Math::PI / 180) half_width = Window.width * 0.5 half_height = Window.height * 0.5 - @x = (((x - Camera.x) * Math.cos(angle)) - ((y - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y = (((x - Camera.x) * Math.sin(angle)) + ((y - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height @radius = radius * Camera.zoom + @x = (((x - Camera.x + radius) * Math.cos(angle)) - ((y - Camera.y + radius) * Math.sin(angle))) * Camera.zoom + half_width + @y = (((x - Camera.x + radius) * Math.sin(angle)) + ((y - Camera.y + radius) * Math.cos(angle))) * Camera.zoom + half_height end # Methods for moving the shape as well as diff --git a/lib/camera/wrappers/line_wrapper.rb b/lib/camera/wrappers/line_wrapper.rb index d2c1801..7d4d944 100644 --- a/lib/camera/wrappers/line_wrapper.rb +++ b/lib/camera/wrappers/line_wrapper.rb @@ -19,7 +19,7 @@ module Camera #Methods for moving the shape def x - @x ||= x1 + @x ||= 0 end def x=(x) @@ -27,7 +27,7 @@ module Camera end def y - @y ||= y1 + @y ||= 0 end def y=(y) diff --git a/lib/camera/wrappers/quad_wrapper.rb b/lib/camera/wrappers/quad_wrapper.rb index 08a2d6c..477dbfd 100644 --- a/lib/camera/wrappers/quad_wrapper.rb +++ b/lib/camera/wrappers/quad_wrapper.rb @@ -22,7 +22,7 @@ module Camera #Methods for moving the shape def x - @x ||= x1 + @x ||= 0 end def x=(x) @@ -30,7 +30,7 @@ module Camera end def y - @y ||= y1 + @y ||= 0 end def y=(y) @@ -87,8 +87,9 @@ module Camera def y3=(y3) @virtual_y3 = y3 end + def x4 - @virtual_x3 ||= @x3 + @virtual_x4 ||= @x4 end def x4=(x4) diff --git a/lib/camera/wrappers/rectangle_wrapper.rb b/lib/camera/wrappers/rectangle_wrapper.rb index 887ab8b..93e888a 100644 --- a/lib/camera/wrappers/rectangle_wrapper.rb +++ b/lib/camera/wrappers/rectangle_wrapper.rb @@ -4,6 +4,15 @@ module Camera # Wraps existing variables as well as adding new methods # so that it can be handled by the Camera Module module RectangleWrapped + # Rectangles are part of the exception where + # their x and y variables need to be reset + # when wrapped + def self.extended(obj) + obj.instance_exec do + @x = 0 + @y = 0 + end + end # Recalculates real coordiantes # Use after changing variables def redraw @@ -22,7 +31,7 @@ module Camera #Methods for moving the shape def x - @x ||= x1 + @x ||= 0 end def x=(x) @@ -30,7 +39,7 @@ module Camera end def y - @y ||= y1 + @y ||= 0 end def y=(y) diff --git a/lib/camera/wrappers/square_wrapper.rb b/lib/camera/wrappers/square_wrapper.rb index 40578e5..2215a30 100644 --- a/lib/camera/wrappers/square_wrapper.rb +++ b/lib/camera/wrappers/square_wrapper.rb @@ -1,9 +1,18 @@ # frozen_string_literal: true module Camera -# Wraps existing variables as well as adding new methods -# so that it can be handled by the Camera Module + # Wraps existing variables as well as adding new methods + # so that it can be handled by the Camera Module module SquareWrapped + # Squares are part of the exception where + # their x and y variables need to be reset + # when wrapped + def self.extended(obj) + obj.instance_exec do + @x = 0 + @y = 0 + end + end # Recalculates real coordiantes # Use after changing variables def redraw @@ -22,7 +31,7 @@ module Camera #Methods for moving the shape def x - @x ||= x1 + @x ||= 0 end def x=(x) @@ -30,7 +39,7 @@ module Camera end def y - @y ||= y1 + @y ||= 0 end def y=(y) diff --git a/lib/camera/wrappers/triangle_wrapper.rb b/lib/camera/wrappers/triangle_wrapper.rb index b26ef81..0aba2c0 100644 --- a/lib/camera/wrappers/triangle_wrapper.rb +++ b/lib/camera/wrappers/triangle_wrapper.rb @@ -20,7 +20,7 @@ module Camera #Methods for moving the shape def x - @x ||= x1 + @x ||= 0 end def x=(x) @@ -28,7 +28,7 @@ module Camera end def y - @y ||= y1 + @y ||= 0 end def y=(y) |
