summaryrefslogtreecommitdiffhomepage
path: root/camera.rb
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2021-01-29 00:31:00 -0500
committerrealtradam <[email protected]>2021-01-29 00:31:00 -0500
commitbee6e8aa782895acefc6b40b2559f4d618a9466d (patch)
tree8d842ce28317bc23bd3bd56a0df07bd27a2e54ff /camera.rb
parent7c87aec3da8f502bc5401264fc68dcefde25caf0 (diff)
downloadruby2d-camera-bee6e8aa782895acefc6b40b2559f4d618a9466d.tar.gz
ruby2d-camera-bee6e8aa782895acefc6b40b2559f4d618a9466d.zip
small progress
Diffstat (limited to 'camera.rb')
-rw-r--r--camera.rb34
1 files changed, 26 insertions, 8 deletions
diff --git a/camera.rb b/camera.rb
index c361806..8623e34 100644
--- a/camera.rb
+++ b/camera.rb
@@ -41,12 +41,15 @@ class Camera
@rotation_degrees ||= 0
end
- def self.rotate_degrees_by(degrees)
+ def self.rotate_by(degrees)
# offset rotation to world
- end
-
- def self.rotate_degree_to(degrees)
- # set rotation
+ objects.each do |object|
+ unless object.is_a?(Image) or object.is_a?(AnimatedSquare)
+ object.update(rotate: degrees)
+ end
+ end
+ self.rotation_degrees += degrees
+ self.rotation_degrees %= 360
end
def self.zoom_by(zoom)
@@ -69,8 +72,10 @@ class Camera
end
def self.follow(item)
- move_to(((item.true_center[0] + item.width / 2) - (Window.width / 2)) / elasticity,
- ((item.true_center[1] + item.height / 2) - (Window.height / 2)) / elasticity)
+ move_by(((item.x - camera_position_x - (Window.width / 2) / zoom_level) /
+ (elasticity / (zoom_level * zoom_level))),
+ ((item.y - camera_position_y - (Window.height / 2) / zoom_level) /
+ (elasticity / (zoom_level * zoom_level))))
end
def self.objects
@@ -102,8 +107,20 @@ class Camera
self.camera_position_x += x / zoom_level
self.camera_position_y += y / zoom_level
end
-
+# SOMETHING MESSED UP
+ # with the camera position thing
def self.move_to(x, y)
+ objects.each do |object|
+ if object.is_a?(Image) or object.is_a?(AnimatedSquare)
+ object.x -= object.x + x
+ object.y -= object.y + y
+ else
+ object.update(x: -Camera.camera_position_x + x, y: -Camera.camera_position_y + y)
+ end
+ end
+ self.camera_position_x = x / zoom_level
+ self.camera_position_y = y / zoom_level
+=begin
self.camera_position_x = x / zoom_level + camera_position[0]
self.camera_position_y = y / zoom_level + camera_position[1]
objects.each do |object|
@@ -114,5 +131,6 @@ class Camera
object.update(x: x, y: y)
end
end
+=end
end
end