diff options
| author | realtradam <[email protected]> | 2021-04-24 01:30:18 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2021-04-24 01:30:18 -0400 |
| commit | 645974e42ce72c95a3ba9f9de2278e71d89ffa6c (patch) | |
| tree | f8c7d1a7d564a2469b794bda2e704aacda5fa6ad | |
| parent | 45767fb1ae8d0da1daa14d716a26674f3d5d24b9 (diff) | |
| download | ruby2d-camera-645974e42ce72c95a3ba9f9de2278e71d89ffa6c.tar.gz ruby2d-camera-645974e42ce72c95a3ba9f9de2278e71d89ffa6c.zip | |
.
| -rw-r--r-- | lib/camera/wrappers/square_wrapper.rb | 26 | ||||
| -rw-r--r-- | 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 @@ -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 |
