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/ruby2d | |
| parent | e9a05cecd41b244977c794931b4706015097774f (diff) | |
| download | ruby2d-camera-cad7a2876013ae52f248d7d3fd35bb6d7a2d36cb.tar.gz ruby2d-camera-cad7a2876013ae52f248d7d3fd35bb6d7a2d36cb.zip | |
fixed formatting and file structure
Diffstat (limited to 'lib/ruby2d')
| -rw-r--r-- | lib/ruby2d/camera.rb | 10 | ||||
| -rw-r--r-- | lib/ruby2d/camera/circle.rb | 8 | ||||
| -rw-r--r-- | lib/ruby2d/camera/image.rb | 32 | ||||
| -rw-r--r-- | lib/ruby2d/camera/line.rb | 32 | ||||
| -rw-r--r-- | lib/ruby2d/camera/quad.rb | 26 | ||||
| -rw-r--r-- | lib/ruby2d/camera/rectangle.rb | 26 | ||||
| -rw-r--r-- | lib/ruby2d/camera/sprite.rb | 22 | ||||
| -rw-r--r-- | lib/ruby2d/camera/square.rb | 27 | ||||
| -rw-r--r-- | lib/ruby2d/camera/text.rb | 20 | ||||
| -rw-r--r-- | lib/ruby2d/camera/triangle.rb | 25 | ||||
| -rw-r--r-- | lib/ruby2d/camera/version.rb | 2 |
11 files changed, 103 insertions, 127 deletions
diff --git a/lib/ruby2d/camera.rb b/lib/ruby2d/camera.rb index d29609d..ba0a280 100644 --- a/lib/ruby2d/camera.rb +++ b/lib/ruby2d/camera.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -#require_relative "camera/version" -#require_relative "camera/triangle" +# require_relative "camera/version" +# require_relative "camera/triangle" require 'ruby2d' Dir[File.join(__dir__, 'camera', '*.rb')].sort.each { |file| require file } @@ -9,9 +9,9 @@ Dir[File.join(__dir__, 'camera', '*.rb')].sort.each { |file| require file } # to a camera location module Ruby2D module Camera - - class <<self + class << self private + # Contains all objects that are tracked def objects @objects ||= [] @@ -38,7 +38,7 @@ module Ruby2D # tracked by the Camera def self.<<(item) objects.push(item) unless objects.include?(item) - objects.sort_by! do |n| + objects.sort_by! do |n| n.z end end diff --git a/lib/ruby2d/camera/circle.rb b/lib/ruby2d/camera/circle.rb index c6e1eb0..60629df 100644 --- a/lib/ruby2d/camera/circle.rb +++ b/lib/ruby2d/camera/circle.rb @@ -9,6 +9,7 @@ module Ruby2D # Use after changing variables def _draw return if @hide + angle = Camera.angle * (Math::PI / 180) half_width = Window.width * 0.5 half_height = Window.height * 0.5 @@ -17,15 +18,16 @@ module Ruby2D 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: temp_y, radius: temp_radius, - sectors: self.sectors, - color: [self.color.r, self.color.g, self.color.b, self.color.a]) + sectors: sectors, + color: [color.r, color.g, color.b, color.a]) end - def initialize(opts= {}) + def initialize(opts = {}) super(opts) Ruby2D::Camera << self Window.remove(self) end + def remove @hide = true end diff --git a/lib/ruby2d/camera/image.rb b/lib/ruby2d/camera/image.rb index fe777b3..dccbec9 100644 --- a/lib/ruby2d/camera/image.rb +++ b/lib/ruby2d/camera/image.rb @@ -8,6 +8,7 @@ module Camera # Use after changing variables def _draw return if @hide + temp_angle = Camera.angle * (Math::PI / 180) half_width = Window.width * 0.5 half_height = Window.height * 0.5 @@ -17,27 +18,28 @@ module Camera * Camera.zoom + half_width - (width * Camera.zoom / 2) temp_y = (((offset_x - Camera.x) * Math.sin(temp_angle)) + ((offset_y - Camera.y) * Math.cos(temp_angle))) \ * Camera.zoom + half_height - (height * Camera.zoom / 2) - temp_rotate = self.rotate + Camera.angle - temp_width = self.width * Camera.zoom - temp_height = self.height * Camera.zoom - self.draw(x: temp_x, y: temp_y, - width: temp_width, - height: temp_height, - rotate: temp_rotate, - color: [self.color.r, self.color.g, self.color.b, self.color.a]) + temp_rotate = rotate + Camera.angle + temp_width = width * Camera.zoom + temp_height = height * Camera.zoom + draw(x: temp_x, y: temp_y, + width: temp_width, + height: temp_height, + rotate: temp_rotate, + color: [color.r, color.g, color.b, color.a]) end - def initialize(path, opts= {}) + def initialize(path, opts = {}) super(path, opts) Ruby2D::Camera << self Window.remove(self) end - def remove - @hide = true - end - def add - @hide = false - end + def remove + @hide = true + end + + def add + @hide = false + end end end diff --git a/lib/ruby2d/camera/line.rb b/lib/ruby2d/camera/line.rb index 9113b92..f6d8f03 100644 --- a/lib/ruby2d/camera/line.rb +++ b/lib/ruby2d/camera/line.rb @@ -9,6 +9,7 @@ module Ruby2D # Use after changing variables def _draw return if @hide + angle = Camera.angle * (Math::PI / 180) half_width = Window.width * 0.5 half_height = Window.height * 0.5 @@ -18,22 +19,23 @@ module Ruby2D temp_y2 = (((x + @x2 - Camera.x) * Math.sin(angle)) + ((y + @y2 - Camera.y) * Math.cos(angle))) * Camera.zoom + half_height temp_width = width * Camera.zoom Ruby2D::Line.draw(x1: temp_x1, y1: temp_y1, - x2: temp_x2, y2: temp_y2, - width: temp_width, - color: [ - [self.color.r, self.color.g, self.color.b, self.color.a], - [self.color.r, self.color.g, self.color.b, self.color.a], - [self.color.r, self.color.g, self.color.b, self.color.a], - [self.color.r, self.color.g, self.color.b, self.color.a] - ], - z: self.z) + x2: temp_x2, y2: temp_y2, + width: temp_width, + color: [ + [color.r, color.g, color.b, color.a], + [color.r, color.g, color.b, color.a], + [color.r, color.g, color.b, color.a], + [color.r, color.g, color.b, color.a] + ], + z: z) end - def initialize(opts= {}) + def initialize(opts = {}) super(opts) Ruby2D::Camera << self Window.remove(self) end + def remove @hide = true end @@ -42,22 +44,16 @@ module Ruby2D @hide = false end - #Methods for moving the shape + # Methods for moving the shape def x @x ||= 0 end - def x=(x) - @x = x - end + attr_writer :x, :y def y @y ||= 0 end - - def y=(y) - @y = y - end end end end diff --git a/lib/ruby2d/camera/quad.rb b/lib/ruby2d/camera/quad.rb index 92d858a..5b778b9 100644 --- a/lib/ruby2d/camera/quad.rb +++ b/lib/ruby2d/camera/quad.rb @@ -9,6 +9,7 @@ module Ruby2D # Use after changing variables def _draw return if @hide + angle = Camera.angle * (Math::PI / 180) half_width = Window.width * 0.5 half_height = Window.height * 0.5 @@ -25,20 +26,20 @@ module Ruby2D x3: temp_x3, y3: temp_y3, x4: temp_x4, y4: temp_y4, color: [ - [self.c1.r, self.c1.g, self.c1.b, self.c1.a], - [self.c2.r, self.c2.g, self.c2.b, self.c2.a], - [self.c3.r, self.c3.g, self.c3.b, self.c3.a], - [self.c4.r, self.c4.g, self.c4.b, self.c4.a] + [c1.r, c1.g, c1.b, c1.a], + [c2.r, c2.g, c2.b, c2.a], + [c3.r, c3.g, c3.b, c3.a], + [c4.r, c4.g, c4.b, c4.a] ], - z: self.z - ) + z: z) end - def initialize(opts= {}) + def initialize(opts = {}) super(opts) Ruby2D::Camera << self Window.remove(self) end + def remove @hide = true end @@ -47,23 +48,16 @@ module Ruby2D @hide = false end - - #Methods for moving the shape + # Methods for moving the shape def x @x ||= 0 end - def x=(x) - @x = x - end + attr_writer :x, :y def y @y ||= 0 end - - def y=(y) - @y = y - end end end end diff --git a/lib/ruby2d/camera/rectangle.rb b/lib/ruby2d/camera/rectangle.rb index 2a3667d..4d06eec 100644 --- a/lib/ruby2d/camera/rectangle.rb +++ b/lib/ruby2d/camera/rectangle.rb @@ -9,6 +9,7 @@ module Ruby2D # Use after changing variables def _draw return if @hide + angle = Camera.angle * (Math::PI / 180) half_width = Window.width * 0.5 half_height = Window.height * 0.5 @@ -25,16 +26,15 @@ module Ruby2D x3: temp_x3, y3: temp_y3, x4: temp_x4, y4: temp_y4, color: [ - [self.c1.r, self.c1.g, self.c1.b, self.c1.a], - [self.c2.r, self.c2.g, self.c2.b, self.c2.a], - [self.c3.r, self.c3.g, self.c3.b, self.c3.a], - [self.c4.r, self.c4.g, self.c4.b, self.c4.a] + [c1.r, c1.g, c1.b, c1.a], + [c2.r, c2.g, c2.b, c2.a], + [c3.r, c3.g, c3.b, c3.a], + [c4.r, c4.g, c4.b, c4.a] ], - z: self.z - ) + z: z) end - def initialize(opts= {}) + def initialize(opts = {}) super(opts) Ruby2D::Camera << self Window.remove(self) @@ -47,6 +47,7 @@ module Ruby2D @y3 -= @y @y4 -= @y end + def remove @hide = true end @@ -54,22 +55,17 @@ module Ruby2D def add @hide = false end - #Methods for moving the shape + + # Methods for moving the shape def x @x ||= 0 end - def x=(x) - @x = x - end + attr_writer :x, :y def y @y ||= 0 end - - def y=(y) - @y = y - end end end end diff --git a/lib/ruby2d/camera/sprite.rb b/lib/ruby2d/camera/sprite.rb index 0d239a1..a1fb7b8 100644 --- a/lib/ruby2d/camera/sprite.rb +++ b/lib/ruby2d/camera/sprite.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Ruby2D module Camera # Wraps existing variables as well as adding new methods @@ -8,6 +9,7 @@ module Ruby2D # Use after changing variables def _draw return if @hide + angle = Camera.angle * (Math::PI / 180) half_width = Window.width * 0.5 half_height = Window.height * 0.5 @@ -22,26 +24,26 @@ module Ruby2D temp_height = height * Camera.zoom case @flip when :both - temp_x = temp_x + temp_height - temp_y = temp_y + temp_width + temp_x += temp_height + temp_y += temp_width temp_width = -temp_width temp_height = -temp_height puts 'both' when :horizontal - temp_y = temp_y + temp_width + temp_y += temp_width temp_height = -temp_height when :vertical temp_width = -temp_width - temp_x = temp_x + temp_height + temp_x += temp_height end - self.draw(x: temp_x, y: temp_y, - width: temp_width, - height: temp_height, - rotate: temp_rotate) - self.update + draw(x: temp_x, y: temp_y, + width: temp_width, + height: temp_height, + rotate: temp_rotate) + update end - def initialize(path, opts= {}) + def initialize(path, opts = {}) super(path, opts) Ruby2D::Camera << self Window.remove(self) diff --git a/lib/ruby2d/camera/square.rb b/lib/ruby2d/camera/square.rb index 584af03..75e1e83 100644 --- a/lib/ruby2d/camera/square.rb +++ b/lib/ruby2d/camera/square.rb @@ -9,6 +9,7 @@ module Ruby2D # Use after changing variables def _draw return if @hide + angle = Camera.angle * (Math::PI / 180) half_width = Window.width * 0.5 half_height = Window.height * 0.5 @@ -25,16 +26,15 @@ module Ruby2D x3: temp_x3, y3: temp_y3, x4: temp_x4, y4: temp_y4, color: [ - [self.c1.r, self.c1.g, self.c1.b, self.c1.a], - [self.c2.r, self.c2.g, self.c2.b, self.c2.a], - [self.c3.r, self.c3.g, self.c3.b, self.c3.a], - [self.c4.r, self.c4.g, self.c4.b, self.c4.a] + [c1.r, c1.g, c1.b, c1.a], + [c2.r, c2.g, c2.b, c2.a], + [c3.r, c3.g, c3.b, c3.a], + [c4.r, c4.g, c4.b, c4.a] ], - z: self.z - ) + z: z) end - def initialize(opts= {}) + def initialize(opts = {}) super(opts) Ruby2D::Camera << self Window.remove(self) @@ -55,24 +55,17 @@ module Ruby2D def add @hide = false end - #Methods for moving the shape + + # Methods for moving the shape def x @x ||= 0 end - def x=(x) - @x = x - end + attr_writer :x, :y def y @y ||= 0 end - - def y=(y) - @y = y - end - end end end - diff --git a/lib/ruby2d/camera/text.rb b/lib/ruby2d/camera/text.rb index 6966a86..00f15b3 100644 --- a/lib/ruby2d/camera/text.rb +++ b/lib/ruby2d/camera/text.rb @@ -14,6 +14,7 @@ module Ruby2D # Use after changing variables def _draw return if @hide + angle = Camera.angle * (Math::PI / 180) half_width = Window.width * 0.5 half_height = Window.height * 0.5 @@ -31,19 +32,20 @@ module Ruby2D temp_rotate = rotate + Camera.angle # Workaround for resizing text # TODO: resizing doesnt work at all even with workaround - temp_size = size# * Camera.zoom + temp_size = size # * Camera.zoom self.size *= Camera.zoom - self.draw(x: temp_x, y: temp_y, - rotate: temp_rotate, - color: [self.color.r, self.color.g, self.color.b, self.color.a]) + draw(x: temp_x, y: temp_y, + rotate: temp_rotate, + color: [color.r, color.g, color.b, color.a]) self.size = temp_size end - def initialize(text, opts= {}) + def initialize(text, opts = {}) super(text, opts) Ruby2D::Camera << self Window.remove(self) end + def remove @hide = true end @@ -52,13 +54,7 @@ module Ruby2D @hide = false end - def center - @center - end - - def center=(center) - @center = center - end + attr_accessor :center end end end diff --git a/lib/ruby2d/camera/triangle.rb b/lib/ruby2d/camera/triangle.rb index 4065b62..b506fb4 100644 --- a/lib/ruby2d/camera/triangle.rb +++ b/lib/ruby2d/camera/triangle.rb @@ -7,6 +7,7 @@ module Ruby2D # Use after changing variables def _draw return if @hide + angle = Ruby2D::Camera.angle * (Math::PI / 180) half_width = Window.width * 0.5 half_height = Window.height * 0.5 @@ -20,19 +21,20 @@ module Ruby2D x2: temp_x2, y2: temp_y2, x3: temp_x3, y3: temp_y3, color: [ - [self.c1.r, self.c1.g, self.c1.b, self.c1.a], - [self.c2.r, self.c2.g, self.c2.b, self.c2.a], - [self.c3.r, self.c3.g, self.c3.b, self.c3.a] + [c1.r, c1.g, c1.b, c1.a], + [c2.r, c2.g, c2.b, c2.a], + [c3.r, c3.g, c3.b, c3.a] ], - z: self.z) + z: z) end - def initialize(opts= {}) + def initialize(opts = {}) super(opts) Ruby2D::Camera << self Window.remove(self) - self.add + add end + def remove @hide = true end @@ -41,23 +43,16 @@ module Ruby2D @hide = false end - #Methods for moving the shape + # Methods for moving the shape def x @x ||= 0 end - def x=(x) - @x = x - end + attr_writer :x, :y def y @y ||= 0 end - - def y=(y) - @y = y - end end end end - diff --git a/lib/ruby2d/camera/version.rb b/lib/ruby2d/camera/version.rb index a78e2f2..29ac7a8 100644 --- a/lib/ruby2d/camera/version.rb +++ b/lib/ruby2d/camera/version.rb @@ -2,6 +2,6 @@ module Ruby2d module Camera - VERSION = "0.1.0" + VERSION = '1.0.0' end end |
