From 8fb5bfdf72c54dbc9161f3be6ebdc1c9e7bcc384 Mon Sep 17 00:00:00 2001 From: realtradam Date: Sat, 7 Aug 2021 16:42:05 -0400 Subject: added circles --- lib/ruby2d/camera/circle.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/ruby2d/camera/circle.rb (limited to 'lib/ruby2d/camera/circle.rb') diff --git a/lib/ruby2d/camera/circle.rb b/lib/ruby2d/camera/circle.rb new file mode 100644 index 0000000..a7416a2 --- /dev/null +++ b/lib/ruby2d/camera/circle.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module Ruby2D + module Camera + # Wraps existing variables as well as adding new methods + # so that it can be handled by the Camera Module + class Circle < Ruby2D::Circle + # Recalculates real coordiantes + # Use after changing variables + def _draw + angle = Camera.angle * (Math::PI / 180) + half_width = Window.width * 0.5 + half_height = Window.height * 0.5 + temp_radius = @radius * Camera.zoom + temp_x = (((@x - Ruby2D::Camera.x + radius) * Math.cos(angle)) - ((@y - Ruby2D::Camera.y + radius) * Math.sin(angle))) * Ruby2D::Camera.zoom + half_width + temp_y = (((@x - Ruby2D::Camera.x + radius) * Math.sin(angle)) + ((@y - Ruby2D::Camera.y + radius) * Math.cos(angle))) * Ruby2D::Camera.zoom + half_height + Ruby2D::Circle.draw(x: temp_x, y: tempy, + radius: temp_radius, + sectors: @sectors, + color: [self.color.r, self.color.g, self.color.b, self.color.a]) + + end + + def initialize(otps= {}) + super(opts) + Ruby2D::Camera << self + self.remove + end + end + end +end -- cgit v1.2.3