diff options
| author | realtradam <[email protected]> | 2021-08-08 02:14:53 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2021-08-08 02:14:53 -0400 |
| commit | cad7a2876013ae52f248d7d3fd35bb6d7a2d36cb (patch) | |
| tree | 7888eb2df8401feaa1426d9ca411a7e7b76cb792 /lib/camera/wrappers/rectangle_wrapper.rb | |
| parent | e9a05cecd41b244977c794931b4706015097774f (diff) | |
| download | ruby2d-camera-cad7a2876013ae52f248d7d3fd35bb6d7a2d36cb.tar.gz ruby2d-camera-cad7a2876013ae52f248d7d3fd35bb6d7a2d36cb.zip | |
fixed formatting and file structure
Diffstat (limited to 'lib/camera/wrappers/rectangle_wrapper.rb')
| -rw-r--r-- | lib/camera/wrappers/rectangle_wrapper.rb | 138 |
1 files changed, 0 insertions, 138 deletions
diff --git a/lib/camera/wrappers/rectangle_wrapper.rb b/lib/camera/wrappers/rectangle_wrapper.rb deleted file mode 100644 index 93e888a..0000000 --- a/lib/camera/wrappers/rectangle_wrapper.rb +++ /dev/null @@ -1,138 +0,0 @@ -# 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 - 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 - angle = Camera.angle * (Math::PI / 180) - half_width = Window.width * 0.5 - half_height = Window.height * 0.5 - @x1 = (((x + x1 - Camera.x) * Math.cos(angle)) - ((y + y1 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y1 = (((x + x1 - Camera.x) * Math.sin(angle)) + ((y + y1 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - @x2 = (((x + x2 - Camera.x) * Math.cos(angle)) - ((y + y2 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y2 = (((x + x2 - Camera.x) * Math.sin(angle)) + ((y + y2 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - @x3 = (((x + x3 - Camera.x) * Math.cos(angle)) - ((y + y3 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y3 = (((x + x3 - Camera.x) * Math.sin(angle)) + ((y + y3 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - @x4 = (((x + x4 - Camera.x) * Math.cos(angle)) - ((y + y4 - Camera.y) * Math.sin(angle))) * Camera.zoom + half_width - @y4 = (((x + x4 - Camera.x) * Math.sin(angle)) + ((y + y4 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height - end - - #Methods for moving the shape - def x - @x ||= 0 - end - - def x=(x) - @x = x - end - - def y - @y ||= 0 - end - - def y=(y) - @y = y - end - - # Wrappers for the coordinates so that - # they are handled by the Camera instead - # and for ease of programming - def x1 - @virtual_x1 ||= @x1 - end - - def x1=(x1) - @virtual_x1 = x1 - end - - def y1 - @virtual_y1 ||= @y1 - end - - def y1=(y1) - @virtual_y1 = y1 - end - - def x2 - @virtual_x2 ||= @x2 - end - - def x2=(x2) - @virtual_x2 = x2 - end - - def y2 - @virtual_y2 ||= @y2 - end - - def y2=(y2) - @virtual_y2 = y2 - end - - def x3 - @virtual_x3 ||= @x3 - end - - def x3=(x3) - @virtual_x3 = x3 - end - - def y3 - @virtual_y3 ||= @y3 - end - - def y3=(y3) - @virtual_y3 = y3 - end - - def x4 - @virtual_x4 ||= @x4 - end - - def x4=(x4) - @virtual_x4 = x4 - end - - def y4 - @virtual_y4 ||= @y4 - end - - def y4=(y4) - @virtual_y4 = y4 - end - - - def width - @width ||= 200 - end - - def width=(width) - self.x2 = width - self.x3 = width - @width = width - end - - def height - @height ||= 100 - end - - def height=(height) - self.y3 = height - self.y4 = height - @height = height - end - end -end - |
