From 645974e42ce72c95a3ba9f9de2278e71d89ffa6c Mon Sep 17 00:00:00 2001 From: realtradam Date: Sat, 24 Apr 2021 01:30:18 -0400 Subject: . --- lib/camera/wrappers/square_wrapper.rb | 26 ++++++++------------------ run.rb | 9 +++++++++ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/camera/wrappers/square_wrapper.rb b/lib/camera/wrappers/square_wrapper.rb index 6cfd3f7..ce0831e 100644 --- a/lib/camera/wrappers/square_wrapper.rb +++ b/lib/camera/wrappers/square_wrapper.rb @@ -8,17 +8,15 @@ module Camera # Use after changing variables def update angle = Camera.angle * (Math::PI / 180) - half_width = Window.width * 0.5 - half_height = Window.height * 0.5 + half_size = Window.size * 0.5 offset_x = x + (width / 2) offset_y = y + (height / 2) @x = (((offset_x - Camera.x) * Math.cos(angle)) - ((offset_y - Camera.y) * Math.sin(angle))) \ - * Camera.zoom + half_width - (width * Camera.zoom / 2) + * Camera.zoom + half_size #- (size * Camera.zoom / 2) @y = (((offset_x - Camera.x) * Math.sin(angle)) + ((offset_y - Camera.y) * Math.cos(angle))) \ - * Camera.zoom + half_height - (height * Camera.zoom / 2) + * Camera.zoom + half_height #- (size * Camera.zoom / 2) @rotate = rotate + Camera.angle - @width = width * Camera.zoom - @height = height * Camera.zoom + @size = size * Camera.zoom end #Methods for moving the shape @@ -54,20 +52,12 @@ module Camera @virtual_rotate = rotate end - def width - @virtual_width ||= @width + def size + @virtual_size ||= @size end - def width=(width) - @virtual_width = width - end - - def height - @virtual_height ||= @height - end - - def height=(height) - @virtual_height = height + def size=(size) + @virtual_size = size end end end diff --git a/run.rb b/run.rb index d1afb77..09e3072 100644 --- a/run.rb +++ b/run.rb @@ -20,6 +20,15 @@ end Window.set(icon: './assets/player.png') # There is 2 ways you can add objects to be known and controlled by the camera, both do the same thing + +@square = Square.new( + x: 100, y: 100, + size: 125, + color: 'random' +) + +Camera << @square + 25.times do tempx = (0..1920).to_a.sample tempy = (0..1080).to_a.sample -- cgit v1.2.3